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 | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 203 | |
| 204 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 205 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 206 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 207 | { |
| 208 | switch (width) { |
| 209 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 210 | return CHAN_WIDTH_20_NOHT; |
| 211 | case NL80211_CHAN_WIDTH_20: |
| 212 | return CHAN_WIDTH_20; |
| 213 | case NL80211_CHAN_WIDTH_40: |
| 214 | return CHAN_WIDTH_40; |
| 215 | case NL80211_CHAN_WIDTH_80: |
| 216 | return CHAN_WIDTH_80; |
| 217 | case NL80211_CHAN_WIDTH_80P80: |
| 218 | return CHAN_WIDTH_80P80; |
| 219 | case NL80211_CHAN_WIDTH_160: |
| 220 | return CHAN_WIDTH_160; |
| 221 | } |
| 222 | return CHAN_WIDTH_UNKNOWN; |
| 223 | } |
| 224 | |
| 225 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 226 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 227 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 228 | return nlmode == NL80211_IFTYPE_AP || |
| 229 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 233 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 234 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 235 | return nlmode == NL80211_IFTYPE_STATION || |
| 236 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 240 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 241 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 242 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 243 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 244 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 245 | |
| 246 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 247 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 248 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 249 | { |
| 250 | struct i802_bss *bss; |
| 251 | |
| 252 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 253 | if (bss->ifindex == ifindex) |
| 254 | return bss; |
| 255 | } |
| 256 | |
| 257 | return NULL; |
| 258 | } |
| 259 | |
| 260 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 261 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 262 | { |
| 263 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 264 | } |
| 265 | |
| 266 | |
| 267 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 268 | { |
| 269 | if (drv->associated) |
| 270 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 271 | drv->associated = 0; |
| 272 | os_memset(drv->bssid, 0, ETH_ALEN); |
| 273 | } |
| 274 | |
| 275 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 276 | /* nl80211 code */ |
| 277 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 278 | { |
| 279 | int *err = arg; |
| 280 | *err = 0; |
| 281 | return NL_STOP; |
| 282 | } |
| 283 | |
| 284 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 285 | { |
| 286 | int *ret = arg; |
| 287 | *ret = 0; |
| 288 | return NL_SKIP; |
| 289 | } |
| 290 | |
| 291 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 292 | void *arg) |
| 293 | { |
| 294 | int *ret = arg; |
| 295 | *ret = err->error; |
| 296 | return NL_SKIP; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 301 | { |
| 302 | return NL_OK; |
| 303 | } |
| 304 | |
| 305 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 306 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 307 | { |
| 308 | /* |
| 309 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 310 | * heap memory for unnecessarily long time. |
| 311 | */ |
| 312 | if (msg) { |
| 313 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 314 | void *data = nlmsg_data(hdr); |
| 315 | /* |
| 316 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 317 | * only libnl were to maintain a stable API.. Neither will work |
| 318 | * with all released versions, so just calculate the length |
| 319 | * here. |
| 320 | */ |
| 321 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 322 | |
| 323 | os_memset(data, 0, len); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 328 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 329 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 330 | int (*valid_handler)(struct nl_msg *, void *), |
| 331 | void *valid_data) |
| 332 | { |
| 333 | struct nl_cb *cb; |
| 334 | int err = -ENOMEM; |
| 335 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 336 | if (!msg) |
| 337 | return -ENOMEM; |
| 338 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 339 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 340 | if (!cb) |
| 341 | goto out; |
| 342 | |
| 343 | err = nl_send_auto_complete(nl_handle, msg); |
| 344 | if (err < 0) |
| 345 | goto out; |
| 346 | |
| 347 | err = 1; |
| 348 | |
| 349 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 350 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 351 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 352 | |
| 353 | if (valid_handler) |
| 354 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 355 | valid_handler, valid_data); |
| 356 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 357 | while (err > 0) { |
| 358 | int res = nl_recvmsgs(nl_handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 359 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 360 | wpa_printf(MSG_INFO, |
| 361 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 362 | __func__, res); |
| 363 | } |
| 364 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 365 | out: |
| 366 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 367 | if (!valid_handler && valid_data == (void *) -1) |
| 368 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 369 | nlmsg_free(msg); |
| 370 | return err; |
| 371 | } |
| 372 | |
| 373 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 374 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 375 | struct nl_msg *msg, |
| 376 | int (*valid_handler)(struct nl_msg *, void *), |
| 377 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 378 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 379 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 380 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | |
| 384 | struct family_data { |
| 385 | const char *group; |
| 386 | int id; |
| 387 | }; |
| 388 | |
| 389 | |
| 390 | static int family_handler(struct nl_msg *msg, void *arg) |
| 391 | { |
| 392 | struct family_data *res = arg; |
| 393 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 394 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 395 | struct nlattr *mcgrp; |
| 396 | int i; |
| 397 | |
| 398 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 399 | genlmsg_attrlen(gnlh, 0), NULL); |
| 400 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 401 | return NL_SKIP; |
| 402 | |
| 403 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 404 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 405 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 406 | nla_len(mcgrp), NULL); |
| 407 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 408 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 409 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 410 | res->group, |
| 411 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 412 | continue; |
| 413 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 414 | break; |
| 415 | }; |
| 416 | |
| 417 | return NL_SKIP; |
| 418 | } |
| 419 | |
| 420 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 421 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 422 | const char *family, const char *group) |
| 423 | { |
| 424 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 425 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | struct family_data res = { group, -ENOENT }; |
| 427 | |
| 428 | msg = nlmsg_alloc(); |
| 429 | if (!msg) |
| 430 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 431 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 432 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 433 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 434 | nlmsg_free(msg); |
| 435 | return -1; |
| 436 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 437 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 438 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 439 | if (ret == 0) |
| 440 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 441 | return ret; |
| 442 | } |
| 443 | |
| 444 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 445 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 446 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 447 | { |
| 448 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 449 | 0, flags, cmd, 0); |
| 450 | } |
| 451 | |
| 452 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 453 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 454 | { |
| 455 | if (bss->wdev_id_set) |
| 456 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 457 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 458 | } |
| 459 | |
| 460 | |
| 461 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 462 | { |
| 463 | struct nl_msg *msg; |
| 464 | |
| 465 | msg = nlmsg_alloc(); |
| 466 | if (!msg) |
| 467 | return NULL; |
| 468 | |
| 469 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 470 | nl80211_set_iface_id(msg, bss) < 0) { |
| 471 | nlmsg_free(msg); |
| 472 | return NULL; |
| 473 | } |
| 474 | |
| 475 | return msg; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | static struct nl_msg * |
| 480 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 481 | int flags, uint8_t cmd) |
| 482 | { |
| 483 | struct nl_msg *msg; |
| 484 | |
| 485 | msg = nlmsg_alloc(); |
| 486 | if (!msg) |
| 487 | return NULL; |
| 488 | |
| 489 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 490 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 491 | nlmsg_free(msg); |
| 492 | return NULL; |
| 493 | } |
| 494 | |
| 495 | return msg; |
| 496 | } |
| 497 | |
| 498 | |
| 499 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 500 | uint8_t cmd) |
| 501 | { |
| 502 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 503 | } |
| 504 | |
| 505 | |
| 506 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 507 | { |
| 508 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 509 | } |
| 510 | |
| 511 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 512 | struct wiphy_idx_data { |
| 513 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 514 | enum nl80211_iftype nlmode; |
| 515 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 516 | }; |
| 517 | |
| 518 | |
| 519 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 520 | { |
| 521 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 522 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 523 | struct wiphy_idx_data *info = arg; |
| 524 | |
| 525 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 526 | genlmsg_attrlen(gnlh, 0), NULL); |
| 527 | |
| 528 | if (tb[NL80211_ATTR_WIPHY]) |
| 529 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 530 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 531 | if (tb[NL80211_ATTR_IFTYPE]) |
| 532 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 533 | |
| 534 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 535 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 536 | ETH_ALEN); |
| 537 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 538 | return NL_SKIP; |
| 539 | } |
| 540 | |
| 541 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 542 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 543 | { |
| 544 | struct nl_msg *msg; |
| 545 | struct wiphy_idx_data data = { |
| 546 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 547 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 548 | }; |
| 549 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 550 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 551 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 552 | |
| 553 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 554 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 555 | return -1; |
| 556 | } |
| 557 | |
| 558 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 559 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 560 | { |
| 561 | struct nl_msg *msg; |
| 562 | struct wiphy_idx_data data = { |
| 563 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 564 | .macaddr = NULL, |
| 565 | }; |
| 566 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 567 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 568 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 569 | |
| 570 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 571 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 572 | return NL80211_IFTYPE_UNSPECIFIED; |
| 573 | } |
| 574 | |
| 575 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 576 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 577 | { |
| 578 | struct nl_msg *msg; |
| 579 | struct wiphy_idx_data data = { |
| 580 | .macaddr = bss->addr, |
| 581 | }; |
| 582 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 583 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 584 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 585 | |
| 586 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 587 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 588 | |
| 589 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 590 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 591 | struct nl80211_wiphy_data *w) |
| 592 | { |
| 593 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 594 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 595 | |
| 596 | msg = nlmsg_alloc(); |
| 597 | if (!msg) |
| 598 | return -1; |
| 599 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 600 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 601 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 602 | nlmsg_free(msg); |
| 603 | return -1; |
| 604 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 605 | |
| 606 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 607 | if (ret) { |
| 608 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 609 | "failed: ret=%d (%s)", |
| 610 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 611 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 612 | return ret; |
| 613 | } |
| 614 | |
| 615 | |
| 616 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 617 | { |
| 618 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 619 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 620 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 621 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 622 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 623 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 624 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 625 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 626 | __func__, res); |
| 627 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | |
| 631 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 632 | { |
| 633 | struct nl80211_wiphy_data *w = arg; |
| 634 | struct wpa_driver_nl80211_data *drv; |
| 635 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 636 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 637 | union wpa_event_data event; |
| 638 | |
| 639 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 640 | genlmsg_attrlen(gnlh, 0), NULL); |
| 641 | |
| 642 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 643 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 644 | gnlh->cmd); |
| 645 | return NL_SKIP; |
| 646 | } |
| 647 | |
| 648 | if (!tb[NL80211_ATTR_FRAME]) |
| 649 | return NL_SKIP; |
| 650 | |
| 651 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 652 | wiphy_list) { |
| 653 | os_memset(&event, 0, sizeof(event)); |
| 654 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 655 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 656 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 657 | } |
| 658 | |
| 659 | return NL_SKIP; |
| 660 | } |
| 661 | |
| 662 | |
| 663 | static struct nl80211_wiphy_data * |
| 664 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 665 | { |
| 666 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 667 | struct nl80211_wiphy_data *w; |
| 668 | int wiphy_idx, found = 0; |
| 669 | struct i802_bss *tmp_bss; |
| 670 | |
| 671 | if (bss->wiphy_data != NULL) |
| 672 | return bss->wiphy_data; |
| 673 | |
| 674 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 675 | |
| 676 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 677 | if (w->wiphy_idx == wiphy_idx) |
| 678 | goto add; |
| 679 | } |
| 680 | |
| 681 | /* alloc new one */ |
| 682 | w = os_zalloc(sizeof(*w)); |
| 683 | if (w == NULL) |
| 684 | return NULL; |
| 685 | w->wiphy_idx = wiphy_idx; |
| 686 | dl_list_init(&w->bsss); |
| 687 | dl_list_init(&w->drvs); |
| 688 | |
| 689 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 690 | if (!w->nl_cb) { |
| 691 | os_free(w); |
| 692 | return NULL; |
| 693 | } |
| 694 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); |
| 695 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, |
| 696 | w); |
| 697 | |
| 698 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 699 | "wiphy beacons"); |
| 700 | if (w->nl_beacons == NULL) { |
| 701 | os_free(w); |
| 702 | return NULL; |
| 703 | } |
| 704 | |
| 705 | if (nl80211_register_beacons(bss->drv, w)) { |
| 706 | nl_destroy_handles(&w->nl_beacons); |
| 707 | os_free(w); |
| 708 | return NULL; |
| 709 | } |
| 710 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 711 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 712 | |
| 713 | dl_list_add(&nl80211_wiphys, &w->list); |
| 714 | |
| 715 | add: |
| 716 | /* drv entry for this bss already there? */ |
| 717 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 718 | if (tmp_bss->drv == bss->drv) { |
| 719 | found = 1; |
| 720 | break; |
| 721 | } |
| 722 | } |
| 723 | /* if not add it */ |
| 724 | if (!found) |
| 725 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 726 | |
| 727 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 728 | bss->wiphy_data = w; |
| 729 | return w; |
| 730 | } |
| 731 | |
| 732 | |
| 733 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 734 | { |
| 735 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 736 | struct i802_bss *tmp_bss; |
| 737 | int found = 0; |
| 738 | |
| 739 | if (w == NULL) |
| 740 | return; |
| 741 | bss->wiphy_data = NULL; |
| 742 | dl_list_del(&bss->wiphy_list); |
| 743 | |
| 744 | /* still any for this drv present? */ |
| 745 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 746 | if (tmp_bss->drv == bss->drv) { |
| 747 | found = 1; |
| 748 | break; |
| 749 | } |
| 750 | } |
| 751 | /* if not remove it */ |
| 752 | if (!found) |
| 753 | dl_list_del(&bss->drv->wiphy_list); |
| 754 | |
| 755 | if (!dl_list_empty(&w->bsss)) |
| 756 | return; |
| 757 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 758 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 759 | |
| 760 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 761 | dl_list_del(&w->list); |
| 762 | os_free(w); |
| 763 | } |
| 764 | |
| 765 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 766 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 767 | { |
| 768 | struct i802_bss *bss = priv; |
| 769 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 770 | if (!drv->associated) |
| 771 | return -1; |
| 772 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | |
| 777 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 778 | { |
| 779 | struct i802_bss *bss = priv; |
| 780 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 781 | if (!drv->associated) |
| 782 | return -1; |
| 783 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 784 | return drv->ssid_len; |
| 785 | } |
| 786 | |
| 787 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 788 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 789 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 790 | { |
| 791 | union wpa_event_data event; |
| 792 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 793 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
| 794 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 795 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 796 | drv->first_bss->ifname); |
| 797 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 798 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 799 | if (!drv->if_removed) |
| 800 | return; |
| 801 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 802 | drv->first_bss->ifname); |
| 803 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 806 | os_memset(&event, 0, sizeof(event)); |
| 807 | os_strlcpy(event.interface_status.ifname, ifname, |
| 808 | sizeof(event.interface_status.ifname)); |
| 809 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
| 810 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 811 | } |
| 812 | |
| 813 | |
| 814 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 815 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 816 | { |
| 817 | union wpa_event_data event; |
| 818 | |
| 819 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
| 820 | if (drv->if_removed) { |
| 821 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 822 | ifname); |
| 823 | return; |
| 824 | } |
| 825 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 826 | ifname); |
| 827 | drv->if_removed = 1; |
| 828 | } else { |
| 829 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 830 | ifname); |
| 831 | } |
| 832 | |
| 833 | os_memset(&event, 0, sizeof(event)); |
| 834 | os_strlcpy(event.interface_status.ifname, ifname, |
| 835 | sizeof(event.interface_status.ifname)); |
| 836 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 837 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 838 | } |
| 839 | |
| 840 | |
| 841 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 842 | u8 *buf, size_t len) |
| 843 | { |
| 844 | int attrlen, rta_len; |
| 845 | struct rtattr *attr; |
| 846 | |
| 847 | attrlen = len; |
| 848 | attr = (struct rtattr *) buf; |
| 849 | |
| 850 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 851 | while (RTA_OK(attr, attrlen)) { |
| 852 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 853 | if (os_strcmp(((char *) attr) + rta_len, |
| 854 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 855 | return 1; |
| 856 | else |
| 857 | break; |
| 858 | } |
| 859 | attr = RTA_NEXT(attr, attrlen); |
| 860 | } |
| 861 | |
| 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | |
| 866 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 867 | int ifindex, u8 *buf, size_t len) |
| 868 | { |
| 869 | if (drv->ifindex == ifindex) |
| 870 | return 1; |
| 871 | |
| 872 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 873 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 874 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 875 | "interface"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 876 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 877 | return 1; |
| 878 | } |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 884 | static struct wpa_driver_nl80211_data * |
| 885 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) |
| 886 | { |
| 887 | struct wpa_driver_nl80211_data *drv; |
| 888 | dl_list_for_each(drv, &global->interfaces, |
| 889 | struct wpa_driver_nl80211_data, list) { |
| 890 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 891 | have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 892 | return drv; |
| 893 | } |
| 894 | return NULL; |
| 895 | } |
| 896 | |
| 897 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 898 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 899 | struct ifinfomsg *ifi, |
| 900 | u8 *buf, size_t len) |
| 901 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 902 | struct nl80211_global *global = ctx; |
| 903 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 904 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 905 | struct rtattr *attr; |
| 906 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 907 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 908 | char ifname[IFNAMSIZ + 1]; |
| 909 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 910 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 911 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 912 | if (!drv) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 913 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d", |
| 914 | ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 915 | return; |
| 916 | } |
| 917 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 918 | extra[0] = '\0'; |
| 919 | pos = extra; |
| 920 | end = pos + sizeof(extra); |
| 921 | ifname[0] = '\0'; |
| 922 | |
| 923 | attrlen = len; |
| 924 | attr = (struct rtattr *) buf; |
| 925 | while (RTA_OK(attr, attrlen)) { |
| 926 | switch (attr->rta_type) { |
| 927 | case IFLA_IFNAME: |
| 928 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 929 | break; |
| 930 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 931 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 932 | break; |
| 933 | case IFLA_MASTER: |
| 934 | brid = nla_get_u32((struct nlattr *) attr); |
| 935 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 936 | break; |
| 937 | case IFLA_WIRELESS: |
| 938 | pos += os_snprintf(pos, end - pos, " wext"); |
| 939 | break; |
| 940 | case IFLA_OPERSTATE: |
| 941 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 942 | nla_get_u32((struct nlattr *) attr)); |
| 943 | break; |
| 944 | case IFLA_LINKMODE: |
| 945 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 946 | nla_get_u32((struct nlattr *) attr)); |
| 947 | break; |
| 948 | } |
| 949 | attr = RTA_NEXT(attr, attrlen); |
| 950 | } |
| 951 | extra[sizeof(extra) - 1] = '\0'; |
| 952 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 953 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 954 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 955 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 956 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 957 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 958 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 959 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 960 | |
| 961 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 962 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 963 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 964 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 965 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 966 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 967 | drv->ignore_if_down_event = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 968 | return; |
| 969 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 970 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 971 | namebuf, ifname); |
| 972 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 973 | wpa_printf(MSG_DEBUG, |
| 974 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 975 | drv->first_bss->ifname); |
| 976 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 977 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 978 | "event generated by mode change"); |
| 979 | drv->ignore_if_down_event = 0; |
| 980 | } else { |
| 981 | drv->if_disabled = 1; |
| 982 | wpa_supplicant_event(drv->ctx, |
| 983 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 984 | |
| 985 | /* |
| 986 | * Try to get drv again, since it may be removed as |
| 987 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 988 | * dynamic interfaces |
| 989 | */ |
| 990 | drv = nl80211_find_drv(global, ifi->ifi_index, |
| 991 | buf, len); |
| 992 | if (!drv) |
| 993 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 994 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 998 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 999 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1000 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1001 | "event since interface %s is down", |
| 1002 | namebuf); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1003 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1004 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1005 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1006 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1007 | } else if (drv->if_removed) { |
| 1008 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1009 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1010 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1011 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1012 | struct i802_bss *bss; |
| 1013 | u8 addr[ETH_ALEN]; |
| 1014 | |
| 1015 | /* Re-read MAC address as it may have changed */ |
| 1016 | bss = get_bss_ifindex(drv, ifi->ifi_index); |
| 1017 | if (bss && |
| 1018 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1019 | bss->ifname, addr) < 0) { |
| 1020 | wpa_printf(MSG_DEBUG, |
| 1021 | "nl80211: %s: failed to re-read MAC address", |
| 1022 | bss->ifname); |
| 1023 | } else if (bss && |
| 1024 | os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1025 | wpa_printf(MSG_DEBUG, |
| 1026 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1027 | MACSTR " to " MACSTR, |
| 1028 | ifi->ifi_index, bss->ifname, |
| 1029 | MAC2STR(bss->addr), |
| 1030 | MAC2STR(addr)); |
| 1031 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 1032 | } |
| 1033 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1034 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
| 1035 | drv->if_disabled = 0; |
| 1036 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1037 | NULL); |
| 1038 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | /* |
| 1042 | * Some drivers send the association event before the operup event--in |
| 1043 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1044 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1045 | * IEEE 802.1X authentication |
| 1046 | */ |
| 1047 | if (drv->operstate == 1 && |
| 1048 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1049 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1050 | 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] | 1051 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1052 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1055 | if (ifname[0]) |
| 1056 | wpa_driver_nl80211_event_newlink(drv, ifname); |
| 1057 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1058 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1059 | struct i802_bss *bss; |
| 1060 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1061 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1062 | if (!if_indextoname(brid, namebuf)) { |
| 1063 | wpa_printf(MSG_DEBUG, |
| 1064 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1065 | brid); |
| 1066 | return; |
| 1067 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1068 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1069 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1070 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1071 | |
| 1072 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1073 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1074 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1075 | break; |
| 1076 | } |
| 1077 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1078 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1083 | struct ifinfomsg *ifi, |
| 1084 | u8 *buf, size_t len) |
| 1085 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1086 | struct nl80211_global *global = ctx; |
| 1087 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1088 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1089 | struct rtattr *attr; |
| 1090 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1091 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1092 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1093 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1094 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 1095 | if (!drv) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1096 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d", |
| 1097 | ifi->ifi_index); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1098 | return; |
| 1099 | } |
| 1100 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1101 | extra[0] = '\0'; |
| 1102 | pos = extra; |
| 1103 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1104 | ifname[0] = '\0'; |
| 1105 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1106 | attrlen = len; |
| 1107 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1108 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1109 | switch (attr->rta_type) { |
| 1110 | case IFLA_IFNAME: |
| 1111 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1112 | break; |
| 1113 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1114 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1115 | break; |
| 1116 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1117 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1118 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1119 | break; |
| 1120 | case IFLA_OPERSTATE: |
| 1121 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1122 | nla_get_u32((struct nlattr *) attr)); |
| 1123 | break; |
| 1124 | case IFLA_LINKMODE: |
| 1125 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1126 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1129 | attr = RTA_NEXT(attr, attrlen); |
| 1130 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1131 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1132 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1133 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1134 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1135 | ifi->ifi_flags, |
| 1136 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1137 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1138 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1139 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1140 | |
| 1141 | if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1142 | wpa_driver_nl80211_event_dellink(drv, ifname); |
| 1143 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1144 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
| 1145 | /* device has been removed from bridge */ |
| 1146 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1147 | |
| 1148 | if (!if_indextoname(brid, namebuf)) { |
| 1149 | wpa_printf(MSG_DEBUG, |
| 1150 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1151 | brid); |
| 1152 | } else { |
| 1153 | wpa_printf(MSG_DEBUG, |
| 1154 | "nl80211: Remove ifindex %u for bridge %s", |
| 1155 | brid, namebuf); |
| 1156 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1157 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1158 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1162 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1163 | { |
| 1164 | struct nl_msg *msg; |
| 1165 | int ret; |
| 1166 | struct nl80211_bss_info_arg arg; |
| 1167 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1168 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1169 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1170 | arg.drv = drv; |
| 1171 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1172 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1173 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1174 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1175 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1176 | "associated BSS from scan results: %u MHz", freq); |
| 1177 | if (freq) |
| 1178 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1179 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1180 | } |
| 1181 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1182 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1183 | return drv->assoc_freq; |
| 1184 | } |
| 1185 | |
| 1186 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1187 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1188 | { |
| 1189 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1190 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1191 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1192 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1193 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1194 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1195 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1196 | }; |
| 1197 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1198 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1199 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1200 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1201 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1202 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1203 | }; |
| 1204 | struct wpa_signal_info *sig_change = arg; |
| 1205 | |
| 1206 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1207 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1208 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1209 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1210 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1211 | return NL_SKIP; |
| 1212 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1213 | return NL_SKIP; |
| 1214 | |
| 1215 | sig_change->current_signal = |
| 1216 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1217 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1218 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1219 | sig_change->avg_signal = |
| 1220 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1221 | else |
| 1222 | sig_change->avg_signal = 0; |
| 1223 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1224 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1225 | sig_change->avg_beacon_signal = |
| 1226 | (s8) |
| 1227 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1228 | else |
| 1229 | sig_change->avg_beacon_signal = 0; |
| 1230 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1231 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1232 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1233 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1234 | rate_policy)) { |
| 1235 | sig_change->current_txrate = 0; |
| 1236 | } else { |
| 1237 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1238 | sig_change->current_txrate = |
| 1239 | nla_get_u16(rinfo[ |
| 1240 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | return NL_SKIP; |
| 1246 | } |
| 1247 | |
| 1248 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1249 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1250 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1251 | { |
| 1252 | struct nl_msg *msg; |
| 1253 | |
| 1254 | sig->current_signal = -9999; |
| 1255 | sig->current_txrate = 0; |
| 1256 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1257 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1258 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1259 | nlmsg_free(msg); |
| 1260 | return -ENOBUFS; |
| 1261 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1262 | |
| 1263 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | |
| 1267 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1268 | { |
| 1269 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1270 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1271 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1272 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1273 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1274 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1275 | }; |
| 1276 | struct wpa_signal_info *sig_change = arg; |
| 1277 | |
| 1278 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1279 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1280 | |
| 1281 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1282 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1283 | return NL_SKIP; |
| 1284 | } |
| 1285 | |
| 1286 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1287 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1288 | survey_policy)) { |
| 1289 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1290 | "attributes!"); |
| 1291 | return NL_SKIP; |
| 1292 | } |
| 1293 | |
| 1294 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1295 | return NL_SKIP; |
| 1296 | |
| 1297 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1298 | sig_change->frequency) |
| 1299 | return NL_SKIP; |
| 1300 | |
| 1301 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1302 | return NL_SKIP; |
| 1303 | |
| 1304 | sig_change->current_noise = |
| 1305 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1306 | |
| 1307 | return NL_SKIP; |
| 1308 | } |
| 1309 | |
| 1310 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1311 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1312 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1313 | { |
| 1314 | struct nl_msg *msg; |
| 1315 | |
| 1316 | sig_change->current_noise = 9999; |
| 1317 | sig_change->frequency = drv->assoc_freq; |
| 1318 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1319 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1320 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | |
| 1324 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1325 | void *handle) |
| 1326 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1327 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1328 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1329 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1330 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1331 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1332 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1333 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1334 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1335 | __func__, res); |
| 1336 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | /** |
| 1341 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1342 | * @priv: driver_nl80211 private data |
| 1343 | * @alpha2_arg: country to which to switch to |
| 1344 | * Returns: 0 on success, -1 on failure |
| 1345 | * |
| 1346 | * This asks nl80211 to set the regulatory domain for given |
| 1347 | * country ISO / IEC alpha2. |
| 1348 | */ |
| 1349 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1350 | { |
| 1351 | struct i802_bss *bss = priv; |
| 1352 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1353 | char alpha2[3]; |
| 1354 | struct nl_msg *msg; |
| 1355 | |
| 1356 | msg = nlmsg_alloc(); |
| 1357 | if (!msg) |
| 1358 | return -ENOMEM; |
| 1359 | |
| 1360 | alpha2[0] = alpha2_arg[0]; |
| 1361 | alpha2[1] = alpha2_arg[1]; |
| 1362 | alpha2[2] = '\0'; |
| 1363 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1364 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1365 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1366 | nlmsg_free(msg); |
| 1367 | return -EINVAL; |
| 1368 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1369 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1370 | return -EINVAL; |
| 1371 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1375 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1376 | { |
| 1377 | char *alpha2 = arg; |
| 1378 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1379 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1380 | |
| 1381 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1382 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1383 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1384 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1385 | return NL_SKIP; |
| 1386 | } |
| 1387 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1388 | return NL_SKIP; |
| 1389 | } |
| 1390 | |
| 1391 | |
| 1392 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1393 | { |
| 1394 | struct i802_bss *bss = priv; |
| 1395 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1396 | struct nl_msg *msg; |
| 1397 | int ret; |
| 1398 | |
| 1399 | msg = nlmsg_alloc(); |
| 1400 | if (!msg) |
| 1401 | return -ENOMEM; |
| 1402 | |
| 1403 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1404 | alpha2[0] = '\0'; |
| 1405 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1406 | if (!alpha2[0]) |
| 1407 | ret = -1; |
| 1408 | |
| 1409 | return ret; |
| 1410 | } |
| 1411 | |
| 1412 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1413 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | { |
| 1415 | int ret; |
| 1416 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1417 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1418 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1419 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1420 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1421 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1424 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1425 | if (global->nl == NULL) |
| 1426 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1427 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1428 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1429 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1430 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1431 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1432 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1435 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1436 | if (global->nl_event == NULL) |
| 1437 | goto err; |
| 1438 | |
| 1439 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1440 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1441 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1442 | if (ret < 0) { |
| 1443 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1444 | "membership for scan events: %d (%s)", |
| 1445 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1446 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1449 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1450 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1451 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1452 | if (ret < 0) { |
| 1453 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1454 | "membership for mlme events: %d (%s)", |
| 1455 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1456 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1459 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1460 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1461 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1462 | if (ret < 0) { |
| 1463 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1464 | "membership for regulatory events: %d (%s)", |
| 1465 | ret, strerror(-ret)); |
| 1466 | /* Continue without regulatory events */ |
| 1467 | } |
| 1468 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1469 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1470 | if (ret >= 0) |
| 1471 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1472 | if (ret < 0) { |
| 1473 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1474 | "membership for vendor events: %d (%s)", |
| 1475 | ret, strerror(-ret)); |
| 1476 | /* Continue without vendor events */ |
| 1477 | } |
| 1478 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1479 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1480 | no_seq_check, NULL); |
| 1481 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1482 | process_global_event, global); |
| 1483 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1484 | nl80211_register_eloop_read(&global->nl_event, |
| 1485 | wpa_driver_nl80211_event_receive, |
| 1486 | global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1487 | |
| 1488 | return 0; |
| 1489 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1490 | err: |
| 1491 | nl_destroy_handles(&global->nl_event); |
| 1492 | nl_destroy_handles(&global->nl); |
| 1493 | nl_cb_put(global->nl_cb); |
| 1494 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1495 | return -1; |
| 1496 | } |
| 1497 | |
| 1498 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1499 | static void nl80211_check_global(struct nl80211_global *global) |
| 1500 | { |
| 1501 | struct nl_handle *handle; |
| 1502 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1503 | int ret; |
| 1504 | unsigned int i; |
| 1505 | |
| 1506 | /* |
| 1507 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1508 | * and all registration having been cleared. |
| 1509 | */ |
| 1510 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1511 | ELOOP_SOCKET_INVALID); |
| 1512 | |
| 1513 | for (i = 0; groups[i]; i++) { |
| 1514 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1515 | if (ret >= 0) |
| 1516 | ret = nl_socket_add_membership(handle, ret); |
| 1517 | if (ret < 0) { |
| 1518 | wpa_printf(MSG_INFO, |
| 1519 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
| 1520 | groups[i], ret, strerror(-ret)); |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1526 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1527 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1528 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1529 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1530 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1531 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1532 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1533 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1534 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1535 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1536 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1537 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | |
| 1541 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1542 | { |
| 1543 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1544 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1545 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1546 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1547 | "after rfkill unblock"); |
| 1548 | return; |
| 1549 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1550 | |
| 1551 | if (is_p2p_net_interface(drv->nlmode)) |
| 1552 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1553 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1554 | /* |
| 1555 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1556 | * Device interface as enabled. |
| 1557 | */ |
| 1558 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1559 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1563 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1564 | void *eloop_ctx, |
| 1565 | void *handle) |
| 1566 | { |
| 1567 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1568 | u8 data[2048]; |
| 1569 | struct msghdr msg; |
| 1570 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1571 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1572 | struct cmsghdr *cmsg; |
| 1573 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1574 | union wpa_event_data event; |
| 1575 | |
| 1576 | memset(&msg, 0, sizeof(msg)); |
| 1577 | msg.msg_iov = &entry; |
| 1578 | msg.msg_iovlen = 1; |
| 1579 | entry.iov_base = data; |
| 1580 | entry.iov_len = sizeof(data); |
| 1581 | msg.msg_control = &control; |
| 1582 | msg.msg_controllen = sizeof(control); |
| 1583 | |
| 1584 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1585 | /* if error or not fitting 802.3 header, return */ |
| 1586 | if (res < 14) |
| 1587 | return; |
| 1588 | |
| 1589 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1590 | { |
| 1591 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1592 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1593 | int *ack; |
| 1594 | |
| 1595 | found_wifi = 1; |
| 1596 | ack = (void *)CMSG_DATA(cmsg); |
| 1597 | acked = *ack; |
| 1598 | } |
| 1599 | |
| 1600 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1601 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1602 | struct sock_extended_err *err = |
| 1603 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1604 | |
| 1605 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1606 | found_ee = 1; |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | if (!found_ee || !found_wifi) |
| 1611 | return; |
| 1612 | |
| 1613 | memset(&event, 0, sizeof(event)); |
| 1614 | event.eapol_tx_status.dst = data; |
| 1615 | event.eapol_tx_status.data = data + 14; |
| 1616 | event.eapol_tx_status.data_len = res - 14; |
| 1617 | event.eapol_tx_status.ack = acked; |
| 1618 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1619 | } |
| 1620 | |
| 1621 | |
| 1622 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1623 | { |
| 1624 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1625 | if (!bss->nl_cb) |
| 1626 | return -1; |
| 1627 | |
| 1628 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1629 | no_seq_check, NULL); |
| 1630 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1631 | process_bss_event, bss); |
| 1632 | |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
| 1636 | |
| 1637 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1638 | { |
| 1639 | nl_cb_put(bss->nl_cb); |
| 1640 | bss->nl_cb = NULL; |
| 1641 | } |
| 1642 | |
| 1643 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1644 | static void |
| 1645 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1646 | { |
| 1647 | struct rfkill_config *rcfg; |
| 1648 | |
| 1649 | if (drv->rfkill) |
| 1650 | return; |
| 1651 | |
| 1652 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1653 | if (!rcfg) |
| 1654 | return; |
| 1655 | |
| 1656 | rcfg->ctx = drv; |
| 1657 | |
| 1658 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1659 | * not associated with a netdev, so use the name of some other interface |
| 1660 | * sharing the same wiphy as the P2P Device interface. |
| 1661 | * |
| 1662 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1663 | * created and is created only once another wpa_s interface was added. |
| 1664 | */ |
| 1665 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1666 | struct nl80211_global *global = drv->global; |
| 1667 | struct wpa_driver_nl80211_data *tmp1; |
| 1668 | |
| 1669 | dl_list_for_each(tmp1, &global->interfaces, |
| 1670 | struct wpa_driver_nl80211_data, list) { |
| 1671 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1672 | !tmp1->rfkill) |
| 1673 | continue; |
| 1674 | |
| 1675 | wpa_printf(MSG_DEBUG, |
| 1676 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1677 | tmp1->first_bss->ifname); |
| 1678 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1679 | sizeof(rcfg->ifname)); |
| 1680 | break; |
| 1681 | } |
| 1682 | } else { |
| 1683 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1684 | sizeof(rcfg->ifname)); |
| 1685 | } |
| 1686 | |
| 1687 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1688 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1689 | drv->rfkill = rfkill_init(rcfg); |
| 1690 | if (!drv->rfkill) { |
| 1691 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1692 | os_free(rcfg); |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1697 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1698 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1699 | const u8 *set_addr, |
| 1700 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1701 | { |
| 1702 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1703 | struct i802_bss *bss; |
| 1704 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1705 | if (global_priv == NULL) |
| 1706 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1707 | drv = os_zalloc(sizeof(*drv)); |
| 1708 | if (drv == NULL) |
| 1709 | return NULL; |
| 1710 | drv->global = global_priv; |
| 1711 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1712 | drv->hostapd = !!hostapd; |
| 1713 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1714 | |
| 1715 | /* |
| 1716 | * There is no driver capability flag for this, so assume it is |
| 1717 | * supported and disable this on first attempt to use if the driver |
| 1718 | * rejects the command due to missing support. |
| 1719 | */ |
| 1720 | drv->set_rekey_offload = 1; |
| 1721 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1722 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1723 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1724 | drv->if_indices_reason = drv->default_if_indices_reason; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1725 | |
| 1726 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1727 | if (!drv->first_bss) { |
| 1728 | os_free(drv); |
| 1729 | return NULL; |
| 1730 | } |
| 1731 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1732 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1733 | bss->ctx = ctx; |
| 1734 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1735 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1736 | drv->monitor_ifidx = -1; |
| 1737 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1738 | drv->eapol_tx_sock = -1; |
| 1739 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1740 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1741 | if (nl80211_init_bss(bss)) |
| 1742 | goto failed; |
| 1743 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1744 | 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] | 1745 | goto failed; |
| 1746 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1747 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1748 | if (drv->eapol_tx_sock < 0) |
| 1749 | goto failed; |
| 1750 | |
| 1751 | if (drv->data_tx_status) { |
| 1752 | int enabled = 1; |
| 1753 | |
| 1754 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1755 | &enabled, sizeof(enabled)) < 0) { |
| 1756 | wpa_printf(MSG_DEBUG, |
| 1757 | "nl80211: wifi status sockopt failed\n"); |
| 1758 | drv->data_tx_status = 0; |
| 1759 | if (!drv->use_monitor) |
| 1760 | drv->capa.flags &= |
| 1761 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1762 | } else { |
| 1763 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1764 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1765 | drv, NULL); |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1770 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1771 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1772 | drv->in_interface_list = 1; |
| 1773 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1774 | |
| 1775 | return bss; |
| 1776 | |
| 1777 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1778 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1779 | return NULL; |
| 1780 | } |
| 1781 | |
| 1782 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1783 | /** |
| 1784 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1785 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1786 | * e.g., wpa_supplicant_event() |
| 1787 | * @ifname: interface name, e.g., wlan0 |
| 1788 | * @global_priv: private driver global data from global_init() |
| 1789 | * Returns: Pointer to private data, %NULL on failure |
| 1790 | */ |
| 1791 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1792 | void *global_priv) |
| 1793 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1794 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1795 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1799 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1800 | struct nl_handle *nl_handle, |
| 1801 | u16 type, const u8 *match, size_t match_len) |
| 1802 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1803 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1804 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1805 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1806 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1807 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1808 | buf[0] = '\0'; |
| 1809 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1810 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1811 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1812 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1813 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1814 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1815 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1816 | nlmsg_free(msg); |
| 1817 | return -1; |
| 1818 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1819 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1820 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1821 | if (ret) { |
| 1822 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1823 | "failed (type=%u): ret=%d (%s)", |
| 1824 | type, ret, strerror(-ret)); |
| 1825 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1826 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1827 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1828 | return ret; |
| 1829 | } |
| 1830 | |
| 1831 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1832 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1833 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1834 | if (bss->nl_mgmt) { |
| 1835 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1836 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 1837 | return -1; |
| 1838 | } |
| 1839 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1840 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1841 | if (bss->nl_mgmt == NULL) |
| 1842 | return -1; |
| 1843 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1844 | return 0; |
| 1845 | } |
| 1846 | |
| 1847 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1848 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 1849 | { |
| 1850 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 1851 | wpa_driver_nl80211_event_receive, |
| 1852 | bss->nl_cb); |
| 1853 | } |
| 1854 | |
| 1855 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1856 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1857 | const u8 *match, size_t match_len) |
| 1858 | { |
| 1859 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1860 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1861 | type, match, match_len); |
| 1862 | } |
| 1863 | |
| 1864 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1865 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1866 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1867 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1868 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1869 | |
| 1870 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1871 | return -1; |
| 1872 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 1873 | "handle %p", bss->nl_mgmt); |
| 1874 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1875 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 1876 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 1877 | |
| 1878 | /* register for any AUTH message */ |
| 1879 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 1880 | } |
| 1881 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1882 | #ifdef CONFIG_INTERWORKING |
| 1883 | /* QoS Map Configure */ |
| 1884 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1885 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1886 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1887 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1888 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1889 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1890 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1891 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1892 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1893 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1894 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1895 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1896 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1897 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1898 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1899 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1900 | /* Protected GAS Initial Request */ |
| 1901 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 1902 | ret = -1; |
| 1903 | /* Protected GAS Initial Response */ |
| 1904 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 1905 | ret = -1; |
| 1906 | /* Protected GAS Comeback Request */ |
| 1907 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 1908 | ret = -1; |
| 1909 | /* Protected GAS Comeback Response */ |
| 1910 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 1911 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1912 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 1913 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1914 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1915 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1916 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 1917 | 6) < 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 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1920 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1921 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 1922 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1923 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1924 | #endif /* CONFIG_P2P */ |
| 1925 | #ifdef CONFIG_IEEE80211W |
| 1926 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1927 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1928 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1929 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1930 | #ifdef CONFIG_TDLS |
| 1931 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 1932 | /* TDLS Discovery Response */ |
| 1933 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 1934 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1935 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1936 | } |
| 1937 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1938 | #ifdef CONFIG_FST |
| 1939 | /* FST Action frames */ |
| 1940 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 1941 | ret = -1; |
| 1942 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1943 | |
| 1944 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1945 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1946 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1947 | else |
| 1948 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 1949 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 1950 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1951 | /* WNM - BSS Transition Management Request */ |
| 1952 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1953 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1954 | /* WNM-Sleep Mode Response */ |
| 1955 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1956 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1957 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1958 | #ifdef CONFIG_HS20 |
| 1959 | /* WNM-Notification */ |
| 1960 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1961 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1962 | #endif /* CONFIG_HS20 */ |
| 1963 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1964 | /* WMM-AC ADDTS Response */ |
| 1965 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 1966 | ret = -1; |
| 1967 | |
| 1968 | /* WMM-AC DELTS */ |
| 1969 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 1970 | ret = -1; |
| 1971 | |
| 1972 | /* Radio Measurement - Neighbor Report Response */ |
| 1973 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 1974 | ret = -1; |
| 1975 | |
| 1976 | /* Radio Measurement - Link Measurement Request */ |
| 1977 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 1978 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 1979 | ret = -1; |
| 1980 | |
| 1981 | nl80211_mgmt_handle_register_eloop(bss); |
| 1982 | |
| 1983 | return ret; |
| 1984 | } |
| 1985 | |
| 1986 | |
| 1987 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 1988 | { |
| 1989 | int ret = 0; |
| 1990 | |
| 1991 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1992 | return -1; |
| 1993 | |
| 1994 | wpa_printf(MSG_DEBUG, |
| 1995 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 1996 | bss->nl_mgmt); |
| 1997 | |
| 1998 | /* Auth frames for mesh SAE */ |
| 1999 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2000 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2001 | (WLAN_FC_STYPE_AUTH << 4), |
| 2002 | NULL, 0) < 0) |
| 2003 | ret = -1; |
| 2004 | |
| 2005 | /* Mesh peering open */ |
| 2006 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2007 | ret = -1; |
| 2008 | /* Mesh peering confirm */ |
| 2009 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2010 | ret = -1; |
| 2011 | /* Mesh peering close */ |
| 2012 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2013 | ret = -1; |
| 2014 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2015 | nl80211_mgmt_handle_register_eloop(bss); |
| 2016 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2017 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2021 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2022 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2023 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2024 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2025 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2026 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2027 | 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] | 2028 | if (ret) { |
| 2029 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2030 | "failed: ret=%d (%s)", |
| 2031 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2032 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2033 | return ret; |
| 2034 | } |
| 2035 | |
| 2036 | |
| 2037 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2038 | { |
| 2039 | static const int stypes[] = { |
| 2040 | WLAN_FC_STYPE_AUTH, |
| 2041 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2042 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2043 | WLAN_FC_STYPE_DISASSOC, |
| 2044 | WLAN_FC_STYPE_DEAUTH, |
| 2045 | WLAN_FC_STYPE_ACTION, |
| 2046 | WLAN_FC_STYPE_PROBE_REQ, |
| 2047 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2048 | * it, but it wouldn't really be the right thing anyway as |
| 2049 | * it isn't per interface ... maybe just dump the scan |
| 2050 | * results periodically for OLBC? |
| 2051 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2052 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2053 | }; |
| 2054 | unsigned int i; |
| 2055 | |
| 2056 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2057 | return -1; |
| 2058 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2059 | "handle %p", bss->nl_mgmt); |
| 2060 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2061 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2062 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2063 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2064 | (stypes[i] << 4), |
| 2065 | NULL, 0) < 0) { |
| 2066 | goto out_err; |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | if (nl80211_register_spurious_class3(bss)) |
| 2071 | goto out_err; |
| 2072 | |
| 2073 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 2074 | goto out_err; |
| 2075 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2076 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2077 | return 0; |
| 2078 | |
| 2079 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2080 | nl_destroy_handles(&bss->nl_mgmt); |
| 2081 | return -1; |
| 2082 | } |
| 2083 | |
| 2084 | |
| 2085 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2086 | { |
| 2087 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2088 | return -1; |
| 2089 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2090 | "handle %p (device SME)", bss->nl_mgmt); |
| 2091 | |
| 2092 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2093 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2094 | (WLAN_FC_STYPE_ACTION << 4), |
| 2095 | NULL, 0) < 0) |
| 2096 | goto out_err; |
| 2097 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2098 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2099 | return 0; |
| 2100 | |
| 2101 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2102 | nl_destroy_handles(&bss->nl_mgmt); |
| 2103 | return -1; |
| 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2108 | { |
| 2109 | if (bss->nl_mgmt == NULL) |
| 2110 | return; |
| 2111 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2112 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2113 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2114 | |
| 2115 | nl80211_put_wiphy_data_ap(bss); |
| 2116 | } |
| 2117 | |
| 2118 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2119 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2120 | { |
| 2121 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2122 | } |
| 2123 | |
| 2124 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2125 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2126 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2127 | struct nl_msg *msg; |
| 2128 | int ret; |
| 2129 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2130 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2131 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2132 | |
| 2133 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2134 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2135 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | |
| 2139 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2140 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2141 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2142 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2143 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2144 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2145 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2146 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2147 | |
| 2148 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2149 | start ? "Start" : "Stop", |
| 2150 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2151 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2152 | return ret; |
| 2153 | } |
| 2154 | |
| 2155 | |
| 2156 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2157 | { |
| 2158 | enum nl80211_iftype nlmode; |
| 2159 | |
| 2160 | nlmode = nl80211_get_ifmode(bss); |
| 2161 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2162 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2163 | bss->ifname, up); |
| 2164 | } |
| 2165 | |
| 2166 | /* P2P Device has start/stop which is equivalent */ |
| 2167 | return nl80211_set_p2pdev(bss, up); |
| 2168 | } |
| 2169 | |
| 2170 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2171 | #ifdef CONFIG_TESTING_OPTIONS |
| 2172 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2173 | { |
| 2174 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2175 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2176 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2177 | |
| 2178 | |
| 2179 | wpa_printf(MSG_DEBUG, |
| 2180 | "nl80211: QCA vendor test command response received"); |
| 2181 | |
| 2182 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2183 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2184 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2185 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2186 | return NL_SKIP; |
| 2187 | } |
| 2188 | |
| 2189 | wpa_hexdump(MSG_DEBUG, |
| 2190 | "nl80211: Received QCA vendor test command response", |
| 2191 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2192 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2193 | |
| 2194 | return NL_SKIP; |
| 2195 | } |
| 2196 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2197 | |
| 2198 | |
| 2199 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2200 | { |
| 2201 | #ifdef CONFIG_TESTING_OPTIONS |
| 2202 | struct nl_msg *msg; |
| 2203 | struct nlattr *params; |
| 2204 | int ret; |
| 2205 | |
| 2206 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2207 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2208 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2209 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2210 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2211 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2212 | nlmsg_free(msg); |
| 2213 | return; |
| 2214 | } |
| 2215 | nla_nest_end(msg, params); |
| 2216 | |
| 2217 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2218 | wpa_printf(MSG_DEBUG, |
| 2219 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2220 | ret, strerror(-ret)); |
| 2221 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2222 | } |
| 2223 | |
| 2224 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2225 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2226 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2227 | const u8 *set_addr, int first, |
| 2228 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2229 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2230 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2231 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2232 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2233 | |
| 2234 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2235 | bss->ifindex = drv->ifindex; |
| 2236 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2237 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2238 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2239 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2240 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2241 | drv->global->if_add_wdevid_set = 0; |
| 2242 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2243 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2244 | bss->static_ap = 1; |
| 2245 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2246 | if (first && |
| 2247 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2248 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2249 | drv->start_iface_up = 1; |
| 2250 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2251 | if (wpa_driver_nl80211_capa(drv)) |
| 2252 | return -1; |
| 2253 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2254 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2255 | return -1; |
| 2256 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2257 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2258 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2259 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2260 | if (set_addr && |
| 2261 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2262 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2263 | set_addr))) |
| 2264 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2265 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2266 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2267 | drv->start_mode_ap = 1; |
| 2268 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2269 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2270 | nlmode = NL80211_IFTYPE_AP; |
| 2271 | else if (bss->if_dynamic) |
| 2272 | nlmode = nl80211_get_ifmode(bss); |
| 2273 | else |
| 2274 | nlmode = NL80211_IFTYPE_STATION; |
| 2275 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2276 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2277 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2278 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2279 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2280 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2281 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2282 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2283 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2284 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2285 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2286 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2287 | int ret = i802_set_iface_flags(bss, 1); |
| 2288 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2289 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2290 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2291 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2292 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2293 | |
| 2294 | if (is_p2p_net_interface(nlmode)) |
| 2295 | nl80211_disable_11b_rates(bss->drv, |
| 2296 | bss->drv->ifindex, 1); |
| 2297 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2298 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2299 | return ret; |
| 2300 | } else { |
| 2301 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2302 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2303 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2304 | drv->if_disabled = 1; |
| 2305 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2306 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2309 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2310 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2311 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2312 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2313 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2314 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2315 | bss->addr)) |
| 2316 | return -1; |
| 2317 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2318 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2319 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2320 | if (send_rfkill_event) { |
| 2321 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2322 | drv, drv->ctx); |
| 2323 | } |
| 2324 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2325 | if (drv->vendor_cmd_test_avail) |
| 2326 | qca_vendor_test(drv); |
| 2327 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2328 | return 0; |
| 2329 | } |
| 2330 | |
| 2331 | |
| 2332 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 2333 | { |
| 2334 | struct nl_msg *msg; |
| 2335 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2336 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2337 | drv->ifindex); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2338 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2339 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | |
| 2343 | /** |
| 2344 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2345 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2346 | * |
| 2347 | * Shut down driver interface and processing of driver events. Free |
| 2348 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2349 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2350 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2351 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2352 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2353 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2354 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2355 | bss->ifname, drv->disabled_11b_rates); |
| 2356 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2357 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2358 | if (drv->data_tx_status) |
| 2359 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2360 | if (drv->eapol_tx_sock >= 0) |
| 2361 | close(drv->eapol_tx_sock); |
| 2362 | |
| 2363 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2364 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2365 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2366 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2367 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2368 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2369 | "interface %s from bridge %s: %s", |
| 2370 | bss->ifname, bss->brname, strerror(errno)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2371 | if (drv->rtnl_sk) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2372 | nl80211_handle_destroy(drv->rtnl_sk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2373 | } |
| 2374 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2375 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2376 | 0) < 0) |
| 2377 | wpa_printf(MSG_INFO, |
| 2378 | "nl80211: Could not set bridge %s down", |
| 2379 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2380 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2382 | "bridge %s: %s", |
| 2383 | bss->brname, strerror(errno)); |
| 2384 | } |
| 2385 | |
| 2386 | nl80211_remove_monitor_interface(drv); |
| 2387 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2388 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2389 | wpa_driver_nl80211_del_beacon(drv); |
| 2390 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2391 | if (drv->eapol_sock >= 0) { |
| 2392 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2393 | close(drv->eapol_sock); |
| 2394 | } |
| 2395 | |
| 2396 | if (drv->if_indices != drv->default_if_indices) |
| 2397 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2398 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2399 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 2400 | os_free(drv->if_indices_reason); |
| 2401 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2402 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2403 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2404 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2405 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2406 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2407 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2408 | rfkill_deinit(drv->rfkill); |
| 2409 | |
| 2410 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2411 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2412 | if (!drv->start_iface_up) |
| 2413 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2414 | |
| 2415 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2416 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2417 | 0) < 0) { |
| 2418 | wpa_printf(MSG_DEBUG, |
| 2419 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2420 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2421 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2422 | drv->perm_addr) < 0) { |
| 2423 | wpa_printf(MSG_DEBUG, |
| 2424 | "nl80211: Could not restore permanent MAC address"); |
| 2425 | } |
| 2426 | } |
| 2427 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2428 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2429 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2430 | wpa_driver_nl80211_set_mode(bss, |
| 2431 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2432 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2433 | } else { |
| 2434 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2435 | nl80211_del_p2pdev(bss); |
| 2436 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2437 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2438 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2439 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2440 | os_free(drv->filter_ssids); |
| 2441 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2442 | os_free(drv->auth_ie); |
| 2443 | |
| 2444 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2445 | dl_list_del(&drv->list); |
| 2446 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2447 | os_free(drv->extended_capa); |
| 2448 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2449 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2450 | os_free(drv); |
| 2451 | } |
| 2452 | |
| 2453 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2454 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2455 | { |
| 2456 | switch (alg) { |
| 2457 | case WPA_ALG_WEP: |
| 2458 | if (key_len == 5) |
| 2459 | return WLAN_CIPHER_SUITE_WEP40; |
| 2460 | return WLAN_CIPHER_SUITE_WEP104; |
| 2461 | case WPA_ALG_TKIP: |
| 2462 | return WLAN_CIPHER_SUITE_TKIP; |
| 2463 | case WPA_ALG_CCMP: |
| 2464 | return WLAN_CIPHER_SUITE_CCMP; |
| 2465 | case WPA_ALG_GCMP: |
| 2466 | return WLAN_CIPHER_SUITE_GCMP; |
| 2467 | case WPA_ALG_CCMP_256: |
| 2468 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2469 | case WPA_ALG_GCMP_256: |
| 2470 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2471 | case WPA_ALG_IGTK: |
| 2472 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 2473 | case WPA_ALG_BIP_GMAC_128: |
| 2474 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 2475 | case WPA_ALG_BIP_GMAC_256: |
| 2476 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 2477 | case WPA_ALG_BIP_CMAC_256: |
| 2478 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 2479 | case WPA_ALG_SMS4: |
| 2480 | return WLAN_CIPHER_SUITE_SMS4; |
| 2481 | case WPA_ALG_KRK: |
| 2482 | return WLAN_CIPHER_SUITE_KRK; |
| 2483 | case WPA_ALG_NONE: |
| 2484 | case WPA_ALG_PMK: |
| 2485 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2486 | alg); |
| 2487 | return 0; |
| 2488 | } |
| 2489 | |
| 2490 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2491 | alg); |
| 2492 | return 0; |
| 2493 | } |
| 2494 | |
| 2495 | |
| 2496 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2497 | { |
| 2498 | switch (cipher) { |
| 2499 | case WPA_CIPHER_CCMP_256: |
| 2500 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2501 | case WPA_CIPHER_GCMP_256: |
| 2502 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2503 | case WPA_CIPHER_CCMP: |
| 2504 | return WLAN_CIPHER_SUITE_CCMP; |
| 2505 | case WPA_CIPHER_GCMP: |
| 2506 | return WLAN_CIPHER_SUITE_GCMP; |
| 2507 | case WPA_CIPHER_TKIP: |
| 2508 | return WLAN_CIPHER_SUITE_TKIP; |
| 2509 | case WPA_CIPHER_WEP104: |
| 2510 | return WLAN_CIPHER_SUITE_WEP104; |
| 2511 | case WPA_CIPHER_WEP40: |
| 2512 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2513 | case WPA_CIPHER_GTK_NOT_USED: |
| 2514 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | return 0; |
| 2518 | } |
| 2519 | |
| 2520 | |
| 2521 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2522 | int max_suites) |
| 2523 | { |
| 2524 | int num_suites = 0; |
| 2525 | |
| 2526 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 2527 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 2528 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 2529 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 2530 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 2531 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 2532 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 2533 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 2534 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 2535 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 2536 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 2537 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 2538 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 2539 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 2540 | |
| 2541 | return num_suites; |
| 2542 | } |
| 2543 | |
| 2544 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2545 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2546 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2547 | const u8 *key, size_t key_len) |
| 2548 | { |
| 2549 | struct nl_msg *msg; |
| 2550 | int ret; |
| 2551 | |
| 2552 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2553 | return 0; |
| 2554 | |
| 2555 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2556 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2557 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2558 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2559 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2560 | nl80211_nlmsg_clear(msg); |
| 2561 | nlmsg_free(msg); |
| 2562 | return -1; |
| 2563 | } |
| 2564 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2565 | if (ret) { |
| 2566 | wpa_printf(MSG_DEBUG, |
| 2567 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2568 | ret, strerror(-ret)); |
| 2569 | } |
| 2570 | |
| 2571 | return ret; |
| 2572 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2573 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2574 | |
| 2575 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2576 | 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] | 2577 | enum wpa_alg alg, const u8 *addr, |
| 2578 | int key_idx, int set_tx, |
| 2579 | const u8 *seq, size_t seq_len, |
| 2580 | const u8 *key, size_t key_len) |
| 2581 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2582 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2583 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2584 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2585 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2586 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2587 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2588 | /* Ignore for P2P Device */ |
| 2589 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2590 | return 0; |
| 2591 | |
| 2592 | ifindex = if_nametoindex(ifname); |
| 2593 | 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] | 2594 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2595 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2596 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2597 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2598 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2599 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2600 | tdls = 1; |
| 2601 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2602 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2603 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2604 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2605 | if (alg == WPA_ALG_PMK && |
| 2606 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2607 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2608 | __func__); |
| 2609 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2610 | return ret; |
| 2611 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2612 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2613 | |
| 2614 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2615 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2616 | if (!msg) |
| 2617 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2618 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2619 | u32 suite; |
| 2620 | |
| 2621 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2622 | if (!suite) |
| 2623 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2624 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2625 | if (!msg || |
| 2626 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2627 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2628 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2629 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2632 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2633 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2634 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2635 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2636 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2637 | |
| 2638 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2639 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2640 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2641 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2642 | |
| 2643 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2644 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2645 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2646 | NL80211_KEYTYPE_GROUP)) |
| 2647 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2648 | } |
| 2649 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2650 | struct nlattr *types; |
| 2651 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2652 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2653 | |
| 2654 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2655 | if (!types || |
| 2656 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2657 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2658 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2659 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2660 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2661 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2662 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2663 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2664 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2665 | ret = 0; |
| 2666 | if (ret) |
| 2667 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2668 | ret, strerror(-ret)); |
| 2669 | |
| 2670 | /* |
| 2671 | * If we failed or don't need to set the default TX key (below), |
| 2672 | * we're done here. |
| 2673 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2674 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2675 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2676 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2677 | !is_broadcast_ether_addr(addr)) |
| 2678 | return ret; |
| 2679 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2680 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2681 | if (!msg || |
| 2682 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2683 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2684 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2685 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2686 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2687 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2688 | NL80211_ATTR_KEY_DEFAULT)) |
| 2689 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2690 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2691 | struct nlattr *types; |
| 2692 | |
| 2693 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2694 | if (!types || |
| 2695 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2696 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2697 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2698 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2699 | struct nlattr *types; |
| 2700 | |
| 2701 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2702 | if (!types || |
| 2703 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2704 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2705 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2709 | if (ret == -ENOENT) |
| 2710 | ret = 0; |
| 2711 | if (ret) |
| 2712 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2713 | "err=%d %s)", ret, strerror(-ret)); |
| 2714 | return ret; |
| 2715 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2716 | fail: |
| 2717 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2718 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2719 | return -ENOBUFS; |
| 2720 | } |
| 2721 | |
| 2722 | |
| 2723 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 2724 | int key_idx, int defkey, |
| 2725 | const u8 *seq, size_t seq_len, |
| 2726 | const u8 *key, size_t key_len) |
| 2727 | { |
| 2728 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2729 | u32 suite; |
| 2730 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2731 | if (!key_attr) |
| 2732 | return -1; |
| 2733 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2734 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2735 | if (!suite) |
| 2736 | return -1; |
| 2737 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2738 | if (defkey && alg == WPA_ALG_IGTK) { |
| 2739 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 2740 | return -1; |
| 2741 | } else if (defkey) { |
| 2742 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 2743 | return -1; |
| 2744 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2745 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2746 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2747 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2748 | (seq && seq_len && |
| 2749 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 2750 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 2751 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2752 | |
| 2753 | nla_nest_end(msg, key_attr); |
| 2754 | |
| 2755 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | |
| 2759 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 2760 | struct nl_msg *msg) |
| 2761 | { |
| 2762 | int i, privacy = 0; |
| 2763 | struct nlattr *nl_keys, *nl_key; |
| 2764 | |
| 2765 | for (i = 0; i < 4; i++) { |
| 2766 | if (!params->wep_key[i]) |
| 2767 | continue; |
| 2768 | privacy = 1; |
| 2769 | break; |
| 2770 | } |
| 2771 | if (params->wps == WPS_MODE_PRIVACY) |
| 2772 | privacy = 1; |
| 2773 | if (params->pairwise_suite && |
| 2774 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 2775 | privacy = 1; |
| 2776 | |
| 2777 | if (!privacy) |
| 2778 | return 0; |
| 2779 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2780 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 2781 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2782 | |
| 2783 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 2784 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2785 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2786 | |
| 2787 | for (i = 0; i < 4; i++) { |
| 2788 | if (!params->wep_key[i]) |
| 2789 | continue; |
| 2790 | |
| 2791 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2792 | if (!nl_key || |
| 2793 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 2794 | params->wep_key[i]) || |
| 2795 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2796 | params->wep_key_len[i] == 5 ? |
| 2797 | WLAN_CIPHER_SUITE_WEP40 : |
| 2798 | WLAN_CIPHER_SUITE_WEP104) || |
| 2799 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 2800 | (i == params->wep_tx_keyidx && |
| 2801 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 2802 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2803 | |
| 2804 | nla_nest_end(msg, nl_key); |
| 2805 | } |
| 2806 | nla_nest_end(msg, nl_keys); |
| 2807 | |
| 2808 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2812 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 2813 | const u8 *addr, int cmd, u16 reason_code, |
| 2814 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2815 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2816 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2817 | struct nl_msg *msg; |
| 2818 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2819 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 2820 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 2821 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 2822 | (local_state_change && |
| 2823 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 2824 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2825 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2826 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2827 | |
| 2828 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2829 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2830 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2831 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 2832 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2833 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2834 | return ret; |
| 2835 | } |
| 2836 | |
| 2837 | |
| 2838 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2839 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2840 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2841 | int ret; |
| 2842 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2843 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2844 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2845 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2846 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 2847 | reason_code, 0); |
| 2848 | /* |
| 2849 | * For locally generated disconnect, supplicant already generates a |
| 2850 | * DEAUTH event, so ignore the event from NL80211. |
| 2851 | */ |
| 2852 | drv->ignore_next_local_disconnect = ret == 0; |
| 2853 | |
| 2854 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2858 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 2859 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2860 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2861 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2862 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2863 | |
| 2864 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 2865 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2866 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2867 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2868 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2869 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2870 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 2871 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2872 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2873 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 2874 | reason_code, 0); |
| 2875 | /* |
| 2876 | * For locally generated deauthenticate, supplicant already generates a |
| 2877 | * DEAUTH event, so ignore the event from NL80211. |
| 2878 | */ |
| 2879 | drv->ignore_next_local_deauth = ret == 0; |
| 2880 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2884 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 2885 | struct wpa_driver_auth_params *params) |
| 2886 | { |
| 2887 | int i; |
| 2888 | |
| 2889 | drv->auth_freq = params->freq; |
| 2890 | drv->auth_alg = params->auth_alg; |
| 2891 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 2892 | drv->auth_local_state_change = params->local_state_change; |
| 2893 | drv->auth_p2p = params->p2p; |
| 2894 | |
| 2895 | if (params->bssid) |
| 2896 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 2897 | else |
| 2898 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 2899 | |
| 2900 | if (params->ssid) { |
| 2901 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 2902 | drv->auth_ssid_len = params->ssid_len; |
| 2903 | } else |
| 2904 | drv->auth_ssid_len = 0; |
| 2905 | |
| 2906 | |
| 2907 | os_free(drv->auth_ie); |
| 2908 | drv->auth_ie = NULL; |
| 2909 | drv->auth_ie_len = 0; |
| 2910 | if (params->ie) { |
| 2911 | drv->auth_ie = os_malloc(params->ie_len); |
| 2912 | if (drv->auth_ie) { |
| 2913 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 2914 | drv->auth_ie_len = params->ie_len; |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | for (i = 0; i < 4; i++) { |
| 2919 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 2920 | params->wep_key_len[i] <= 16) { |
| 2921 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 2922 | params->wep_key_len[i]); |
| 2923 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 2924 | } else |
| 2925 | drv->auth_wep_key_len[i] = 0; |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2930 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 2931 | { |
| 2932 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2933 | |
| 2934 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 2935 | return; |
| 2936 | |
| 2937 | /* |
| 2938 | * Looks like we failed to unmask 11b rates previously. This could |
| 2939 | * happen, e.g., if the interface was down at the point in time when a |
| 2940 | * P2P group was terminated. |
| 2941 | */ |
| 2942 | wpa_printf(MSG_DEBUG, |
| 2943 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 2944 | bss->ifname); |
| 2945 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2946 | } |
| 2947 | |
| 2948 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2949 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2950 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2951 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2952 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2953 | int ret = -1, i; |
| 2954 | struct nl_msg *msg; |
| 2955 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2956 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2957 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2958 | int is_retry; |
| 2959 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2960 | nl80211_unmask_11b_rates(bss); |
| 2961 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2962 | is_retry = drv->retry_auth; |
| 2963 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2964 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2965 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2966 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2967 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2968 | if (params->bssid) |
| 2969 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 2970 | else |
| 2971 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2972 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2973 | nlmode = params->p2p ? |
| 2974 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 2975 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2976 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2977 | return -1; |
| 2978 | |
| 2979 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2980 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 2981 | drv->ifindex); |
| 2982 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2983 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 2984 | if (!msg) |
| 2985 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2986 | |
| 2987 | for (i = 0; i < 4; i++) { |
| 2988 | if (!params->wep_key[i]) |
| 2989 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2990 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2991 | NULL, i, |
| 2992 | i == params->wep_tx_keyidx, NULL, 0, |
| 2993 | params->wep_key[i], |
| 2994 | params->wep_key_len[i]); |
| 2995 | if (params->wep_tx_keyidx != i) |
| 2996 | continue; |
| 2997 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2998 | params->wep_key[i], params->wep_key_len[i])) |
| 2999 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3002 | if (params->bssid) { |
| 3003 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3004 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3005 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3006 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3007 | } |
| 3008 | if (params->freq) { |
| 3009 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3010 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3011 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3012 | } |
| 3013 | if (params->ssid) { |
| 3014 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 3015 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3016 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3017 | params->ssid)) |
| 3018 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3019 | } |
| 3020 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3021 | if (params->ie && |
| 3022 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3023 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3024 | if (params->sae_data) { |
| 3025 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 3026 | params->sae_data_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3027 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 3028 | params->sae_data)) |
| 3029 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3030 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3031 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 3032 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3033 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 3034 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 3035 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 3036 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 3037 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 3038 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3039 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 3040 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3041 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3042 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3043 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3044 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 3045 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3046 | if (params->local_state_change) { |
| 3047 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3048 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3049 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3053 | msg = NULL; |
| 3054 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3055 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3056 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 3057 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3058 | count++; |
| 3059 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 3060 | !params->local_state_change) { |
| 3061 | /* |
| 3062 | * mac80211 does not currently accept new |
| 3063 | * authentication if we are already authenticated. As a |
| 3064 | * workaround, force deauthentication and try again. |
| 3065 | */ |
| 3066 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3067 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3068 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3069 | wpa_driver_nl80211_deauthenticate( |
| 3070 | bss, params->bssid, |
| 3071 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3072 | nlmsg_free(msg); |
| 3073 | goto retry; |
| 3074 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3075 | |
| 3076 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3077 | /* |
| 3078 | * cfg80211 has likely expired the BSS entry even |
| 3079 | * though it was previously available in our internal |
| 3080 | * BSS table. To recover quickly, start a single |
| 3081 | * channel scan on the specified channel. |
| 3082 | */ |
| 3083 | struct wpa_driver_scan_params scan; |
| 3084 | int freqs[2]; |
| 3085 | |
| 3086 | os_memset(&scan, 0, sizeof(scan)); |
| 3087 | scan.num_ssids = 1; |
| 3088 | if (params->ssid) { |
| 3089 | scan.ssids[0].ssid = params->ssid; |
| 3090 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3091 | } |
| 3092 | freqs[0] = params->freq; |
| 3093 | freqs[1] = 0; |
| 3094 | scan.freqs = freqs; |
| 3095 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3096 | "channel scan to refresh cfg80211 BSS " |
| 3097 | "entry"); |
| 3098 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3099 | if (ret == 0) { |
| 3100 | nl80211_copy_auth_params(drv, params); |
| 3101 | drv->scan_for_auth = 1; |
| 3102 | } |
| 3103 | } else if (is_retry) { |
| 3104 | /* |
| 3105 | * Need to indicate this with an event since the return |
| 3106 | * value from the retry is not delivered to core code. |
| 3107 | */ |
| 3108 | union wpa_event_data event; |
| 3109 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3110 | "failed"); |
| 3111 | os_memset(&event, 0, sizeof(event)); |
| 3112 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3113 | ETH_ALEN); |
| 3114 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3115 | &event); |
| 3116 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3117 | } else { |
| 3118 | wpa_printf(MSG_DEBUG, |
| 3119 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3120 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3121 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3122 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3123 | nlmsg_free(msg); |
| 3124 | return ret; |
| 3125 | } |
| 3126 | |
| 3127 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3128 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3129 | { |
| 3130 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3131 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3132 | int i; |
| 3133 | |
| 3134 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3135 | |
| 3136 | os_memset(¶ms, 0, sizeof(params)); |
| 3137 | params.freq = drv->auth_freq; |
| 3138 | params.auth_alg = drv->auth_alg; |
| 3139 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3140 | params.local_state_change = drv->auth_local_state_change; |
| 3141 | params.p2p = drv->auth_p2p; |
| 3142 | |
| 3143 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3144 | params.bssid = drv->auth_bssid_; |
| 3145 | |
| 3146 | if (drv->auth_ssid_len) { |
| 3147 | params.ssid = drv->auth_ssid; |
| 3148 | params.ssid_len = drv->auth_ssid_len; |
| 3149 | } |
| 3150 | |
| 3151 | params.ie = drv->auth_ie; |
| 3152 | params.ie_len = drv->auth_ie_len; |
| 3153 | |
| 3154 | for (i = 0; i < 4; i++) { |
| 3155 | if (drv->auth_wep_key_len[i]) { |
| 3156 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3157 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | drv->retry_auth = 1; |
| 3162 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3163 | } |
| 3164 | |
| 3165 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3166 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3167 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3168 | int encrypt, int noack, |
| 3169 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3170 | int offchanok, unsigned int wait_time, |
| 3171 | const u16 *csa_offs, |
| 3172 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3173 | { |
| 3174 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3175 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3176 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3177 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3178 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3179 | freq = nl80211_get_assoc_freq(drv); |
| 3180 | wpa_printf(MSG_DEBUG, |
| 3181 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3182 | freq); |
| 3183 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3184 | if (freq == 0) { |
| 3185 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3186 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3187 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3188 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3189 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3190 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3191 | 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] | 3192 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3193 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3194 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3195 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3196 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3197 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3198 | &cookie, no_cck, noack, offchanok, |
| 3199 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3200 | if (res == 0 && !noack) { |
| 3201 | const struct ieee80211_mgmt *mgmt; |
| 3202 | u16 fc; |
| 3203 | |
| 3204 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3205 | fc = le_to_host16(mgmt->frame_control); |
| 3206 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3207 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3208 | wpa_printf(MSG_MSGDUMP, |
| 3209 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3210 | (long long unsigned int) |
| 3211 | drv->send_action_cookie, |
| 3212 | (long long unsigned int) cookie); |
| 3213 | drv->send_action_cookie = cookie; |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3221 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3222 | size_t data_len, int noack, |
| 3223 | unsigned int freq, int no_cck, |
| 3224 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3225 | unsigned int wait_time, |
| 3226 | const u16 *csa_offs, |
| 3227 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3228 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3229 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3230 | struct ieee80211_mgmt *mgmt; |
| 3231 | int encrypt = 1; |
| 3232 | u16 fc; |
| 3233 | |
| 3234 | mgmt = (struct ieee80211_mgmt *) data; |
| 3235 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3236 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3237 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3238 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3239 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3240 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3241 | if ((is_sta_interface(drv->nlmode) || |
| 3242 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3243 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3244 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3245 | /* |
| 3246 | * The use of last_mgmt_freq is a bit of a hack, |
| 3247 | * but it works due to the single-threaded nature |
| 3248 | * of wpa_supplicant. |
| 3249 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3250 | if (freq == 0) { |
| 3251 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3252 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3253 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3254 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3255 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3256 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3257 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3258 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3259 | |
| 3260 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3261 | if (freq == 0) { |
| 3262 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3263 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3264 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3265 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3266 | return nl80211_send_frame_cmd(bss, freq, |
| 3267 | (int) freq == bss->freq ? 0 : |
| 3268 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3269 | data, data_len, |
| 3270 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3271 | no_cck, noack, offchanok, |
| 3272 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3273 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3274 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3275 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3276 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3277 | /* |
| 3278 | * Only one of the authentication frame types is encrypted. |
| 3279 | * In order for static WEP encryption to work properly (i.e., |
| 3280 | * to not encrypt the frame), we need to tell mac80211 about |
| 3281 | * the frames that must not be encrypted. |
| 3282 | */ |
| 3283 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3284 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3285 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3286 | encrypt = 0; |
| 3287 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3288 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3289 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3290 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3291 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3292 | wait_time, csa_offs, |
| 3293 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3297 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3298 | { |
| 3299 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3300 | u8 rates_len = 0; |
| 3301 | int i; |
| 3302 | |
| 3303 | if (!basic_rates) |
| 3304 | return 0; |
| 3305 | |
| 3306 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3307 | rates[rates_len++] = basic_rates[i] / 5; |
| 3308 | |
| 3309 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3310 | } |
| 3311 | |
| 3312 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3313 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3314 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3315 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3316 | { |
| 3317 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3318 | struct nl_msg *msg; |
| 3319 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3320 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3321 | (cts >= 0 && |
| 3322 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3323 | (preamble >= 0 && |
| 3324 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3325 | (slot >= 0 && |
| 3326 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3327 | (ht_opmode >= 0 && |
| 3328 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3329 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3330 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3331 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3332 | nlmsg_free(msg); |
| 3333 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3334 | } |
| 3335 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3336 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3337 | } |
| 3338 | |
| 3339 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3340 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3341 | struct hostapd_acl_params *params) |
| 3342 | { |
| 3343 | struct i802_bss *bss = priv; |
| 3344 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3345 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3346 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3347 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3348 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3349 | |
| 3350 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3351 | return -ENOTSUP; |
| 3352 | |
| 3353 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3354 | return -ENOTSUP; |
| 3355 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3356 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3357 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3358 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3359 | acl = nlmsg_alloc(); |
| 3360 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3361 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3362 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3363 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3364 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3365 | return -ENOMEM; |
| 3366 | } |
| 3367 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3368 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3369 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3370 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3371 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3372 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3373 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3374 | nlmsg_free(msg); |
| 3375 | nlmsg_free(acl); |
| 3376 | return -ENOMEM; |
| 3377 | } |
| 3378 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3379 | |
| 3380 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3381 | if (ret) { |
| 3382 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3383 | ret, strerror(-ret)); |
| 3384 | } |
| 3385 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3386 | return ret; |
| 3387 | } |
| 3388 | |
| 3389 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3390 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3391 | { |
| 3392 | if (beacon_int > 0) { |
| 3393 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3394 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3395 | beacon_int); |
| 3396 | } |
| 3397 | |
| 3398 | return 0; |
| 3399 | } |
| 3400 | |
| 3401 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3402 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3403 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3404 | { |
| 3405 | struct i802_bss *bss = priv; |
| 3406 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3407 | struct nl_msg *msg; |
| 3408 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3409 | int ret; |
| 3410 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3411 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3412 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3413 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3414 | u32 ver; |
| 3415 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3416 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3417 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3418 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3419 | beacon_set); |
| 3420 | if (beacon_set) |
| 3421 | cmd = NL80211_CMD_SET_BEACON; |
| 3422 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3423 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3424 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3425 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3426 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3427 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3428 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3429 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3430 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3431 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3432 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3433 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3434 | params->head) || |
| 3435 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3436 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3437 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3438 | nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) || |
| 3439 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3440 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3441 | if (params->proberesp && params->proberesp_len) { |
| 3442 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3443 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3444 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3445 | params->proberesp)) |
| 3446 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3447 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3448 | switch (params->hide_ssid) { |
| 3449 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3450 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3451 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3452 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3453 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3454 | break; |
| 3455 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3456 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3457 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3458 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3459 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3460 | break; |
| 3461 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3462 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3463 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3464 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3465 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3466 | break; |
| 3467 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3468 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3469 | if (params->privacy && |
| 3470 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3471 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3472 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3473 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3474 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3475 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3476 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3477 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3478 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3479 | goto fail; |
| 3480 | } else { |
| 3481 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3482 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3483 | goto fail; |
| 3484 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3485 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3486 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3487 | ver = 0; |
| 3488 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3489 | ver |= NL80211_WPA_VERSION_1; |
| 3490 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3491 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3492 | if (ver && |
| 3493 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3494 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3495 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3496 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3497 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3498 | num_suites = 0; |
| 3499 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 3500 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 3501 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 3502 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3503 | if (num_suites && |
| 3504 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3505 | suites)) |
| 3506 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3507 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3508 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 3509 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) && |
| 3510 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) |
| 3511 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3512 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3513 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 3514 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3515 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 3516 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3517 | if (num_suites && |
| 3518 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 3519 | num_suites * sizeof(u32), suites)) |
| 3520 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3521 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3522 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 3523 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3524 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3525 | if (suite && |
| 3526 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 3527 | goto fail; |
| 3528 | |
| 3529 | switch (params->smps_mode) { |
| 3530 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 3531 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 3532 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 3533 | break; |
| 3534 | case HT_CAP_INFO_SMPS_STATIC: |
| 3535 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 3536 | smps_mode = NL80211_SMPS_STATIC; |
| 3537 | break; |
| 3538 | default: |
| 3539 | /* invalid - fallback to smps off */ |
| 3540 | case HT_CAP_INFO_SMPS_DISABLED: |
| 3541 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 3542 | smps_mode = NL80211_SMPS_OFF; |
| 3543 | break; |
| 3544 | } |
| 3545 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
| 3546 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3547 | |
| 3548 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3549 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 3550 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3551 | if (nla_put(msg, NL80211_ATTR_IE, |
| 3552 | wpabuf_len(params->beacon_ies), |
| 3553 | wpabuf_head(params->beacon_ies))) |
| 3554 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3555 | } |
| 3556 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3557 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 3558 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3559 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 3560 | wpabuf_len(params->proberesp_ies), |
| 3561 | wpabuf_head(params->proberesp_ies))) |
| 3562 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3563 | } |
| 3564 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3565 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 3566 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3567 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 3568 | wpabuf_len(params->assocresp_ies), |
| 3569 | wpabuf_head(params->assocresp_ies))) |
| 3570 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3571 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3572 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3573 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3574 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 3575 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3576 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 3577 | params->ap_max_inactivity)) |
| 3578 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3581 | #ifdef CONFIG_P2P |
| 3582 | if (params->p2p_go_ctwindow > 0) { |
| 3583 | if (drv->p2p_go_ctwindow_supported) { |
| 3584 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 3585 | params->p2p_go_ctwindow); |
| 3586 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 3587 | params->p2p_go_ctwindow)) |
| 3588 | goto fail; |
| 3589 | } else { |
| 3590 | wpa_printf(MSG_INFO, |
| 3591 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 3592 | } |
| 3593 | } |
| 3594 | #endif /* CONFIG_P2P */ |
| 3595 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3596 | if (params->pbss) { |
| 3597 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 3598 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 3599 | goto fail; |
| 3600 | } |
| 3601 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3602 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3603 | if (ret) { |
| 3604 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 3605 | ret, strerror(-ret)); |
| 3606 | } else { |
| 3607 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3608 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 3609 | params->short_slot_time, params->ht_opmode, |
| 3610 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3611 | if (beacon_set && params->freq && |
| 3612 | params->freq->bandwidth != bss->bandwidth) { |
| 3613 | wpa_printf(MSG_DEBUG, |
| 3614 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 3615 | bss->ifname, bss->bandwidth, |
| 3616 | params->freq->bandwidth); |
| 3617 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 3618 | if (ret) { |
| 3619 | wpa_printf(MSG_DEBUG, |
| 3620 | "nl80211: Frequency set failed: %d (%s)", |
| 3621 | ret, strerror(-ret)); |
| 3622 | } else { |
| 3623 | wpa_printf(MSG_DEBUG, |
| 3624 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 3625 | bss->bandwidth = params->freq->bandwidth; |
| 3626 | } |
| 3627 | } else if (!beacon_set) { |
| 3628 | /* |
| 3629 | * cfg80211 updates the driver on frequence change in AP |
| 3630 | * mode only at the point when beaconing is started, so |
| 3631 | * set the initial value here. |
| 3632 | */ |
| 3633 | bss->bandwidth = params->freq->bandwidth; |
| 3634 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3635 | } |
| 3636 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3637 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3638 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3639 | return -ENOBUFS; |
| 3640 | } |
| 3641 | |
| 3642 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3643 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3644 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3645 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3646 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3647 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 3648 | return -ENOBUFS; |
| 3649 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3650 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 3651 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 3652 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3653 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3654 | enum nl80211_chan_width cw; |
| 3655 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3656 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3657 | switch (freq->bandwidth) { |
| 3658 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3659 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3660 | break; |
| 3661 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3662 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3663 | break; |
| 3664 | case 80: |
| 3665 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3666 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3667 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3668 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3669 | break; |
| 3670 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3671 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3672 | break; |
| 3673 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3674 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3675 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3676 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3677 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 3678 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 3679 | freq->center_freq1); |
| 3680 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 3681 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3682 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 3683 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 3684 | freq->center_freq1) || |
| 3685 | (freq->center_freq2 && |
| 3686 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 3687 | freq->center_freq2))) |
| 3688 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3689 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3690 | enum nl80211_channel_type ct; |
| 3691 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3692 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 3693 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3694 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3695 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3696 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3697 | break; |
| 3698 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3699 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3700 | break; |
| 3701 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3702 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3703 | break; |
| 3704 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3705 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3706 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3707 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 3708 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3709 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3710 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3714 | static int nl80211_set_channel(struct i802_bss *bss, |
| 3715 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3716 | { |
| 3717 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3718 | struct nl_msg *msg; |
| 3719 | int ret; |
| 3720 | |
| 3721 | wpa_printf(MSG_DEBUG, |
| 3722 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 3723 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 3724 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3725 | |
| 3726 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 3727 | NL80211_CMD_SET_WIPHY); |
| 3728 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 3729 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3730 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3731 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3732 | |
| 3733 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3734 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3735 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3736 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3737 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3738 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3739 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3740 | return -1; |
| 3741 | } |
| 3742 | |
| 3743 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3744 | static u32 sta_flags_nl80211(int flags) |
| 3745 | { |
| 3746 | u32 f = 0; |
| 3747 | |
| 3748 | if (flags & WPA_STA_AUTHORIZED) |
| 3749 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3750 | if (flags & WPA_STA_WMM) |
| 3751 | f |= BIT(NL80211_STA_FLAG_WME); |
| 3752 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 3753 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 3754 | if (flags & WPA_STA_MFP) |
| 3755 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 3756 | if (flags & WPA_STA_TDLS_PEER) |
| 3757 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3758 | if (flags & WPA_STA_AUTHENTICATED) |
| 3759 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3760 | if (flags & WPA_STA_ASSOCIATED) |
| 3761 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3762 | |
| 3763 | return f; |
| 3764 | } |
| 3765 | |
| 3766 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3767 | #ifdef CONFIG_MESH |
| 3768 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 3769 | { |
| 3770 | switch (state) { |
| 3771 | case PLINK_LISTEN: |
| 3772 | return NL80211_PLINK_LISTEN; |
| 3773 | case PLINK_OPEN_SENT: |
| 3774 | return NL80211_PLINK_OPN_SNT; |
| 3775 | case PLINK_OPEN_RCVD: |
| 3776 | return NL80211_PLINK_OPN_RCVD; |
| 3777 | case PLINK_CNF_RCVD: |
| 3778 | return NL80211_PLINK_CNF_RCVD; |
| 3779 | case PLINK_ESTAB: |
| 3780 | return NL80211_PLINK_ESTAB; |
| 3781 | case PLINK_HOLDING: |
| 3782 | return NL80211_PLINK_HOLDING; |
| 3783 | case PLINK_BLOCKED: |
| 3784 | return NL80211_PLINK_BLOCKED; |
| 3785 | default: |
| 3786 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 3787 | state); |
| 3788 | } |
| 3789 | return -1; |
| 3790 | } |
| 3791 | #endif /* CONFIG_MESH */ |
| 3792 | |
| 3793 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3794 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 3795 | struct hostapd_sta_add_params *params) |
| 3796 | { |
| 3797 | struct i802_bss *bss = priv; |
| 3798 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3799 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3800 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3801 | int ret = -ENOBUFS; |
| 3802 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3803 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 3804 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 3805 | return -EOPNOTSUPP; |
| 3806 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3807 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 3808 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3809 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 3810 | NL80211_CMD_NEW_STATION); |
| 3811 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 3812 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3813 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3814 | /* |
| 3815 | * Set the below properties only in one of the following cases: |
| 3816 | * 1. New station is added, already associated. |
| 3817 | * 2. Set WPA_STA_TDLS_PEER station. |
| 3818 | * 3. Set an already added unassociated station, if driver supports |
| 3819 | * full AP client state. (Set these properties after station became |
| 3820 | * associated will be rejected by the driver). |
| 3821 | */ |
| 3822 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 3823 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 3824 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3825 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 3826 | params->supp_rates, params->supp_rates_len); |
| 3827 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 3828 | params->capability); |
| 3829 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 3830 | params->supp_rates_len, params->supp_rates) || |
| 3831 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 3832 | params->capability)) |
| 3833 | goto fail; |
| 3834 | |
| 3835 | if (params->ht_capabilities) { |
| 3836 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 3837 | (u8 *) params->ht_capabilities, |
| 3838 | sizeof(*params->ht_capabilities)); |
| 3839 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 3840 | sizeof(*params->ht_capabilities), |
| 3841 | params->ht_capabilities)) |
| 3842 | goto fail; |
| 3843 | } |
| 3844 | |
| 3845 | if (params->vht_capabilities) { |
| 3846 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 3847 | (u8 *) params->vht_capabilities, |
| 3848 | sizeof(*params->vht_capabilities)); |
| 3849 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 3850 | sizeof(*params->vht_capabilities), |
| 3851 | params->vht_capabilities)) |
| 3852 | goto fail; |
| 3853 | } |
| 3854 | |
| 3855 | if (params->ext_capab) { |
| 3856 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 3857 | params->ext_capab, params->ext_capab_len); |
| 3858 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 3859 | params->ext_capab_len, params->ext_capab)) |
| 3860 | goto fail; |
| 3861 | } |
| 3862 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3863 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3864 | if (params->aid) { |
| 3865 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3866 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 3867 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3868 | } else { |
| 3869 | /* |
| 3870 | * cfg80211 validates that AID is non-zero, so we have |
| 3871 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3872 | * a dummy STA entry is used for now and for a station |
| 3873 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3874 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3875 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 3876 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 3877 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3878 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 3879 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3880 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3881 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 3882 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3883 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 3884 | params->listen_interval)) |
| 3885 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3886 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 3887 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3888 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 3889 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3890 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 3891 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 3892 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 3893 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 3894 | params->listen_interval); |
| 3895 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 3896 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 3897 | params->listen_interval)) |
| 3898 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3899 | } |
| 3900 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3901 | if (params->vht_opmode_enabled) { |
| 3902 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3903 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 3904 | params->vht_opmode)) |
| 3905 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3906 | } |
| 3907 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3908 | if (params->supp_channels) { |
| 3909 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 3910 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3911 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 3912 | params->supp_channels_len, params->supp_channels)) |
| 3913 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | if (params->supp_oper_classes) { |
| 3917 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 3918 | params->supp_oper_classes, |
| 3919 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3920 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 3921 | params->supp_oper_classes_len, |
| 3922 | params->supp_oper_classes)) |
| 3923 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3924 | } |
| 3925 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3926 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3927 | upd.set = sta_flags_nl80211(params->flags); |
| 3928 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3929 | |
| 3930 | /* |
| 3931 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 3932 | * flags, as nl80211 driver moves a new station, by default, into |
| 3933 | * associated state. |
| 3934 | * |
| 3935 | * On the other hand, if the driver supports that feature and the |
| 3936 | * station is added in unauthenticated state, set the |
| 3937 | * authenticated/associated bits in the mask to prevent moving this |
| 3938 | * station to associated state before it is actually associated. |
| 3939 | * |
| 3940 | * This is irrelevant for mesh mode where the station is added to the |
| 3941 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 3942 | * nl80211 API. |
| 3943 | */ |
| 3944 | if (!is_mesh_interface(drv->nlmode)) { |
| 3945 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 3946 | wpa_printf(MSG_DEBUG, |
| 3947 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 3948 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3949 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 3950 | } else if (!params->set && |
| 3951 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 3952 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 3953 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 3954 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 3955 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 3956 | } |
| 3957 | } |
| 3958 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3959 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 3960 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3961 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 3962 | goto fail; |
| 3963 | |
| 3964 | #ifdef CONFIG_MESH |
| 3965 | if (params->plink_state && |
| 3966 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 3967 | sta_plink_state_nl80211(params->plink_state))) |
| 3968 | goto fail; |
| 3969 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3970 | |
| 3971 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3972 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 3973 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3974 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3975 | if (!wme || |
| 3976 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 3977 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 3978 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 3979 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 3980 | WMM_QOSINFO_STA_SP_MASK)) |
| 3981 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3982 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3983 | } |
| 3984 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3985 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3986 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3987 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3988 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 3989 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 3990 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3991 | if (ret == -EEXIST) |
| 3992 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3993 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3994 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3995 | return ret; |
| 3996 | } |
| 3997 | |
| 3998 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3999 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 4000 | { |
| 4001 | #ifdef CONFIG_LIBNL3_ROUTE |
| 4002 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4003 | struct rtnl_neigh *rn; |
| 4004 | struct nl_addr *nl_addr; |
| 4005 | int err; |
| 4006 | |
| 4007 | rn = rtnl_neigh_alloc(); |
| 4008 | if (!rn) |
| 4009 | return; |
| 4010 | |
| 4011 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4012 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4013 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4014 | if (!nl_addr) { |
| 4015 | rtnl_neigh_put(rn); |
| 4016 | return; |
| 4017 | } |
| 4018 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4019 | |
| 4020 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4021 | if (err < 0) { |
| 4022 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4023 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4024 | bss->ifindex, nl_geterror(err)); |
| 4025 | } else { |
| 4026 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4027 | MACSTR, MAC2STR(addr)); |
| 4028 | } |
| 4029 | |
| 4030 | nl_addr_put(nl_addr); |
| 4031 | rtnl_neigh_put(rn); |
| 4032 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4033 | } |
| 4034 | |
| 4035 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4036 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4037 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4038 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4039 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4040 | struct nl_msg *msg; |
| 4041 | int ret; |
| 4042 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4043 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4044 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4045 | (deauth == 0 && |
| 4046 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4047 | WLAN_FC_STYPE_DISASSOC)) || |
| 4048 | (deauth == 1 && |
| 4049 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4050 | WLAN_FC_STYPE_DEAUTH)) || |
| 4051 | (reason_code && |
| 4052 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4053 | nlmsg_free(msg); |
| 4054 | return -ENOBUFS; |
| 4055 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4056 | |
| 4057 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4058 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4059 | " --> %d (%s)", |
| 4060 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4061 | |
| 4062 | if (drv->rtnl_sk) |
| 4063 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4064 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4065 | if (ret == -ENOENT) |
| 4066 | return 0; |
| 4067 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4071 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4072 | { |
| 4073 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4074 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4075 | |
| 4076 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4077 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4078 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4079 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4080 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4081 | { |
| 4082 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 4083 | /* Remove all bridges learned for this iface */ |
| 4084 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 4085 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4086 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4087 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4088 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4089 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4090 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4091 | } |
| 4092 | |
| 4093 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4094 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 4095 | { |
| 4096 | switch (mode) { |
| 4097 | case NL80211_IFTYPE_ADHOC: |
| 4098 | return "ADHOC"; |
| 4099 | case NL80211_IFTYPE_STATION: |
| 4100 | return "STATION"; |
| 4101 | case NL80211_IFTYPE_AP: |
| 4102 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4103 | case NL80211_IFTYPE_AP_VLAN: |
| 4104 | return "AP_VLAN"; |
| 4105 | case NL80211_IFTYPE_WDS: |
| 4106 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4107 | case NL80211_IFTYPE_MONITOR: |
| 4108 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4109 | case NL80211_IFTYPE_MESH_POINT: |
| 4110 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4111 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4112 | return "P2P_CLIENT"; |
| 4113 | case NL80211_IFTYPE_P2P_GO: |
| 4114 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4115 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4116 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4117 | default: |
| 4118 | return "unknown"; |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4123 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 4124 | const char *ifname, |
| 4125 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4126 | const u8 *addr, int wds, |
| 4127 | int (*handler)(struct nl_msg *, void *), |
| 4128 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4129 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4130 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4131 | int ifidx; |
| 4132 | int ret = -ENOBUFS; |
| 4133 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4134 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4135 | iftype, nl80211_iftype_str(iftype)); |
| 4136 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4137 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4138 | if (!msg || |
| 4139 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4140 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4141 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4142 | |
| 4143 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4144 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4145 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4146 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4147 | if (!flags || |
| 4148 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4149 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4150 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4151 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4152 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4153 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4154 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4155 | } |
| 4156 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4157 | /* |
| 4158 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4159 | * it, and the interface should be deleted when the socket is closed. |
| 4160 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4161 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4162 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4163 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4164 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4165 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4166 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4167 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4168 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4169 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4170 | ifname, ret, strerror(-ret)); |
| 4171 | return ret; |
| 4172 | } |
| 4173 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4174 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4175 | return 0; |
| 4176 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4177 | ifidx = if_nametoindex(ifname); |
| 4178 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4179 | ifname, ifidx); |
| 4180 | |
| 4181 | if (ifidx <= 0) |
| 4182 | return -1; |
| 4183 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4184 | /* |
| 4185 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4186 | * the parent interface. This is used mainly with hostapd. |
| 4187 | */ |
| 4188 | if (drv->hostapd || |
| 4189 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4190 | iftype == NL80211_IFTYPE_WDS || |
| 4191 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4192 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4193 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4194 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4195 | |
| 4196 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4197 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4198 | nl80211_remove_iface(drv, ifidx); |
| 4199 | return -1; |
| 4200 | } |
| 4201 | |
| 4202 | return ifidx; |
| 4203 | } |
| 4204 | |
| 4205 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4206 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4207 | const char *ifname, enum nl80211_iftype iftype, |
| 4208 | const u8 *addr, int wds, |
| 4209 | int (*handler)(struct nl_msg *, void *), |
| 4210 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4211 | { |
| 4212 | int ret; |
| 4213 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4214 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4215 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4216 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4217 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4218 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4219 | if (use_existing) { |
| 4220 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4221 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4222 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4223 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4224 | addr) < 0 && |
| 4225 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4226 | ifname, 0) < 0 || |
| 4227 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4228 | addr) < 0 || |
| 4229 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4230 | ifname, 1) < 0)) |
| 4231 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4232 | return -ENFILE; |
| 4233 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4234 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4235 | |
| 4236 | /* Try to remove the interface that was already there. */ |
| 4237 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4238 | |
| 4239 | /* Try to create the interface again */ |
| 4240 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4241 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4242 | } |
| 4243 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4244 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4245 | wpa_printf(MSG_DEBUG, |
| 4246 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4247 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4248 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4249 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4250 | |
| 4251 | return ret; |
| 4252 | } |
| 4253 | |
| 4254 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4255 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4256 | { |
| 4257 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4258 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4259 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4260 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4261 | |
| 4262 | /* |
| 4263 | * Disable Probe Request reporting unless we need it in this way for |
| 4264 | * devices that include the AP SME, in the other case (unless using |
| 4265 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4266 | */ |
| 4267 | if (!drv->device_ap_sme) |
| 4268 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4269 | |
| 4270 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4271 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4272 | return -1; |
| 4273 | |
| 4274 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4275 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 4276 | return -1; |
| 4277 | |
| 4278 | if (!drv->device_ap_sme && drv->use_monitor && |
| 4279 | nl80211_create_monitor_interface(drv) && |
| 4280 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4281 | return -1; |
| 4282 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4283 | if (drv->device_ap_sme && |
| 4284 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4285 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4286 | "Probe Request frame reporting in AP mode"); |
| 4287 | /* Try to survive without this */ |
| 4288 | } |
| 4289 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4290 | return 0; |
| 4291 | } |
| 4292 | |
| 4293 | |
| 4294 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4295 | { |
| 4296 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4297 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4298 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4299 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4300 | if (drv->device_ap_sme) { |
| 4301 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4302 | if (!drv->use_monitor) |
| 4303 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4304 | } else if (drv->use_monitor) |
| 4305 | nl80211_remove_monitor_interface(drv); |
| 4306 | else |
| 4307 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4308 | |
| 4309 | bss->beacon_set = 0; |
| 4310 | } |
| 4311 | |
| 4312 | |
| 4313 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4314 | const u8 *addr, const u8 *data, |
| 4315 | size_t data_len) |
| 4316 | { |
| 4317 | struct sockaddr_ll ll; |
| 4318 | int ret; |
| 4319 | |
| 4320 | if (bss->drv->eapol_tx_sock < 0) { |
| 4321 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4322 | return -1; |
| 4323 | } |
| 4324 | |
| 4325 | os_memset(&ll, 0, sizeof(ll)); |
| 4326 | ll.sll_family = AF_PACKET; |
| 4327 | ll.sll_ifindex = bss->ifindex; |
| 4328 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4329 | ll.sll_halen = ETH_ALEN; |
| 4330 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4331 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4332 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4333 | if (ret < 0) |
| 4334 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4335 | strerror(errno)); |
| 4336 | |
| 4337 | return ret; |
| 4338 | } |
| 4339 | |
| 4340 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4341 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4342 | |
| 4343 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4344 | void *priv, const u8 *addr, const u8 *data, |
| 4345 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4346 | { |
| 4347 | struct i802_bss *bss = priv; |
| 4348 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4349 | struct ieee80211_hdr *hdr; |
| 4350 | size_t len; |
| 4351 | u8 *pos; |
| 4352 | int res; |
| 4353 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4354 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4355 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4356 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4357 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4358 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4359 | data_len; |
| 4360 | hdr = os_zalloc(len); |
| 4361 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4362 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4363 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4364 | return -1; |
| 4365 | } |
| 4366 | |
| 4367 | hdr->frame_control = |
| 4368 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4369 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4370 | if (encrypt) |
| 4371 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4372 | if (qos) { |
| 4373 | hdr->frame_control |= |
| 4374 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4375 | } |
| 4376 | |
| 4377 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4378 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4379 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4380 | pos = (u8 *) (hdr + 1); |
| 4381 | |
| 4382 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4383 | /* Set highest priority in QoS header */ |
| 4384 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4385 | pos[1] = 0; |
| 4386 | pos += 2; |
| 4387 | } |
| 4388 | |
| 4389 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4390 | pos += sizeof(rfc1042_header); |
| 4391 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4392 | pos += 2; |
| 4393 | memcpy(pos, data, data_len); |
| 4394 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4395 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4396 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4397 | if (res < 0) { |
| 4398 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4399 | "failed: %d (%s)", |
| 4400 | (unsigned long) len, errno, strerror(errno)); |
| 4401 | } |
| 4402 | os_free(hdr); |
| 4403 | |
| 4404 | return res; |
| 4405 | } |
| 4406 | |
| 4407 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4408 | 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] | 4409 | unsigned int total_flags, |
| 4410 | unsigned int flags_or, |
| 4411 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4412 | { |
| 4413 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4414 | struct nl_msg *msg; |
| 4415 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4416 | struct nl80211_sta_flag_update upd; |
| 4417 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4418 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4419 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4420 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4421 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4422 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4423 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4424 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4425 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4426 | |
| 4427 | /* |
| 4428 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4429 | * can be removed eventually. |
| 4430 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4431 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4432 | if (!flags || |
| 4433 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4434 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4435 | ((total_flags & WPA_STA_WMM) && |
| 4436 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4437 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4438 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4439 | ((total_flags & WPA_STA_MFP) && |
| 4440 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4441 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4442 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4443 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4444 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4445 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4446 | |
| 4447 | os_memset(&upd, 0, sizeof(upd)); |
| 4448 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4449 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4450 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4451 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4452 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4453 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4454 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4455 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4456 | return -ENOBUFS; |
| 4457 | } |
| 4458 | |
| 4459 | |
| 4460 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4461 | struct wpa_driver_associate_params *params) |
| 4462 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4463 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4464 | |
| 4465 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4466 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4467 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4468 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4469 | } else |
| 4470 | nlmode = NL80211_IFTYPE_AP; |
| 4471 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4472 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4473 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4474 | nl80211_remove_monitor_interface(drv); |
| 4475 | return -1; |
| 4476 | } |
| 4477 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4478 | if (params->freq.freq && |
| 4479 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4480 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4481 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4482 | nl80211_remove_monitor_interface(drv); |
| 4483 | return -1; |
| 4484 | } |
| 4485 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4486 | return 0; |
| 4487 | } |
| 4488 | |
| 4489 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4490 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 4491 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4492 | { |
| 4493 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4494 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4495 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4496 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4497 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4498 | if (ret) { |
| 4499 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 4500 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4501 | } else { |
| 4502 | wpa_printf(MSG_DEBUG, |
| 4503 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4506 | if (reset_mode && |
| 4507 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4508 | NL80211_IFTYPE_STATION)) { |
| 4509 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4510 | "station mode"); |
| 4511 | } |
| 4512 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4513 | return ret; |
| 4514 | } |
| 4515 | |
| 4516 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4517 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 4518 | struct wpa_driver_associate_params *params) |
| 4519 | { |
| 4520 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 4521 | return -1; |
| 4522 | |
| 4523 | if (params->htcaps && params->htcaps_mask) { |
| 4524 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 4525 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 4526 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 4527 | params->htcaps_mask, sz); |
| 4528 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 4529 | params->htcaps) || |
| 4530 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 4531 | params->htcaps_mask)) |
| 4532 | return -1; |
| 4533 | } |
| 4534 | |
| 4535 | #ifdef CONFIG_VHT_OVERRIDES |
| 4536 | if (params->disable_vht) { |
| 4537 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 4538 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 4539 | return -1; |
| 4540 | } |
| 4541 | |
| 4542 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 4543 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 4544 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 4545 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 4546 | params->vhtcaps_mask, sz); |
| 4547 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 4548 | params->vhtcaps) || |
| 4549 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 4550 | params->vhtcaps_mask)) |
| 4551 | return -1; |
| 4552 | } |
| 4553 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 4554 | |
| 4555 | return 0; |
| 4556 | } |
| 4557 | |
| 4558 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4559 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 4560 | struct wpa_driver_associate_params *params) |
| 4561 | { |
| 4562 | struct nl_msg *msg; |
| 4563 | int ret = -1; |
| 4564 | int count = 0; |
| 4565 | |
| 4566 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 4567 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4568 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4569 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4570 | "IBSS mode"); |
| 4571 | return -1; |
| 4572 | } |
| 4573 | |
| 4574 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4575 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 4576 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 4577 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4578 | |
| 4579 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4580 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4581 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4582 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4583 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4584 | drv->ssid_len = params->ssid_len; |
| 4585 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4586 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 4587 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4588 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4589 | |
| 4590 | ret = nl80211_set_conn_keys(params, msg); |
| 4591 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4592 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4593 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4594 | if (params->bssid && params->fixed_bssid) { |
| 4595 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 4596 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4597 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4598 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4599 | } |
| 4600 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4601 | if (params->fixed_freq) { |
| 4602 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 4603 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 4604 | goto fail; |
| 4605 | } |
| 4606 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4607 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4608 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4609 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 4610 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4611 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4612 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4613 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4614 | } |
| 4615 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4616 | if (params->wpa_ie) { |
| 4617 | wpa_hexdump(MSG_DEBUG, |
| 4618 | " * Extra IEs for Beacon/Probe Response frames", |
| 4619 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4620 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 4621 | params->wpa_ie)) |
| 4622 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 4625 | ret = nl80211_ht_vht_overrides(msg, params); |
| 4626 | if (ret < 0) |
| 4627 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4628 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4629 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4630 | msg = NULL; |
| 4631 | if (ret) { |
| 4632 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 4633 | ret, strerror(-ret)); |
| 4634 | count++; |
| 4635 | if (ret == -EALREADY && count == 1) { |
| 4636 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 4637 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4638 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4639 | nlmsg_free(msg); |
| 4640 | goto retry; |
| 4641 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4642 | } else { |
| 4643 | wpa_printf(MSG_DEBUG, |
| 4644 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4645 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4646 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4647 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4648 | nlmsg_free(msg); |
| 4649 | return ret; |
| 4650 | } |
| 4651 | |
| 4652 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4653 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 4654 | struct wpa_driver_associate_params *params, |
| 4655 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4656 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4657 | if (params->bssid) { |
| 4658 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4659 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4660 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4661 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4662 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4663 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4664 | if (params->bssid_hint) { |
| 4665 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 4666 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4667 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 4668 | params->bssid_hint)) |
| 4669 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4670 | } |
| 4671 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4672 | if (params->freq.freq) { |
| 4673 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4674 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 4675 | params->freq.freq)) |
| 4676 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4677 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4678 | } else |
| 4679 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4680 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4681 | if (params->freq_hint) { |
| 4682 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4683 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 4684 | params->freq_hint)) |
| 4685 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4686 | } |
| 4687 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4688 | if (params->bg_scan_period >= 0) { |
| 4689 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 4690 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4691 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 4692 | params->bg_scan_period)) |
| 4693 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4694 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4695 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4696 | if (params->ssid) { |
| 4697 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4698 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4699 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4700 | params->ssid)) |
| 4701 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4702 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4703 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4704 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4705 | drv->ssid_len = params->ssid_len; |
| 4706 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4707 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4708 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4709 | if (params->wpa_ie && |
| 4710 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 4711 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4712 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4713 | if (params->wpa_proto) { |
| 4714 | enum nl80211_wpa_versions ver = 0; |
| 4715 | |
| 4716 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 4717 | ver |= NL80211_WPA_VERSION_1; |
| 4718 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 4719 | ver |= NL80211_WPA_VERSION_2; |
| 4720 | |
| 4721 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4722 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4723 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 4727 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 4728 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4729 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4730 | cipher)) |
| 4731 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4732 | } |
| 4733 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4734 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 4735 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 4736 | /* |
| 4737 | * This is likely to work even though many drivers do not |
| 4738 | * advertise support for operations without GTK. |
| 4739 | */ |
| 4740 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 4741 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4742 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 4743 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4744 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 4745 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4749 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4750 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 4751 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4752 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4753 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 4754 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4755 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4756 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
| 4757 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4758 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 4759 | |
| 4760 | switch (params->key_mgmt_suite) { |
| 4761 | case WPA_KEY_MGMT_CCKM: |
| 4762 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 4763 | break; |
| 4764 | case WPA_KEY_MGMT_IEEE8021X: |
| 4765 | mgmt = WLAN_AKM_SUITE_8021X; |
| 4766 | break; |
| 4767 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 4768 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 4769 | break; |
| 4770 | case WPA_KEY_MGMT_FT_PSK: |
| 4771 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 4772 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4773 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 4774 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; |
| 4775 | break; |
| 4776 | case WPA_KEY_MGMT_PSK_SHA256: |
| 4777 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; |
| 4778 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4779 | case WPA_KEY_MGMT_OSEN: |
| 4780 | mgmt = WLAN_AKM_SUITE_OSEN; |
| 4781 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4782 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 4783 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; |
| 4784 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4785 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
| 4786 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; |
| 4787 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4788 | case WPA_KEY_MGMT_PSK: |
| 4789 | default: |
| 4790 | mgmt = WLAN_AKM_SUITE_PSK; |
| 4791 | break; |
| 4792 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4793 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4794 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 4795 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4796 | } |
| 4797 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4798 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4799 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4800 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4801 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 4802 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 4803 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4804 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4805 | if (params->rrm_used) { |
| 4806 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
| 4807 | if (!(drv_rrm_flags & |
| 4808 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) || |
| 4809 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) || |
| 4810 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 4811 | return -1; |
| 4812 | } |
| 4813 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4814 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4815 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4816 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4817 | if (params->p2p) |
| 4818 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 4819 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4820 | if (params->pbss) { |
| 4821 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 4822 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4823 | return -1; |
| 4824 | } |
| 4825 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4826 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | |
| 4830 | static int wpa_driver_nl80211_try_connect( |
| 4831 | struct wpa_driver_nl80211_data *drv, |
| 4832 | struct wpa_driver_associate_params *params) |
| 4833 | { |
| 4834 | struct nl_msg *msg; |
| 4835 | enum nl80211_auth_type type; |
| 4836 | int ret; |
| 4837 | int algs; |
| 4838 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4839 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4840 | if (params->req_key_mgmt_offload && params->psk && |
| 4841 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4842 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 4843 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 4844 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 4845 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 4846 | if (ret) |
| 4847 | return ret; |
| 4848 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4849 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4850 | |
| 4851 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 4852 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4853 | if (!msg) |
| 4854 | return -1; |
| 4855 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4856 | ret = nl80211_connect_common(drv, params, msg); |
| 4857 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4858 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4859 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4860 | algs = 0; |
| 4861 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4862 | algs++; |
| 4863 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4864 | algs++; |
| 4865 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4866 | algs++; |
| 4867 | if (algs > 1) { |
| 4868 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 4869 | "selection"); |
| 4870 | goto skip_auth_type; |
| 4871 | } |
| 4872 | |
| 4873 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4874 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 4875 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4876 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 4877 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4878 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 4879 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 4880 | type = NL80211_AUTHTYPE_FT; |
| 4881 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4882 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4883 | |
| 4884 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4885 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 4886 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4887 | |
| 4888 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4889 | ret = nl80211_set_conn_keys(params, msg); |
| 4890 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4891 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4892 | |
| 4893 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4894 | msg = NULL; |
| 4895 | if (ret) { |
| 4896 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 4897 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4898 | } else { |
| 4899 | wpa_printf(MSG_DEBUG, |
| 4900 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4901 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4902 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4903 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4904 | nlmsg_free(msg); |
| 4905 | return ret; |
| 4906 | |
| 4907 | } |
| 4908 | |
| 4909 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4910 | static int wpa_driver_nl80211_connect( |
| 4911 | struct wpa_driver_nl80211_data *drv, |
| 4912 | struct wpa_driver_associate_params *params) |
| 4913 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 4914 | int ret; |
| 4915 | |
| 4916 | /* Store the connection attempted bssid for future use */ |
| 4917 | if (params->bssid) |
| 4918 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 4919 | else |
| 4920 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 4921 | |
| 4922 | ret = wpa_driver_nl80211_try_connect(drv, params); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4923 | if (ret == -EALREADY) { |
| 4924 | /* |
| 4925 | * cfg80211 does not currently accept new connections if |
| 4926 | * we are already connected. As a workaround, force |
| 4927 | * disconnection and try again. |
| 4928 | */ |
| 4929 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 4930 | "disconnecting before reassociation " |
| 4931 | "attempt"); |
| 4932 | if (wpa_driver_nl80211_disconnect( |
| 4933 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 4934 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4935 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 4936 | } |
| 4937 | return ret; |
| 4938 | } |
| 4939 | |
| 4940 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4941 | static int wpa_driver_nl80211_associate( |
| 4942 | void *priv, struct wpa_driver_associate_params *params) |
| 4943 | { |
| 4944 | struct i802_bss *bss = priv; |
| 4945 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4946 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4947 | struct nl_msg *msg; |
| 4948 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4949 | nl80211_unmask_11b_rates(bss); |
| 4950 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4951 | if (params->mode == IEEE80211_MODE_AP) |
| 4952 | return wpa_driver_nl80211_ap(drv, params); |
| 4953 | |
| 4954 | if (params->mode == IEEE80211_MODE_IBSS) |
| 4955 | return wpa_driver_nl80211_ibss(drv, params); |
| 4956 | |
| 4957 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4958 | enum nl80211_iftype nlmode = params->p2p ? |
| 4959 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 4960 | |
| 4961 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4962 | return -1; |
| 4963 | return wpa_driver_nl80211_connect(drv, params); |
| 4964 | } |
| 4965 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4966 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4967 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4968 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 4969 | drv->ifindex); |
| 4970 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4971 | if (!msg) |
| 4972 | return -1; |
| 4973 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4974 | ret = nl80211_connect_common(drv, params, msg); |
| 4975 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4976 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4977 | |
| 4978 | if (params->prev_bssid) { |
| 4979 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 4980 | MAC2STR(params->prev_bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4981 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 4982 | params->prev_bssid)) |
| 4983 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4984 | } |
| 4985 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4986 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4987 | msg = NULL; |
| 4988 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4989 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 4990 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 4991 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4992 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4993 | } else { |
| 4994 | wpa_printf(MSG_DEBUG, |
| 4995 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4996 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4997 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4998 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4999 | nlmsg_free(msg); |
| 5000 | return ret; |
| 5001 | } |
| 5002 | |
| 5003 | |
| 5004 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5005 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5006 | { |
| 5007 | struct nl_msg *msg; |
| 5008 | int ret = -ENOBUFS; |
| 5009 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5010 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 5011 | ifindex, mode, nl80211_iftype_str(mode)); |
| 5012 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5013 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 5014 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 5015 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5016 | |
| 5017 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5018 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5019 | if (!ret) |
| 5020 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5021 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5022 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5023 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 5024 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 5025 | return ret; |
| 5026 | } |
| 5027 | |
| 5028 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5029 | static int wpa_driver_nl80211_set_mode_impl( |
| 5030 | struct i802_bss *bss, |
| 5031 | enum nl80211_iftype nlmode, |
| 5032 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5033 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5034 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5035 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5036 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5037 | int was_ap = is_ap_interface(drv->nlmode); |
| 5038 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5039 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5040 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5041 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5042 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 5043 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5044 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5045 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5046 | drv->nlmode = nlmode; |
| 5047 | ret = 0; |
| 5048 | goto done; |
| 5049 | } |
| 5050 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5051 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5052 | return -1; |
| 5053 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5054 | if (nlmode == drv->nlmode) { |
| 5055 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 5056 | "requested mode - ignore error"); |
| 5057 | ret = 0; |
| 5058 | goto done; /* Already in the requested mode */ |
| 5059 | } |
| 5060 | |
| 5061 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 5062 | * take the device down, try to set the mode again, and bring the |
| 5063 | * device back up. |
| 5064 | */ |
| 5065 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 5066 | "interface down"); |
| 5067 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5068 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5069 | if (res == -EACCES || res == -ENODEV) |
| 5070 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5071 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5072 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 5073 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5074 | os_sleep(0, 100000); |
| 5075 | continue; |
| 5076 | } |
| 5077 | |
| 5078 | /* |
| 5079 | * Setting the mode will fail for some drivers if the phy is |
| 5080 | * on a frequency that the mode is disallowed in. |
| 5081 | */ |
| 5082 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5083 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5084 | if (res) { |
| 5085 | wpa_printf(MSG_DEBUG, |
| 5086 | "nl80211: Failed to set frequency on interface"); |
| 5087 | } |
| 5088 | } |
| 5089 | |
| 5090 | /* Try to set the mode again while the interface is down */ |
| 5091 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5092 | if (mode_switch_res == -EBUSY) { |
| 5093 | wpa_printf(MSG_DEBUG, |
| 5094 | "nl80211: Delaying mode set while interface going down"); |
| 5095 | os_sleep(0, 100000); |
| 5096 | continue; |
| 5097 | } |
| 5098 | ret = mode_switch_res; |
| 5099 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | if (!ret) { |
| 5103 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 5104 | "interface is down"); |
| 5105 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5106 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5107 | } |
| 5108 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5109 | /* Bring the interface back up */ |
| 5110 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 5111 | if (res != 0) { |
| 5112 | wpa_printf(MSG_DEBUG, |
| 5113 | "nl80211: Failed to set interface up after switching mode"); |
| 5114 | ret = -1; |
| 5115 | } |
| 5116 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5117 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5118 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5119 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 5120 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5121 | return ret; |
| 5122 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5123 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5124 | if (is_p2p_net_interface(nlmode)) { |
| 5125 | wpa_printf(MSG_DEBUG, |
| 5126 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 5127 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5128 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5129 | } else if (drv->disabled_11b_rates) { |
| 5130 | wpa_printf(MSG_DEBUG, |
| 5131 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 5132 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5133 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5134 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5135 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5136 | if (is_ap_interface(nlmode)) { |
| 5137 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 5138 | /* Setup additional AP mode functionality if needed */ |
| 5139 | if (nl80211_setup_ap(bss)) |
| 5140 | return -1; |
| 5141 | } else if (was_ap) { |
| 5142 | /* Remove additional AP mode functionality */ |
| 5143 | nl80211_teardown_ap(bss); |
| 5144 | } else { |
| 5145 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 5146 | } |
| 5147 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5148 | if (is_mesh_interface(nlmode) && |
| 5149 | nl80211_mgmt_subscribe_mesh(bss)) |
| 5150 | return -1; |
| 5151 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5152 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5153 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5154 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 5155 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 5156 | "frame processing - ignore for now"); |
| 5157 | |
| 5158 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5162 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 5163 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5164 | { |
| 5165 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5166 | } |
| 5167 | |
| 5168 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5169 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5170 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5171 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5172 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5173 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5177 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5178 | struct wpa_driver_capa *capa) |
| 5179 | { |
| 5180 | struct i802_bss *bss = priv; |
| 5181 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5182 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5183 | if (!drv->has_capability) |
| 5184 | return -1; |
| 5185 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5186 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5187 | capa->extended_capa = drv->extended_capa; |
| 5188 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5189 | capa->extended_capa_len = drv->extended_capa_len; |
| 5190 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5191 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5192 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | |
| 5196 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5197 | { |
| 5198 | struct i802_bss *bss = priv; |
| 5199 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5200 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5201 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5202 | bss->ifname, drv->operstate, state, |
| 5203 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5204 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5205 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5206 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5207 | } |
| 5208 | |
| 5209 | |
| 5210 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5211 | { |
| 5212 | struct i802_bss *bss = priv; |
| 5213 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5214 | struct nl_msg *msg; |
| 5215 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5216 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5217 | |
| 5218 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5219 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5220 | return 0; |
| 5221 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5222 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5223 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5224 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5225 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5226 | os_memset(&upd, 0, sizeof(upd)); |
| 5227 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5228 | if (authorized) |
| 5229 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5230 | |
| 5231 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5232 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5233 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5234 | nlmsg_free(msg); |
| 5235 | return -ENOBUFS; |
| 5236 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5237 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5238 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5239 | if (!ret) |
| 5240 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5241 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5242 | ret, strerror(-ret)); |
| 5243 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5244 | } |
| 5245 | |
| 5246 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5247 | /* Set kernel driver on given frequency (MHz) */ |
| 5248 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5249 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5250 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5251 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5255 | static inline int min_int(int a, int b) |
| 5256 | { |
| 5257 | if (a < b) |
| 5258 | return a; |
| 5259 | return b; |
| 5260 | } |
| 5261 | |
| 5262 | |
| 5263 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5264 | { |
| 5265 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5266 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5267 | |
| 5268 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5269 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5270 | |
| 5271 | /* |
| 5272 | * TODO: validate the key index and mac address! |
| 5273 | * Otherwise, there's a race condition as soon as |
| 5274 | * the kernel starts sending key notifications. |
| 5275 | */ |
| 5276 | |
| 5277 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5278 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5279 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5280 | return NL_SKIP; |
| 5281 | } |
| 5282 | |
| 5283 | |
| 5284 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5285 | int idx, u8 *seq) |
| 5286 | { |
| 5287 | struct i802_bss *bss = priv; |
| 5288 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5289 | struct nl_msg *msg; |
| 5290 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5291 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5292 | NL80211_CMD_GET_KEY); |
| 5293 | if (!msg || |
| 5294 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5295 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5296 | nlmsg_free(msg); |
| 5297 | return -ENOBUFS; |
| 5298 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5299 | |
| 5300 | memset(seq, 0, 6); |
| 5301 | |
| 5302 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5303 | } |
| 5304 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5305 | |
| 5306 | static int i802_set_rts(void *priv, int rts) |
| 5307 | { |
| 5308 | struct i802_bss *bss = priv; |
| 5309 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5310 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5311 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5312 | u32 val; |
| 5313 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5314 | if (rts >= 2347) |
| 5315 | val = (u32) -1; |
| 5316 | else |
| 5317 | val = rts; |
| 5318 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5319 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5320 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5321 | nlmsg_free(msg); |
| 5322 | return -ENOBUFS; |
| 5323 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5324 | |
| 5325 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5326 | if (!ret) |
| 5327 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5328 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5329 | "%d (%s)", rts, ret, strerror(-ret)); |
| 5330 | return ret; |
| 5331 | } |
| 5332 | |
| 5333 | |
| 5334 | static int i802_set_frag(void *priv, int frag) |
| 5335 | { |
| 5336 | struct i802_bss *bss = priv; |
| 5337 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5338 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5339 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5340 | u32 val; |
| 5341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5342 | if (frag >= 2346) |
| 5343 | val = (u32) -1; |
| 5344 | else |
| 5345 | val = frag; |
| 5346 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5347 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5348 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 5349 | nlmsg_free(msg); |
| 5350 | return -ENOBUFS; |
| 5351 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5352 | |
| 5353 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5354 | if (!ret) |
| 5355 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5356 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 5357 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 5358 | return ret; |
| 5359 | } |
| 5360 | |
| 5361 | |
| 5362 | static int i802_flush(void *priv) |
| 5363 | { |
| 5364 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5365 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5366 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5367 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5368 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 5369 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5370 | |
| 5371 | /* |
| 5372 | * XXX: FIX! this needs to flush all VLANs too |
| 5373 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5374 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 5375 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5376 | if (res) { |
| 5377 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 5378 | "(%s)", res, strerror(-res)); |
| 5379 | } |
| 5380 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | |
| 5384 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 5385 | { |
| 5386 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5387 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5388 | struct hostap_sta_driver_data *data = arg; |
| 5389 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 5390 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 5391 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 5392 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 5393 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 5394 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 5395 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5396 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5397 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 5398 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5399 | }; |
| 5400 | |
| 5401 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5402 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5403 | |
| 5404 | /* |
| 5405 | * TODO: validate the interface and mac address! |
| 5406 | * Otherwise, there's a race condition as soon as |
| 5407 | * the kernel starts sending station notifications. |
| 5408 | */ |
| 5409 | |
| 5410 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 5411 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 5412 | return NL_SKIP; |
| 5413 | } |
| 5414 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 5415 | tb[NL80211_ATTR_STA_INFO], |
| 5416 | stats_policy)) { |
| 5417 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 5418 | return NL_SKIP; |
| 5419 | } |
| 5420 | |
| 5421 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 5422 | data->inactive_msec = |
| 5423 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5424 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5425 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 5426 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 5427 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 5428 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5429 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 5430 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 5431 | /* |
| 5432 | * The driver supports 64-bit counters, so use them to override |
| 5433 | * the 32-bit values. |
| 5434 | */ |
| 5435 | data->rx_bytes = |
| 5436 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 5437 | data->tx_bytes = |
| 5438 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 5439 | data->bytes_64bit = 1; |
| 5440 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5441 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 5442 | data->rx_packets = |
| 5443 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 5444 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 5445 | data->tx_packets = |
| 5446 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5447 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 5448 | data->tx_retry_failed = |
| 5449 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5450 | |
| 5451 | return NL_SKIP; |
| 5452 | } |
| 5453 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5454 | static int i802_read_sta_data(struct i802_bss *bss, |
| 5455 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5456 | const u8 *addr) |
| 5457 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5458 | struct nl_msg *msg; |
| 5459 | |
| 5460 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5461 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5462 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 5463 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 5464 | nlmsg_free(msg); |
| 5465 | return -ENOBUFS; |
| 5466 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5467 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5468 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | |
| 5472 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 5473 | int cw_min, int cw_max, int burst_time) |
| 5474 | { |
| 5475 | struct i802_bss *bss = priv; |
| 5476 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5477 | struct nl_msg *msg; |
| 5478 | struct nlattr *txq, *params; |
| 5479 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5480 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5481 | if (!msg) |
| 5482 | return -1; |
| 5483 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5484 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 5485 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5486 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5487 | |
| 5488 | /* We are only sending parameters for a single TXQ at a time */ |
| 5489 | params = nla_nest_start(msg, 1); |
| 5490 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5491 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5492 | |
| 5493 | switch (queue) { |
| 5494 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5495 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 5496 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5497 | break; |
| 5498 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5499 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 5500 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5501 | break; |
| 5502 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5503 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 5504 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5505 | break; |
| 5506 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5507 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 5508 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5509 | break; |
| 5510 | } |
| 5511 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 5512 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5513 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 5514 | (burst_time * 100 + 16) / 32) || |
| 5515 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 5516 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 5517 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 5518 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5519 | |
| 5520 | nla_nest_end(msg, params); |
| 5521 | |
| 5522 | nla_nest_end(msg, txq); |
| 5523 | |
| 5524 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 5525 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5526 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5527 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5528 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5529 | return -1; |
| 5530 | } |
| 5531 | |
| 5532 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5533 | 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] | 5534 | const char *ifname, int vlan_id) |
| 5535 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5536 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5537 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5538 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5539 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5540 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 5541 | ", ifname=%s[%d], vlan_id=%d)", |
| 5542 | bss->ifname, if_nametoindex(bss->ifname), |
| 5543 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5544 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5545 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5546 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 5547 | nlmsg_free(msg); |
| 5548 | return -ENOBUFS; |
| 5549 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5550 | |
| 5551 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5552 | if (ret < 0) { |
| 5553 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 5554 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 5555 | MAC2STR(addr), ifname, vlan_id, ret, |
| 5556 | strerror(-ret)); |
| 5557 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5558 | return ret; |
| 5559 | } |
| 5560 | |
| 5561 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5562 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 5563 | { |
| 5564 | struct hostap_sta_driver_data data; |
| 5565 | int ret; |
| 5566 | |
| 5567 | data.inactive_msec = (unsigned long) -1; |
| 5568 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5569 | if (ret == -ENOENT) |
| 5570 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5571 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 5572 | return -1; |
| 5573 | return data.inactive_msec / 1000; |
| 5574 | } |
| 5575 | |
| 5576 | |
| 5577 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 5578 | { |
| 5579 | #if 0 |
| 5580 | /* TODO */ |
| 5581 | #endif |
| 5582 | return 0; |
| 5583 | } |
| 5584 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5585 | |
| 5586 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 5587 | int reason) |
| 5588 | { |
| 5589 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5590 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5591 | struct ieee80211_mgmt mgmt; |
| 5592 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5593 | if (is_mesh_interface(drv->nlmode)) |
| 5594 | return -1; |
| 5595 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5596 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5597 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5598 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5599 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5600 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5601 | WLAN_FC_STYPE_DEAUTH); |
| 5602 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5603 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5604 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5605 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 5606 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5607 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5608 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5609 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | |
| 5613 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 5614 | int reason) |
| 5615 | { |
| 5616 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5617 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5618 | struct ieee80211_mgmt mgmt; |
| 5619 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5620 | if (is_mesh_interface(drv->nlmode)) |
| 5621 | return -1; |
| 5622 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5623 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5624 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5625 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5626 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5627 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5628 | WLAN_FC_STYPE_DISASSOC); |
| 5629 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5630 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5631 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5632 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 5633 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5634 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5635 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5636 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5637 | } |
| 5638 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5639 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5640 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 5641 | { |
| 5642 | char buf[200], *pos, *end; |
| 5643 | int i, res; |
| 5644 | |
| 5645 | pos = buf; |
| 5646 | end = pos + sizeof(buf); |
| 5647 | |
| 5648 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5649 | if (!drv->if_indices[i]) |
| 5650 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5651 | res = os_snprintf(pos, end - pos, " %d(%d)", |
| 5652 | drv->if_indices[i], |
| 5653 | drv->if_indices_reason[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5654 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5655 | break; |
| 5656 | pos += res; |
| 5657 | } |
| 5658 | *pos = '\0'; |
| 5659 | |
| 5660 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 5661 | drv->num_if_indices, buf); |
| 5662 | } |
| 5663 | |
| 5664 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5665 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 5666 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5667 | { |
| 5668 | int i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5669 | int *old, *old_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5670 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5671 | wpa_printf(MSG_DEBUG, |
| 5672 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 5673 | ifidx, ifidx_reason); |
| 5674 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5675 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 5676 | ifidx); |
| 5677 | return; |
| 5678 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5679 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5680 | if (drv->if_indices[i] == 0) { |
| 5681 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5682 | drv->if_indices_reason[i] = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5683 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5684 | return; |
| 5685 | } |
| 5686 | } |
| 5687 | |
| 5688 | if (drv->if_indices != drv->default_if_indices) |
| 5689 | old = drv->if_indices; |
| 5690 | else |
| 5691 | old = NULL; |
| 5692 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5693 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 5694 | old_reason = drv->if_indices_reason; |
| 5695 | else |
| 5696 | old_reason = NULL; |
| 5697 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5698 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 5699 | sizeof(int)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5700 | drv->if_indices_reason = os_realloc_array(old_reason, |
| 5701 | drv->num_if_indices + 1, |
| 5702 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5703 | if (!drv->if_indices) { |
| 5704 | if (!old) |
| 5705 | drv->if_indices = drv->default_if_indices; |
| 5706 | else |
| 5707 | drv->if_indices = old; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5708 | } |
| 5709 | if (!drv->if_indices_reason) { |
| 5710 | if (!old_reason) |
| 5711 | drv->if_indices_reason = drv->default_if_indices_reason; |
| 5712 | else |
| 5713 | drv->if_indices = old_reason; |
| 5714 | } |
| 5715 | if (!drv->if_indices || !drv->if_indices_reason) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5716 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 5717 | "interfaces"); |
| 5718 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 5719 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5720 | } |
| 5721 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5722 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 5723 | sizeof(drv->default_if_indices)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5724 | if (!old_reason) |
| 5725 | os_memcpy(drv->if_indices_reason, |
| 5726 | drv->default_if_indices_reason, |
| 5727 | sizeof(drv->default_if_indices_reason)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5728 | drv->if_indices[drv->num_if_indices] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5729 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5730 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5731 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5732 | } |
| 5733 | |
| 5734 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5735 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 5736 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5737 | { |
| 5738 | int i; |
| 5739 | |
| 5740 | for (i = 0; i < drv->num_if_indices; i++) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5741 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
| 5742 | (drv->if_indices_reason[i] == ifidx_reason || |
| 5743 | ifidx_reason == IFIDX_ANY)) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5744 | drv->if_indices[i] = 0; |
| 5745 | break; |
| 5746 | } |
| 5747 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5748 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5749 | } |
| 5750 | |
| 5751 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5752 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 5753 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5754 | { |
| 5755 | int i; |
| 5756 | |
| 5757 | for (i = 0; i < drv->num_if_indices; i++) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5758 | if (drv->if_indices[i] == ifidx && |
| 5759 | (drv->if_indices_reason[i] == ifidx_reason || |
| 5760 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5761 | return 1; |
| 5762 | |
| 5763 | return 0; |
| 5764 | } |
| 5765 | |
| 5766 | |
| 5767 | 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] | 5768 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5769 | { |
| 5770 | struct i802_bss *bss = priv; |
| 5771 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5772 | char name[IFNAMSIZ + 1]; |
| 5773 | |
| 5774 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5775 | if (ifname_wds) |
| 5776 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 5777 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5778 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 5779 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 5780 | if (val) { |
| 5781 | if (!if_nametoindex(name)) { |
| 5782 | if (nl80211_create_iface(drv, name, |
| 5783 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5784 | bss->addr, 1, NULL, NULL, 0) < |
| 5785 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5786 | return -1; |
| 5787 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5788 | linux_br_add_if(drv->global->ioctl_sock, |
| 5789 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5790 | return -1; |
| 5791 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5792 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 5793 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 5794 | "interface %s up", name); |
| 5795 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5796 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 5797 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5798 | if (bridge_ifname) |
| 5799 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 5800 | name); |
| 5801 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5802 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 5803 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 5804 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | |
| 5809 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 5810 | { |
| 5811 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 5812 | struct sockaddr_ll lladdr; |
| 5813 | unsigned char buf[3000]; |
| 5814 | int len; |
| 5815 | socklen_t fromlen = sizeof(lladdr); |
| 5816 | |
| 5817 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 5818 | (struct sockaddr *)&lladdr, &fromlen); |
| 5819 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5820 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 5821 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5822 | return; |
| 5823 | } |
| 5824 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5825 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5826 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 5827 | } |
| 5828 | |
| 5829 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5830 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 5831 | struct i802_bss *bss, |
| 5832 | const char *brname, const char *ifname) |
| 5833 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5834 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5835 | char in_br[IFNAMSIZ]; |
| 5836 | |
| 5837 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5838 | br_ifindex = if_nametoindex(brname); |
| 5839 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5840 | /* |
| 5841 | * Bridge was configured, but the bridge device does |
| 5842 | * not exist. Try to add it now. |
| 5843 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5844 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5845 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 5846 | "bridge interface %s: %s", |
| 5847 | brname, strerror(errno)); |
| 5848 | return -1; |
| 5849 | } |
| 5850 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5851 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5852 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5853 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5854 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5855 | |
| 5856 | if (linux_br_get(in_br, ifname) == 0) { |
| 5857 | if (os_strcmp(in_br, brname) == 0) |
| 5858 | return 0; /* already in the bridge */ |
| 5859 | |
| 5860 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 5861 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5862 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 5863 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5864 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 5865 | "remove interface %s from bridge " |
| 5866 | "%s: %s", |
| 5867 | ifname, brname, strerror(errno)); |
| 5868 | return -1; |
| 5869 | } |
| 5870 | } |
| 5871 | |
| 5872 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 5873 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5874 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5875 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 5876 | "into bridge %s: %s", |
| 5877 | ifname, brname, strerror(errno)); |
| 5878 | return -1; |
| 5879 | } |
| 5880 | bss->added_if_into_bridge = 1; |
| 5881 | |
| 5882 | return 0; |
| 5883 | } |
| 5884 | |
| 5885 | |
| 5886 | static void *i802_init(struct hostapd_data *hapd, |
| 5887 | struct wpa_init_params *params) |
| 5888 | { |
| 5889 | struct wpa_driver_nl80211_data *drv; |
| 5890 | struct i802_bss *bss; |
| 5891 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5892 | char master_ifname[IFNAMSIZ]; |
| 5893 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5894 | int br_added = 0; |
| 5895 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5896 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 5897 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5898 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5899 | if (bss == NULL) |
| 5900 | return NULL; |
| 5901 | |
| 5902 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5903 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5904 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5905 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5906 | params->ifname, master_ifname); |
| 5907 | br_ifindex = if_nametoindex(master_ifname); |
| 5908 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 5909 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 5910 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 5911 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 5912 | params->ifname, master_ifname); |
| 5913 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5914 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame^] | 5915 | |
| 5916 | /* check if master itself is under bridge */ |
| 5917 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 5918 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 5919 | master_ifname); |
| 5920 | br_ifindex = if_nametoindex(master_ifname); |
| 5921 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 5922 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5923 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5924 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5925 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5926 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5927 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5928 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5929 | for (i = 0; i < params->num_bridge; i++) { |
| 5930 | if (params->bridge[i]) { |
| 5931 | ifindex = if_nametoindex(params->bridge[i]); |
| 5932 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5933 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5934 | if (ifindex == br_ifindex) |
| 5935 | br_added = 1; |
| 5936 | } |
| 5937 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5938 | |
| 5939 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5940 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5941 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5942 | if (params->num_bridge && params->bridge[0]) { |
| 5943 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 5944 | params->ifname) < 0) |
| 5945 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5946 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5947 | br_added = 1; |
| 5948 | } |
| 5949 | |
| 5950 | if (!br_added && br_ifindex && |
| 5951 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5952 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5953 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5954 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5955 | if (bss->added_if_into_bridge) { |
| 5956 | drv->rtnl_sk = nl_socket_alloc(); |
| 5957 | if (drv->rtnl_sk == NULL) { |
| 5958 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 5959 | goto failed; |
| 5960 | } |
| 5961 | |
| 5962 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 5963 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 5964 | strerror(errno)); |
| 5965 | goto failed; |
| 5966 | } |
| 5967 | } |
| 5968 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5969 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5970 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 5971 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5972 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 5973 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5974 | goto failed; |
| 5975 | } |
| 5976 | |
| 5977 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 5978 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5979 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5980 | goto failed; |
| 5981 | } |
| 5982 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5983 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 5984 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5985 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5986 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5987 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5988 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 5989 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5990 | return bss; |
| 5991 | |
| 5992 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5993 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5994 | return NULL; |
| 5995 | } |
| 5996 | |
| 5997 | |
| 5998 | static void i802_deinit(void *priv) |
| 5999 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6000 | struct i802_bss *bss = priv; |
| 6001 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6002 | } |
| 6003 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6004 | |
| 6005 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 6006 | enum wpa_driver_if_type type) |
| 6007 | { |
| 6008 | switch (type) { |
| 6009 | case WPA_IF_STATION: |
| 6010 | return NL80211_IFTYPE_STATION; |
| 6011 | case WPA_IF_P2P_CLIENT: |
| 6012 | case WPA_IF_P2P_GROUP: |
| 6013 | return NL80211_IFTYPE_P2P_CLIENT; |
| 6014 | case WPA_IF_AP_VLAN: |
| 6015 | return NL80211_IFTYPE_AP_VLAN; |
| 6016 | case WPA_IF_AP_BSS: |
| 6017 | return NL80211_IFTYPE_AP; |
| 6018 | case WPA_IF_P2P_GO: |
| 6019 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6020 | case WPA_IF_P2P_DEVICE: |
| 6021 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6022 | case WPA_IF_MESH: |
| 6023 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6024 | default: |
| 6025 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6026 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6027 | } |
| 6028 | |
| 6029 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6030 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 6031 | { |
| 6032 | struct wpa_driver_nl80211_data *drv; |
| 6033 | dl_list_for_each(drv, &global->interfaces, |
| 6034 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6035 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6036 | return 1; |
| 6037 | } |
| 6038 | return 0; |
| 6039 | } |
| 6040 | |
| 6041 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6042 | 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] | 6043 | { |
| 6044 | unsigned int idx; |
| 6045 | |
| 6046 | if (!drv->global) |
| 6047 | return -1; |
| 6048 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6049 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6050 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6051 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6052 | new_addr[0] ^= idx << 2; |
| 6053 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 6054 | break; |
| 6055 | } |
| 6056 | if (idx == 64) |
| 6057 | return -1; |
| 6058 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6059 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6060 | MACSTR, MAC2STR(new_addr)); |
| 6061 | |
| 6062 | return 0; |
| 6063 | } |
| 6064 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6065 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6066 | struct wdev_info { |
| 6067 | u64 wdev_id; |
| 6068 | int wdev_id_set; |
| 6069 | u8 macaddr[ETH_ALEN]; |
| 6070 | }; |
| 6071 | |
| 6072 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 6073 | { |
| 6074 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6075 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6076 | struct wdev_info *wi = arg; |
| 6077 | |
| 6078 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6079 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6080 | if (tb[NL80211_ATTR_WDEV]) { |
| 6081 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 6082 | wi->wdev_id_set = 1; |
| 6083 | } |
| 6084 | |
| 6085 | if (tb[NL80211_ATTR_MAC]) |
| 6086 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 6087 | ETH_ALEN); |
| 6088 | |
| 6089 | return NL_SKIP; |
| 6090 | } |
| 6091 | |
| 6092 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6093 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 6094 | const char *ifname, const u8 *addr, |
| 6095 | void *bss_ctx, void **drv_priv, |
| 6096 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6097 | const char *bridge, int use_existing, |
| 6098 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6099 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6100 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6101 | struct i802_bss *bss = priv; |
| 6102 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6103 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6104 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6105 | |
| 6106 | if (addr) |
| 6107 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6108 | nlmode = wpa_driver_nl80211_if_type(type); |
| 6109 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 6110 | struct wdev_info p2pdev_info; |
| 6111 | |
| 6112 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 6113 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 6114 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6115 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6116 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 6117 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 6118 | ifname); |
| 6119 | return -1; |
| 6120 | } |
| 6121 | |
| 6122 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 6123 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 6124 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 6125 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 6126 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 6127 | ifname, |
| 6128 | (long long unsigned int) p2pdev_info.wdev_id); |
| 6129 | } else { |
| 6130 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6131 | 0, NULL, NULL, use_existing); |
| 6132 | if (use_existing && ifidx == -ENFILE) { |
| 6133 | added = 0; |
| 6134 | ifidx = if_nametoindex(ifname); |
| 6135 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6136 | return -1; |
| 6137 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6138 | } |
| 6139 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6140 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6141 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6142 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 6143 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6144 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6145 | if (added) |
| 6146 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6147 | return -1; |
| 6148 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6149 | } |
| 6150 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6151 | if (!addr && |
| 6152 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6153 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 6154 | type == WPA_IF_STATION)) { |
| 6155 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6156 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6157 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6158 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6159 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6160 | if (added) |
| 6161 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6162 | return -1; |
| 6163 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6164 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6165 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6166 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6167 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6168 | if (added) |
| 6169 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6170 | return -1; |
| 6171 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6172 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6173 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6174 | if (added) |
| 6175 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6176 | return -1; |
| 6177 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6178 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6179 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6180 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6181 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6182 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6183 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 6184 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6185 | if (added) |
| 6186 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6187 | return -1; |
| 6188 | } |
| 6189 | |
| 6190 | if (bridge && |
| 6191 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 6192 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 6193 | "interface %s to a bridge %s", |
| 6194 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6195 | if (added) |
| 6196 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6197 | os_free(new_bss); |
| 6198 | return -1; |
| 6199 | } |
| 6200 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6201 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 6202 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6203 | if (added) |
| 6204 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6205 | os_free(new_bss); |
| 6206 | return -1; |
| 6207 | } |
| 6208 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6209 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6210 | new_bss->ifindex = ifidx; |
| 6211 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6212 | new_bss->next = drv->first_bss->next; |
| 6213 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6214 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6215 | new_bss->added_if = added; |
| 6216 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6217 | if (drv_priv) |
| 6218 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6219 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6220 | |
| 6221 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 6222 | if (nl80211_setup_ap(new_bss)) |
| 6223 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6224 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6225 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6226 | if (drv->global) |
| 6227 | drv->global->if_add_ifindex = ifidx; |
| 6228 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6229 | /* |
| 6230 | * Some virtual interfaces need to process EAPOL packets and events on |
| 6231 | * the parent interface. This is used mainly with hostapd. |
| 6232 | */ |
| 6233 | if (ifidx > 0 && |
| 6234 | (drv->hostapd || |
| 6235 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 6236 | nlmode == NL80211_IFTYPE_WDS || |
| 6237 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6238 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6239 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6240 | return 0; |
| 6241 | } |
| 6242 | |
| 6243 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6244 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6245 | enum wpa_driver_if_type type, |
| 6246 | const char *ifname) |
| 6247 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6248 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6249 | int ifindex = if_nametoindex(ifname); |
| 6250 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6251 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 6252 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6253 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6254 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6255 | else if (ifindex > 0 && !bss->added_if) { |
| 6256 | struct wpa_driver_nl80211_data *drv2; |
| 6257 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6258 | struct wpa_driver_nl80211_data, list) { |
| 6259 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 6260 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 6261 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6262 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6263 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6264 | if (type != WPA_IF_AP_BSS) |
| 6265 | return 0; |
| 6266 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6267 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6268 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 6269 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6270 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6271 | "interface %s from bridge %s: %s", |
| 6272 | bss->ifname, bss->brname, strerror(errno)); |
| 6273 | } |
| 6274 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6275 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6276 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6277 | "bridge %s: %s", |
| 6278 | bss->brname, strerror(errno)); |
| 6279 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6280 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6281 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6282 | struct i802_bss *tbss; |
| 6283 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6284 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 6285 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6286 | if (tbss->next == bss) { |
| 6287 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6288 | /* Unsubscribe management frames */ |
| 6289 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6290 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6291 | if (!bss->added_if) |
| 6292 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6293 | os_free(bss); |
| 6294 | bss = NULL; |
| 6295 | break; |
| 6296 | } |
| 6297 | } |
| 6298 | if (bss) |
| 6299 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 6300 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6301 | } else { |
| 6302 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 6303 | nl80211_teardown_ap(bss); |
| 6304 | if (!bss->added_if && !drv->first_bss->next) |
| 6305 | wpa_driver_nl80211_del_beacon(drv); |
| 6306 | nl80211_destroy_bss(bss); |
| 6307 | if (!bss->added_if) |
| 6308 | i802_set_iface_flags(bss, 0); |
| 6309 | if (drv->first_bss->next) { |
| 6310 | drv->first_bss = drv->first_bss->next; |
| 6311 | drv->ctx = drv->first_bss->ctx; |
| 6312 | os_free(bss); |
| 6313 | } else { |
| 6314 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 6315 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6316 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6317 | |
| 6318 | return 0; |
| 6319 | } |
| 6320 | |
| 6321 | |
| 6322 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 6323 | { |
| 6324 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6325 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6326 | u64 *cookie = arg; |
| 6327 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6328 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6329 | if (tb[NL80211_ATTR_COOKIE]) |
| 6330 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 6331 | return NL_SKIP; |
| 6332 | } |
| 6333 | |
| 6334 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6335 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6336 | unsigned int freq, unsigned int wait, |
| 6337 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6338 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6339 | int offchanok, const u16 *csa_offs, |
| 6340 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6341 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6342 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6343 | struct nl_msg *msg; |
| 6344 | u64 cookie; |
| 6345 | int ret = -1; |
| 6346 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6347 | 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] | 6348 | "no_ack=%d offchanok=%d", |
| 6349 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6350 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6351 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6352 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 6353 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 6354 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 6355 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6356 | drv->test_use_roc_tx) && |
| 6357 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 6358 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 6359 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6360 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 6361 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6362 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 6363 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6364 | |
| 6365 | cookie = 0; |
| 6366 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6367 | msg = NULL; |
| 6368 | if (ret) { |
| 6369 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6370 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 6371 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6372 | } else { |
| 6373 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 6374 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 6375 | (long long unsigned int) cookie); |
| 6376 | |
| 6377 | if (cookie_out) |
| 6378 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6379 | |
| 6380 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { |
| 6381 | wpa_printf(MSG_DEBUG, |
| 6382 | "nl80211: Drop oldest pending send action cookie 0x%llx", |
| 6383 | (long long unsigned int) |
| 6384 | drv->send_action_cookies[0]); |
| 6385 | os_memmove(&drv->send_action_cookies[0], |
| 6386 | &drv->send_action_cookies[1], |
| 6387 | (MAX_SEND_ACTION_COOKIES - 1) * |
| 6388 | sizeof(u64)); |
| 6389 | drv->num_send_action_cookies--; |
| 6390 | } |
| 6391 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; |
| 6392 | drv->num_send_action_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6393 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6394 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6395 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6396 | nlmsg_free(msg); |
| 6397 | return ret; |
| 6398 | } |
| 6399 | |
| 6400 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6401 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 6402 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6403 | unsigned int wait_time, |
| 6404 | const u8 *dst, const u8 *src, |
| 6405 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6406 | const u8 *data, size_t data_len, |
| 6407 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6408 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6409 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6410 | int ret = -1; |
| 6411 | u8 *buf; |
| 6412 | struct ieee80211_hdr *hdr; |
| 6413 | |
| 6414 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6415 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 6416 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6417 | |
| 6418 | buf = os_zalloc(24 + data_len); |
| 6419 | if (buf == NULL) |
| 6420 | return ret; |
| 6421 | os_memcpy(buf + 24, data, data_len); |
| 6422 | hdr = (struct ieee80211_hdr *) buf; |
| 6423 | hdr->frame_control = |
| 6424 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 6425 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 6426 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 6427 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 6428 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6429 | if (is_ap_interface(drv->nlmode) && |
| 6430 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6431 | (int) freq == bss->freq || drv->device_ap_sme || |
| 6432 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6433 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 6434 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6435 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6436 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6437 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6438 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6439 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6440 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6441 | |
| 6442 | os_free(buf); |
| 6443 | return ret; |
| 6444 | } |
| 6445 | |
| 6446 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6447 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6448 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6449 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6450 | struct nl_msg *msg; |
| 6451 | int ret; |
| 6452 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 6453 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6454 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6455 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6456 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6457 | nlmsg_free(msg); |
| 6458 | return; |
| 6459 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6460 | |
| 6461 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6462 | if (ret) |
| 6463 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 6464 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6465 | } |
| 6466 | |
| 6467 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6468 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 6469 | { |
| 6470 | struct i802_bss *bss = priv; |
| 6471 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6472 | unsigned int i; |
| 6473 | u64 cookie; |
| 6474 | |
| 6475 | /* Cancel the last pending TX cookie */ |
| 6476 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); |
| 6477 | |
| 6478 | /* |
| 6479 | * Cancel the other pending TX cookies, if any. This is needed since |
| 6480 | * the driver may keep a list of all pending offchannel TX operations |
| 6481 | * and free up the radio only once they have expired or cancelled. |
| 6482 | */ |
| 6483 | for (i = drv->num_send_action_cookies; i > 0; i--) { |
| 6484 | cookie = drv->send_action_cookies[i - 1]; |
| 6485 | if (cookie != drv->send_action_cookie) |
| 6486 | nl80211_frame_wait_cancel(bss, cookie); |
| 6487 | } |
| 6488 | drv->num_send_action_cookies = 0; |
| 6489 | } |
| 6490 | |
| 6491 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6492 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 6493 | unsigned int duration) |
| 6494 | { |
| 6495 | struct i802_bss *bss = priv; |
| 6496 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6497 | struct nl_msg *msg; |
| 6498 | int ret; |
| 6499 | u64 cookie; |
| 6500 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6501 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 6502 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 6503 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 6504 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6505 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6506 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6507 | |
| 6508 | cookie = 0; |
| 6509 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6510 | if (ret == 0) { |
| 6511 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 6512 | "0x%llx for freq=%u MHz duration=%u", |
| 6513 | (long long unsigned int) cookie, freq, duration); |
| 6514 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6515 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6516 | return 0; |
| 6517 | } |
| 6518 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 6519 | "(freq=%d duration=%u): %d (%s)", |
| 6520 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6521 | return -1; |
| 6522 | } |
| 6523 | |
| 6524 | |
| 6525 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 6526 | { |
| 6527 | struct i802_bss *bss = priv; |
| 6528 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6529 | struct nl_msg *msg; |
| 6530 | int ret; |
| 6531 | |
| 6532 | if (!drv->pending_remain_on_chan) { |
| 6533 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 6534 | "to cancel"); |
| 6535 | return -1; |
| 6536 | } |
| 6537 | |
| 6538 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 6539 | "0x%llx", |
| 6540 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 6541 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6542 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 6543 | if (!msg || |
| 6544 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 6545 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6546 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6547 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6548 | |
| 6549 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6550 | if (ret == 0) |
| 6551 | return 0; |
| 6552 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 6553 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6554 | return -1; |
| 6555 | } |
| 6556 | |
| 6557 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6558 | 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] | 6559 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6560 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6561 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6562 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6563 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 6564 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 6565 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6566 | /* |
| 6567 | * Do not disable Probe Request reporting that was |
| 6568 | * enabled in nl80211_setup_ap(). |
| 6569 | */ |
| 6570 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 6571 | "Probe Request reporting nl_preq=%p while " |
| 6572 | "in AP mode", bss->nl_preq); |
| 6573 | } else if (bss->nl_preq) { |
| 6574 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 6575 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6576 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6577 | } |
| 6578 | return 0; |
| 6579 | } |
| 6580 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6581 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6582 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6583 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6584 | return 0; |
| 6585 | } |
| 6586 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6587 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 6588 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6589 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6590 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 6591 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6592 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6593 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6594 | (WLAN_FC_TYPE_MGMT << 2) | |
| 6595 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6596 | NULL, 0) < 0) |
| 6597 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 6598 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6599 | nl80211_register_eloop_read(&bss->nl_preq, |
| 6600 | wpa_driver_nl80211_event_receive, |
| 6601 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6602 | |
| 6603 | return 0; |
| 6604 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6605 | out_err: |
| 6606 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6607 | return -1; |
| 6608 | } |
| 6609 | |
| 6610 | |
| 6611 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 6612 | int ifindex, int disabled) |
| 6613 | { |
| 6614 | struct nl_msg *msg; |
| 6615 | struct nlattr *bands, *band; |
| 6616 | int ret; |
| 6617 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6618 | wpa_printf(MSG_DEBUG, |
| 6619 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 6620 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 6621 | "no NL80211_TXRATE_LEGACY constraint"); |
| 6622 | |
| 6623 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 6624 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6625 | if (!msg) |
| 6626 | return -1; |
| 6627 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6628 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 6629 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6630 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6631 | |
| 6632 | /* |
| 6633 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 6634 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 6635 | * rates. All 5 GHz rates are left enabled. |
| 6636 | */ |
| 6637 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6638 | if (!band || |
| 6639 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 6640 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 6641 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6642 | nla_nest_end(msg, band); |
| 6643 | |
| 6644 | nla_nest_end(msg, bands); |
| 6645 | |
| 6646 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6647 | if (ret) { |
| 6648 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 6649 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6650 | } else |
| 6651 | drv->disabled_11b_rates = disabled; |
| 6652 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6653 | return ret; |
| 6654 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6655 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6656 | nlmsg_free(msg); |
| 6657 | return -1; |
| 6658 | } |
| 6659 | |
| 6660 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6661 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 6662 | { |
| 6663 | struct i802_bss *bss = priv; |
| 6664 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6665 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6666 | return -1; |
| 6667 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6668 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6669 | |
| 6670 | /* |
| 6671 | * If the P2P GO interface was dynamically added, then it is |
| 6672 | * possible that the interface change to station is not possible. |
| 6673 | */ |
| 6674 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 6675 | return 0; |
| 6676 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6677 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6678 | } |
| 6679 | |
| 6680 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6681 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 6682 | { |
| 6683 | struct i802_bss *bss = priv; |
| 6684 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6685 | if (!is_ap_interface(drv->nlmode)) |
| 6686 | return -1; |
| 6687 | wpa_driver_nl80211_del_beacon(drv); |
| 6688 | bss->beacon_set = 0; |
| 6689 | return 0; |
| 6690 | } |
| 6691 | |
| 6692 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6693 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 6694 | { |
| 6695 | struct i802_bss *bss = priv; |
| 6696 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6697 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 6698 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6699 | |
| 6700 | /* |
| 6701 | * If the P2P Client interface was dynamically added, then it is |
| 6702 | * possible that the interface change to station is not possible. |
| 6703 | */ |
| 6704 | if (bss->if_dynamic) |
| 6705 | return 0; |
| 6706 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6707 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 6708 | } |
| 6709 | |
| 6710 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6711 | static void wpa_driver_nl80211_resume(void *priv) |
| 6712 | { |
| 6713 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6714 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6715 | |
| 6716 | if (i802_set_iface_flags(bss, 1)) |
| 6717 | 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] | 6718 | |
| 6719 | if (is_p2p_net_interface(nlmode)) |
| 6720 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6724 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 6725 | { |
| 6726 | struct i802_bss *bss = priv; |
| 6727 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6728 | struct nl_msg *msg; |
| 6729 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6730 | |
| 6731 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 6732 | "hysteresis=%d", threshold, hysteresis); |
| 6733 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6734 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 6735 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 6736 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 6737 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 6738 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6739 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6740 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6741 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6742 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6743 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6747 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 6748 | { |
| 6749 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6750 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6751 | struct wpa_signal_info *sig_change = arg; |
| 6752 | |
| 6753 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6754 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6755 | |
| 6756 | sig_change->center_frq1 = -1; |
| 6757 | sig_change->center_frq2 = -1; |
| 6758 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 6759 | |
| 6760 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 6761 | sig_change->chanwidth = convert2width( |
| 6762 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 6763 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 6764 | sig_change->center_frq1 = |
| 6765 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 6766 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 6767 | sig_change->center_frq2 = |
| 6768 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 6769 | } |
| 6770 | |
| 6771 | return NL_SKIP; |
| 6772 | } |
| 6773 | |
| 6774 | |
| 6775 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 6776 | struct wpa_signal_info *sig) |
| 6777 | { |
| 6778 | struct nl_msg *msg; |
| 6779 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6780 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6781 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6785 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 6786 | { |
| 6787 | struct i802_bss *bss = priv; |
| 6788 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6789 | int res; |
| 6790 | |
| 6791 | os_memset(si, 0, sizeof(*si)); |
| 6792 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6793 | if (res) { |
| 6794 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 6795 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 6796 | return res; |
| 6797 | si->current_signal = 0; |
| 6798 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6799 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6800 | res = nl80211_get_channel_width(drv, si); |
| 6801 | if (res != 0) |
| 6802 | return res; |
| 6803 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6804 | return nl80211_get_link_noise(drv, si); |
| 6805 | } |
| 6806 | |
| 6807 | |
| 6808 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 6809 | int encrypt) |
| 6810 | { |
| 6811 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6812 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6813 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6814 | } |
| 6815 | |
| 6816 | |
| 6817 | static int nl80211_set_param(void *priv, const char *param) |
| 6818 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6819 | if (param == NULL) |
| 6820 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6821 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6822 | |
| 6823 | #ifdef CONFIG_P2P |
| 6824 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 6825 | struct i802_bss *bss = priv; |
| 6826 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6827 | |
| 6828 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 6829 | "interface"); |
| 6830 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 6831 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 6832 | } |
| 6833 | #endif /* CONFIG_P2P */ |
| 6834 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6835 | if (os_strstr(param, "use_monitor=1")) { |
| 6836 | struct i802_bss *bss = priv; |
| 6837 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6838 | drv->use_monitor = 1; |
| 6839 | } |
| 6840 | |
| 6841 | if (os_strstr(param, "force_connect_cmd=1")) { |
| 6842 | struct i802_bss *bss = priv; |
| 6843 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6844 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6845 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6846 | } |
| 6847 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 6848 | if (os_strstr(param, "no_offchannel_tx=1")) { |
| 6849 | struct i802_bss *bss = priv; |
| 6850 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6851 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 6852 | drv->test_use_roc_tx = 1; |
| 6853 | } |
| 6854 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6855 | return 0; |
| 6856 | } |
| 6857 | |
| 6858 | |
| 6859 | static void * nl80211_global_init(void) |
| 6860 | { |
| 6861 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6862 | struct netlink_config *cfg; |
| 6863 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6864 | global = os_zalloc(sizeof(*global)); |
| 6865 | if (global == NULL) |
| 6866 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6867 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6868 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6869 | global->if_add_ifindex = -1; |
| 6870 | |
| 6871 | cfg = os_zalloc(sizeof(*cfg)); |
| 6872 | if (cfg == NULL) |
| 6873 | goto err; |
| 6874 | |
| 6875 | cfg->ctx = global; |
| 6876 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 6877 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 6878 | global->netlink = netlink_init(cfg); |
| 6879 | if (global->netlink == NULL) { |
| 6880 | os_free(cfg); |
| 6881 | goto err; |
| 6882 | } |
| 6883 | |
| 6884 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 6885 | goto err; |
| 6886 | |
| 6887 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 6888 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6889 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 6890 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6891 | goto err; |
| 6892 | } |
| 6893 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6894 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6895 | |
| 6896 | err: |
| 6897 | nl80211_global_deinit(global); |
| 6898 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | |
| 6902 | static void nl80211_global_deinit(void *priv) |
| 6903 | { |
| 6904 | struct nl80211_global *global = priv; |
| 6905 | if (global == NULL) |
| 6906 | return; |
| 6907 | if (!dl_list_empty(&global->interfaces)) { |
| 6908 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 6909 | "nl80211_global_deinit", |
| 6910 | dl_list_len(&global->interfaces)); |
| 6911 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6912 | |
| 6913 | if (global->netlink) |
| 6914 | netlink_deinit(global->netlink); |
| 6915 | |
| 6916 | nl_destroy_handles(&global->nl); |
| 6917 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6918 | if (global->nl_event) |
| 6919 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6920 | |
| 6921 | nl_cb_put(global->nl_cb); |
| 6922 | |
| 6923 | if (global->ioctl_sock >= 0) |
| 6924 | close(global->ioctl_sock); |
| 6925 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6926 | os_free(global); |
| 6927 | } |
| 6928 | |
| 6929 | |
| 6930 | static const char * nl80211_get_radio_name(void *priv) |
| 6931 | { |
| 6932 | struct i802_bss *bss = priv; |
| 6933 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6934 | return drv->phyname; |
| 6935 | } |
| 6936 | |
| 6937 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6938 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 6939 | const u8 *pmkid) |
| 6940 | { |
| 6941 | struct nl_msg *msg; |
| 6942 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6943 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 6944 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
| 6945 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { |
| 6946 | nlmsg_free(msg); |
| 6947 | return -ENOBUFS; |
| 6948 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6949 | |
| 6950 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6951 | } |
| 6952 | |
| 6953 | |
| 6954 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6955 | { |
| 6956 | struct i802_bss *bss = priv; |
| 6957 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 6958 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 6959 | } |
| 6960 | |
| 6961 | |
| 6962 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6963 | { |
| 6964 | struct i802_bss *bss = priv; |
| 6965 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 6966 | MAC2STR(bssid)); |
| 6967 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 6968 | } |
| 6969 | |
| 6970 | |
| 6971 | static int nl80211_flush_pmkid(void *priv) |
| 6972 | { |
| 6973 | struct i802_bss *bss = priv; |
| 6974 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 6975 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 6976 | } |
| 6977 | |
| 6978 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6979 | static void clean_survey_results(struct survey_results *survey_results) |
| 6980 | { |
| 6981 | struct freq_survey *survey, *tmp; |
| 6982 | |
| 6983 | if (dl_list_empty(&survey_results->survey_list)) |
| 6984 | return; |
| 6985 | |
| 6986 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 6987 | struct freq_survey, list) { |
| 6988 | dl_list_del(&survey->list); |
| 6989 | os_free(survey); |
| 6990 | } |
| 6991 | } |
| 6992 | |
| 6993 | |
| 6994 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 6995 | struct dl_list *survey_list) |
| 6996 | { |
| 6997 | struct freq_survey *survey; |
| 6998 | |
| 6999 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 7000 | if (!survey) |
| 7001 | return; |
| 7002 | |
| 7003 | survey->ifidx = ifidx; |
| 7004 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7005 | survey->filled = 0; |
| 7006 | |
| 7007 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 7008 | survey->nf = (int8_t) |
| 7009 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 7010 | survey->filled |= SURVEY_HAS_NF; |
| 7011 | } |
| 7012 | |
| 7013 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 7014 | survey->channel_time = |
| 7015 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 7016 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 7017 | } |
| 7018 | |
| 7019 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 7020 | survey->channel_time_busy = |
| 7021 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 7022 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 7023 | } |
| 7024 | |
| 7025 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 7026 | survey->channel_time_rx = |
| 7027 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 7028 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 7029 | } |
| 7030 | |
| 7031 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 7032 | survey->channel_time_tx = |
| 7033 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 7034 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 7035 | } |
| 7036 | |
| 7037 | 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)", |
| 7038 | survey->freq, |
| 7039 | survey->nf, |
| 7040 | (unsigned long int) survey->channel_time, |
| 7041 | (unsigned long int) survey->channel_time_busy, |
| 7042 | (unsigned long int) survey->channel_time_tx, |
| 7043 | (unsigned long int) survey->channel_time_rx, |
| 7044 | survey->filled); |
| 7045 | |
| 7046 | dl_list_add_tail(survey_list, &survey->list); |
| 7047 | } |
| 7048 | |
| 7049 | |
| 7050 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 7051 | unsigned int freq_filter) |
| 7052 | { |
| 7053 | if (!freq_filter) |
| 7054 | return 1; |
| 7055 | |
| 7056 | return freq_filter == surveyed_freq; |
| 7057 | } |
| 7058 | |
| 7059 | |
| 7060 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 7061 | { |
| 7062 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7063 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7064 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 7065 | struct survey_results *survey_results; |
| 7066 | u32 surveyed_freq = 0; |
| 7067 | u32 ifidx; |
| 7068 | |
| 7069 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 7070 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 7071 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 7072 | }; |
| 7073 | |
| 7074 | survey_results = (struct survey_results *) arg; |
| 7075 | |
| 7076 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7077 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7078 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 7079 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 7080 | return NL_SKIP; |
| 7081 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7082 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 7083 | |
| 7084 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 7085 | return NL_SKIP; |
| 7086 | |
| 7087 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 7088 | tb[NL80211_ATTR_SURVEY_INFO], |
| 7089 | survey_policy)) |
| 7090 | return NL_SKIP; |
| 7091 | |
| 7092 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 7093 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 7094 | return NL_SKIP; |
| 7095 | } |
| 7096 | |
| 7097 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7098 | |
| 7099 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 7100 | survey_results->freq_filter)) |
| 7101 | return NL_SKIP; |
| 7102 | |
| 7103 | if (survey_results->freq_filter && |
| 7104 | survey_results->freq_filter != surveyed_freq) { |
| 7105 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 7106 | surveyed_freq); |
| 7107 | return NL_SKIP; |
| 7108 | } |
| 7109 | |
| 7110 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 7111 | |
| 7112 | return NL_SKIP; |
| 7113 | } |
| 7114 | |
| 7115 | |
| 7116 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 7117 | { |
| 7118 | struct i802_bss *bss = priv; |
| 7119 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7120 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7121 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7122 | union wpa_event_data data; |
| 7123 | struct survey_results *survey_results; |
| 7124 | |
| 7125 | os_memset(&data, 0, sizeof(data)); |
| 7126 | survey_results = &data.survey_results; |
| 7127 | |
| 7128 | dl_list_init(&survey_results->survey_list); |
| 7129 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7130 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7131 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7132 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7133 | |
| 7134 | if (freq) |
| 7135 | data.survey_results.freq_filter = freq; |
| 7136 | |
| 7137 | do { |
| 7138 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 7139 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 7140 | survey_results); |
| 7141 | } while (err > 0); |
| 7142 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7143 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7144 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7145 | else |
| 7146 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7147 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7148 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7149 | return err; |
| 7150 | } |
| 7151 | |
| 7152 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7153 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 7154 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7155 | const u8 *replay_ctr) |
| 7156 | { |
| 7157 | struct i802_bss *bss = priv; |
| 7158 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7159 | struct nlattr *replay_nested; |
| 7160 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7161 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7162 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7163 | if (!drv->set_rekey_offload) |
| 7164 | return; |
| 7165 | |
| 7166 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7167 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 7168 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7169 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
| 7170 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7171 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 7172 | replay_ctr)) { |
| 7173 | nl80211_nlmsg_clear(msg); |
| 7174 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7175 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7176 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7177 | |
| 7178 | nla_nest_end(msg, replay_nested); |
| 7179 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7180 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 7181 | if (ret == -EOPNOTSUPP) { |
| 7182 | wpa_printf(MSG_DEBUG, |
| 7183 | "nl80211: Driver does not support rekey offload"); |
| 7184 | drv->set_rekey_offload = 0; |
| 7185 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | |
| 7189 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 7190 | const u8 *addr, int qos) |
| 7191 | { |
| 7192 | /* send data frame to poll STA and check whether |
| 7193 | * this frame is ACKed */ |
| 7194 | struct { |
| 7195 | struct ieee80211_hdr hdr; |
| 7196 | u16 qos_ctl; |
| 7197 | } STRUCT_PACKED nulldata; |
| 7198 | size_t size; |
| 7199 | |
| 7200 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 7201 | |
| 7202 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 7203 | |
| 7204 | if (qos) { |
| 7205 | nulldata.hdr.frame_control = |
| 7206 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 7207 | WLAN_FC_STYPE_QOS_NULL); |
| 7208 | size = sizeof(nulldata); |
| 7209 | } else { |
| 7210 | nulldata.hdr.frame_control = |
| 7211 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 7212 | WLAN_FC_STYPE_NULLFUNC); |
| 7213 | size = sizeof(struct ieee80211_hdr); |
| 7214 | } |
| 7215 | |
| 7216 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 7217 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 7218 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 7219 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 7220 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7221 | 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] | 7222 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7223 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 7224 | "send poll frame"); |
| 7225 | } |
| 7226 | |
| 7227 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 7228 | int qos) |
| 7229 | { |
| 7230 | struct i802_bss *bss = priv; |
| 7231 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7232 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7233 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7234 | |
| 7235 | if (!drv->poll_command_supported) { |
| 7236 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 7237 | return; |
| 7238 | } |
| 7239 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7240 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 7241 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7242 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7243 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7244 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7245 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7246 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7247 | if (ret < 0) { |
| 7248 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 7249 | MACSTR " failed: ret=%d (%s)", |
| 7250 | MAC2STR(addr), ret, strerror(-ret)); |
| 7251 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7252 | } |
| 7253 | |
| 7254 | |
| 7255 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 7256 | { |
| 7257 | struct nl_msg *msg; |
| 7258 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7259 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 7260 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 7261 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 7262 | nlmsg_free(msg); |
| 7263 | return -ENOBUFS; |
| 7264 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7265 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7266 | } |
| 7267 | |
| 7268 | |
| 7269 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 7270 | int ctwindow) |
| 7271 | { |
| 7272 | struct i802_bss *bss = priv; |
| 7273 | |
| 7274 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 7275 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 7276 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7277 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7278 | #ifdef ANDROID_P2P |
| 7279 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7280 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7281 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7282 | #endif /* ANDROID_P2P */ |
| 7283 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7284 | |
| 7285 | if (legacy_ps == -1) |
| 7286 | return 0; |
| 7287 | if (legacy_ps != 0 && legacy_ps != 1) |
| 7288 | return -1; /* Not yet supported */ |
| 7289 | |
| 7290 | return nl80211_set_power_save(bss, legacy_ps); |
| 7291 | } |
| 7292 | |
| 7293 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7294 | static int nl80211_start_radar_detection(void *priv, |
| 7295 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7296 | { |
| 7297 | struct i802_bss *bss = priv; |
| 7298 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7299 | struct nl_msg *msg; |
| 7300 | int ret; |
| 7301 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7302 | 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)", |
| 7303 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7304 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7305 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7306 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 7307 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 7308 | "detection"); |
| 7309 | return -1; |
| 7310 | } |
| 7311 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7312 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 7313 | nl80211_put_freq_params(msg, freq) < 0) { |
| 7314 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7315 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7316 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7317 | |
| 7318 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7319 | if (ret == 0) |
| 7320 | return 0; |
| 7321 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 7322 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7323 | return -1; |
| 7324 | } |
| 7325 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7326 | #ifdef CONFIG_TDLS |
| 7327 | |
| 7328 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 7329 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7330 | u32 peer_capab, int initiator, const u8 *buf, |
| 7331 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7332 | { |
| 7333 | struct i802_bss *bss = priv; |
| 7334 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7335 | struct nl_msg *msg; |
| 7336 | |
| 7337 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7338 | return -EOPNOTSUPP; |
| 7339 | |
| 7340 | if (!dst) |
| 7341 | return -EINVAL; |
| 7342 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7343 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 7344 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 7345 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 7346 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 7347 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 7348 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7349 | if (peer_capab) { |
| 7350 | /* |
| 7351 | * The internal enum tdls_peer_capability definition is |
| 7352 | * currently identical with the nl80211 enum |
| 7353 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 7354 | * here. |
| 7355 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7356 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 7357 | peer_capab)) |
| 7358 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7359 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7360 | if ((initiator && |
| 7361 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 7362 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 7363 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7364 | |
| 7365 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7366 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7367 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7368 | nlmsg_free(msg); |
| 7369 | return -ENOBUFS; |
| 7370 | } |
| 7371 | |
| 7372 | |
| 7373 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 7374 | { |
| 7375 | struct i802_bss *bss = priv; |
| 7376 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7377 | struct nl_msg *msg; |
| 7378 | enum nl80211_tdls_operation nl80211_oper; |
| 7379 | |
| 7380 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7381 | return -EOPNOTSUPP; |
| 7382 | |
| 7383 | switch (oper) { |
| 7384 | case TDLS_DISCOVERY_REQ: |
| 7385 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 7386 | break; |
| 7387 | case TDLS_SETUP: |
| 7388 | nl80211_oper = NL80211_TDLS_SETUP; |
| 7389 | break; |
| 7390 | case TDLS_TEARDOWN: |
| 7391 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 7392 | break; |
| 7393 | case TDLS_ENABLE_LINK: |
| 7394 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 7395 | break; |
| 7396 | case TDLS_DISABLE_LINK: |
| 7397 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 7398 | break; |
| 7399 | case TDLS_ENABLE: |
| 7400 | return 0; |
| 7401 | case TDLS_DISABLE: |
| 7402 | return 0; |
| 7403 | default: |
| 7404 | return -EINVAL; |
| 7405 | } |
| 7406 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7407 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 7408 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 7409 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 7410 | nlmsg_free(msg); |
| 7411 | return -ENOBUFS; |
| 7412 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7413 | |
| 7414 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7415 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7416 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7417 | |
| 7418 | static int |
| 7419 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 7420 | const struct hostapd_freq_params *params) |
| 7421 | { |
| 7422 | struct i802_bss *bss = priv; |
| 7423 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7424 | struct nl_msg *msg; |
| 7425 | int ret = -ENOBUFS; |
| 7426 | |
| 7427 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7428 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7429 | return -EOPNOTSUPP; |
| 7430 | |
| 7431 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 7432 | " oper_class=%u freq=%u", |
| 7433 | MAC2STR(addr), oper_class, params->freq); |
| 7434 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 7435 | if (!msg || |
| 7436 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7437 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 7438 | (ret = nl80211_put_freq_params(msg, params))) { |
| 7439 | nlmsg_free(msg); |
| 7440 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 7441 | return ret; |
| 7442 | } |
| 7443 | |
| 7444 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7445 | } |
| 7446 | |
| 7447 | |
| 7448 | static int |
| 7449 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 7450 | { |
| 7451 | struct i802_bss *bss = priv; |
| 7452 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7453 | struct nl_msg *msg; |
| 7454 | |
| 7455 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7456 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7457 | return -EOPNOTSUPP; |
| 7458 | |
| 7459 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 7460 | MAC2STR(addr)); |
| 7461 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 7462 | if (!msg || |
| 7463 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7464 | nlmsg_free(msg); |
| 7465 | wpa_printf(MSG_DEBUG, |
| 7466 | "nl80211: Could not build TDLS cancel chan switch"); |
| 7467 | return -ENOBUFS; |
| 7468 | } |
| 7469 | |
| 7470 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7471 | } |
| 7472 | |
| 7473 | #endif /* CONFIG TDLS */ |
| 7474 | |
| 7475 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7476 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 7477 | enum wpa_alg alg, const u8 *addr, |
| 7478 | int key_idx, int set_tx, |
| 7479 | const u8 *seq, size_t seq_len, |
| 7480 | const u8 *key, size_t key_len) |
| 7481 | { |
| 7482 | struct i802_bss *bss = priv; |
| 7483 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 7484 | set_tx, seq, seq_len, key, key_len); |
| 7485 | } |
| 7486 | |
| 7487 | |
| 7488 | static int driver_nl80211_scan2(void *priv, |
| 7489 | struct wpa_driver_scan_params *params) |
| 7490 | { |
| 7491 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7492 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 7493 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7494 | |
| 7495 | /* |
| 7496 | * Do a vendor specific scan if possible. If only_new_results is |
| 7497 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 7498 | * cannot be achieved through a vendor scan. The below condition may |
| 7499 | * need to be modified if new scan flags are added in the future whose |
| 7500 | * functionality can only be achieved through a normal scan. |
| 7501 | */ |
| 7502 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 7503 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 7504 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7505 | return wpa_driver_nl80211_scan(bss, params); |
| 7506 | } |
| 7507 | |
| 7508 | |
| 7509 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 7510 | int reason_code) |
| 7511 | { |
| 7512 | struct i802_bss *bss = priv; |
| 7513 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 7514 | } |
| 7515 | |
| 7516 | |
| 7517 | static int driver_nl80211_authenticate(void *priv, |
| 7518 | struct wpa_driver_auth_params *params) |
| 7519 | { |
| 7520 | struct i802_bss *bss = priv; |
| 7521 | return wpa_driver_nl80211_authenticate(bss, params); |
| 7522 | } |
| 7523 | |
| 7524 | |
| 7525 | static void driver_nl80211_deinit(void *priv) |
| 7526 | { |
| 7527 | struct i802_bss *bss = priv; |
| 7528 | wpa_driver_nl80211_deinit(bss); |
| 7529 | } |
| 7530 | |
| 7531 | |
| 7532 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 7533 | const char *ifname) |
| 7534 | { |
| 7535 | struct i802_bss *bss = priv; |
| 7536 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 7537 | } |
| 7538 | |
| 7539 | |
| 7540 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7541 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7542 | unsigned int freq, |
| 7543 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7544 | { |
| 7545 | struct i802_bss *bss = priv; |
| 7546 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7547 | freq, 0, 0, 0, csa_offs, |
| 7548 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7549 | } |
| 7550 | |
| 7551 | |
| 7552 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 7553 | { |
| 7554 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7555 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7556 | } |
| 7557 | |
| 7558 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7559 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 7560 | const char *ifname, int vlan_id) |
| 7561 | { |
| 7562 | struct i802_bss *bss = priv; |
| 7563 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 7564 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7565 | |
| 7566 | |
| 7567 | static int driver_nl80211_read_sta_data(void *priv, |
| 7568 | struct hostap_sta_driver_data *data, |
| 7569 | const u8 *addr) |
| 7570 | { |
| 7571 | struct i802_bss *bss = priv; |
| 7572 | return i802_read_sta_data(bss, data, addr); |
| 7573 | } |
| 7574 | |
| 7575 | |
| 7576 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 7577 | unsigned int wait_time, |
| 7578 | const u8 *dst, const u8 *src, |
| 7579 | const u8 *bssid, |
| 7580 | const u8 *data, size_t data_len, |
| 7581 | int no_cck) |
| 7582 | { |
| 7583 | struct i802_bss *bss = priv; |
| 7584 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 7585 | bssid, data, data_len, no_cck); |
| 7586 | } |
| 7587 | |
| 7588 | |
| 7589 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 7590 | { |
| 7591 | struct i802_bss *bss = priv; |
| 7592 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 7593 | } |
| 7594 | |
| 7595 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7596 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 7597 | const u8 *ies, size_t ies_len) |
| 7598 | { |
| 7599 | int ret; |
| 7600 | struct nl_msg *msg; |
| 7601 | struct i802_bss *bss = priv; |
| 7602 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7603 | u16 mdid = WPA_GET_LE16(md); |
| 7604 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7605 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7606 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 7607 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 7608 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 7609 | nlmsg_free(msg); |
| 7610 | return -ENOBUFS; |
| 7611 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7612 | |
| 7613 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7614 | if (ret) { |
| 7615 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 7616 | "err=%d (%s)", ret, strerror(-ret)); |
| 7617 | } |
| 7618 | |
| 7619 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7620 | } |
| 7621 | |
| 7622 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7623 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
| 7624 | { |
| 7625 | struct i802_bss *bss = priv; |
| 7626 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7627 | |
| 7628 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 7629 | return NULL; |
| 7630 | |
| 7631 | return bss->addr; |
| 7632 | } |
| 7633 | |
| 7634 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7635 | static const char * scan_state_str(enum scan_states scan_state) |
| 7636 | { |
| 7637 | switch (scan_state) { |
| 7638 | case NO_SCAN: |
| 7639 | return "NO_SCAN"; |
| 7640 | case SCAN_REQUESTED: |
| 7641 | return "SCAN_REQUESTED"; |
| 7642 | case SCAN_STARTED: |
| 7643 | return "SCAN_STARTED"; |
| 7644 | case SCAN_COMPLETED: |
| 7645 | return "SCAN_COMPLETED"; |
| 7646 | case SCAN_ABORTED: |
| 7647 | return "SCAN_ABORTED"; |
| 7648 | case SCHED_SCAN_STARTED: |
| 7649 | return "SCHED_SCAN_STARTED"; |
| 7650 | case SCHED_SCAN_STOPPED: |
| 7651 | return "SCHED_SCAN_STOPPED"; |
| 7652 | case SCHED_SCAN_RESULTS: |
| 7653 | return "SCHED_SCAN_RESULTS"; |
| 7654 | } |
| 7655 | |
| 7656 | return "??"; |
| 7657 | } |
| 7658 | |
| 7659 | |
| 7660 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 7661 | { |
| 7662 | struct i802_bss *bss = priv; |
| 7663 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7664 | int res; |
| 7665 | char *pos, *end; |
| 7666 | |
| 7667 | pos = buf; |
| 7668 | end = buf + buflen; |
| 7669 | |
| 7670 | res = os_snprintf(pos, end - pos, |
| 7671 | "ifindex=%d\n" |
| 7672 | "ifname=%s\n" |
| 7673 | "brname=%s\n" |
| 7674 | "addr=" MACSTR "\n" |
| 7675 | "freq=%d\n" |
| 7676 | "%s%s%s%s%s", |
| 7677 | bss->ifindex, |
| 7678 | bss->ifname, |
| 7679 | bss->brname, |
| 7680 | MAC2STR(bss->addr), |
| 7681 | bss->freq, |
| 7682 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 7683 | bss->added_if_into_bridge ? |
| 7684 | "added_if_into_bridge=1\n" : "", |
| 7685 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 7686 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 7687 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7688 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7689 | return pos - buf; |
| 7690 | pos += res; |
| 7691 | |
| 7692 | if (bss->wdev_id_set) { |
| 7693 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 7694 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7695 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7696 | return pos - buf; |
| 7697 | pos += res; |
| 7698 | } |
| 7699 | |
| 7700 | res = os_snprintf(pos, end - pos, |
| 7701 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7702 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7703 | "drv_ifindex=%d\n" |
| 7704 | "operstate=%d\n" |
| 7705 | "scan_state=%s\n" |
| 7706 | "auth_bssid=" MACSTR "\n" |
| 7707 | "auth_attempt_bssid=" MACSTR "\n" |
| 7708 | "bssid=" MACSTR "\n" |
| 7709 | "prev_bssid=" MACSTR "\n" |
| 7710 | "associated=%d\n" |
| 7711 | "assoc_freq=%u\n" |
| 7712 | "monitor_sock=%d\n" |
| 7713 | "monitor_ifidx=%d\n" |
| 7714 | "monitor_refcount=%d\n" |
| 7715 | "last_mgmt_freq=%u\n" |
| 7716 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7717 | "%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] | 7718 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7719 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7720 | drv->ifindex, |
| 7721 | drv->operstate, |
| 7722 | scan_state_str(drv->scan_state), |
| 7723 | MAC2STR(drv->auth_bssid), |
| 7724 | MAC2STR(drv->auth_attempt_bssid), |
| 7725 | MAC2STR(drv->bssid), |
| 7726 | MAC2STR(drv->prev_bssid), |
| 7727 | drv->associated, |
| 7728 | drv->assoc_freq, |
| 7729 | drv->monitor_sock, |
| 7730 | drv->monitor_ifidx, |
| 7731 | drv->monitor_refcount, |
| 7732 | drv->last_mgmt_freq, |
| 7733 | drv->eapol_tx_sock, |
| 7734 | drv->ignore_if_down_event ? |
| 7735 | "ignore_if_down_event=1\n" : "", |
| 7736 | drv->scan_complete_events ? |
| 7737 | "scan_complete_events=1\n" : "", |
| 7738 | drv->disabled_11b_rates ? |
| 7739 | "disabled_11b_rates=1\n" : "", |
| 7740 | drv->pending_remain_on_chan ? |
| 7741 | "pending_remain_on_chan=1\n" : "", |
| 7742 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 7743 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 7744 | drv->poll_command_supported ? |
| 7745 | "poll_command_supported=1\n" : "", |
| 7746 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 7747 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 7748 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 7749 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 7750 | drv->ignore_next_local_disconnect ? |
| 7751 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 7752 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7753 | "ignore_next_local_deauth=1\n" : ""); |
| 7754 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7755 | return pos - buf; |
| 7756 | pos += res; |
| 7757 | |
| 7758 | if (drv->has_capability) { |
| 7759 | res = os_snprintf(pos, end - pos, |
| 7760 | "capa.key_mgmt=0x%x\n" |
| 7761 | "capa.enc=0x%x\n" |
| 7762 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7763 | "capa.flags=0x%llx\n" |
| 7764 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7765 | "capa.max_scan_ssids=%d\n" |
| 7766 | "capa.max_sched_scan_ssids=%d\n" |
| 7767 | "capa.sched_scan_supported=%d\n" |
| 7768 | "capa.max_match_sets=%d\n" |
| 7769 | "capa.max_remain_on_chan=%u\n" |
| 7770 | "capa.max_stations=%u\n" |
| 7771 | "capa.probe_resp_offloads=0x%x\n" |
| 7772 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7773 | "capa.num_multichan_concurrent=%u\n" |
| 7774 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7775 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 7776 | "capa.conc_capab=%u\n" |
| 7777 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7778 | "capa.max_conc_chan_5_0=%u\n" |
| 7779 | "capa.max_sched_scan_plans=%u\n" |
| 7780 | "capa.max_sched_scan_plan_interval=%u\n" |
| 7781 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7782 | drv->capa.key_mgmt, |
| 7783 | drv->capa.enc, |
| 7784 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7785 | (unsigned long long) drv->capa.flags, |
| 7786 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7787 | drv->capa.max_scan_ssids, |
| 7788 | drv->capa.max_sched_scan_ssids, |
| 7789 | drv->capa.sched_scan_supported, |
| 7790 | drv->capa.max_match_sets, |
| 7791 | drv->capa.max_remain_on_chan, |
| 7792 | drv->capa.max_stations, |
| 7793 | drv->capa.probe_resp_offloads, |
| 7794 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7795 | drv->capa.num_multichan_concurrent, |
| 7796 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7797 | drv->capa.mac_addr_rand_scan_supported, |
| 7798 | drv->capa.conc_capab, |
| 7799 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7800 | drv->capa.max_conc_chan_5_0, |
| 7801 | drv->capa.max_sched_scan_plans, |
| 7802 | drv->capa.max_sched_scan_plan_interval, |
| 7803 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7804 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7805 | return pos - buf; |
| 7806 | pos += res; |
| 7807 | } |
| 7808 | |
| 7809 | return pos - buf; |
| 7810 | } |
| 7811 | |
| 7812 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7813 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 7814 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7815 | if ((settings->head && |
| 7816 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 7817 | settings->head_len, settings->head)) || |
| 7818 | (settings->tail && |
| 7819 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 7820 | settings->tail_len, settings->tail)) || |
| 7821 | (settings->beacon_ies && |
| 7822 | nla_put(msg, NL80211_ATTR_IE, |
| 7823 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 7824 | (settings->proberesp_ies && |
| 7825 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 7826 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 7827 | (settings->assocresp_ies && |
| 7828 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 7829 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 7830 | (settings->probe_resp && |
| 7831 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 7832 | settings->probe_resp_len, settings->probe_resp))) |
| 7833 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7834 | |
| 7835 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7836 | } |
| 7837 | |
| 7838 | |
| 7839 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 7840 | { |
| 7841 | struct nl_msg *msg; |
| 7842 | struct i802_bss *bss = priv; |
| 7843 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7844 | struct nlattr *beacon_csa; |
| 7845 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7846 | int csa_off_len = 0; |
| 7847 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7848 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7849 | 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] | 7850 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7851 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 7852 | settings->freq_params.center_freq1, |
| 7853 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7854 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7855 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7856 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 7857 | return -EOPNOTSUPP; |
| 7858 | } |
| 7859 | |
| 7860 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 7861 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 7862 | return -EOPNOTSUPP; |
| 7863 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7864 | /* |
| 7865 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 7866 | * counters match. This implementation assumes that there are only two |
| 7867 | * counters. |
| 7868 | */ |
| 7869 | if (settings->counter_offset_beacon[0] && |
| 7870 | !settings->counter_offset_beacon[1]) { |
| 7871 | csa_off_len = 1; |
| 7872 | } else if (settings->counter_offset_beacon[1] && |
| 7873 | !settings->counter_offset_beacon[0]) { |
| 7874 | csa_off_len = 1; |
| 7875 | settings->counter_offset_beacon[0] = |
| 7876 | settings->counter_offset_beacon[1]; |
| 7877 | settings->counter_offset_presp[0] = |
| 7878 | settings->counter_offset_presp[1]; |
| 7879 | } else if (settings->counter_offset_beacon[1] && |
| 7880 | settings->counter_offset_beacon[0]) { |
| 7881 | csa_off_len = 2; |
| 7882 | } else { |
| 7883 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 7884 | return -EINVAL; |
| 7885 | } |
| 7886 | |
| 7887 | /* Check CSA counters validity */ |
| 7888 | if (drv->capa.max_csa_counters && |
| 7889 | csa_off_len > drv->capa.max_csa_counters) { |
| 7890 | wpa_printf(MSG_ERROR, |
| 7891 | "nl80211: Too many CSA counters provided"); |
| 7892 | return -EINVAL; |
| 7893 | } |
| 7894 | |
| 7895 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7896 | return -EINVAL; |
| 7897 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7898 | for (i = 0; i < csa_off_len; i++) { |
| 7899 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 7900 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 7901 | |
| 7902 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 7903 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 7904 | settings->cs_count)) |
| 7905 | return -EINVAL; |
| 7906 | |
| 7907 | if (settings->beacon_csa.probe_resp && |
| 7908 | ((settings->beacon_csa.probe_resp_len <= |
| 7909 | csa_c_off_presp) || |
| 7910 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 7911 | settings->cs_count))) |
| 7912 | return -EINVAL; |
| 7913 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7914 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7915 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 7916 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 7917 | settings->cs_count) || |
| 7918 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 7919 | (settings->block_tx && |
| 7920 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7921 | goto error; |
| 7922 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7923 | /* beacon_after params */ |
| 7924 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 7925 | if (ret) |
| 7926 | goto error; |
| 7927 | |
| 7928 | /* beacon_csa params */ |
| 7929 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 7930 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7931 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7932 | |
| 7933 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 7934 | if (ret) |
| 7935 | goto error; |
| 7936 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7937 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 7938 | csa_off_len * sizeof(u16), |
| 7939 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7940 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7941 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 7942 | csa_off_len * sizeof(u16), |
| 7943 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7944 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7945 | |
| 7946 | nla_nest_end(msg, beacon_csa); |
| 7947 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7948 | if (ret) { |
| 7949 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 7950 | ret, strerror(-ret)); |
| 7951 | } |
| 7952 | return ret; |
| 7953 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7954 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7955 | ret = -ENOBUFS; |
| 7956 | error: |
| 7957 | nlmsg_free(msg); |
| 7958 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 7959 | return ret; |
| 7960 | } |
| 7961 | |
| 7962 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7963 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 7964 | u8 user_priority, u16 admitted_time) |
| 7965 | { |
| 7966 | struct i802_bss *bss = priv; |
| 7967 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7968 | struct nl_msg *msg; |
| 7969 | int ret; |
| 7970 | |
| 7971 | wpa_printf(MSG_DEBUG, |
| 7972 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 7973 | tsid, admitted_time, user_priority); |
| 7974 | |
| 7975 | if (!is_sta_interface(drv->nlmode)) |
| 7976 | return -ENOTSUP; |
| 7977 | |
| 7978 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 7979 | if (!msg || |
| 7980 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7981 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7982 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 7983 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 7984 | nlmsg_free(msg); |
| 7985 | return -ENOBUFS; |
| 7986 | } |
| 7987 | |
| 7988 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7989 | if (ret) |
| 7990 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 7991 | ret, strerror(-ret)); |
| 7992 | return ret; |
| 7993 | } |
| 7994 | |
| 7995 | |
| 7996 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 7997 | { |
| 7998 | struct i802_bss *bss = priv; |
| 7999 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8000 | struct nl_msg *msg; |
| 8001 | int ret; |
| 8002 | |
| 8003 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 8004 | |
| 8005 | if (!is_sta_interface(drv->nlmode)) |
| 8006 | return -ENOTSUP; |
| 8007 | |
| 8008 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 8009 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8010 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8011 | nlmsg_free(msg); |
| 8012 | return -ENOBUFS; |
| 8013 | } |
| 8014 | |
| 8015 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8016 | if (ret) |
| 8017 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 8018 | ret, strerror(-ret)); |
| 8019 | return ret; |
| 8020 | } |
| 8021 | |
| 8022 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8023 | #ifdef CONFIG_TESTING_OPTIONS |
| 8024 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 8025 | { |
| 8026 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8027 | struct wpabuf *buf = arg; |
| 8028 | |
| 8029 | if (!buf) |
| 8030 | return NL_SKIP; |
| 8031 | |
| 8032 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 8033 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 8034 | return NL_SKIP; |
| 8035 | } |
| 8036 | |
| 8037 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 8038 | genlmsg_attrlen(gnlh, 0)); |
| 8039 | |
| 8040 | return NL_SKIP; |
| 8041 | } |
| 8042 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8043 | |
| 8044 | |
| 8045 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 8046 | { |
| 8047 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8048 | struct nlattr *nl_vendor_reply, *nl; |
| 8049 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8050 | struct wpabuf *buf = arg; |
| 8051 | int rem; |
| 8052 | |
| 8053 | if (!buf) |
| 8054 | return NL_SKIP; |
| 8055 | |
| 8056 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8057 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8058 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8059 | |
| 8060 | if (!nl_vendor_reply) |
| 8061 | return NL_SKIP; |
| 8062 | |
| 8063 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 8064 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 8065 | return NL_SKIP; |
| 8066 | } |
| 8067 | |
| 8068 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 8069 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 8070 | } |
| 8071 | |
| 8072 | return NL_SKIP; |
| 8073 | } |
| 8074 | |
| 8075 | |
| 8076 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 8077 | unsigned int subcmd, const u8 *data, |
| 8078 | size_t data_len, struct wpabuf *buf) |
| 8079 | { |
| 8080 | struct i802_bss *bss = priv; |
| 8081 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8082 | struct nl_msg *msg; |
| 8083 | int ret; |
| 8084 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8085 | #ifdef CONFIG_TESTING_OPTIONS |
| 8086 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8087 | msg = nlmsg_alloc(); |
| 8088 | if (!msg) |
| 8089 | return -ENOMEM; |
| 8090 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8091 | nl80211_cmd(drv, msg, 0, subcmd); |
| 8092 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 8093 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8094 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8095 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 8096 | if (ret) |
| 8097 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 8098 | ret); |
| 8099 | return ret; |
| 8100 | } |
| 8101 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8102 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8103 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 8104 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 8105 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 8106 | (data && |
| 8107 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 8108 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8109 | |
| 8110 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 8111 | if (ret) |
| 8112 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 8113 | ret); |
| 8114 | return ret; |
| 8115 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8116 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8117 | nlmsg_free(msg); |
| 8118 | return -ENOBUFS; |
| 8119 | } |
| 8120 | |
| 8121 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8122 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 8123 | u8 qos_map_set_len) |
| 8124 | { |
| 8125 | struct i802_bss *bss = priv; |
| 8126 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8127 | struct nl_msg *msg; |
| 8128 | int ret; |
| 8129 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8130 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 8131 | qos_map_set, qos_map_set_len); |
| 8132 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8133 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 8134 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 8135 | nlmsg_free(msg); |
| 8136 | return -ENOBUFS; |
| 8137 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8138 | |
| 8139 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8140 | if (ret) |
| 8141 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 8142 | |
| 8143 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8144 | } |
| 8145 | |
| 8146 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8147 | static int nl80211_set_wowlan(void *priv, |
| 8148 | const struct wowlan_triggers *triggers) |
| 8149 | { |
| 8150 | struct i802_bss *bss = priv; |
| 8151 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8152 | struct nl_msg *msg; |
| 8153 | struct nlattr *wowlan_triggers; |
| 8154 | int ret; |
| 8155 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8156 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 8157 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8158 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8159 | !(wowlan_triggers = nla_nest_start(msg, |
| 8160 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 8161 | (triggers->any && |
| 8162 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 8163 | (triggers->disconnect && |
| 8164 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 8165 | (triggers->magic_pkt && |
| 8166 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 8167 | (triggers->gtk_rekey_failure && |
| 8168 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 8169 | (triggers->eap_identity_req && |
| 8170 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 8171 | (triggers->four_way_handshake && |
| 8172 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 8173 | (triggers->rfkill_release && |
| 8174 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 8175 | nlmsg_free(msg); |
| 8176 | return -ENOBUFS; |
| 8177 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8178 | |
| 8179 | nla_nest_end(msg, wowlan_triggers); |
| 8180 | |
| 8181 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8182 | if (ret) |
| 8183 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 8184 | |
| 8185 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8186 | } |
| 8187 | |
| 8188 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8189 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8190 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 8191 | { |
| 8192 | struct i802_bss *bss = priv; |
| 8193 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8194 | struct nl_msg *msg; |
| 8195 | struct nlattr *params; |
| 8196 | |
| 8197 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 8198 | |
| 8199 | if (!drv->roaming_vendor_cmd_avail) { |
| 8200 | wpa_printf(MSG_DEBUG, |
| 8201 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 8202 | return -1; |
| 8203 | } |
| 8204 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8205 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8206 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8207 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8208 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 8209 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8210 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 8211 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 8212 | QCA_ROAMING_NOT_ALLOWED) || |
| 8213 | (bssid && |
| 8214 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 8215 | nlmsg_free(msg); |
| 8216 | return -1; |
| 8217 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8218 | nla_nest_end(msg, params); |
| 8219 | |
| 8220 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8221 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8222 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8223 | |
| 8224 | |
| 8225 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 8226 | { |
| 8227 | struct i802_bss *bss = priv; |
| 8228 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8229 | int new_addr = addr != NULL; |
| 8230 | |
| 8231 | if (!addr) |
| 8232 | addr = drv->perm_addr; |
| 8233 | |
| 8234 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 8235 | return -1; |
| 8236 | |
| 8237 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 8238 | { |
| 8239 | wpa_printf(MSG_DEBUG, |
| 8240 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 8241 | bss->ifname, MAC2STR(addr)); |
| 8242 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 8243 | 1) < 0) { |
| 8244 | wpa_printf(MSG_DEBUG, |
| 8245 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 8246 | } |
| 8247 | return -1; |
| 8248 | } |
| 8249 | |
| 8250 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 8251 | bss->ifname, MAC2STR(addr)); |
| 8252 | drv->addr_changed = new_addr; |
| 8253 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 8254 | |
| 8255 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 8256 | { |
| 8257 | wpa_printf(MSG_DEBUG, |
| 8258 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 8259 | } |
| 8260 | |
| 8261 | return 0; |
| 8262 | } |
| 8263 | |
| 8264 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8265 | #ifdef CONFIG_MESH |
| 8266 | |
| 8267 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 8268 | { |
| 8269 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 8270 | wpa_printf(MSG_INFO, |
| 8271 | "nl80211: Failed to set interface into mesh mode"); |
| 8272 | return -1; |
| 8273 | } |
| 8274 | return 0; |
| 8275 | } |
| 8276 | |
| 8277 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8278 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 8279 | size_t mesh_id_len) |
| 8280 | { |
| 8281 | if (mesh_id) { |
| 8282 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 8283 | mesh_id, mesh_id_len); |
| 8284 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 8285 | } |
| 8286 | |
| 8287 | return 0; |
| 8288 | } |
| 8289 | |
| 8290 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8291 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8292 | struct wpa_driver_mesh_join_params *params) |
| 8293 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8294 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8295 | struct nl_msg *msg; |
| 8296 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8297 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8298 | |
| 8299 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 8300 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8301 | if (!msg || |
| 8302 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 8303 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 8304 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
| 8305 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8306 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8307 | |
| 8308 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 8309 | |
| 8310 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 8311 | if (!container) |
| 8312 | goto fail; |
| 8313 | |
| 8314 | if (params->ies) { |
| 8315 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 8316 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 8317 | params->ies)) |
| 8318 | goto fail; |
| 8319 | } |
| 8320 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 8321 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 8322 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 8323 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 8324 | goto fail; |
| 8325 | } |
| 8326 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 8327 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 8328 | goto fail; |
| 8329 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 8330 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 8331 | goto fail; |
| 8332 | nla_nest_end(msg, container); |
| 8333 | |
| 8334 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 8335 | if (!container) |
| 8336 | goto fail; |
| 8337 | |
| 8338 | if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
| 8339 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0)) |
| 8340 | goto fail; |
| 8341 | if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) && |
| 8342 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 8343 | params->max_peer_links)) |
| 8344 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8345 | |
| 8346 | /* |
| 8347 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 8348 | * the timer could disconnect stations even in that case. |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8349 | */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8350 | if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 8351 | params->conf.peer_link_timeout)) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8352 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 8353 | goto fail; |
| 8354 | } |
| 8355 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8356 | nla_nest_end(msg, container); |
| 8357 | |
| 8358 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8359 | msg = NULL; |
| 8360 | if (ret) { |
| 8361 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 8362 | ret, strerror(-ret)); |
| 8363 | goto fail; |
| 8364 | } |
| 8365 | ret = 0; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8366 | bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8367 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 8368 | |
| 8369 | fail: |
| 8370 | nlmsg_free(msg); |
| 8371 | return ret; |
| 8372 | } |
| 8373 | |
| 8374 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8375 | static int |
| 8376 | wpa_driver_nl80211_join_mesh(void *priv, |
| 8377 | struct wpa_driver_mesh_join_params *params) |
| 8378 | { |
| 8379 | struct i802_bss *bss = priv; |
| 8380 | int ret, timeout; |
| 8381 | |
| 8382 | timeout = params->conf.peer_link_timeout; |
| 8383 | |
| 8384 | /* Disable kernel inactivity timer */ |
| 8385 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 8386 | params->conf.peer_link_timeout = 0; |
| 8387 | |
| 8388 | ret = nl80211_join_mesh(bss, params); |
| 8389 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 8390 | wpa_printf(MSG_DEBUG, |
| 8391 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 8392 | /* |
| 8393 | * Old kernel does not support setting |
| 8394 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 8395 | * into future from peer_link_timeout. |
| 8396 | */ |
| 8397 | params->conf.peer_link_timeout = timeout + 60; |
| 8398 | ret = nl80211_join_mesh(priv, params); |
| 8399 | } |
| 8400 | |
| 8401 | params->conf.peer_link_timeout = timeout; |
| 8402 | return ret; |
| 8403 | } |
| 8404 | |
| 8405 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8406 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 8407 | { |
| 8408 | struct i802_bss *bss = priv; |
| 8409 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8410 | struct nl_msg *msg; |
| 8411 | int ret; |
| 8412 | |
| 8413 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 8414 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 8415 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8416 | if (ret) { |
| 8417 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 8418 | ret, strerror(-ret)); |
| 8419 | } else { |
| 8420 | wpa_printf(MSG_DEBUG, |
| 8421 | "nl80211: mesh leave request send successfully"); |
| 8422 | } |
| 8423 | |
| 8424 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 8425 | NL80211_IFTYPE_STATION)) { |
| 8426 | wpa_printf(MSG_INFO, |
| 8427 | "nl80211: Failed to set interface into station mode"); |
| 8428 | } |
| 8429 | return ret; |
| 8430 | } |
| 8431 | |
| 8432 | #endif /* CONFIG_MESH */ |
| 8433 | |
| 8434 | |
| 8435 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 8436 | const u8 *ipaddr, int prefixlen, |
| 8437 | const u8 *addr) |
| 8438 | { |
| 8439 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8440 | struct i802_bss *bss = priv; |
| 8441 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8442 | struct rtnl_neigh *rn; |
| 8443 | struct nl_addr *nl_ipaddr = NULL; |
| 8444 | struct nl_addr *nl_lladdr = NULL; |
| 8445 | int family, addrsize; |
| 8446 | int res; |
| 8447 | |
| 8448 | if (!ipaddr || prefixlen == 0 || !addr) |
| 8449 | return -EINVAL; |
| 8450 | |
| 8451 | if (bss->br_ifindex == 0) { |
| 8452 | wpa_printf(MSG_DEBUG, |
| 8453 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 8454 | return -1; |
| 8455 | } |
| 8456 | |
| 8457 | if (!drv->rtnl_sk) { |
| 8458 | wpa_printf(MSG_DEBUG, |
| 8459 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8460 | return -1; |
| 8461 | } |
| 8462 | |
| 8463 | if (version == 4) { |
| 8464 | family = AF_INET; |
| 8465 | addrsize = 4; |
| 8466 | } else if (version == 6) { |
| 8467 | family = AF_INET6; |
| 8468 | addrsize = 16; |
| 8469 | } else { |
| 8470 | return -EINVAL; |
| 8471 | } |
| 8472 | |
| 8473 | rn = rtnl_neigh_alloc(); |
| 8474 | if (rn == NULL) |
| 8475 | return -ENOMEM; |
| 8476 | |
| 8477 | /* set the destination ip address for neigh */ |
| 8478 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8479 | if (nl_ipaddr == NULL) { |
| 8480 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8481 | res = -ENOMEM; |
| 8482 | goto errout; |
| 8483 | } |
| 8484 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 8485 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8486 | if (res) { |
| 8487 | wpa_printf(MSG_DEBUG, |
| 8488 | "nl80211: neigh set destination addr failed"); |
| 8489 | goto errout; |
| 8490 | } |
| 8491 | |
| 8492 | /* set the corresponding lladdr for neigh */ |
| 8493 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 8494 | if (nl_lladdr == NULL) { |
| 8495 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 8496 | res = -ENOMEM; |
| 8497 | goto errout; |
| 8498 | } |
| 8499 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 8500 | |
| 8501 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8502 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 8503 | |
| 8504 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 8505 | if (res) { |
| 8506 | wpa_printf(MSG_DEBUG, |
| 8507 | "nl80211: Adding bridge ip neigh failed: %s", |
| 8508 | strerror(errno)); |
| 8509 | } |
| 8510 | errout: |
| 8511 | if (nl_lladdr) |
| 8512 | nl_addr_put(nl_lladdr); |
| 8513 | if (nl_ipaddr) |
| 8514 | nl_addr_put(nl_ipaddr); |
| 8515 | if (rn) |
| 8516 | rtnl_neigh_put(rn); |
| 8517 | return res; |
| 8518 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8519 | return -1; |
| 8520 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8521 | } |
| 8522 | |
| 8523 | |
| 8524 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 8525 | const u8 *ipaddr) |
| 8526 | { |
| 8527 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8528 | struct i802_bss *bss = priv; |
| 8529 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8530 | struct rtnl_neigh *rn; |
| 8531 | struct nl_addr *nl_ipaddr; |
| 8532 | int family, addrsize; |
| 8533 | int res; |
| 8534 | |
| 8535 | if (!ipaddr) |
| 8536 | return -EINVAL; |
| 8537 | |
| 8538 | if (version == 4) { |
| 8539 | family = AF_INET; |
| 8540 | addrsize = 4; |
| 8541 | } else if (version == 6) { |
| 8542 | family = AF_INET6; |
| 8543 | addrsize = 16; |
| 8544 | } else { |
| 8545 | return -EINVAL; |
| 8546 | } |
| 8547 | |
| 8548 | if (bss->br_ifindex == 0) { |
| 8549 | wpa_printf(MSG_DEBUG, |
| 8550 | "nl80211: bridge must be set to delete an ip neigh"); |
| 8551 | return -1; |
| 8552 | } |
| 8553 | |
| 8554 | if (!drv->rtnl_sk) { |
| 8555 | wpa_printf(MSG_DEBUG, |
| 8556 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8557 | return -1; |
| 8558 | } |
| 8559 | |
| 8560 | rn = rtnl_neigh_alloc(); |
| 8561 | if (rn == NULL) |
| 8562 | return -ENOMEM; |
| 8563 | |
| 8564 | /* set the destination ip address for neigh */ |
| 8565 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8566 | if (nl_ipaddr == NULL) { |
| 8567 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8568 | res = -ENOMEM; |
| 8569 | goto errout; |
| 8570 | } |
| 8571 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8572 | if (res) { |
| 8573 | wpa_printf(MSG_DEBUG, |
| 8574 | "nl80211: neigh set destination addr failed"); |
| 8575 | goto errout; |
| 8576 | } |
| 8577 | |
| 8578 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8579 | |
| 8580 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 8581 | if (res) { |
| 8582 | wpa_printf(MSG_DEBUG, |
| 8583 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 8584 | strerror(errno)); |
| 8585 | } |
| 8586 | errout: |
| 8587 | if (nl_ipaddr) |
| 8588 | nl_addr_put(nl_ipaddr); |
| 8589 | if (rn) |
| 8590 | rtnl_neigh_put(rn); |
| 8591 | return res; |
| 8592 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8593 | return -1; |
| 8594 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8595 | } |
| 8596 | |
| 8597 | |
| 8598 | static int linux_write_system_file(const char *path, unsigned int val) |
| 8599 | { |
| 8600 | char buf[50]; |
| 8601 | int fd, len; |
| 8602 | |
| 8603 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 8604 | if (os_snprintf_error(sizeof(buf), len)) |
| 8605 | return -1; |
| 8606 | |
| 8607 | fd = open(path, O_WRONLY); |
| 8608 | if (fd < 0) |
| 8609 | return -1; |
| 8610 | |
| 8611 | if (write(fd, buf, len) < 0) { |
| 8612 | wpa_printf(MSG_DEBUG, |
| 8613 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 8614 | path, val); |
| 8615 | close(fd); |
| 8616 | return -1; |
| 8617 | } |
| 8618 | close(fd); |
| 8619 | |
| 8620 | return 0; |
| 8621 | } |
| 8622 | |
| 8623 | |
| 8624 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 8625 | { |
| 8626 | switch (attr) { |
| 8627 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 8628 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8629 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 8630 | return "hairpin_mode"; |
| 8631 | } |
| 8632 | |
| 8633 | return NULL; |
| 8634 | } |
| 8635 | |
| 8636 | |
| 8637 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 8638 | unsigned int val) |
| 8639 | { |
| 8640 | struct i802_bss *bss = priv; |
| 8641 | char path[128]; |
| 8642 | const char *attr_txt; |
| 8643 | |
| 8644 | attr_txt = drv_br_port_attr_str(attr); |
| 8645 | if (attr_txt == NULL) |
| 8646 | return -EINVAL; |
| 8647 | |
| 8648 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 8649 | bss->ifname, attr_txt); |
| 8650 | |
| 8651 | if (linux_write_system_file(path, val)) |
| 8652 | return -1; |
| 8653 | |
| 8654 | return 0; |
| 8655 | } |
| 8656 | |
| 8657 | |
| 8658 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 8659 | { |
| 8660 | switch (param) { |
| 8661 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8662 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8663 | default: |
| 8664 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8665 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8666 | } |
| 8667 | |
| 8668 | |
| 8669 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 8670 | unsigned int val) |
| 8671 | { |
| 8672 | struct i802_bss *bss = priv; |
| 8673 | char path[128]; |
| 8674 | const char *param_txt; |
| 8675 | int ip_version = 4; |
| 8676 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8677 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 8678 | os_snprintf(path, sizeof(path), |
| 8679 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 8680 | bss->brname); |
| 8681 | goto set_val; |
| 8682 | } |
| 8683 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8684 | param_txt = drv_br_net_param_str(param); |
| 8685 | if (param_txt == NULL) |
| 8686 | return -EINVAL; |
| 8687 | |
| 8688 | switch (param) { |
| 8689 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8690 | ip_version = 4; |
| 8691 | break; |
| 8692 | default: |
| 8693 | return -EINVAL; |
| 8694 | } |
| 8695 | |
| 8696 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 8697 | ip_version, bss->brname, param_txt); |
| 8698 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8699 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8700 | if (linux_write_system_file(path, val)) |
| 8701 | return -1; |
| 8702 | |
| 8703 | return 0; |
| 8704 | } |
| 8705 | |
| 8706 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8707 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8708 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8709 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 8710 | { |
| 8711 | switch (hw_mode) { |
| 8712 | case HOSTAPD_MODE_IEEE80211B: |
| 8713 | return QCA_ACS_MODE_IEEE80211B; |
| 8714 | case HOSTAPD_MODE_IEEE80211G: |
| 8715 | return QCA_ACS_MODE_IEEE80211G; |
| 8716 | case HOSTAPD_MODE_IEEE80211A: |
| 8717 | return QCA_ACS_MODE_IEEE80211A; |
| 8718 | case HOSTAPD_MODE_IEEE80211AD: |
| 8719 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 8720 | case HOSTAPD_MODE_IEEE80211ANY: |
| 8721 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8722 | default: |
| 8723 | return -1; |
| 8724 | } |
| 8725 | } |
| 8726 | |
| 8727 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8728 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 8729 | { |
| 8730 | int i, len, ret; |
| 8731 | u32 *freqs; |
| 8732 | |
| 8733 | if (!freq_list) |
| 8734 | return 0; |
| 8735 | len = int_array_len(freq_list); |
| 8736 | freqs = os_malloc(sizeof(u32) * len); |
| 8737 | if (!freqs) |
| 8738 | return -1; |
| 8739 | for (i = 0; i < len; i++) |
| 8740 | freqs[i] = freq_list[i]; |
| 8741 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 8742 | sizeof(u32) * len, freqs); |
| 8743 | os_free(freqs); |
| 8744 | return ret; |
| 8745 | } |
| 8746 | |
| 8747 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8748 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 8749 | { |
| 8750 | struct i802_bss *bss = priv; |
| 8751 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8752 | struct nl_msg *msg; |
| 8753 | struct nlattr *data; |
| 8754 | int ret; |
| 8755 | int mode; |
| 8756 | |
| 8757 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 8758 | if (mode < 0) |
| 8759 | return -1; |
| 8760 | |
| 8761 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8762 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8763 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8764 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 8765 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8766 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 8767 | (params->ht_enabled && |
| 8768 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 8769 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8770 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 8771 | (params->vht_enabled && |
| 8772 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 8773 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 8774 | params->ch_width) || |
| 8775 | (params->ch_list_len && |
| 8776 | 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] | 8777 | params->ch_list)) || |
| 8778 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8779 | nlmsg_free(msg); |
| 8780 | return -ENOBUFS; |
| 8781 | } |
| 8782 | nla_nest_end(msg, data); |
| 8783 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8784 | wpa_printf(MSG_DEBUG, |
| 8785 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 8786 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 8787 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 8788 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8789 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8790 | if (ret) { |
| 8791 | wpa_printf(MSG_DEBUG, |
| 8792 | "nl80211: Failed to invoke driver ACS function: %s", |
| 8793 | strerror(errno)); |
| 8794 | } |
| 8795 | return ret; |
| 8796 | } |
| 8797 | |
| 8798 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 8799 | static int nl80211_set_band(void *priv, enum set_band band) |
| 8800 | { |
| 8801 | struct i802_bss *bss = priv; |
| 8802 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8803 | struct nl_msg *msg; |
| 8804 | struct nlattr *data; |
| 8805 | int ret; |
| 8806 | enum qca_set_band qca_band; |
| 8807 | |
| 8808 | if (!drv->setband_vendor_cmd_avail) |
| 8809 | return -1; |
| 8810 | |
| 8811 | switch (band) { |
| 8812 | case WPA_SETBAND_AUTO: |
| 8813 | qca_band = QCA_SETBAND_AUTO; |
| 8814 | break; |
| 8815 | case WPA_SETBAND_5G: |
| 8816 | qca_band = QCA_SETBAND_5G; |
| 8817 | break; |
| 8818 | case WPA_SETBAND_2G: |
| 8819 | qca_band = QCA_SETBAND_2G; |
| 8820 | break; |
| 8821 | default: |
| 8822 | return -1; |
| 8823 | } |
| 8824 | |
| 8825 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8826 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8827 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8828 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 8829 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8830 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 8831 | nlmsg_free(msg); |
| 8832 | return -ENOBUFS; |
| 8833 | } |
| 8834 | nla_nest_end(msg, data); |
| 8835 | |
| 8836 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8837 | if (ret) { |
| 8838 | wpa_printf(MSG_DEBUG, |
| 8839 | "nl80211: Driver setband function failed: %s", |
| 8840 | strerror(errno)); |
| 8841 | } |
| 8842 | return ret; |
| 8843 | } |
| 8844 | |
| 8845 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8846 | struct nl80211_pcl { |
| 8847 | unsigned int num; |
| 8848 | unsigned int *freq_list; |
| 8849 | }; |
| 8850 | |
| 8851 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 8852 | { |
| 8853 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8854 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8855 | struct nl80211_pcl *param = arg; |
| 8856 | struct nlattr *nl_vend, *attr; |
| 8857 | enum qca_iface_type iface_type; |
| 8858 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 8859 | unsigned int num, max_num; |
| 8860 | u32 *freqs; |
| 8861 | |
| 8862 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8863 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8864 | |
| 8865 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8866 | if (!nl_vend) |
| 8867 | return NL_SKIP; |
| 8868 | |
| 8869 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 8870 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 8871 | |
| 8872 | attr = tb_vendor[ |
| 8873 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 8874 | if (!attr) { |
| 8875 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 8876 | param->num = 0; |
| 8877 | return NL_SKIP; |
| 8878 | } |
| 8879 | |
| 8880 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 8881 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 8882 | iface_type); |
| 8883 | |
| 8884 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 8885 | if (!attr) { |
| 8886 | wpa_printf(MSG_ERROR, |
| 8887 | "nl80211: preferred_freq_list couldn't be found"); |
| 8888 | param->num = 0; |
| 8889 | return NL_SKIP; |
| 8890 | } |
| 8891 | |
| 8892 | /* |
| 8893 | * param->num has the maximum number of entries for which there |
| 8894 | * is room in the freq_list provided by the caller. |
| 8895 | */ |
| 8896 | freqs = nla_data(attr); |
| 8897 | max_num = nla_len(attr) / sizeof(u32); |
| 8898 | if (max_num > param->num) |
| 8899 | max_num = param->num; |
| 8900 | for (num = 0; num < max_num; num++) |
| 8901 | param->freq_list[num] = freqs[num]; |
| 8902 | param->num = num; |
| 8903 | |
| 8904 | return NL_SKIP; |
| 8905 | } |
| 8906 | |
| 8907 | |
| 8908 | static int nl80211_get_pref_freq_list(void *priv, |
| 8909 | enum wpa_driver_if_type if_type, |
| 8910 | unsigned int *num, |
| 8911 | unsigned int *freq_list) |
| 8912 | { |
| 8913 | struct i802_bss *bss = priv; |
| 8914 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8915 | struct nl_msg *msg; |
| 8916 | int ret; |
| 8917 | unsigned int i; |
| 8918 | struct nlattr *params; |
| 8919 | struct nl80211_pcl param; |
| 8920 | enum qca_iface_type iface_type; |
| 8921 | |
| 8922 | if (!drv->get_pref_freq_list) |
| 8923 | return -1; |
| 8924 | |
| 8925 | switch (if_type) { |
| 8926 | case WPA_IF_STATION: |
| 8927 | iface_type = QCA_IFACE_TYPE_STA; |
| 8928 | break; |
| 8929 | case WPA_IF_AP_BSS: |
| 8930 | iface_type = QCA_IFACE_TYPE_AP; |
| 8931 | break; |
| 8932 | case WPA_IF_P2P_GO: |
| 8933 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 8934 | break; |
| 8935 | case WPA_IF_P2P_CLIENT: |
| 8936 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 8937 | break; |
| 8938 | case WPA_IF_IBSS: |
| 8939 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 8940 | break; |
| 8941 | case WPA_IF_TDLS: |
| 8942 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 8943 | break; |
| 8944 | default: |
| 8945 | return -1; |
| 8946 | } |
| 8947 | |
| 8948 | param.num = *num; |
| 8949 | param.freq_list = freq_list; |
| 8950 | |
| 8951 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8952 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 8953 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8954 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8955 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 8956 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8957 | nla_put_u32(msg, |
| 8958 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 8959 | iface_type)) { |
| 8960 | wpa_printf(MSG_ERROR, |
| 8961 | "%s: err in adding vendor_cmd and vendor_data", |
| 8962 | __func__); |
| 8963 | nlmsg_free(msg); |
| 8964 | return -1; |
| 8965 | } |
| 8966 | nla_nest_end(msg, params); |
| 8967 | |
| 8968 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 8969 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 8970 | if (ret) { |
| 8971 | wpa_printf(MSG_ERROR, |
| 8972 | "%s: err in send_and_recv_msgs", __func__); |
| 8973 | return ret; |
| 8974 | } |
| 8975 | |
| 8976 | *num = param.num; |
| 8977 | |
| 8978 | for (i = 0; i < *num; i++) { |
| 8979 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 8980 | i, freq_list[i]); |
| 8981 | } |
| 8982 | |
| 8983 | return 0; |
| 8984 | } |
| 8985 | |
| 8986 | |
| 8987 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 8988 | { |
| 8989 | struct i802_bss *bss = priv; |
| 8990 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8991 | struct nl_msg *msg; |
| 8992 | int ret; |
| 8993 | struct nlattr *params; |
| 8994 | |
| 8995 | if (!drv->set_prob_oper_freq) |
| 8996 | return -1; |
| 8997 | |
| 8998 | wpa_printf(MSG_DEBUG, |
| 8999 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 9000 | freq, bss->ifindex); |
| 9001 | |
| 9002 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9003 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9004 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9005 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 9006 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9007 | nla_put_u32(msg, |
| 9008 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 9009 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 9010 | nla_put_u32(msg, |
| 9011 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 9012 | freq)) { |
| 9013 | wpa_printf(MSG_ERROR, |
| 9014 | "%s: err in adding vendor_cmd and vendor_data", |
| 9015 | __func__); |
| 9016 | nlmsg_free(msg); |
| 9017 | return -1; |
| 9018 | } |
| 9019 | nla_nest_end(msg, params); |
| 9020 | |
| 9021 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9022 | msg = NULL; |
| 9023 | if (ret) { |
| 9024 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 9025 | __func__); |
| 9026 | return ret; |
| 9027 | } |
| 9028 | nlmsg_free(msg); |
| 9029 | return 0; |
| 9030 | } |
| 9031 | |
| 9032 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 9033 | |
| 9034 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9035 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 9036 | .name = "nl80211", |
| 9037 | .desc = "Linux nl80211/cfg80211", |
| 9038 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 9039 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9040 | .set_key = driver_nl80211_set_key, |
| 9041 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9042 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 9043 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9044 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9045 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9046 | .deauthenticate = driver_nl80211_deauthenticate, |
| 9047 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9048 | .associate = wpa_driver_nl80211_associate, |
| 9049 | .global_init = nl80211_global_init, |
| 9050 | .global_deinit = nl80211_global_deinit, |
| 9051 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9052 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9053 | .get_capa = wpa_driver_nl80211_get_capa, |
| 9054 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 9055 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 9056 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9057 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9058 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 9059 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9060 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9061 | .if_remove = driver_nl80211_if_remove, |
| 9062 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9063 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9064 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9065 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9066 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 9067 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9068 | .hapd_init = i802_init, |
| 9069 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9070 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9071 | .get_seqnum = i802_get_seqnum, |
| 9072 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9073 | .get_inact_sec = i802_get_inact_sec, |
| 9074 | .sta_clear_stats = i802_sta_clear_stats, |
| 9075 | .set_rts = i802_set_rts, |
| 9076 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9077 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9078 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9079 | .sta_deauth = i802_sta_deauth, |
| 9080 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9081 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9082 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9083 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9084 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 9085 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 9086 | .cancel_remain_on_channel = |
| 9087 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9088 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9089 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9090 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9091 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9092 | .signal_monitor = nl80211_signal_monitor, |
| 9093 | .signal_poll = nl80211_signal_poll, |
| 9094 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9095 | .set_param = nl80211_set_param, |
| 9096 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9097 | .add_pmkid = nl80211_add_pmkid, |
| 9098 | .remove_pmkid = nl80211_remove_pmkid, |
| 9099 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9100 | .set_rekey_info = nl80211_set_rekey_info, |
| 9101 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9102 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9103 | .start_dfs_cac = nl80211_start_radar_detection, |
| 9104 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9105 | #ifdef CONFIG_TDLS |
| 9106 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 9107 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9108 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 9109 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9110 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9111 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9112 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9113 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9114 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9115 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9116 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9117 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9118 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9119 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9120 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9121 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 9122 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9123 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 9124 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9125 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9126 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9127 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9128 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9129 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9130 | .roaming = nl80211_roaming, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9131 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9132 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9133 | #ifdef CONFIG_MESH |
| 9134 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 9135 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 9136 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 9137 | #endif /* CONFIG_MESH */ |
| 9138 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 9139 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 9140 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 9141 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 9142 | .add_tx_ts = nl80211_add_ts, |
| 9143 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9144 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9145 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9146 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9147 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 9148 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
| 9149 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9150 | }; |