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 | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 184 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
| 185 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
| 186 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 187 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 188 | static int nl80211_set_channel(struct i802_bss *bss, |
| 189 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 190 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 191 | int ifindex, int disabled); |
| 192 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 193 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 194 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 195 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 196 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 197 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 198 | |
| 199 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 200 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 201 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 202 | { |
| 203 | switch (width) { |
| 204 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 205 | return CHAN_WIDTH_20_NOHT; |
| 206 | case NL80211_CHAN_WIDTH_20: |
| 207 | return CHAN_WIDTH_20; |
| 208 | case NL80211_CHAN_WIDTH_40: |
| 209 | return CHAN_WIDTH_40; |
| 210 | case NL80211_CHAN_WIDTH_80: |
| 211 | return CHAN_WIDTH_80; |
| 212 | case NL80211_CHAN_WIDTH_80P80: |
| 213 | return CHAN_WIDTH_80P80; |
| 214 | case NL80211_CHAN_WIDTH_160: |
| 215 | return CHAN_WIDTH_160; |
| 216 | } |
| 217 | return CHAN_WIDTH_UNKNOWN; |
| 218 | } |
| 219 | |
| 220 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 221 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 222 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 223 | return nlmode == NL80211_IFTYPE_AP || |
| 224 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 228 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 229 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 230 | return nlmode == NL80211_IFTYPE_STATION || |
| 231 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 235 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 236 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 237 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 238 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 239 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 240 | |
| 241 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 242 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 243 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 244 | { |
| 245 | struct i802_bss *bss; |
| 246 | |
| 247 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 248 | if (bss->ifindex == ifindex) |
| 249 | return bss; |
| 250 | } |
| 251 | |
| 252 | return NULL; |
| 253 | } |
| 254 | |
| 255 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 256 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 257 | { |
| 258 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 263 | { |
| 264 | if (drv->associated) |
| 265 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 266 | drv->associated = 0; |
| 267 | os_memset(drv->bssid, 0, ETH_ALEN); |
| 268 | } |
| 269 | |
| 270 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 271 | /* nl80211 code */ |
| 272 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 273 | { |
| 274 | int *err = arg; |
| 275 | *err = 0; |
| 276 | return NL_STOP; |
| 277 | } |
| 278 | |
| 279 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 280 | { |
| 281 | int *ret = arg; |
| 282 | *ret = 0; |
| 283 | return NL_SKIP; |
| 284 | } |
| 285 | |
| 286 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 287 | void *arg) |
| 288 | { |
| 289 | int *ret = arg; |
| 290 | *ret = err->error; |
| 291 | return NL_SKIP; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 296 | { |
| 297 | return NL_OK; |
| 298 | } |
| 299 | |
| 300 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 301 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 302 | { |
| 303 | /* |
| 304 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 305 | * heap memory for unnecessarily long time. |
| 306 | */ |
| 307 | if (msg) { |
| 308 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 309 | void *data = nlmsg_data(hdr); |
| 310 | /* |
| 311 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 312 | * only libnl were to maintain a stable API.. Neither will work |
| 313 | * with all released versions, so just calculate the length |
| 314 | * here. |
| 315 | */ |
| 316 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 317 | |
| 318 | os_memset(data, 0, len); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 323 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 324 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 325 | int (*valid_handler)(struct nl_msg *, void *), |
| 326 | void *valid_data) |
| 327 | { |
| 328 | struct nl_cb *cb; |
| 329 | int err = -ENOMEM; |
| 330 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 331 | if (!msg) |
| 332 | return -ENOMEM; |
| 333 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 334 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 335 | if (!cb) |
| 336 | goto out; |
| 337 | |
| 338 | err = nl_send_auto_complete(nl_handle, msg); |
| 339 | if (err < 0) |
| 340 | goto out; |
| 341 | |
| 342 | err = 1; |
| 343 | |
| 344 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 345 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 346 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 347 | |
| 348 | if (valid_handler) |
| 349 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 350 | valid_handler, valid_data); |
| 351 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 352 | while (err > 0) { |
| 353 | int res = nl_recvmsgs(nl_handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 354 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 355 | wpa_printf(MSG_INFO, |
| 356 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 357 | __func__, res); |
| 358 | } |
| 359 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 360 | out: |
| 361 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 362 | if (!valid_handler && valid_data == (void *) -1) |
| 363 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 364 | nlmsg_free(msg); |
| 365 | return err; |
| 366 | } |
| 367 | |
| 368 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 369 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 370 | struct nl_msg *msg, |
| 371 | int (*valid_handler)(struct nl_msg *, void *), |
| 372 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 373 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 374 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 375 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | |
| 379 | struct family_data { |
| 380 | const char *group; |
| 381 | int id; |
| 382 | }; |
| 383 | |
| 384 | |
| 385 | static int family_handler(struct nl_msg *msg, void *arg) |
| 386 | { |
| 387 | struct family_data *res = arg; |
| 388 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 389 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 390 | struct nlattr *mcgrp; |
| 391 | int i; |
| 392 | |
| 393 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 394 | genlmsg_attrlen(gnlh, 0), NULL); |
| 395 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 396 | return NL_SKIP; |
| 397 | |
| 398 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 399 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 400 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 401 | nla_len(mcgrp), NULL); |
| 402 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 403 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 404 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 405 | res->group, |
| 406 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 407 | continue; |
| 408 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 409 | break; |
| 410 | }; |
| 411 | |
| 412 | return NL_SKIP; |
| 413 | } |
| 414 | |
| 415 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 416 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 417 | const char *family, const char *group) |
| 418 | { |
| 419 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 420 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 421 | struct family_data res = { group, -ENOENT }; |
| 422 | |
| 423 | msg = nlmsg_alloc(); |
| 424 | if (!msg) |
| 425 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 426 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 427 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 428 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 429 | nlmsg_free(msg); |
| 430 | return -1; |
| 431 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 432 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 433 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 434 | if (ret == 0) |
| 435 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 436 | return ret; |
| 437 | } |
| 438 | |
| 439 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 440 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 441 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 442 | { |
| 443 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 444 | 0, flags, cmd, 0); |
| 445 | } |
| 446 | |
| 447 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 448 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 449 | { |
| 450 | if (bss->wdev_id_set) |
| 451 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 452 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 453 | } |
| 454 | |
| 455 | |
| 456 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 457 | { |
| 458 | struct nl_msg *msg; |
| 459 | |
| 460 | msg = nlmsg_alloc(); |
| 461 | if (!msg) |
| 462 | return NULL; |
| 463 | |
| 464 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 465 | nl80211_set_iface_id(msg, bss) < 0) { |
| 466 | nlmsg_free(msg); |
| 467 | return NULL; |
| 468 | } |
| 469 | |
| 470 | return msg; |
| 471 | } |
| 472 | |
| 473 | |
| 474 | static struct nl_msg * |
| 475 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 476 | int flags, uint8_t cmd) |
| 477 | { |
| 478 | struct nl_msg *msg; |
| 479 | |
| 480 | msg = nlmsg_alloc(); |
| 481 | if (!msg) |
| 482 | return NULL; |
| 483 | |
| 484 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 485 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 486 | nlmsg_free(msg); |
| 487 | return NULL; |
| 488 | } |
| 489 | |
| 490 | return msg; |
| 491 | } |
| 492 | |
| 493 | |
| 494 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 495 | uint8_t cmd) |
| 496 | { |
| 497 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 498 | } |
| 499 | |
| 500 | |
| 501 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 502 | { |
| 503 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 504 | } |
| 505 | |
| 506 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 507 | struct wiphy_idx_data { |
| 508 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 509 | enum nl80211_iftype nlmode; |
| 510 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 511 | }; |
| 512 | |
| 513 | |
| 514 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 515 | { |
| 516 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 517 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 518 | struct wiphy_idx_data *info = arg; |
| 519 | |
| 520 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 521 | genlmsg_attrlen(gnlh, 0), NULL); |
| 522 | |
| 523 | if (tb[NL80211_ATTR_WIPHY]) |
| 524 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 525 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 526 | if (tb[NL80211_ATTR_IFTYPE]) |
| 527 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 528 | |
| 529 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 530 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 531 | ETH_ALEN); |
| 532 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 533 | return NL_SKIP; |
| 534 | } |
| 535 | |
| 536 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 537 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 538 | { |
| 539 | struct nl_msg *msg; |
| 540 | struct wiphy_idx_data data = { |
| 541 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 542 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 543 | }; |
| 544 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 545 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 546 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 547 | |
| 548 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 549 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 550 | return -1; |
| 551 | } |
| 552 | |
| 553 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 554 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 555 | { |
| 556 | struct nl_msg *msg; |
| 557 | struct wiphy_idx_data data = { |
| 558 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 559 | .macaddr = NULL, |
| 560 | }; |
| 561 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 562 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 563 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 564 | |
| 565 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 566 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 567 | return NL80211_IFTYPE_UNSPECIFIED; |
| 568 | } |
| 569 | |
| 570 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 571 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 572 | { |
| 573 | struct nl_msg *msg; |
| 574 | struct wiphy_idx_data data = { |
| 575 | .macaddr = bss->addr, |
| 576 | }; |
| 577 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 578 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 579 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 580 | |
| 581 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 582 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 583 | |
| 584 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 585 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 586 | struct nl80211_wiphy_data *w) |
| 587 | { |
| 588 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 589 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 590 | |
| 591 | msg = nlmsg_alloc(); |
| 592 | if (!msg) |
| 593 | return -1; |
| 594 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 595 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 596 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 597 | nlmsg_free(msg); |
| 598 | return -1; |
| 599 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 600 | |
| 601 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 602 | if (ret) { |
| 603 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 604 | "failed: ret=%d (%s)", |
| 605 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 606 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 607 | return ret; |
| 608 | } |
| 609 | |
| 610 | |
| 611 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 612 | { |
| 613 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 614 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 615 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 616 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 617 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 618 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 619 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 620 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 621 | __func__, res); |
| 622 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | |
| 626 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 627 | { |
| 628 | struct nl80211_wiphy_data *w = arg; |
| 629 | struct wpa_driver_nl80211_data *drv; |
| 630 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 631 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 632 | union wpa_event_data event; |
| 633 | |
| 634 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 635 | genlmsg_attrlen(gnlh, 0), NULL); |
| 636 | |
| 637 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 638 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 639 | gnlh->cmd); |
| 640 | return NL_SKIP; |
| 641 | } |
| 642 | |
| 643 | if (!tb[NL80211_ATTR_FRAME]) |
| 644 | return NL_SKIP; |
| 645 | |
| 646 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 647 | wiphy_list) { |
| 648 | os_memset(&event, 0, sizeof(event)); |
| 649 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 650 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 651 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 652 | } |
| 653 | |
| 654 | return NL_SKIP; |
| 655 | } |
| 656 | |
| 657 | |
| 658 | static struct nl80211_wiphy_data * |
| 659 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 660 | { |
| 661 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 662 | struct nl80211_wiphy_data *w; |
| 663 | int wiphy_idx, found = 0; |
| 664 | struct i802_bss *tmp_bss; |
| 665 | |
| 666 | if (bss->wiphy_data != NULL) |
| 667 | return bss->wiphy_data; |
| 668 | |
| 669 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 670 | |
| 671 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 672 | if (w->wiphy_idx == wiphy_idx) |
| 673 | goto add; |
| 674 | } |
| 675 | |
| 676 | /* alloc new one */ |
| 677 | w = os_zalloc(sizeof(*w)); |
| 678 | if (w == NULL) |
| 679 | return NULL; |
| 680 | w->wiphy_idx = wiphy_idx; |
| 681 | dl_list_init(&w->bsss); |
| 682 | dl_list_init(&w->drvs); |
| 683 | |
| 684 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 685 | if (!w->nl_cb) { |
| 686 | os_free(w); |
| 687 | return NULL; |
| 688 | } |
| 689 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); |
| 690 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, |
| 691 | w); |
| 692 | |
| 693 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 694 | "wiphy beacons"); |
| 695 | if (w->nl_beacons == NULL) { |
| 696 | os_free(w); |
| 697 | return NULL; |
| 698 | } |
| 699 | |
| 700 | if (nl80211_register_beacons(bss->drv, w)) { |
| 701 | nl_destroy_handles(&w->nl_beacons); |
| 702 | os_free(w); |
| 703 | return NULL; |
| 704 | } |
| 705 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 706 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 707 | |
| 708 | dl_list_add(&nl80211_wiphys, &w->list); |
| 709 | |
| 710 | add: |
| 711 | /* drv entry for this bss already there? */ |
| 712 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 713 | if (tmp_bss->drv == bss->drv) { |
| 714 | found = 1; |
| 715 | break; |
| 716 | } |
| 717 | } |
| 718 | /* if not add it */ |
| 719 | if (!found) |
| 720 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 721 | |
| 722 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 723 | bss->wiphy_data = w; |
| 724 | return w; |
| 725 | } |
| 726 | |
| 727 | |
| 728 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 729 | { |
| 730 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 731 | struct i802_bss *tmp_bss; |
| 732 | int found = 0; |
| 733 | |
| 734 | if (w == NULL) |
| 735 | return; |
| 736 | bss->wiphy_data = NULL; |
| 737 | dl_list_del(&bss->wiphy_list); |
| 738 | |
| 739 | /* still any for this drv present? */ |
| 740 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 741 | if (tmp_bss->drv == bss->drv) { |
| 742 | found = 1; |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | /* if not remove it */ |
| 747 | if (!found) |
| 748 | dl_list_del(&bss->drv->wiphy_list); |
| 749 | |
| 750 | if (!dl_list_empty(&w->bsss)) |
| 751 | return; |
| 752 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 753 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 754 | |
| 755 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 756 | dl_list_del(&w->list); |
| 757 | os_free(w); |
| 758 | } |
| 759 | |
| 760 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 761 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 762 | { |
| 763 | struct i802_bss *bss = priv; |
| 764 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 765 | if (!drv->associated) |
| 766 | return -1; |
| 767 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | |
| 772 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 773 | { |
| 774 | struct i802_bss *bss = priv; |
| 775 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 776 | if (!drv->associated) |
| 777 | return -1; |
| 778 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 779 | return drv->ssid_len; |
| 780 | } |
| 781 | |
| 782 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 783 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 784 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 785 | { |
| 786 | union wpa_event_data event; |
| 787 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 788 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
| 789 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 790 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 791 | drv->first_bss->ifname); |
| 792 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 793 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 794 | if (!drv->if_removed) |
| 795 | return; |
| 796 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 797 | drv->first_bss->ifname); |
| 798 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 801 | os_memset(&event, 0, sizeof(event)); |
| 802 | os_strlcpy(event.interface_status.ifname, ifname, |
| 803 | sizeof(event.interface_status.ifname)); |
| 804 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
| 805 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 806 | } |
| 807 | |
| 808 | |
| 809 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 810 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 811 | { |
| 812 | union wpa_event_data event; |
| 813 | |
| 814 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
| 815 | if (drv->if_removed) { |
| 816 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 817 | ifname); |
| 818 | return; |
| 819 | } |
| 820 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 821 | ifname); |
| 822 | drv->if_removed = 1; |
| 823 | } else { |
| 824 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 825 | ifname); |
| 826 | } |
| 827 | |
| 828 | os_memset(&event, 0, sizeof(event)); |
| 829 | os_strlcpy(event.interface_status.ifname, ifname, |
| 830 | sizeof(event.interface_status.ifname)); |
| 831 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 832 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 833 | } |
| 834 | |
| 835 | |
| 836 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 837 | u8 *buf, size_t len) |
| 838 | { |
| 839 | int attrlen, rta_len; |
| 840 | struct rtattr *attr; |
| 841 | |
| 842 | attrlen = len; |
| 843 | attr = (struct rtattr *) buf; |
| 844 | |
| 845 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 846 | while (RTA_OK(attr, attrlen)) { |
| 847 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 848 | if (os_strcmp(((char *) attr) + rta_len, |
| 849 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 850 | return 1; |
| 851 | else |
| 852 | break; |
| 853 | } |
| 854 | attr = RTA_NEXT(attr, attrlen); |
| 855 | } |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | |
| 861 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 862 | int ifindex, u8 *buf, size_t len) |
| 863 | { |
| 864 | if (drv->ifindex == ifindex) |
| 865 | return 1; |
| 866 | |
| 867 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 868 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 869 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 870 | "interface"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 871 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 872 | return 1; |
| 873 | } |
| 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 879 | static struct wpa_driver_nl80211_data * |
| 880 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) |
| 881 | { |
| 882 | struct wpa_driver_nl80211_data *drv; |
| 883 | dl_list_for_each(drv, &global->interfaces, |
| 884 | struct wpa_driver_nl80211_data, list) { |
| 885 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || |
| 886 | have_ifidx(drv, idx)) |
| 887 | return drv; |
| 888 | } |
| 889 | return NULL; |
| 890 | } |
| 891 | |
| 892 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 893 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 894 | struct ifinfomsg *ifi, |
| 895 | u8 *buf, size_t len) |
| 896 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 897 | struct nl80211_global *global = ctx; |
| 898 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 899 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 900 | struct rtattr *attr; |
| 901 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 902 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 903 | char ifname[IFNAMSIZ + 1]; |
| 904 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 905 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 906 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 907 | if (!drv) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 908 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d", |
| 909 | ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 910 | return; |
| 911 | } |
| 912 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 913 | extra[0] = '\0'; |
| 914 | pos = extra; |
| 915 | end = pos + sizeof(extra); |
| 916 | ifname[0] = '\0'; |
| 917 | |
| 918 | attrlen = len; |
| 919 | attr = (struct rtattr *) buf; |
| 920 | while (RTA_OK(attr, attrlen)) { |
| 921 | switch (attr->rta_type) { |
| 922 | case IFLA_IFNAME: |
| 923 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 924 | break; |
| 925 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 926 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 927 | break; |
| 928 | case IFLA_MASTER: |
| 929 | brid = nla_get_u32((struct nlattr *) attr); |
| 930 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 931 | break; |
| 932 | case IFLA_WIRELESS: |
| 933 | pos += os_snprintf(pos, end - pos, " wext"); |
| 934 | break; |
| 935 | case IFLA_OPERSTATE: |
| 936 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 937 | nla_get_u32((struct nlattr *) attr)); |
| 938 | break; |
| 939 | case IFLA_LINKMODE: |
| 940 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 941 | nla_get_u32((struct nlattr *) attr)); |
| 942 | break; |
| 943 | } |
| 944 | attr = RTA_NEXT(attr, attrlen); |
| 945 | } |
| 946 | extra[sizeof(extra) - 1] = '\0'; |
| 947 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 948 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 949 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 950 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 951 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 952 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 953 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 954 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 955 | |
| 956 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 957 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 958 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 959 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 960 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 961 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 962 | drv->ignore_if_down_event = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 963 | return; |
| 964 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 965 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 966 | namebuf, ifname); |
| 967 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 968 | wpa_printf(MSG_DEBUG, |
| 969 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 970 | drv->first_bss->ifname); |
| 971 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 972 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 973 | "event generated by mode change"); |
| 974 | drv->ignore_if_down_event = 0; |
| 975 | } else { |
| 976 | drv->if_disabled = 1; |
| 977 | wpa_supplicant_event(drv->ctx, |
| 978 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 979 | |
| 980 | /* |
| 981 | * Try to get drv again, since it may be removed as |
| 982 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 983 | * dynamic interfaces |
| 984 | */ |
| 985 | drv = nl80211_find_drv(global, ifi->ifi_index, |
| 986 | buf, len); |
| 987 | if (!drv) |
| 988 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 989 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 993 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 994 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 995 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 996 | "event since interface %s is down", |
| 997 | namebuf); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 998 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 999 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1000 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1001 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1002 | } else if (drv->if_removed) { |
| 1003 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1004 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1005 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1006 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1007 | struct i802_bss *bss; |
| 1008 | u8 addr[ETH_ALEN]; |
| 1009 | |
| 1010 | /* Re-read MAC address as it may have changed */ |
| 1011 | bss = get_bss_ifindex(drv, ifi->ifi_index); |
| 1012 | if (bss && |
| 1013 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1014 | bss->ifname, addr) < 0) { |
| 1015 | wpa_printf(MSG_DEBUG, |
| 1016 | "nl80211: %s: failed to re-read MAC address", |
| 1017 | bss->ifname); |
| 1018 | } else if (bss && |
| 1019 | os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1020 | wpa_printf(MSG_DEBUG, |
| 1021 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1022 | MACSTR " to " MACSTR, |
| 1023 | ifi->ifi_index, bss->ifname, |
| 1024 | MAC2STR(bss->addr), |
| 1025 | MAC2STR(addr)); |
| 1026 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 1027 | } |
| 1028 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1029 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
| 1030 | drv->if_disabled = 0; |
| 1031 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1032 | NULL); |
| 1033 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * Some drivers send the association event before the operup event--in |
| 1038 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1039 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1040 | * IEEE 802.1X authentication |
| 1041 | */ |
| 1042 | if (drv->operstate == 1 && |
| 1043 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1044 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1045 | 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] | 1046 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1047 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1050 | if (ifname[0]) |
| 1051 | wpa_driver_nl80211_event_newlink(drv, ifname); |
| 1052 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1053 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1054 | struct i802_bss *bss; |
| 1055 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1056 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1057 | if (!if_indextoname(brid, namebuf)) { |
| 1058 | wpa_printf(MSG_DEBUG, |
| 1059 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1060 | brid); |
| 1061 | return; |
| 1062 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1063 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1064 | brid, namebuf); |
| 1065 | add_ifidx(drv, brid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1066 | |
| 1067 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1068 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1069 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1070 | break; |
| 1071 | } |
| 1072 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1073 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1078 | struct ifinfomsg *ifi, |
| 1079 | u8 *buf, size_t len) |
| 1080 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1081 | struct nl80211_global *global = ctx; |
| 1082 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1083 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1084 | struct rtattr *attr; |
| 1085 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1086 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1087 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1088 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1089 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 1090 | if (!drv) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1091 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d", |
| 1092 | ifi->ifi_index); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1093 | return; |
| 1094 | } |
| 1095 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1096 | extra[0] = '\0'; |
| 1097 | pos = extra; |
| 1098 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1099 | ifname[0] = '\0'; |
| 1100 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1101 | attrlen = len; |
| 1102 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1103 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1104 | switch (attr->rta_type) { |
| 1105 | case IFLA_IFNAME: |
| 1106 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1107 | break; |
| 1108 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1109 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1110 | break; |
| 1111 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1112 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1113 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1114 | break; |
| 1115 | case IFLA_OPERSTATE: |
| 1116 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1117 | nla_get_u32((struct nlattr *) attr)); |
| 1118 | break; |
| 1119 | case IFLA_LINKMODE: |
| 1120 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1121 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1122 | break; |
| 1123 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1124 | attr = RTA_NEXT(attr, attrlen); |
| 1125 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1126 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1127 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1128 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1129 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1130 | ifi->ifi_flags, |
| 1131 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1132 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1133 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1134 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1135 | |
| 1136 | if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1137 | wpa_driver_nl80211_event_dellink(drv, ifname); |
| 1138 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1139 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
| 1140 | /* device has been removed from bridge */ |
| 1141 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1142 | |
| 1143 | if (!if_indextoname(brid, namebuf)) { |
| 1144 | wpa_printf(MSG_DEBUG, |
| 1145 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1146 | brid); |
| 1147 | } else { |
| 1148 | wpa_printf(MSG_DEBUG, |
| 1149 | "nl80211: Remove ifindex %u for bridge %s", |
| 1150 | brid, namebuf); |
| 1151 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1152 | del_ifidx(drv, brid); |
| 1153 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1157 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1158 | { |
| 1159 | struct nl_msg *msg; |
| 1160 | int ret; |
| 1161 | struct nl80211_bss_info_arg arg; |
| 1162 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1163 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1164 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1165 | arg.drv = drv; |
| 1166 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1167 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1168 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1169 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1170 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1171 | "associated BSS from scan results: %u MHz", freq); |
| 1172 | if (freq) |
| 1173 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1174 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1175 | } |
| 1176 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1177 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1178 | return drv->assoc_freq; |
| 1179 | } |
| 1180 | |
| 1181 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1182 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1183 | { |
| 1184 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1185 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1186 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1187 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1188 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1189 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1190 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1191 | }; |
| 1192 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1193 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1194 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1195 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1196 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1197 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1198 | }; |
| 1199 | struct wpa_signal_info *sig_change = arg; |
| 1200 | |
| 1201 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1202 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1203 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1204 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1205 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1206 | return NL_SKIP; |
| 1207 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1208 | return NL_SKIP; |
| 1209 | |
| 1210 | sig_change->current_signal = |
| 1211 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1212 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1213 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1214 | sig_change->avg_signal = |
| 1215 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1216 | else |
| 1217 | sig_change->avg_signal = 0; |
| 1218 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1219 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1220 | sig_change->avg_beacon_signal = |
| 1221 | (s8) |
| 1222 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1223 | else |
| 1224 | sig_change->avg_beacon_signal = 0; |
| 1225 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1226 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1227 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1228 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1229 | rate_policy)) { |
| 1230 | sig_change->current_txrate = 0; |
| 1231 | } else { |
| 1232 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1233 | sig_change->current_txrate = |
| 1234 | nla_get_u16(rinfo[ |
| 1235 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | return NL_SKIP; |
| 1241 | } |
| 1242 | |
| 1243 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1244 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1245 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1246 | { |
| 1247 | struct nl_msg *msg; |
| 1248 | |
| 1249 | sig->current_signal = -9999; |
| 1250 | sig->current_txrate = 0; |
| 1251 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1252 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1253 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1254 | nlmsg_free(msg); |
| 1255 | return -ENOBUFS; |
| 1256 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1257 | |
| 1258 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1263 | { |
| 1264 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1265 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1266 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1267 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1268 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1269 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1270 | }; |
| 1271 | struct wpa_signal_info *sig_change = arg; |
| 1272 | |
| 1273 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1274 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1275 | |
| 1276 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1277 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1278 | return NL_SKIP; |
| 1279 | } |
| 1280 | |
| 1281 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1282 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1283 | survey_policy)) { |
| 1284 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1285 | "attributes!"); |
| 1286 | return NL_SKIP; |
| 1287 | } |
| 1288 | |
| 1289 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1290 | return NL_SKIP; |
| 1291 | |
| 1292 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1293 | sig_change->frequency) |
| 1294 | return NL_SKIP; |
| 1295 | |
| 1296 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1297 | return NL_SKIP; |
| 1298 | |
| 1299 | sig_change->current_noise = |
| 1300 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1301 | |
| 1302 | return NL_SKIP; |
| 1303 | } |
| 1304 | |
| 1305 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1306 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1307 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1308 | { |
| 1309 | struct nl_msg *msg; |
| 1310 | |
| 1311 | sig_change->current_noise = 9999; |
| 1312 | sig_change->frequency = drv->assoc_freq; |
| 1313 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1314 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1315 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1320 | void *handle) |
| 1321 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1322 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1323 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1324 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1325 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1326 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1327 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1328 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1329 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1330 | __func__, res); |
| 1331 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | /** |
| 1336 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1337 | * @priv: driver_nl80211 private data |
| 1338 | * @alpha2_arg: country to which to switch to |
| 1339 | * Returns: 0 on success, -1 on failure |
| 1340 | * |
| 1341 | * This asks nl80211 to set the regulatory domain for given |
| 1342 | * country ISO / IEC alpha2. |
| 1343 | */ |
| 1344 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1345 | { |
| 1346 | struct i802_bss *bss = priv; |
| 1347 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1348 | char alpha2[3]; |
| 1349 | struct nl_msg *msg; |
| 1350 | |
| 1351 | msg = nlmsg_alloc(); |
| 1352 | if (!msg) |
| 1353 | return -ENOMEM; |
| 1354 | |
| 1355 | alpha2[0] = alpha2_arg[0]; |
| 1356 | alpha2[1] = alpha2_arg[1]; |
| 1357 | alpha2[2] = '\0'; |
| 1358 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1359 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1360 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1361 | nlmsg_free(msg); |
| 1362 | return -EINVAL; |
| 1363 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1364 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1365 | return -EINVAL; |
| 1366 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1370 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1371 | { |
| 1372 | char *alpha2 = arg; |
| 1373 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1374 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1375 | |
| 1376 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1377 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1378 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1379 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1380 | return NL_SKIP; |
| 1381 | } |
| 1382 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1383 | return NL_SKIP; |
| 1384 | } |
| 1385 | |
| 1386 | |
| 1387 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1388 | { |
| 1389 | struct i802_bss *bss = priv; |
| 1390 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1391 | struct nl_msg *msg; |
| 1392 | int ret; |
| 1393 | |
| 1394 | msg = nlmsg_alloc(); |
| 1395 | if (!msg) |
| 1396 | return -ENOMEM; |
| 1397 | |
| 1398 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1399 | alpha2[0] = '\0'; |
| 1400 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1401 | if (!alpha2[0]) |
| 1402 | ret = -1; |
| 1403 | |
| 1404 | return ret; |
| 1405 | } |
| 1406 | |
| 1407 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1408 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1409 | { |
| 1410 | int ret; |
| 1411 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1412 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1413 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1415 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1416 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1419 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1420 | if (global->nl == NULL) |
| 1421 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1422 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1423 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1424 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1425 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1426 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1427 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1430 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1431 | if (global->nl_event == NULL) |
| 1432 | goto err; |
| 1433 | |
| 1434 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1435 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1436 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1437 | if (ret < 0) { |
| 1438 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1439 | "membership for scan events: %d (%s)", |
| 1440 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1441 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1444 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1445 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1446 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1447 | if (ret < 0) { |
| 1448 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1449 | "membership for mlme events: %d (%s)", |
| 1450 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1451 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1454 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1455 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1456 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1457 | if (ret < 0) { |
| 1458 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1459 | "membership for regulatory events: %d (%s)", |
| 1460 | ret, strerror(-ret)); |
| 1461 | /* Continue without regulatory events */ |
| 1462 | } |
| 1463 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1464 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1465 | if (ret >= 0) |
| 1466 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1467 | if (ret < 0) { |
| 1468 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1469 | "membership for vendor events: %d (%s)", |
| 1470 | ret, strerror(-ret)); |
| 1471 | /* Continue without vendor events */ |
| 1472 | } |
| 1473 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1474 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1475 | no_seq_check, NULL); |
| 1476 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1477 | process_global_event, global); |
| 1478 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1479 | nl80211_register_eloop_read(&global->nl_event, |
| 1480 | wpa_driver_nl80211_event_receive, |
| 1481 | global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1482 | |
| 1483 | return 0; |
| 1484 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1485 | err: |
| 1486 | nl_destroy_handles(&global->nl_event); |
| 1487 | nl_destroy_handles(&global->nl); |
| 1488 | nl_cb_put(global->nl_cb); |
| 1489 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1490 | return -1; |
| 1491 | } |
| 1492 | |
| 1493 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1494 | static void nl80211_check_global(struct nl80211_global *global) |
| 1495 | { |
| 1496 | struct nl_handle *handle; |
| 1497 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1498 | int ret; |
| 1499 | unsigned int i; |
| 1500 | |
| 1501 | /* |
| 1502 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1503 | * and all registration having been cleared. |
| 1504 | */ |
| 1505 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1506 | ELOOP_SOCKET_INVALID); |
| 1507 | |
| 1508 | for (i = 0; groups[i]; i++) { |
| 1509 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1510 | if (ret >= 0) |
| 1511 | ret = nl_socket_add_membership(handle, ret); |
| 1512 | if (ret < 0) { |
| 1513 | wpa_printf(MSG_INFO, |
| 1514 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
| 1515 | groups[i], ret, strerror(-ret)); |
| 1516 | } |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1521 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1522 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1523 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1524 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1525 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1526 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1527 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1528 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1529 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1530 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1531 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1532 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | |
| 1536 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1537 | { |
| 1538 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1539 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1540 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1541 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1542 | "after rfkill unblock"); |
| 1543 | return; |
| 1544 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1545 | |
| 1546 | if (is_p2p_net_interface(drv->nlmode)) |
| 1547 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1548 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1549 | /* |
| 1550 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1551 | * Device interface as enabled. |
| 1552 | */ |
| 1553 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1554 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1558 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1559 | void *eloop_ctx, |
| 1560 | void *handle) |
| 1561 | { |
| 1562 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1563 | u8 data[2048]; |
| 1564 | struct msghdr msg; |
| 1565 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1566 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1567 | struct cmsghdr *cmsg; |
| 1568 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1569 | union wpa_event_data event; |
| 1570 | |
| 1571 | memset(&msg, 0, sizeof(msg)); |
| 1572 | msg.msg_iov = &entry; |
| 1573 | msg.msg_iovlen = 1; |
| 1574 | entry.iov_base = data; |
| 1575 | entry.iov_len = sizeof(data); |
| 1576 | msg.msg_control = &control; |
| 1577 | msg.msg_controllen = sizeof(control); |
| 1578 | |
| 1579 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1580 | /* if error or not fitting 802.3 header, return */ |
| 1581 | if (res < 14) |
| 1582 | return; |
| 1583 | |
| 1584 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1585 | { |
| 1586 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1587 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1588 | int *ack; |
| 1589 | |
| 1590 | found_wifi = 1; |
| 1591 | ack = (void *)CMSG_DATA(cmsg); |
| 1592 | acked = *ack; |
| 1593 | } |
| 1594 | |
| 1595 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1596 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1597 | struct sock_extended_err *err = |
| 1598 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1599 | |
| 1600 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1601 | found_ee = 1; |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | if (!found_ee || !found_wifi) |
| 1606 | return; |
| 1607 | |
| 1608 | memset(&event, 0, sizeof(event)); |
| 1609 | event.eapol_tx_status.dst = data; |
| 1610 | event.eapol_tx_status.data = data + 14; |
| 1611 | event.eapol_tx_status.data_len = res - 14; |
| 1612 | event.eapol_tx_status.ack = acked; |
| 1613 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1614 | } |
| 1615 | |
| 1616 | |
| 1617 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1618 | { |
| 1619 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1620 | if (!bss->nl_cb) |
| 1621 | return -1; |
| 1622 | |
| 1623 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1624 | no_seq_check, NULL); |
| 1625 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1626 | process_bss_event, bss); |
| 1627 | |
| 1628 | return 0; |
| 1629 | } |
| 1630 | |
| 1631 | |
| 1632 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1633 | { |
| 1634 | nl_cb_put(bss->nl_cb); |
| 1635 | bss->nl_cb = NULL; |
| 1636 | } |
| 1637 | |
| 1638 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1639 | static void |
| 1640 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1641 | { |
| 1642 | struct rfkill_config *rcfg; |
| 1643 | |
| 1644 | if (drv->rfkill) |
| 1645 | return; |
| 1646 | |
| 1647 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1648 | if (!rcfg) |
| 1649 | return; |
| 1650 | |
| 1651 | rcfg->ctx = drv; |
| 1652 | |
| 1653 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1654 | * not associated with a netdev, so use the name of some other interface |
| 1655 | * sharing the same wiphy as the P2P Device interface. |
| 1656 | * |
| 1657 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1658 | * created and is created only once another wpa_s interface was added. |
| 1659 | */ |
| 1660 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1661 | struct nl80211_global *global = drv->global; |
| 1662 | struct wpa_driver_nl80211_data *tmp1; |
| 1663 | |
| 1664 | dl_list_for_each(tmp1, &global->interfaces, |
| 1665 | struct wpa_driver_nl80211_data, list) { |
| 1666 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1667 | !tmp1->rfkill) |
| 1668 | continue; |
| 1669 | |
| 1670 | wpa_printf(MSG_DEBUG, |
| 1671 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1672 | tmp1->first_bss->ifname); |
| 1673 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1674 | sizeof(rcfg->ifname)); |
| 1675 | break; |
| 1676 | } |
| 1677 | } else { |
| 1678 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1679 | sizeof(rcfg->ifname)); |
| 1680 | } |
| 1681 | |
| 1682 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1683 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1684 | drv->rfkill = rfkill_init(rcfg); |
| 1685 | if (!drv->rfkill) { |
| 1686 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1687 | os_free(rcfg); |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1692 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1693 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1694 | const u8 *set_addr, |
| 1695 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1696 | { |
| 1697 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1698 | struct i802_bss *bss; |
| 1699 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1700 | if (global_priv == NULL) |
| 1701 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1702 | drv = os_zalloc(sizeof(*drv)); |
| 1703 | if (drv == NULL) |
| 1704 | return NULL; |
| 1705 | drv->global = global_priv; |
| 1706 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1707 | drv->hostapd = !!hostapd; |
| 1708 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1709 | |
| 1710 | /* |
| 1711 | * There is no driver capability flag for this, so assume it is |
| 1712 | * supported and disable this on first attempt to use if the driver |
| 1713 | * rejects the command due to missing support. |
| 1714 | */ |
| 1715 | drv->set_rekey_offload = 1; |
| 1716 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1717 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1718 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1719 | |
| 1720 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1721 | if (!drv->first_bss) { |
| 1722 | os_free(drv); |
| 1723 | return NULL; |
| 1724 | } |
| 1725 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1726 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1727 | bss->ctx = ctx; |
| 1728 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1729 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1730 | drv->monitor_ifidx = -1; |
| 1731 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1732 | drv->eapol_tx_sock = -1; |
| 1733 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1734 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1735 | if (nl80211_init_bss(bss)) |
| 1736 | goto failed; |
| 1737 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1738 | 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] | 1739 | goto failed; |
| 1740 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1741 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1742 | if (drv->eapol_tx_sock < 0) |
| 1743 | goto failed; |
| 1744 | |
| 1745 | if (drv->data_tx_status) { |
| 1746 | int enabled = 1; |
| 1747 | |
| 1748 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1749 | &enabled, sizeof(enabled)) < 0) { |
| 1750 | wpa_printf(MSG_DEBUG, |
| 1751 | "nl80211: wifi status sockopt failed\n"); |
| 1752 | drv->data_tx_status = 0; |
| 1753 | if (!drv->use_monitor) |
| 1754 | drv->capa.flags &= |
| 1755 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1756 | } else { |
| 1757 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1758 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1759 | drv, NULL); |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1764 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1765 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1766 | drv->in_interface_list = 1; |
| 1767 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1768 | |
| 1769 | return bss; |
| 1770 | |
| 1771 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1772 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1773 | return NULL; |
| 1774 | } |
| 1775 | |
| 1776 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1777 | /** |
| 1778 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1779 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1780 | * e.g., wpa_supplicant_event() |
| 1781 | * @ifname: interface name, e.g., wlan0 |
| 1782 | * @global_priv: private driver global data from global_init() |
| 1783 | * Returns: Pointer to private data, %NULL on failure |
| 1784 | */ |
| 1785 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1786 | void *global_priv) |
| 1787 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1788 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1789 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1793 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1794 | struct nl_handle *nl_handle, |
| 1795 | u16 type, const u8 *match, size_t match_len) |
| 1796 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1797 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1798 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1799 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1800 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1801 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1802 | buf[0] = '\0'; |
| 1803 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1804 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1805 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1806 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1807 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1808 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1809 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1810 | nlmsg_free(msg); |
| 1811 | return -1; |
| 1812 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1813 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1814 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1815 | if (ret) { |
| 1816 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1817 | "failed (type=%u): ret=%d (%s)", |
| 1818 | type, ret, strerror(-ret)); |
| 1819 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1820 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1821 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1822 | return ret; |
| 1823 | } |
| 1824 | |
| 1825 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1826 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1827 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1828 | if (bss->nl_mgmt) { |
| 1829 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1830 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 1831 | return -1; |
| 1832 | } |
| 1833 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1834 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1835 | if (bss->nl_mgmt == NULL) |
| 1836 | return -1; |
| 1837 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1838 | return 0; |
| 1839 | } |
| 1840 | |
| 1841 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1842 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 1843 | { |
| 1844 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 1845 | wpa_driver_nl80211_event_receive, |
| 1846 | bss->nl_cb); |
| 1847 | } |
| 1848 | |
| 1849 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1850 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1851 | const u8 *match, size_t match_len) |
| 1852 | { |
| 1853 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1854 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1855 | type, match, match_len); |
| 1856 | } |
| 1857 | |
| 1858 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1859 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1860 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1861 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1862 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1863 | |
| 1864 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1865 | return -1; |
| 1866 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 1867 | "handle %p", bss->nl_mgmt); |
| 1868 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1869 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 1870 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 1871 | |
| 1872 | /* register for any AUTH message */ |
| 1873 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 1874 | } |
| 1875 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1876 | #ifdef CONFIG_INTERWORKING |
| 1877 | /* QoS Map Configure */ |
| 1878 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1879 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1880 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1881 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1882 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1883 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1884 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1885 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1886 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1887 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1888 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1889 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 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 Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1892 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1893 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1894 | /* Protected GAS Initial Request */ |
| 1895 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 1896 | ret = -1; |
| 1897 | /* Protected GAS Initial Response */ |
| 1898 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 1899 | ret = -1; |
| 1900 | /* Protected GAS Comeback Request */ |
| 1901 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 1902 | ret = -1; |
| 1903 | /* Protected GAS Comeback Response */ |
| 1904 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 1905 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1906 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 1907 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1908 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1909 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1910 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 1911 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1912 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1913 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1914 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1915 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 1916 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1917 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1918 | #endif /* CONFIG_P2P */ |
| 1919 | #ifdef CONFIG_IEEE80211W |
| 1920 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1921 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1922 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1923 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1924 | #ifdef CONFIG_TDLS |
| 1925 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 1926 | /* TDLS Discovery Response */ |
| 1927 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 1928 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1929 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1930 | } |
| 1931 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1932 | #ifdef CONFIG_FST |
| 1933 | /* FST Action frames */ |
| 1934 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 1935 | ret = -1; |
| 1936 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1937 | |
| 1938 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1939 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1940 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1941 | else |
| 1942 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 1943 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 1944 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1945 | /* WNM - BSS Transition Management Request */ |
| 1946 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1947 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1948 | /* WNM-Sleep Mode Response */ |
| 1949 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1950 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1951 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1952 | #ifdef CONFIG_HS20 |
| 1953 | /* WNM-Notification */ |
| 1954 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1955 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1956 | #endif /* CONFIG_HS20 */ |
| 1957 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1958 | /* WMM-AC ADDTS Response */ |
| 1959 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 1960 | ret = -1; |
| 1961 | |
| 1962 | /* WMM-AC DELTS */ |
| 1963 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 1964 | ret = -1; |
| 1965 | |
| 1966 | /* Radio Measurement - Neighbor Report Response */ |
| 1967 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 1968 | ret = -1; |
| 1969 | |
| 1970 | /* Radio Measurement - Link Measurement Request */ |
| 1971 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 1972 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 1973 | ret = -1; |
| 1974 | |
| 1975 | nl80211_mgmt_handle_register_eloop(bss); |
| 1976 | |
| 1977 | return ret; |
| 1978 | } |
| 1979 | |
| 1980 | |
| 1981 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 1982 | { |
| 1983 | int ret = 0; |
| 1984 | |
| 1985 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1986 | return -1; |
| 1987 | |
| 1988 | wpa_printf(MSG_DEBUG, |
| 1989 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 1990 | bss->nl_mgmt); |
| 1991 | |
| 1992 | /* Auth frames for mesh SAE */ |
| 1993 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 1994 | (WLAN_FC_TYPE_MGMT << 2) | |
| 1995 | (WLAN_FC_STYPE_AUTH << 4), |
| 1996 | NULL, 0) < 0) |
| 1997 | ret = -1; |
| 1998 | |
| 1999 | /* Mesh peering open */ |
| 2000 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2001 | ret = -1; |
| 2002 | /* Mesh peering confirm */ |
| 2003 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2004 | ret = -1; |
| 2005 | /* Mesh peering close */ |
| 2006 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2007 | ret = -1; |
| 2008 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2009 | nl80211_mgmt_handle_register_eloop(bss); |
| 2010 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2011 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2015 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2016 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2017 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2018 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2019 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2020 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2021 | 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] | 2022 | if (ret) { |
| 2023 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2024 | "failed: ret=%d (%s)", |
| 2025 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2026 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2027 | return ret; |
| 2028 | } |
| 2029 | |
| 2030 | |
| 2031 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2032 | { |
| 2033 | static const int stypes[] = { |
| 2034 | WLAN_FC_STYPE_AUTH, |
| 2035 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2036 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2037 | WLAN_FC_STYPE_DISASSOC, |
| 2038 | WLAN_FC_STYPE_DEAUTH, |
| 2039 | WLAN_FC_STYPE_ACTION, |
| 2040 | WLAN_FC_STYPE_PROBE_REQ, |
| 2041 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2042 | * it, but it wouldn't really be the right thing anyway as |
| 2043 | * it isn't per interface ... maybe just dump the scan |
| 2044 | * results periodically for OLBC? |
| 2045 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2046 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2047 | }; |
| 2048 | unsigned int i; |
| 2049 | |
| 2050 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2051 | return -1; |
| 2052 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2053 | "handle %p", bss->nl_mgmt); |
| 2054 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2055 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2056 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2057 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2058 | (stypes[i] << 4), |
| 2059 | NULL, 0) < 0) { |
| 2060 | goto out_err; |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | if (nl80211_register_spurious_class3(bss)) |
| 2065 | goto out_err; |
| 2066 | |
| 2067 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 2068 | goto out_err; |
| 2069 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2070 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2071 | return 0; |
| 2072 | |
| 2073 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2074 | nl_destroy_handles(&bss->nl_mgmt); |
| 2075 | return -1; |
| 2076 | } |
| 2077 | |
| 2078 | |
| 2079 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2080 | { |
| 2081 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2082 | return -1; |
| 2083 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2084 | "handle %p (device SME)", bss->nl_mgmt); |
| 2085 | |
| 2086 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2087 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2088 | (WLAN_FC_STYPE_ACTION << 4), |
| 2089 | NULL, 0) < 0) |
| 2090 | goto out_err; |
| 2091 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2092 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2093 | return 0; |
| 2094 | |
| 2095 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2096 | nl_destroy_handles(&bss->nl_mgmt); |
| 2097 | return -1; |
| 2098 | } |
| 2099 | |
| 2100 | |
| 2101 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2102 | { |
| 2103 | if (bss->nl_mgmt == NULL) |
| 2104 | return; |
| 2105 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2106 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2107 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2108 | |
| 2109 | nl80211_put_wiphy_data_ap(bss); |
| 2110 | } |
| 2111 | |
| 2112 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2113 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2114 | { |
| 2115 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2116 | } |
| 2117 | |
| 2118 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2119 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2120 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2121 | struct nl_msg *msg; |
| 2122 | int ret; |
| 2123 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2124 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2125 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2126 | |
| 2127 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2128 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2129 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2134 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2135 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2136 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2137 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2138 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2139 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2140 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2141 | |
| 2142 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2143 | start ? "Start" : "Stop", |
| 2144 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2145 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2146 | return ret; |
| 2147 | } |
| 2148 | |
| 2149 | |
| 2150 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2151 | { |
| 2152 | enum nl80211_iftype nlmode; |
| 2153 | |
| 2154 | nlmode = nl80211_get_ifmode(bss); |
| 2155 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2156 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2157 | bss->ifname, up); |
| 2158 | } |
| 2159 | |
| 2160 | /* P2P Device has start/stop which is equivalent */ |
| 2161 | return nl80211_set_p2pdev(bss, up); |
| 2162 | } |
| 2163 | |
| 2164 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2165 | #ifdef CONFIG_TESTING_OPTIONS |
| 2166 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2167 | { |
| 2168 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2169 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2170 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2171 | |
| 2172 | |
| 2173 | wpa_printf(MSG_DEBUG, |
| 2174 | "nl80211: QCA vendor test command response received"); |
| 2175 | |
| 2176 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2177 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2178 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2179 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2180 | return NL_SKIP; |
| 2181 | } |
| 2182 | |
| 2183 | wpa_hexdump(MSG_DEBUG, |
| 2184 | "nl80211: Received QCA vendor test command response", |
| 2185 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2186 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2187 | |
| 2188 | return NL_SKIP; |
| 2189 | } |
| 2190 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2191 | |
| 2192 | |
| 2193 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2194 | { |
| 2195 | #ifdef CONFIG_TESTING_OPTIONS |
| 2196 | struct nl_msg *msg; |
| 2197 | struct nlattr *params; |
| 2198 | int ret; |
| 2199 | |
| 2200 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2201 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2202 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2203 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2204 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2205 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2206 | nlmsg_free(msg); |
| 2207 | return; |
| 2208 | } |
| 2209 | nla_nest_end(msg, params); |
| 2210 | |
| 2211 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2212 | wpa_printf(MSG_DEBUG, |
| 2213 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2214 | ret, strerror(-ret)); |
| 2215 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2216 | } |
| 2217 | |
| 2218 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2219 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2220 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2221 | const u8 *set_addr, int first, |
| 2222 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2223 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2224 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2225 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2226 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2227 | |
| 2228 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2229 | bss->ifindex = drv->ifindex; |
| 2230 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2231 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2232 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2233 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2234 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2235 | drv->global->if_add_wdevid_set = 0; |
| 2236 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2237 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2238 | bss->static_ap = 1; |
| 2239 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2240 | if (first && |
| 2241 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2242 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2243 | drv->start_iface_up = 1; |
| 2244 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2245 | if (wpa_driver_nl80211_capa(drv)) |
| 2246 | return -1; |
| 2247 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2248 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2249 | return -1; |
| 2250 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2251 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2252 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2253 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2254 | if (set_addr && |
| 2255 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2256 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2257 | set_addr))) |
| 2258 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2259 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2260 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2261 | drv->start_mode_ap = 1; |
| 2262 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2263 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2264 | nlmode = NL80211_IFTYPE_AP; |
| 2265 | else if (bss->if_dynamic) |
| 2266 | nlmode = nl80211_get_ifmode(bss); |
| 2267 | else |
| 2268 | nlmode = NL80211_IFTYPE_STATION; |
| 2269 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2270 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2271 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2272 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2273 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2274 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2275 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2276 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2277 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2278 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2279 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2280 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2281 | int ret = i802_set_iface_flags(bss, 1); |
| 2282 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2283 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2284 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2285 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2286 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2287 | |
| 2288 | if (is_p2p_net_interface(nlmode)) |
| 2289 | nl80211_disable_11b_rates(bss->drv, |
| 2290 | bss->drv->ifindex, 1); |
| 2291 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2292 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2293 | return ret; |
| 2294 | } else { |
| 2295 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2296 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2297 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2298 | drv->if_disabled = 1; |
| 2299 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2300 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2303 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2304 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2305 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2306 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2307 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2308 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2309 | bss->addr)) |
| 2310 | return -1; |
| 2311 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2312 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2313 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2314 | if (send_rfkill_event) { |
| 2315 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2316 | drv, drv->ctx); |
| 2317 | } |
| 2318 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2319 | if (drv->vendor_cmd_test_avail) |
| 2320 | qca_vendor_test(drv); |
| 2321 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2322 | return 0; |
| 2323 | } |
| 2324 | |
| 2325 | |
| 2326 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 2327 | { |
| 2328 | struct nl_msg *msg; |
| 2329 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2330 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2331 | drv->ifindex); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2332 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2333 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | |
| 2337 | /** |
| 2338 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2339 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2340 | * |
| 2341 | * Shut down driver interface and processing of driver events. Free |
| 2342 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2343 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2344 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2345 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2346 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2347 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2348 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2349 | bss->ifname, drv->disabled_11b_rates); |
| 2350 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2351 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2352 | if (drv->data_tx_status) |
| 2353 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2354 | if (drv->eapol_tx_sock >= 0) |
| 2355 | close(drv->eapol_tx_sock); |
| 2356 | |
| 2357 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2358 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2359 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2360 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2361 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2362 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2363 | "interface %s from bridge %s: %s", |
| 2364 | bss->ifname, bss->brname, strerror(errno)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2365 | if (drv->rtnl_sk) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2366 | nl80211_handle_destroy(drv->rtnl_sk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2367 | } |
| 2368 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2369 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2370 | 0) < 0) |
| 2371 | wpa_printf(MSG_INFO, |
| 2372 | "nl80211: Could not set bridge %s down", |
| 2373 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2374 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2375 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2376 | "bridge %s: %s", |
| 2377 | bss->brname, strerror(errno)); |
| 2378 | } |
| 2379 | |
| 2380 | nl80211_remove_monitor_interface(drv); |
| 2381 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2382 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2383 | wpa_driver_nl80211_del_beacon(drv); |
| 2384 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2385 | if (drv->eapol_sock >= 0) { |
| 2386 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2387 | close(drv->eapol_sock); |
| 2388 | } |
| 2389 | |
| 2390 | if (drv->if_indices != drv->default_if_indices) |
| 2391 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2392 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2393 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2394 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2395 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2396 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2397 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2398 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2399 | rfkill_deinit(drv->rfkill); |
| 2400 | |
| 2401 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2402 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2403 | if (!drv->start_iface_up) |
| 2404 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2405 | |
| 2406 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2407 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2408 | 0) < 0) { |
| 2409 | wpa_printf(MSG_DEBUG, |
| 2410 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2411 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2412 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2413 | drv->perm_addr) < 0) { |
| 2414 | wpa_printf(MSG_DEBUG, |
| 2415 | "nl80211: Could not restore permanent MAC address"); |
| 2416 | } |
| 2417 | } |
| 2418 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2419 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2420 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2421 | wpa_driver_nl80211_set_mode(bss, |
| 2422 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2423 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2424 | } else { |
| 2425 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2426 | nl80211_del_p2pdev(bss); |
| 2427 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2428 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2429 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2430 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2431 | os_free(drv->filter_ssids); |
| 2432 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2433 | os_free(drv->auth_ie); |
| 2434 | |
| 2435 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2436 | dl_list_del(&drv->list); |
| 2437 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2438 | os_free(drv->extended_capa); |
| 2439 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2440 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2441 | os_free(drv); |
| 2442 | } |
| 2443 | |
| 2444 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2445 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2446 | { |
| 2447 | switch (alg) { |
| 2448 | case WPA_ALG_WEP: |
| 2449 | if (key_len == 5) |
| 2450 | return WLAN_CIPHER_SUITE_WEP40; |
| 2451 | return WLAN_CIPHER_SUITE_WEP104; |
| 2452 | case WPA_ALG_TKIP: |
| 2453 | return WLAN_CIPHER_SUITE_TKIP; |
| 2454 | case WPA_ALG_CCMP: |
| 2455 | return WLAN_CIPHER_SUITE_CCMP; |
| 2456 | case WPA_ALG_GCMP: |
| 2457 | return WLAN_CIPHER_SUITE_GCMP; |
| 2458 | case WPA_ALG_CCMP_256: |
| 2459 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2460 | case WPA_ALG_GCMP_256: |
| 2461 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2462 | case WPA_ALG_IGTK: |
| 2463 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 2464 | case WPA_ALG_BIP_GMAC_128: |
| 2465 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 2466 | case WPA_ALG_BIP_GMAC_256: |
| 2467 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 2468 | case WPA_ALG_BIP_CMAC_256: |
| 2469 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 2470 | case WPA_ALG_SMS4: |
| 2471 | return WLAN_CIPHER_SUITE_SMS4; |
| 2472 | case WPA_ALG_KRK: |
| 2473 | return WLAN_CIPHER_SUITE_KRK; |
| 2474 | case WPA_ALG_NONE: |
| 2475 | case WPA_ALG_PMK: |
| 2476 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2477 | alg); |
| 2478 | return 0; |
| 2479 | } |
| 2480 | |
| 2481 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2482 | alg); |
| 2483 | return 0; |
| 2484 | } |
| 2485 | |
| 2486 | |
| 2487 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2488 | { |
| 2489 | switch (cipher) { |
| 2490 | case WPA_CIPHER_CCMP_256: |
| 2491 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2492 | case WPA_CIPHER_GCMP_256: |
| 2493 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2494 | case WPA_CIPHER_CCMP: |
| 2495 | return WLAN_CIPHER_SUITE_CCMP; |
| 2496 | case WPA_CIPHER_GCMP: |
| 2497 | return WLAN_CIPHER_SUITE_GCMP; |
| 2498 | case WPA_CIPHER_TKIP: |
| 2499 | return WLAN_CIPHER_SUITE_TKIP; |
| 2500 | case WPA_CIPHER_WEP104: |
| 2501 | return WLAN_CIPHER_SUITE_WEP104; |
| 2502 | case WPA_CIPHER_WEP40: |
| 2503 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2504 | case WPA_CIPHER_GTK_NOT_USED: |
| 2505 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
| 2511 | |
| 2512 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2513 | int max_suites) |
| 2514 | { |
| 2515 | int num_suites = 0; |
| 2516 | |
| 2517 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 2518 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 2519 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 2520 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 2521 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 2522 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 2523 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 2524 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 2525 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 2526 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 2527 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 2528 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 2529 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 2530 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 2531 | |
| 2532 | return num_suites; |
| 2533 | } |
| 2534 | |
| 2535 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2536 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2537 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2538 | const u8 *key, size_t key_len) |
| 2539 | { |
| 2540 | struct nl_msg *msg; |
| 2541 | int ret; |
| 2542 | |
| 2543 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2544 | return 0; |
| 2545 | |
| 2546 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2547 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2548 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2549 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2550 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2551 | nl80211_nlmsg_clear(msg); |
| 2552 | nlmsg_free(msg); |
| 2553 | return -1; |
| 2554 | } |
| 2555 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2556 | if (ret) { |
| 2557 | wpa_printf(MSG_DEBUG, |
| 2558 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2559 | ret, strerror(-ret)); |
| 2560 | } |
| 2561 | |
| 2562 | return ret; |
| 2563 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2564 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2565 | |
| 2566 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2567 | 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] | 2568 | enum wpa_alg alg, const u8 *addr, |
| 2569 | int key_idx, int set_tx, |
| 2570 | const u8 *seq, size_t seq_len, |
| 2571 | const u8 *key, size_t key_len) |
| 2572 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2573 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2574 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2575 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2576 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2577 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2578 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2579 | /* Ignore for P2P Device */ |
| 2580 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2581 | return 0; |
| 2582 | |
| 2583 | ifindex = if_nametoindex(ifname); |
| 2584 | 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] | 2585 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2586 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2587 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2588 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2589 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2590 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2591 | tdls = 1; |
| 2592 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2593 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2594 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2595 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2596 | if (alg == WPA_ALG_PMK && |
| 2597 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2598 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2599 | __func__); |
| 2600 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2601 | return ret; |
| 2602 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2603 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2604 | |
| 2605 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2606 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2607 | if (!msg) |
| 2608 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2609 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2610 | u32 suite; |
| 2611 | |
| 2612 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2613 | if (!suite) |
| 2614 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2615 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2616 | if (!msg || |
| 2617 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2618 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2619 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2620 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2621 | } |
| 2622 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2623 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2624 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2625 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2626 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2627 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2628 | |
| 2629 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2630 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2631 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2632 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2633 | |
| 2634 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2635 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2636 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2637 | NL80211_KEYTYPE_GROUP)) |
| 2638 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2639 | } |
| 2640 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2641 | struct nlattr *types; |
| 2642 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2643 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2644 | |
| 2645 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2646 | if (!types || |
| 2647 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2648 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2649 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2650 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2651 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2652 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2653 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2654 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2655 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2656 | ret = 0; |
| 2657 | if (ret) |
| 2658 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2659 | ret, strerror(-ret)); |
| 2660 | |
| 2661 | /* |
| 2662 | * If we failed or don't need to set the default TX key (below), |
| 2663 | * we're done here. |
| 2664 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2665 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2666 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2667 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2668 | !is_broadcast_ether_addr(addr)) |
| 2669 | return ret; |
| 2670 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2671 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2672 | if (!msg || |
| 2673 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2674 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2675 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2676 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2677 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2678 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2679 | NL80211_ATTR_KEY_DEFAULT)) |
| 2680 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2681 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2682 | struct nlattr *types; |
| 2683 | |
| 2684 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2685 | if (!types || |
| 2686 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2687 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2688 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2689 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2690 | struct nlattr *types; |
| 2691 | |
| 2692 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2693 | if (!types || |
| 2694 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2695 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2696 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2700 | if (ret == -ENOENT) |
| 2701 | ret = 0; |
| 2702 | if (ret) |
| 2703 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2704 | "err=%d %s)", ret, strerror(-ret)); |
| 2705 | return ret; |
| 2706 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2707 | fail: |
| 2708 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2709 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2710 | return -ENOBUFS; |
| 2711 | } |
| 2712 | |
| 2713 | |
| 2714 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 2715 | int key_idx, int defkey, |
| 2716 | const u8 *seq, size_t seq_len, |
| 2717 | const u8 *key, size_t key_len) |
| 2718 | { |
| 2719 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2720 | u32 suite; |
| 2721 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2722 | if (!key_attr) |
| 2723 | return -1; |
| 2724 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2725 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2726 | if (!suite) |
| 2727 | return -1; |
| 2728 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2729 | if (defkey && alg == WPA_ALG_IGTK) { |
| 2730 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 2731 | return -1; |
| 2732 | } else if (defkey) { |
| 2733 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 2734 | return -1; |
| 2735 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2736 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2737 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2738 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2739 | (seq && seq_len && |
| 2740 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 2741 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 2742 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2743 | |
| 2744 | nla_nest_end(msg, key_attr); |
| 2745 | |
| 2746 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | |
| 2750 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 2751 | struct nl_msg *msg) |
| 2752 | { |
| 2753 | int i, privacy = 0; |
| 2754 | struct nlattr *nl_keys, *nl_key; |
| 2755 | |
| 2756 | for (i = 0; i < 4; i++) { |
| 2757 | if (!params->wep_key[i]) |
| 2758 | continue; |
| 2759 | privacy = 1; |
| 2760 | break; |
| 2761 | } |
| 2762 | if (params->wps == WPS_MODE_PRIVACY) |
| 2763 | privacy = 1; |
| 2764 | if (params->pairwise_suite && |
| 2765 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 2766 | privacy = 1; |
| 2767 | |
| 2768 | if (!privacy) |
| 2769 | return 0; |
| 2770 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2771 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 2772 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2773 | |
| 2774 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 2775 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2776 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2777 | |
| 2778 | for (i = 0; i < 4; i++) { |
| 2779 | if (!params->wep_key[i]) |
| 2780 | continue; |
| 2781 | |
| 2782 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2783 | if (!nl_key || |
| 2784 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 2785 | params->wep_key[i]) || |
| 2786 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2787 | params->wep_key_len[i] == 5 ? |
| 2788 | WLAN_CIPHER_SUITE_WEP40 : |
| 2789 | WLAN_CIPHER_SUITE_WEP104) || |
| 2790 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 2791 | (i == params->wep_tx_keyidx && |
| 2792 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 2793 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2794 | |
| 2795 | nla_nest_end(msg, nl_key); |
| 2796 | } |
| 2797 | nla_nest_end(msg, nl_keys); |
| 2798 | |
| 2799 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2803 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 2804 | const u8 *addr, int cmd, u16 reason_code, |
| 2805 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2806 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2807 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2808 | struct nl_msg *msg; |
| 2809 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2810 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 2811 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 2812 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 2813 | (local_state_change && |
| 2814 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 2815 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2816 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2817 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2818 | |
| 2819 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2820 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2821 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2822 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 2823 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2824 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2825 | return ret; |
| 2826 | } |
| 2827 | |
| 2828 | |
| 2829 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2830 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2831 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2832 | int ret; |
| 2833 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2834 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2835 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2836 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2837 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 2838 | reason_code, 0); |
| 2839 | /* |
| 2840 | * For locally generated disconnect, supplicant already generates a |
| 2841 | * DEAUTH event, so ignore the event from NL80211. |
| 2842 | */ |
| 2843 | drv->ignore_next_local_disconnect = ret == 0; |
| 2844 | |
| 2845 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2849 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 2850 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2851 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2852 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2853 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2854 | |
| 2855 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 2856 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2857 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2858 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2859 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2860 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2861 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 2862 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2863 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2864 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 2865 | reason_code, 0); |
| 2866 | /* |
| 2867 | * For locally generated deauthenticate, supplicant already generates a |
| 2868 | * DEAUTH event, so ignore the event from NL80211. |
| 2869 | */ |
| 2870 | drv->ignore_next_local_deauth = ret == 0; |
| 2871 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2875 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 2876 | struct wpa_driver_auth_params *params) |
| 2877 | { |
| 2878 | int i; |
| 2879 | |
| 2880 | drv->auth_freq = params->freq; |
| 2881 | drv->auth_alg = params->auth_alg; |
| 2882 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 2883 | drv->auth_local_state_change = params->local_state_change; |
| 2884 | drv->auth_p2p = params->p2p; |
| 2885 | |
| 2886 | if (params->bssid) |
| 2887 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 2888 | else |
| 2889 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 2890 | |
| 2891 | if (params->ssid) { |
| 2892 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 2893 | drv->auth_ssid_len = params->ssid_len; |
| 2894 | } else |
| 2895 | drv->auth_ssid_len = 0; |
| 2896 | |
| 2897 | |
| 2898 | os_free(drv->auth_ie); |
| 2899 | drv->auth_ie = NULL; |
| 2900 | drv->auth_ie_len = 0; |
| 2901 | if (params->ie) { |
| 2902 | drv->auth_ie = os_malloc(params->ie_len); |
| 2903 | if (drv->auth_ie) { |
| 2904 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 2905 | drv->auth_ie_len = params->ie_len; |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | for (i = 0; i < 4; i++) { |
| 2910 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 2911 | params->wep_key_len[i] <= 16) { |
| 2912 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 2913 | params->wep_key_len[i]); |
| 2914 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 2915 | } else |
| 2916 | drv->auth_wep_key_len[i] = 0; |
| 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2921 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 2922 | { |
| 2923 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2924 | |
| 2925 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 2926 | return; |
| 2927 | |
| 2928 | /* |
| 2929 | * Looks like we failed to unmask 11b rates previously. This could |
| 2930 | * happen, e.g., if the interface was down at the point in time when a |
| 2931 | * P2P group was terminated. |
| 2932 | */ |
| 2933 | wpa_printf(MSG_DEBUG, |
| 2934 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 2935 | bss->ifname); |
| 2936 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2937 | } |
| 2938 | |
| 2939 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2941 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2942 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2943 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2944 | int ret = -1, i; |
| 2945 | struct nl_msg *msg; |
| 2946 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2947 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2948 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2949 | int is_retry; |
| 2950 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2951 | nl80211_unmask_11b_rates(bss); |
| 2952 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2953 | is_retry = drv->retry_auth; |
| 2954 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2955 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2956 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2957 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2958 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2959 | if (params->bssid) |
| 2960 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 2961 | else |
| 2962 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2963 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2964 | nlmode = params->p2p ? |
| 2965 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 2966 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2967 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2968 | return -1; |
| 2969 | |
| 2970 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2971 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 2972 | drv->ifindex); |
| 2973 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2974 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 2975 | if (!msg) |
| 2976 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2977 | |
| 2978 | for (i = 0; i < 4; i++) { |
| 2979 | if (!params->wep_key[i]) |
| 2980 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2981 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2982 | NULL, i, |
| 2983 | i == params->wep_tx_keyidx, NULL, 0, |
| 2984 | params->wep_key[i], |
| 2985 | params->wep_key_len[i]); |
| 2986 | if (params->wep_tx_keyidx != i) |
| 2987 | continue; |
| 2988 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2989 | params->wep_key[i], params->wep_key_len[i])) |
| 2990 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2993 | if (params->bssid) { |
| 2994 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 2995 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2996 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 2997 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2998 | } |
| 2999 | if (params->freq) { |
| 3000 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3001 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3002 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3003 | } |
| 3004 | if (params->ssid) { |
| 3005 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 3006 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3007 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3008 | params->ssid)) |
| 3009 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3010 | } |
| 3011 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3012 | if (params->ie && |
| 3013 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3014 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3015 | if (params->sae_data) { |
| 3016 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 3017 | params->sae_data_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3018 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 3019 | params->sae_data)) |
| 3020 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3021 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3022 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 3023 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3024 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 3025 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 3026 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 3027 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 3028 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 3029 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3030 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 3031 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3032 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3033 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3034 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3035 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 3036 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3037 | if (params->local_state_change) { |
| 3038 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3039 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3040 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3044 | msg = NULL; |
| 3045 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3046 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3047 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 3048 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3049 | count++; |
| 3050 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 3051 | !params->local_state_change) { |
| 3052 | /* |
| 3053 | * mac80211 does not currently accept new |
| 3054 | * authentication if we are already authenticated. As a |
| 3055 | * workaround, force deauthentication and try again. |
| 3056 | */ |
| 3057 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3058 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3059 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3060 | wpa_driver_nl80211_deauthenticate( |
| 3061 | bss, params->bssid, |
| 3062 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3063 | nlmsg_free(msg); |
| 3064 | goto retry; |
| 3065 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3066 | |
| 3067 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3068 | /* |
| 3069 | * cfg80211 has likely expired the BSS entry even |
| 3070 | * though it was previously available in our internal |
| 3071 | * BSS table. To recover quickly, start a single |
| 3072 | * channel scan on the specified channel. |
| 3073 | */ |
| 3074 | struct wpa_driver_scan_params scan; |
| 3075 | int freqs[2]; |
| 3076 | |
| 3077 | os_memset(&scan, 0, sizeof(scan)); |
| 3078 | scan.num_ssids = 1; |
| 3079 | if (params->ssid) { |
| 3080 | scan.ssids[0].ssid = params->ssid; |
| 3081 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3082 | } |
| 3083 | freqs[0] = params->freq; |
| 3084 | freqs[1] = 0; |
| 3085 | scan.freqs = freqs; |
| 3086 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3087 | "channel scan to refresh cfg80211 BSS " |
| 3088 | "entry"); |
| 3089 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3090 | if (ret == 0) { |
| 3091 | nl80211_copy_auth_params(drv, params); |
| 3092 | drv->scan_for_auth = 1; |
| 3093 | } |
| 3094 | } else if (is_retry) { |
| 3095 | /* |
| 3096 | * Need to indicate this with an event since the return |
| 3097 | * value from the retry is not delivered to core code. |
| 3098 | */ |
| 3099 | union wpa_event_data event; |
| 3100 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3101 | "failed"); |
| 3102 | os_memset(&event, 0, sizeof(event)); |
| 3103 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3104 | ETH_ALEN); |
| 3105 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3106 | &event); |
| 3107 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3108 | } else { |
| 3109 | wpa_printf(MSG_DEBUG, |
| 3110 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3111 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3112 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3113 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3114 | nlmsg_free(msg); |
| 3115 | return ret; |
| 3116 | } |
| 3117 | |
| 3118 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3119 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3120 | { |
| 3121 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3122 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3123 | int i; |
| 3124 | |
| 3125 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3126 | |
| 3127 | os_memset(¶ms, 0, sizeof(params)); |
| 3128 | params.freq = drv->auth_freq; |
| 3129 | params.auth_alg = drv->auth_alg; |
| 3130 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3131 | params.local_state_change = drv->auth_local_state_change; |
| 3132 | params.p2p = drv->auth_p2p; |
| 3133 | |
| 3134 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3135 | params.bssid = drv->auth_bssid_; |
| 3136 | |
| 3137 | if (drv->auth_ssid_len) { |
| 3138 | params.ssid = drv->auth_ssid; |
| 3139 | params.ssid_len = drv->auth_ssid_len; |
| 3140 | } |
| 3141 | |
| 3142 | params.ie = drv->auth_ie; |
| 3143 | params.ie_len = drv->auth_ie_len; |
| 3144 | |
| 3145 | for (i = 0; i < 4; i++) { |
| 3146 | if (drv->auth_wep_key_len[i]) { |
| 3147 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3148 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | drv->retry_auth = 1; |
| 3153 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3154 | } |
| 3155 | |
| 3156 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3157 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3158 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3159 | int encrypt, int noack, |
| 3160 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3161 | int offchanok, unsigned int wait_time, |
| 3162 | const u16 *csa_offs, |
| 3163 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3164 | { |
| 3165 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3166 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3167 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3168 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3169 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3170 | freq = nl80211_get_assoc_freq(drv); |
| 3171 | wpa_printf(MSG_DEBUG, |
| 3172 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3173 | freq); |
| 3174 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3175 | if (freq == 0) { |
| 3176 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3177 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3178 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3179 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3180 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3181 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3182 | 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] | 3183 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3184 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3185 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3186 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3187 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3188 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3189 | &cookie, no_cck, noack, offchanok, |
| 3190 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3191 | if (res == 0 && !noack) { |
| 3192 | const struct ieee80211_mgmt *mgmt; |
| 3193 | u16 fc; |
| 3194 | |
| 3195 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3196 | fc = le_to_host16(mgmt->frame_control); |
| 3197 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3198 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3199 | wpa_printf(MSG_MSGDUMP, |
| 3200 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3201 | (long long unsigned int) |
| 3202 | drv->send_action_cookie, |
| 3203 | (long long unsigned int) cookie); |
| 3204 | drv->send_action_cookie = cookie; |
| 3205 | } |
| 3206 | } |
| 3207 | |
| 3208 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3212 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3213 | size_t data_len, int noack, |
| 3214 | unsigned int freq, int no_cck, |
| 3215 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3216 | unsigned int wait_time, |
| 3217 | const u16 *csa_offs, |
| 3218 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3219 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3220 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3221 | struct ieee80211_mgmt *mgmt; |
| 3222 | int encrypt = 1; |
| 3223 | u16 fc; |
| 3224 | |
| 3225 | mgmt = (struct ieee80211_mgmt *) data; |
| 3226 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3227 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3228 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3229 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3230 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3231 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3232 | if ((is_sta_interface(drv->nlmode) || |
| 3233 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3234 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3235 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3236 | /* |
| 3237 | * The use of last_mgmt_freq is a bit of a hack, |
| 3238 | * but it works due to the single-threaded nature |
| 3239 | * of wpa_supplicant. |
| 3240 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3241 | if (freq == 0) { |
| 3242 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3243 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3244 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3245 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3246 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3247 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3248 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3249 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3250 | |
| 3251 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3252 | if (freq == 0) { |
| 3253 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3254 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3255 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3256 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3257 | return nl80211_send_frame_cmd(bss, freq, |
| 3258 | (int) freq == bss->freq ? 0 : |
| 3259 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3260 | data, data_len, |
| 3261 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3262 | no_cck, noack, offchanok, |
| 3263 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3264 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3265 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3266 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3267 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3268 | /* |
| 3269 | * Only one of the authentication frame types is encrypted. |
| 3270 | * In order for static WEP encryption to work properly (i.e., |
| 3271 | * to not encrypt the frame), we need to tell mac80211 about |
| 3272 | * the frames that must not be encrypted. |
| 3273 | */ |
| 3274 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3275 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3276 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3277 | encrypt = 0; |
| 3278 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3279 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3280 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3281 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3282 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3283 | wait_time, csa_offs, |
| 3284 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3288 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3289 | { |
| 3290 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3291 | u8 rates_len = 0; |
| 3292 | int i; |
| 3293 | |
| 3294 | if (!basic_rates) |
| 3295 | return 0; |
| 3296 | |
| 3297 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3298 | rates[rates_len++] = basic_rates[i] / 5; |
| 3299 | |
| 3300 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3301 | } |
| 3302 | |
| 3303 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3304 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3305 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3306 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3307 | { |
| 3308 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3309 | struct nl_msg *msg; |
| 3310 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3311 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3312 | (cts >= 0 && |
| 3313 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3314 | (preamble >= 0 && |
| 3315 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3316 | (slot >= 0 && |
| 3317 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3318 | (ht_opmode >= 0 && |
| 3319 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3320 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3321 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3322 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3323 | nlmsg_free(msg); |
| 3324 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3325 | } |
| 3326 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3327 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3331 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3332 | struct hostapd_acl_params *params) |
| 3333 | { |
| 3334 | struct i802_bss *bss = priv; |
| 3335 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3336 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3337 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3338 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3339 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3340 | |
| 3341 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3342 | return -ENOTSUP; |
| 3343 | |
| 3344 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3345 | return -ENOTSUP; |
| 3346 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3347 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3348 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3349 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3350 | acl = nlmsg_alloc(); |
| 3351 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3352 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3353 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3354 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3355 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3356 | return -ENOMEM; |
| 3357 | } |
| 3358 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3359 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3360 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3361 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3362 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3363 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3364 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3365 | nlmsg_free(msg); |
| 3366 | nlmsg_free(acl); |
| 3367 | return -ENOMEM; |
| 3368 | } |
| 3369 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3370 | |
| 3371 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3372 | if (ret) { |
| 3373 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3374 | ret, strerror(-ret)); |
| 3375 | } |
| 3376 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3377 | return ret; |
| 3378 | } |
| 3379 | |
| 3380 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3381 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3382 | { |
| 3383 | if (beacon_int > 0) { |
| 3384 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3385 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3386 | beacon_int); |
| 3387 | } |
| 3388 | |
| 3389 | return 0; |
| 3390 | } |
| 3391 | |
| 3392 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3393 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3394 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3395 | { |
| 3396 | struct i802_bss *bss = priv; |
| 3397 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3398 | struct nl_msg *msg; |
| 3399 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3400 | int ret; |
| 3401 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3402 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3403 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3404 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3405 | u32 ver; |
| 3406 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3407 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3408 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3409 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3410 | beacon_set); |
| 3411 | if (beacon_set) |
| 3412 | cmd = NL80211_CMD_SET_BEACON; |
| 3413 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3414 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3415 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3416 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3417 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3418 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3419 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3420 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3421 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3422 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3423 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3424 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3425 | params->head) || |
| 3426 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3427 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3428 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3429 | nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) || |
| 3430 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3431 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3432 | if (params->proberesp && params->proberesp_len) { |
| 3433 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3434 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3435 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3436 | params->proberesp)) |
| 3437 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3438 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3439 | switch (params->hide_ssid) { |
| 3440 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3441 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3442 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3443 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3444 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3445 | break; |
| 3446 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3447 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3448 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3449 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3450 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3451 | break; |
| 3452 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3453 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3454 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3455 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3456 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3457 | break; |
| 3458 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3459 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3460 | if (params->privacy && |
| 3461 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3462 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3463 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3464 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3465 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3466 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3467 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3468 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3469 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3470 | goto fail; |
| 3471 | } else { |
| 3472 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3473 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3474 | goto fail; |
| 3475 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3476 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3477 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3478 | ver = 0; |
| 3479 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3480 | ver |= NL80211_WPA_VERSION_1; |
| 3481 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3482 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3483 | if (ver && |
| 3484 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3485 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3486 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3487 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3488 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3489 | num_suites = 0; |
| 3490 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 3491 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 3492 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 3493 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3494 | if (num_suites && |
| 3495 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3496 | suites)) |
| 3497 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3498 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3499 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 3500 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) && |
| 3501 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) |
| 3502 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3503 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3504 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 3505 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3506 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 3507 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3508 | if (num_suites && |
| 3509 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 3510 | num_suites * sizeof(u32), suites)) |
| 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: group_cipher=0x%x", |
| 3514 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3515 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3516 | if (suite && |
| 3517 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 3518 | goto fail; |
| 3519 | |
| 3520 | switch (params->smps_mode) { |
| 3521 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 3522 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 3523 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 3524 | break; |
| 3525 | case HT_CAP_INFO_SMPS_STATIC: |
| 3526 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 3527 | smps_mode = NL80211_SMPS_STATIC; |
| 3528 | break; |
| 3529 | default: |
| 3530 | /* invalid - fallback to smps off */ |
| 3531 | case HT_CAP_INFO_SMPS_DISABLED: |
| 3532 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 3533 | smps_mode = NL80211_SMPS_OFF; |
| 3534 | break; |
| 3535 | } |
| 3536 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
| 3537 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3538 | |
| 3539 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3540 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 3541 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3542 | if (nla_put(msg, NL80211_ATTR_IE, |
| 3543 | wpabuf_len(params->beacon_ies), |
| 3544 | wpabuf_head(params->beacon_ies))) |
| 3545 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3546 | } |
| 3547 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3548 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 3549 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3550 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 3551 | wpabuf_len(params->proberesp_ies), |
| 3552 | wpabuf_head(params->proberesp_ies))) |
| 3553 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3554 | } |
| 3555 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3556 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 3557 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3558 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 3559 | wpabuf_len(params->assocresp_ies), |
| 3560 | wpabuf_head(params->assocresp_ies))) |
| 3561 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3562 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3563 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3564 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3565 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 3566 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3567 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 3568 | params->ap_max_inactivity)) |
| 3569 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3572 | #ifdef CONFIG_P2P |
| 3573 | if (params->p2p_go_ctwindow > 0) { |
| 3574 | if (drv->p2p_go_ctwindow_supported) { |
| 3575 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 3576 | params->p2p_go_ctwindow); |
| 3577 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 3578 | params->p2p_go_ctwindow)) |
| 3579 | goto fail; |
| 3580 | } else { |
| 3581 | wpa_printf(MSG_INFO, |
| 3582 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 3583 | } |
| 3584 | } |
| 3585 | #endif /* CONFIG_P2P */ |
| 3586 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 3587 | if (params->pbss) { |
| 3588 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 3589 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 3590 | goto fail; |
| 3591 | } |
| 3592 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3593 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3594 | if (ret) { |
| 3595 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 3596 | ret, strerror(-ret)); |
| 3597 | } else { |
| 3598 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3599 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 3600 | params->short_slot_time, params->ht_opmode, |
| 3601 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3602 | if (beacon_set && params->freq && |
| 3603 | params->freq->bandwidth != bss->bandwidth) { |
| 3604 | wpa_printf(MSG_DEBUG, |
| 3605 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 3606 | bss->ifname, bss->bandwidth, |
| 3607 | params->freq->bandwidth); |
| 3608 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 3609 | if (ret) { |
| 3610 | wpa_printf(MSG_DEBUG, |
| 3611 | "nl80211: Frequency set failed: %d (%s)", |
| 3612 | ret, strerror(-ret)); |
| 3613 | } else { |
| 3614 | wpa_printf(MSG_DEBUG, |
| 3615 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 3616 | bss->bandwidth = params->freq->bandwidth; |
| 3617 | } |
| 3618 | } else if (!beacon_set) { |
| 3619 | /* |
| 3620 | * cfg80211 updates the driver on frequence change in AP |
| 3621 | * mode only at the point when beaconing is started, so |
| 3622 | * set the initial value here. |
| 3623 | */ |
| 3624 | bss->bandwidth = params->freq->bandwidth; |
| 3625 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3626 | } |
| 3627 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3628 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3629 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3630 | return -ENOBUFS; |
| 3631 | } |
| 3632 | |
| 3633 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3634 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3635 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3636 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3637 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3638 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 3639 | return -ENOBUFS; |
| 3640 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3641 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 3642 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 3643 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3644 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3645 | enum nl80211_chan_width cw; |
| 3646 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3647 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3648 | switch (freq->bandwidth) { |
| 3649 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3650 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3651 | break; |
| 3652 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3653 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3654 | break; |
| 3655 | case 80: |
| 3656 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3657 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3658 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3659 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3660 | break; |
| 3661 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3662 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3663 | break; |
| 3664 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3665 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3666 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3667 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3668 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 3669 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 3670 | freq->center_freq1); |
| 3671 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 3672 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3673 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 3674 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 3675 | freq->center_freq1) || |
| 3676 | (freq->center_freq2 && |
| 3677 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 3678 | freq->center_freq2))) |
| 3679 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3680 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3681 | enum nl80211_channel_type ct; |
| 3682 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3683 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 3684 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3685 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3686 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3687 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3688 | break; |
| 3689 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3690 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3691 | break; |
| 3692 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3693 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3694 | break; |
| 3695 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3696 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3697 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3698 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 3699 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3700 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3701 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3705 | static int nl80211_set_channel(struct i802_bss *bss, |
| 3706 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3707 | { |
| 3708 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3709 | struct nl_msg *msg; |
| 3710 | int ret; |
| 3711 | |
| 3712 | wpa_printf(MSG_DEBUG, |
| 3713 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 3714 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 3715 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3716 | |
| 3717 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 3718 | NL80211_CMD_SET_WIPHY); |
| 3719 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 3720 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3721 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3722 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3723 | |
| 3724 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3725 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3726 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3727 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3728 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3729 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3730 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3731 | return -1; |
| 3732 | } |
| 3733 | |
| 3734 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3735 | static u32 sta_flags_nl80211(int flags) |
| 3736 | { |
| 3737 | u32 f = 0; |
| 3738 | |
| 3739 | if (flags & WPA_STA_AUTHORIZED) |
| 3740 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3741 | if (flags & WPA_STA_WMM) |
| 3742 | f |= BIT(NL80211_STA_FLAG_WME); |
| 3743 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 3744 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 3745 | if (flags & WPA_STA_MFP) |
| 3746 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 3747 | if (flags & WPA_STA_TDLS_PEER) |
| 3748 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3749 | if (flags & WPA_STA_AUTHENTICATED) |
| 3750 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 3751 | if (flags & WPA_STA_ASSOCIATED) |
| 3752 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3753 | |
| 3754 | return f; |
| 3755 | } |
| 3756 | |
| 3757 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3758 | #ifdef CONFIG_MESH |
| 3759 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 3760 | { |
| 3761 | switch (state) { |
| 3762 | case PLINK_LISTEN: |
| 3763 | return NL80211_PLINK_LISTEN; |
| 3764 | case PLINK_OPEN_SENT: |
| 3765 | return NL80211_PLINK_OPN_SNT; |
| 3766 | case PLINK_OPEN_RCVD: |
| 3767 | return NL80211_PLINK_OPN_RCVD; |
| 3768 | case PLINK_CNF_RCVD: |
| 3769 | return NL80211_PLINK_CNF_RCVD; |
| 3770 | case PLINK_ESTAB: |
| 3771 | return NL80211_PLINK_ESTAB; |
| 3772 | case PLINK_HOLDING: |
| 3773 | return NL80211_PLINK_HOLDING; |
| 3774 | case PLINK_BLOCKED: |
| 3775 | return NL80211_PLINK_BLOCKED; |
| 3776 | default: |
| 3777 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 3778 | state); |
| 3779 | } |
| 3780 | return -1; |
| 3781 | } |
| 3782 | #endif /* CONFIG_MESH */ |
| 3783 | |
| 3784 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3785 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 3786 | struct hostapd_sta_add_params *params) |
| 3787 | { |
| 3788 | struct i802_bss *bss = priv; |
| 3789 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3790 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3791 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3792 | int ret = -ENOBUFS; |
| 3793 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3794 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 3795 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 3796 | return -EOPNOTSUPP; |
| 3797 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3798 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 3799 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3800 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 3801 | NL80211_CMD_NEW_STATION); |
| 3802 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 3803 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3804 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 3805 | /* |
| 3806 | * Set the below properties only in one of the following cases: |
| 3807 | * 1. New station is added, already associated. |
| 3808 | * 2. Set WPA_STA_TDLS_PEER station. |
| 3809 | * 3. Set an already added unassociated station, if driver supports |
| 3810 | * full AP client state. (Set these properties after station became |
| 3811 | * associated will be rejected by the driver). |
| 3812 | */ |
| 3813 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 3814 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 3815 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3816 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 3817 | params->supp_rates, params->supp_rates_len); |
| 3818 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 3819 | params->capability); |
| 3820 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 3821 | params->supp_rates_len, params->supp_rates) || |
| 3822 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 3823 | params->capability)) |
| 3824 | goto fail; |
| 3825 | |
| 3826 | if (params->ht_capabilities) { |
| 3827 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 3828 | (u8 *) params->ht_capabilities, |
| 3829 | sizeof(*params->ht_capabilities)); |
| 3830 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 3831 | sizeof(*params->ht_capabilities), |
| 3832 | params->ht_capabilities)) |
| 3833 | goto fail; |
| 3834 | } |
| 3835 | |
| 3836 | if (params->vht_capabilities) { |
| 3837 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 3838 | (u8 *) params->vht_capabilities, |
| 3839 | sizeof(*params->vht_capabilities)); |
| 3840 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 3841 | sizeof(*params->vht_capabilities), |
| 3842 | params->vht_capabilities)) |
| 3843 | goto fail; |
| 3844 | } |
| 3845 | |
| 3846 | if (params->ext_capab) { |
| 3847 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 3848 | params->ext_capab, params->ext_capab_len); |
| 3849 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 3850 | params->ext_capab_len, params->ext_capab)) |
| 3851 | goto fail; |
| 3852 | } |
| 3853 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3854 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3855 | if (params->aid) { |
| 3856 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3857 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 3858 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3859 | } else { |
| 3860 | /* |
| 3861 | * cfg80211 validates that AID is non-zero, so we have |
| 3862 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 3863 | * a dummy STA entry is used for now and for a station |
| 3864 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3865 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 3866 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 3867 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 3868 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3869 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 3870 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3871 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3872 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 3873 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3874 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 3875 | params->listen_interval)) |
| 3876 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3877 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 3878 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3879 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 3880 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 3881 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 3882 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 3883 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 3884 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 3885 | params->listen_interval); |
| 3886 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 3887 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 3888 | params->listen_interval)) |
| 3889 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3890 | } |
| 3891 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3892 | if (params->vht_opmode_enabled) { |
| 3893 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3894 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 3895 | params->vht_opmode)) |
| 3896 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3897 | } |
| 3898 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3899 | if (params->supp_channels) { |
| 3900 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 3901 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3902 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 3903 | params->supp_channels_len, params->supp_channels)) |
| 3904 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | if (params->supp_oper_classes) { |
| 3908 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 3909 | params->supp_oper_classes, |
| 3910 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3911 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 3912 | params->supp_oper_classes_len, |
| 3913 | params->supp_oper_classes)) |
| 3914 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3915 | } |
| 3916 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3917 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3918 | upd.set = sta_flags_nl80211(params->flags); |
| 3919 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 3920 | |
| 3921 | /* |
| 3922 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 3923 | * flags, as nl80211 driver moves a new station, by default, into |
| 3924 | * associated state. |
| 3925 | * |
| 3926 | * On the other hand, if the driver supports that feature and the |
| 3927 | * station is added in unauthenticated state, set the |
| 3928 | * authenticated/associated bits in the mask to prevent moving this |
| 3929 | * station to associated state before it is actually associated. |
| 3930 | * |
| 3931 | * This is irrelevant for mesh mode where the station is added to the |
| 3932 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 3933 | * nl80211 API. |
| 3934 | */ |
| 3935 | if (!is_mesh_interface(drv->nlmode)) { |
| 3936 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 3937 | wpa_printf(MSG_DEBUG, |
| 3938 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 3939 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3940 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 3941 | } else if (!params->set && |
| 3942 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 3943 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 3944 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 3945 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 3946 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 3947 | } |
| 3948 | } |
| 3949 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3950 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 3951 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3952 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 3953 | goto fail; |
| 3954 | |
| 3955 | #ifdef CONFIG_MESH |
| 3956 | if (params->plink_state && |
| 3957 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 3958 | sta_plink_state_nl80211(params->plink_state))) |
| 3959 | goto fail; |
| 3960 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3961 | |
| 3962 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3963 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 3964 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3965 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3966 | if (!wme || |
| 3967 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 3968 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 3969 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 3970 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 3971 | WMM_QOSINFO_STA_SP_MASK)) |
| 3972 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3973 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3974 | } |
| 3975 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3976 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3977 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3978 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3979 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 3980 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 3981 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3982 | if (ret == -EEXIST) |
| 3983 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3984 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3985 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3986 | return ret; |
| 3987 | } |
| 3988 | |
| 3989 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3990 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 3991 | { |
| 3992 | #ifdef CONFIG_LIBNL3_ROUTE |
| 3993 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3994 | struct rtnl_neigh *rn; |
| 3995 | struct nl_addr *nl_addr; |
| 3996 | int err; |
| 3997 | |
| 3998 | rn = rtnl_neigh_alloc(); |
| 3999 | if (!rn) |
| 4000 | return; |
| 4001 | |
| 4002 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4003 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4004 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4005 | if (!nl_addr) { |
| 4006 | rtnl_neigh_put(rn); |
| 4007 | return; |
| 4008 | } |
| 4009 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4010 | |
| 4011 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4012 | if (err < 0) { |
| 4013 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4014 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4015 | bss->ifindex, nl_geterror(err)); |
| 4016 | } else { |
| 4017 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4018 | MACSTR, MAC2STR(addr)); |
| 4019 | } |
| 4020 | |
| 4021 | nl_addr_put(nl_addr); |
| 4022 | rtnl_neigh_put(rn); |
| 4023 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4024 | } |
| 4025 | |
| 4026 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4027 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4028 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4029 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4030 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4031 | struct nl_msg *msg; |
| 4032 | int ret; |
| 4033 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4034 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4035 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4036 | (deauth == 0 && |
| 4037 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4038 | WLAN_FC_STYPE_DISASSOC)) || |
| 4039 | (deauth == 1 && |
| 4040 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4041 | WLAN_FC_STYPE_DEAUTH)) || |
| 4042 | (reason_code && |
| 4043 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4044 | nlmsg_free(msg); |
| 4045 | return -ENOBUFS; |
| 4046 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4047 | |
| 4048 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4049 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4050 | " --> %d (%s)", |
| 4051 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4052 | |
| 4053 | if (drv->rtnl_sk) |
| 4054 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4055 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4056 | if (ret == -ENOENT) |
| 4057 | return 0; |
| 4058 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4062 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4063 | { |
| 4064 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4065 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4066 | |
| 4067 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4068 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4069 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4070 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4071 | struct wpa_driver_nl80211_data, list) |
| 4072 | del_ifidx(drv2, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4073 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4074 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4075 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4076 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4077 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4078 | } |
| 4079 | |
| 4080 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4081 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 4082 | { |
| 4083 | switch (mode) { |
| 4084 | case NL80211_IFTYPE_ADHOC: |
| 4085 | return "ADHOC"; |
| 4086 | case NL80211_IFTYPE_STATION: |
| 4087 | return "STATION"; |
| 4088 | case NL80211_IFTYPE_AP: |
| 4089 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4090 | case NL80211_IFTYPE_AP_VLAN: |
| 4091 | return "AP_VLAN"; |
| 4092 | case NL80211_IFTYPE_WDS: |
| 4093 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4094 | case NL80211_IFTYPE_MONITOR: |
| 4095 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4096 | case NL80211_IFTYPE_MESH_POINT: |
| 4097 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4098 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4099 | return "P2P_CLIENT"; |
| 4100 | case NL80211_IFTYPE_P2P_GO: |
| 4101 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4102 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4103 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4104 | default: |
| 4105 | return "unknown"; |
| 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4110 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 4111 | const char *ifname, |
| 4112 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4113 | const u8 *addr, int wds, |
| 4114 | int (*handler)(struct nl_msg *, void *), |
| 4115 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4116 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4117 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4118 | int ifidx; |
| 4119 | int ret = -ENOBUFS; |
| 4120 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4121 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4122 | iftype, nl80211_iftype_str(iftype)); |
| 4123 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4124 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4125 | if (!msg || |
| 4126 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4127 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4128 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4129 | |
| 4130 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4131 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4132 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4133 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4134 | if (!flags || |
| 4135 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4136 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4137 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4138 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4139 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4140 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4141 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4142 | } |
| 4143 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4144 | /* |
| 4145 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4146 | * it, and the interface should be deleted when the socket is closed. |
| 4147 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4148 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4149 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4150 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4151 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4152 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4153 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4154 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4155 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4156 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4157 | ifname, ret, strerror(-ret)); |
| 4158 | return ret; |
| 4159 | } |
| 4160 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4161 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4162 | return 0; |
| 4163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4164 | ifidx = if_nametoindex(ifname); |
| 4165 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4166 | ifname, ifidx); |
| 4167 | |
| 4168 | if (ifidx <= 0) |
| 4169 | return -1; |
| 4170 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4171 | /* |
| 4172 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4173 | * the parent interface. This is used mainly with hostapd. |
| 4174 | */ |
| 4175 | if (drv->hostapd || |
| 4176 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4177 | iftype == NL80211_IFTYPE_WDS || |
| 4178 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4179 | /* start listening for EAPOL on this interface */ |
| 4180 | add_ifidx(drv, ifidx); |
| 4181 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4182 | |
| 4183 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4184 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4185 | nl80211_remove_iface(drv, ifidx); |
| 4186 | return -1; |
| 4187 | } |
| 4188 | |
| 4189 | return ifidx; |
| 4190 | } |
| 4191 | |
| 4192 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4193 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4194 | const char *ifname, enum nl80211_iftype iftype, |
| 4195 | const u8 *addr, int wds, |
| 4196 | int (*handler)(struct nl_msg *, void *), |
| 4197 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4198 | { |
| 4199 | int ret; |
| 4200 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4201 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4202 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4203 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4204 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4205 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4206 | if (use_existing) { |
| 4207 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4208 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4209 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4210 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4211 | addr) < 0 && |
| 4212 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4213 | ifname, 0) < 0 || |
| 4214 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4215 | addr) < 0 || |
| 4216 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4217 | ifname, 1) < 0)) |
| 4218 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4219 | return -ENFILE; |
| 4220 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4221 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4222 | |
| 4223 | /* Try to remove the interface that was already there. */ |
| 4224 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4225 | |
| 4226 | /* Try to create the interface again */ |
| 4227 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4228 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4229 | } |
| 4230 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4231 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4232 | wpa_printf(MSG_DEBUG, |
| 4233 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4234 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4235 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4236 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4237 | |
| 4238 | return ret; |
| 4239 | } |
| 4240 | |
| 4241 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4242 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4243 | { |
| 4244 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4245 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4246 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4247 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4248 | |
| 4249 | /* |
| 4250 | * Disable Probe Request reporting unless we need it in this way for |
| 4251 | * devices that include the AP SME, in the other case (unless using |
| 4252 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4253 | */ |
| 4254 | if (!drv->device_ap_sme) |
| 4255 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4256 | |
| 4257 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4258 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4259 | return -1; |
| 4260 | |
| 4261 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4262 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 4263 | return -1; |
| 4264 | |
| 4265 | if (!drv->device_ap_sme && drv->use_monitor && |
| 4266 | nl80211_create_monitor_interface(drv) && |
| 4267 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4268 | return -1; |
| 4269 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4270 | if (drv->device_ap_sme && |
| 4271 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4272 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4273 | "Probe Request frame reporting in AP mode"); |
| 4274 | /* Try to survive without this */ |
| 4275 | } |
| 4276 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4277 | return 0; |
| 4278 | } |
| 4279 | |
| 4280 | |
| 4281 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4282 | { |
| 4283 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4284 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4285 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4286 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4287 | if (drv->device_ap_sme) { |
| 4288 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4289 | if (!drv->use_monitor) |
| 4290 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4291 | } else if (drv->use_monitor) |
| 4292 | nl80211_remove_monitor_interface(drv); |
| 4293 | else |
| 4294 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4295 | |
| 4296 | bss->beacon_set = 0; |
| 4297 | } |
| 4298 | |
| 4299 | |
| 4300 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4301 | const u8 *addr, const u8 *data, |
| 4302 | size_t data_len) |
| 4303 | { |
| 4304 | struct sockaddr_ll ll; |
| 4305 | int ret; |
| 4306 | |
| 4307 | if (bss->drv->eapol_tx_sock < 0) { |
| 4308 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4309 | return -1; |
| 4310 | } |
| 4311 | |
| 4312 | os_memset(&ll, 0, sizeof(ll)); |
| 4313 | ll.sll_family = AF_PACKET; |
| 4314 | ll.sll_ifindex = bss->ifindex; |
| 4315 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4316 | ll.sll_halen = ETH_ALEN; |
| 4317 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4318 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4319 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4320 | if (ret < 0) |
| 4321 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4322 | strerror(errno)); |
| 4323 | |
| 4324 | return ret; |
| 4325 | } |
| 4326 | |
| 4327 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4328 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4329 | |
| 4330 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4331 | void *priv, const u8 *addr, const u8 *data, |
| 4332 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4333 | { |
| 4334 | struct i802_bss *bss = priv; |
| 4335 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4336 | struct ieee80211_hdr *hdr; |
| 4337 | size_t len; |
| 4338 | u8 *pos; |
| 4339 | int res; |
| 4340 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4341 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4342 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4343 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4344 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4345 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4346 | data_len; |
| 4347 | hdr = os_zalloc(len); |
| 4348 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4349 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4350 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4351 | return -1; |
| 4352 | } |
| 4353 | |
| 4354 | hdr->frame_control = |
| 4355 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4356 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4357 | if (encrypt) |
| 4358 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4359 | if (qos) { |
| 4360 | hdr->frame_control |= |
| 4361 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4362 | } |
| 4363 | |
| 4364 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4365 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4366 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4367 | pos = (u8 *) (hdr + 1); |
| 4368 | |
| 4369 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4370 | /* Set highest priority in QoS header */ |
| 4371 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4372 | pos[1] = 0; |
| 4373 | pos += 2; |
| 4374 | } |
| 4375 | |
| 4376 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4377 | pos += sizeof(rfc1042_header); |
| 4378 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4379 | pos += 2; |
| 4380 | memcpy(pos, data, data_len); |
| 4381 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4382 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4383 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4384 | if (res < 0) { |
| 4385 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4386 | "failed: %d (%s)", |
| 4387 | (unsigned long) len, errno, strerror(errno)); |
| 4388 | } |
| 4389 | os_free(hdr); |
| 4390 | |
| 4391 | return res; |
| 4392 | } |
| 4393 | |
| 4394 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4395 | 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] | 4396 | unsigned int total_flags, |
| 4397 | unsigned int flags_or, |
| 4398 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4399 | { |
| 4400 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4401 | struct nl_msg *msg; |
| 4402 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4403 | struct nl80211_sta_flag_update upd; |
| 4404 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4405 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4406 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4407 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4408 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4409 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4410 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4411 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4412 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4413 | |
| 4414 | /* |
| 4415 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4416 | * can be removed eventually. |
| 4417 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4418 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4419 | if (!flags || |
| 4420 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4421 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4422 | ((total_flags & WPA_STA_WMM) && |
| 4423 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4424 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4425 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4426 | ((total_flags & WPA_STA_MFP) && |
| 4427 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4428 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4429 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4430 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4431 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4432 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4433 | |
| 4434 | os_memset(&upd, 0, sizeof(upd)); |
| 4435 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4436 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4437 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4438 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4439 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4440 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4441 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4442 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4443 | return -ENOBUFS; |
| 4444 | } |
| 4445 | |
| 4446 | |
| 4447 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4448 | struct wpa_driver_associate_params *params) |
| 4449 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4450 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4451 | |
| 4452 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4453 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4454 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4455 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4456 | } else |
| 4457 | nlmode = NL80211_IFTYPE_AP; |
| 4458 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4459 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4460 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4461 | nl80211_remove_monitor_interface(drv); |
| 4462 | return -1; |
| 4463 | } |
| 4464 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4465 | if (params->freq.freq && |
| 4466 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4467 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4468 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4469 | nl80211_remove_monitor_interface(drv); |
| 4470 | return -1; |
| 4471 | } |
| 4472 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4473 | return 0; |
| 4474 | } |
| 4475 | |
| 4476 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4477 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 4478 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4479 | { |
| 4480 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4481 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4482 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4483 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4484 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4485 | if (ret) { |
| 4486 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 4487 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4488 | } else { |
| 4489 | wpa_printf(MSG_DEBUG, |
| 4490 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4491 | } |
| 4492 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4493 | if (reset_mode && |
| 4494 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4495 | NL80211_IFTYPE_STATION)) { |
| 4496 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4497 | "station mode"); |
| 4498 | } |
| 4499 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4500 | return ret; |
| 4501 | } |
| 4502 | |
| 4503 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4504 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 4505 | struct wpa_driver_associate_params *params) |
| 4506 | { |
| 4507 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 4508 | return -1; |
| 4509 | |
| 4510 | if (params->htcaps && params->htcaps_mask) { |
| 4511 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 4512 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 4513 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 4514 | params->htcaps_mask, sz); |
| 4515 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 4516 | params->htcaps) || |
| 4517 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 4518 | params->htcaps_mask)) |
| 4519 | return -1; |
| 4520 | } |
| 4521 | |
| 4522 | #ifdef CONFIG_VHT_OVERRIDES |
| 4523 | if (params->disable_vht) { |
| 4524 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 4525 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 4526 | return -1; |
| 4527 | } |
| 4528 | |
| 4529 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 4530 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 4531 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 4532 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 4533 | params->vhtcaps_mask, sz); |
| 4534 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 4535 | params->vhtcaps) || |
| 4536 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 4537 | params->vhtcaps_mask)) |
| 4538 | return -1; |
| 4539 | } |
| 4540 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 4541 | |
| 4542 | return 0; |
| 4543 | } |
| 4544 | |
| 4545 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4546 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 4547 | struct wpa_driver_associate_params *params) |
| 4548 | { |
| 4549 | struct nl_msg *msg; |
| 4550 | int ret = -1; |
| 4551 | int count = 0; |
| 4552 | |
| 4553 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 4554 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4555 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4556 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4557 | "IBSS mode"); |
| 4558 | return -1; |
| 4559 | } |
| 4560 | |
| 4561 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4562 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 4563 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 4564 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4565 | |
| 4566 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4567 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4568 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4569 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4570 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4571 | drv->ssid_len = params->ssid_len; |
| 4572 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4573 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 4574 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4575 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4576 | |
| 4577 | ret = nl80211_set_conn_keys(params, msg); |
| 4578 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4579 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4580 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4581 | if (params->bssid && params->fixed_bssid) { |
| 4582 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 4583 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4584 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4585 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4586 | } |
| 4587 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4588 | if (params->fixed_freq) { |
| 4589 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 4590 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 4591 | goto fail; |
| 4592 | } |
| 4593 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4594 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4595 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4596 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 4597 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4598 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4599 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4600 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4601 | } |
| 4602 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4603 | if (params->wpa_ie) { |
| 4604 | wpa_hexdump(MSG_DEBUG, |
| 4605 | " * Extra IEs for Beacon/Probe Response frames", |
| 4606 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4607 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 4608 | params->wpa_ie)) |
| 4609 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4610 | } |
| 4611 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 4612 | ret = nl80211_ht_vht_overrides(msg, params); |
| 4613 | if (ret < 0) |
| 4614 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4615 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4616 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4617 | msg = NULL; |
| 4618 | if (ret) { |
| 4619 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 4620 | ret, strerror(-ret)); |
| 4621 | count++; |
| 4622 | if (ret == -EALREADY && count == 1) { |
| 4623 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 4624 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4625 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4626 | nlmsg_free(msg); |
| 4627 | goto retry; |
| 4628 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4629 | } else { |
| 4630 | wpa_printf(MSG_DEBUG, |
| 4631 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4632 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4633 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4634 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4635 | nlmsg_free(msg); |
| 4636 | return ret; |
| 4637 | } |
| 4638 | |
| 4639 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4640 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 4641 | struct wpa_driver_associate_params *params, |
| 4642 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4643 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4644 | if (params->bssid) { |
| 4645 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4646 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4647 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4648 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4649 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4650 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4651 | if (params->bssid_hint) { |
| 4652 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 4653 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4654 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 4655 | params->bssid_hint)) |
| 4656 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4657 | } |
| 4658 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4659 | if (params->freq.freq) { |
| 4660 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4661 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 4662 | params->freq.freq)) |
| 4663 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4664 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4665 | } else |
| 4666 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4667 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4668 | if (params->freq_hint) { |
| 4669 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4670 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 4671 | params->freq_hint)) |
| 4672 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4673 | } |
| 4674 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4675 | if (params->bg_scan_period >= 0) { |
| 4676 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 4677 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4678 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 4679 | params->bg_scan_period)) |
| 4680 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4681 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4682 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4683 | if (params->ssid) { |
| 4684 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4685 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4686 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4687 | params->ssid)) |
| 4688 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4689 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4690 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4691 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4692 | drv->ssid_len = params->ssid_len; |
| 4693 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4694 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4695 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4696 | if (params->wpa_ie && |
| 4697 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 4698 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4699 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4700 | if (params->wpa_proto) { |
| 4701 | enum nl80211_wpa_versions ver = 0; |
| 4702 | |
| 4703 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 4704 | ver |= NL80211_WPA_VERSION_1; |
| 4705 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 4706 | ver |= NL80211_WPA_VERSION_2; |
| 4707 | |
| 4708 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4709 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4710 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 4714 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 4715 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4716 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4717 | cipher)) |
| 4718 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4719 | } |
| 4720 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4721 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 4722 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 4723 | /* |
| 4724 | * This is likely to work even though many drivers do not |
| 4725 | * advertise support for operations without GTK. |
| 4726 | */ |
| 4727 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 4728 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4729 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 4730 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4731 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 4732 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4736 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4737 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 4738 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4739 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4740 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 4741 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4742 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4743 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
| 4744 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4745 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 4746 | |
| 4747 | switch (params->key_mgmt_suite) { |
| 4748 | case WPA_KEY_MGMT_CCKM: |
| 4749 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 4750 | break; |
| 4751 | case WPA_KEY_MGMT_IEEE8021X: |
| 4752 | mgmt = WLAN_AKM_SUITE_8021X; |
| 4753 | break; |
| 4754 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 4755 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 4756 | break; |
| 4757 | case WPA_KEY_MGMT_FT_PSK: |
| 4758 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 4759 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4760 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 4761 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; |
| 4762 | break; |
| 4763 | case WPA_KEY_MGMT_PSK_SHA256: |
| 4764 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; |
| 4765 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4766 | case WPA_KEY_MGMT_OSEN: |
| 4767 | mgmt = WLAN_AKM_SUITE_OSEN; |
| 4768 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4769 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 4770 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; |
| 4771 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4772 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
| 4773 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; |
| 4774 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4775 | case WPA_KEY_MGMT_PSK: |
| 4776 | default: |
| 4777 | mgmt = WLAN_AKM_SUITE_PSK; |
| 4778 | break; |
| 4779 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4780 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4781 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 4782 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4783 | } |
| 4784 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4785 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4786 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4787 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4788 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 4789 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 4790 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4791 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4792 | if (params->rrm_used) { |
| 4793 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
| 4794 | if (!(drv_rrm_flags & |
| 4795 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) || |
| 4796 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) || |
| 4797 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 4798 | return -1; |
| 4799 | } |
| 4800 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4801 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4802 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4803 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4804 | if (params->p2p) |
| 4805 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 4806 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 4807 | if (params->pbss) { |
| 4808 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 4809 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4810 | return -1; |
| 4811 | } |
| 4812 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4813 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | |
| 4817 | static int wpa_driver_nl80211_try_connect( |
| 4818 | struct wpa_driver_nl80211_data *drv, |
| 4819 | struct wpa_driver_associate_params *params) |
| 4820 | { |
| 4821 | struct nl_msg *msg; |
| 4822 | enum nl80211_auth_type type; |
| 4823 | int ret; |
| 4824 | int algs; |
| 4825 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4826 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4827 | if (params->req_key_mgmt_offload && params->psk && |
| 4828 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4829 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 4830 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 4831 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 4832 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 4833 | if (ret) |
| 4834 | return ret; |
| 4835 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4836 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4837 | |
| 4838 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 4839 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4840 | if (!msg) |
| 4841 | return -1; |
| 4842 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4843 | ret = nl80211_connect_common(drv, params, msg); |
| 4844 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4845 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4846 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4847 | algs = 0; |
| 4848 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4849 | algs++; |
| 4850 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4851 | algs++; |
| 4852 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4853 | algs++; |
| 4854 | if (algs > 1) { |
| 4855 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 4856 | "selection"); |
| 4857 | goto skip_auth_type; |
| 4858 | } |
| 4859 | |
| 4860 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4861 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 4862 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4863 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 4864 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4865 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 4866 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 4867 | type = NL80211_AUTHTYPE_FT; |
| 4868 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4869 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4870 | |
| 4871 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4872 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 4873 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4874 | |
| 4875 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4876 | ret = nl80211_set_conn_keys(params, msg); |
| 4877 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4878 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4879 | |
| 4880 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4881 | msg = NULL; |
| 4882 | if (ret) { |
| 4883 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 4884 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4885 | } else { |
| 4886 | wpa_printf(MSG_DEBUG, |
| 4887 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4888 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4889 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4890 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4891 | nlmsg_free(msg); |
| 4892 | return ret; |
| 4893 | |
| 4894 | } |
| 4895 | |
| 4896 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4897 | static int wpa_driver_nl80211_connect( |
| 4898 | struct wpa_driver_nl80211_data *drv, |
| 4899 | struct wpa_driver_associate_params *params) |
| 4900 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 4901 | int ret; |
| 4902 | |
| 4903 | /* Store the connection attempted bssid for future use */ |
| 4904 | if (params->bssid) |
| 4905 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 4906 | else |
| 4907 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 4908 | |
| 4909 | ret = wpa_driver_nl80211_try_connect(drv, params); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4910 | if (ret == -EALREADY) { |
| 4911 | /* |
| 4912 | * cfg80211 does not currently accept new connections if |
| 4913 | * we are already connected. As a workaround, force |
| 4914 | * disconnection and try again. |
| 4915 | */ |
| 4916 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 4917 | "disconnecting before reassociation " |
| 4918 | "attempt"); |
| 4919 | if (wpa_driver_nl80211_disconnect( |
| 4920 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 4921 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4922 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 4923 | } |
| 4924 | return ret; |
| 4925 | } |
| 4926 | |
| 4927 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4928 | static int wpa_driver_nl80211_associate( |
| 4929 | void *priv, struct wpa_driver_associate_params *params) |
| 4930 | { |
| 4931 | struct i802_bss *bss = priv; |
| 4932 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4933 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4934 | struct nl_msg *msg; |
| 4935 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4936 | nl80211_unmask_11b_rates(bss); |
| 4937 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4938 | if (params->mode == IEEE80211_MODE_AP) |
| 4939 | return wpa_driver_nl80211_ap(drv, params); |
| 4940 | |
| 4941 | if (params->mode == IEEE80211_MODE_IBSS) |
| 4942 | return wpa_driver_nl80211_ibss(drv, params); |
| 4943 | |
| 4944 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4945 | enum nl80211_iftype nlmode = params->p2p ? |
| 4946 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 4947 | |
| 4948 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4949 | return -1; |
| 4950 | return wpa_driver_nl80211_connect(drv, params); |
| 4951 | } |
| 4952 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4953 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4954 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4955 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 4956 | drv->ifindex); |
| 4957 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4958 | if (!msg) |
| 4959 | return -1; |
| 4960 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4961 | ret = nl80211_connect_common(drv, params, msg); |
| 4962 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4963 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4964 | |
| 4965 | if (params->prev_bssid) { |
| 4966 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 4967 | MAC2STR(params->prev_bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4968 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 4969 | params->prev_bssid)) |
| 4970 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4973 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4974 | msg = NULL; |
| 4975 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4976 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 4977 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 4978 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4979 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4980 | } else { |
| 4981 | wpa_printf(MSG_DEBUG, |
| 4982 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4983 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4984 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4985 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4986 | nlmsg_free(msg); |
| 4987 | return ret; |
| 4988 | } |
| 4989 | |
| 4990 | |
| 4991 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4992 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4993 | { |
| 4994 | struct nl_msg *msg; |
| 4995 | int ret = -ENOBUFS; |
| 4996 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4997 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 4998 | ifindex, mode, nl80211_iftype_str(mode)); |
| 4999 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5000 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 5001 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 5002 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5003 | |
| 5004 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5005 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5006 | if (!ret) |
| 5007 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5008 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5009 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5010 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 5011 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 5012 | return ret; |
| 5013 | } |
| 5014 | |
| 5015 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5016 | static int wpa_driver_nl80211_set_mode_impl( |
| 5017 | struct i802_bss *bss, |
| 5018 | enum nl80211_iftype nlmode, |
| 5019 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5020 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5021 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5022 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5023 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5024 | int was_ap = is_ap_interface(drv->nlmode); |
| 5025 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5026 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5027 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5028 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5029 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 5030 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5031 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5032 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5033 | drv->nlmode = nlmode; |
| 5034 | ret = 0; |
| 5035 | goto done; |
| 5036 | } |
| 5037 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5038 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5039 | return -1; |
| 5040 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5041 | if (nlmode == drv->nlmode) { |
| 5042 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 5043 | "requested mode - ignore error"); |
| 5044 | ret = 0; |
| 5045 | goto done; /* Already in the requested mode */ |
| 5046 | } |
| 5047 | |
| 5048 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 5049 | * take the device down, try to set the mode again, and bring the |
| 5050 | * device back up. |
| 5051 | */ |
| 5052 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 5053 | "interface down"); |
| 5054 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5055 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5056 | if (res == -EACCES || res == -ENODEV) |
| 5057 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5058 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5059 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 5060 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5061 | os_sleep(0, 100000); |
| 5062 | continue; |
| 5063 | } |
| 5064 | |
| 5065 | /* |
| 5066 | * Setting the mode will fail for some drivers if the phy is |
| 5067 | * on a frequency that the mode is disallowed in. |
| 5068 | */ |
| 5069 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5070 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5071 | if (res) { |
| 5072 | wpa_printf(MSG_DEBUG, |
| 5073 | "nl80211: Failed to set frequency on interface"); |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | /* Try to set the mode again while the interface is down */ |
| 5078 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5079 | if (mode_switch_res == -EBUSY) { |
| 5080 | wpa_printf(MSG_DEBUG, |
| 5081 | "nl80211: Delaying mode set while interface going down"); |
| 5082 | os_sleep(0, 100000); |
| 5083 | continue; |
| 5084 | } |
| 5085 | ret = mode_switch_res; |
| 5086 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5087 | } |
| 5088 | |
| 5089 | if (!ret) { |
| 5090 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 5091 | "interface is down"); |
| 5092 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5093 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5094 | } |
| 5095 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5096 | /* Bring the interface back up */ |
| 5097 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 5098 | if (res != 0) { |
| 5099 | wpa_printf(MSG_DEBUG, |
| 5100 | "nl80211: Failed to set interface up after switching mode"); |
| 5101 | ret = -1; |
| 5102 | } |
| 5103 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5104 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5105 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5106 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 5107 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5108 | return ret; |
| 5109 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5110 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5111 | if (is_p2p_net_interface(nlmode)) { |
| 5112 | wpa_printf(MSG_DEBUG, |
| 5113 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 5114 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5115 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5116 | } else if (drv->disabled_11b_rates) { |
| 5117 | wpa_printf(MSG_DEBUG, |
| 5118 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 5119 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5120 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5121 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5122 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5123 | if (is_ap_interface(nlmode)) { |
| 5124 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 5125 | /* Setup additional AP mode functionality if needed */ |
| 5126 | if (nl80211_setup_ap(bss)) |
| 5127 | return -1; |
| 5128 | } else if (was_ap) { |
| 5129 | /* Remove additional AP mode functionality */ |
| 5130 | nl80211_teardown_ap(bss); |
| 5131 | } else { |
| 5132 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 5133 | } |
| 5134 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5135 | if (is_mesh_interface(nlmode) && |
| 5136 | nl80211_mgmt_subscribe_mesh(bss)) |
| 5137 | return -1; |
| 5138 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5139 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5140 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5141 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 5142 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 5143 | "frame processing - ignore for now"); |
| 5144 | |
| 5145 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5149 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 5150 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5151 | { |
| 5152 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5153 | } |
| 5154 | |
| 5155 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5156 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5157 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5158 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5159 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5160 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5164 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5165 | struct wpa_driver_capa *capa) |
| 5166 | { |
| 5167 | struct i802_bss *bss = priv; |
| 5168 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5169 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5170 | if (!drv->has_capability) |
| 5171 | return -1; |
| 5172 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5173 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5174 | capa->extended_capa = drv->extended_capa; |
| 5175 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5176 | capa->extended_capa_len = drv->extended_capa_len; |
| 5177 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5178 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5179 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | |
| 5183 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5184 | { |
| 5185 | struct i802_bss *bss = priv; |
| 5186 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5187 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5188 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5189 | bss->ifname, drv->operstate, state, |
| 5190 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5191 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5192 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5193 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5194 | } |
| 5195 | |
| 5196 | |
| 5197 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5198 | { |
| 5199 | struct i802_bss *bss = priv; |
| 5200 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5201 | struct nl_msg *msg; |
| 5202 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5203 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5204 | |
| 5205 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5206 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5207 | return 0; |
| 5208 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5209 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5210 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5211 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5212 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5213 | os_memset(&upd, 0, sizeof(upd)); |
| 5214 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5215 | if (authorized) |
| 5216 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5217 | |
| 5218 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5219 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5220 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5221 | nlmsg_free(msg); |
| 5222 | return -ENOBUFS; |
| 5223 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5224 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5225 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5226 | if (!ret) |
| 5227 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5228 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5229 | ret, strerror(-ret)); |
| 5230 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5234 | /* Set kernel driver on given frequency (MHz) */ |
| 5235 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5236 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5237 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5238 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5242 | static inline int min_int(int a, int b) |
| 5243 | { |
| 5244 | if (a < b) |
| 5245 | return a; |
| 5246 | return b; |
| 5247 | } |
| 5248 | |
| 5249 | |
| 5250 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5251 | { |
| 5252 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5253 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5254 | |
| 5255 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5256 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5257 | |
| 5258 | /* |
| 5259 | * TODO: validate the key index and mac address! |
| 5260 | * Otherwise, there's a race condition as soon as |
| 5261 | * the kernel starts sending key notifications. |
| 5262 | */ |
| 5263 | |
| 5264 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5265 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5266 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5267 | return NL_SKIP; |
| 5268 | } |
| 5269 | |
| 5270 | |
| 5271 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5272 | int idx, u8 *seq) |
| 5273 | { |
| 5274 | struct i802_bss *bss = priv; |
| 5275 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5276 | struct nl_msg *msg; |
| 5277 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5278 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5279 | NL80211_CMD_GET_KEY); |
| 5280 | if (!msg || |
| 5281 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5282 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5283 | nlmsg_free(msg); |
| 5284 | return -ENOBUFS; |
| 5285 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5286 | |
| 5287 | memset(seq, 0, 6); |
| 5288 | |
| 5289 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5292 | |
| 5293 | static int i802_set_rts(void *priv, int rts) |
| 5294 | { |
| 5295 | struct i802_bss *bss = priv; |
| 5296 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5297 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5298 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5299 | u32 val; |
| 5300 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5301 | if (rts >= 2347) |
| 5302 | val = (u32) -1; |
| 5303 | else |
| 5304 | val = rts; |
| 5305 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5306 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5307 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5308 | nlmsg_free(msg); |
| 5309 | return -ENOBUFS; |
| 5310 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5311 | |
| 5312 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5313 | if (!ret) |
| 5314 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5315 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5316 | "%d (%s)", rts, ret, strerror(-ret)); |
| 5317 | return ret; |
| 5318 | } |
| 5319 | |
| 5320 | |
| 5321 | static int i802_set_frag(void *priv, int frag) |
| 5322 | { |
| 5323 | struct i802_bss *bss = priv; |
| 5324 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5325 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5326 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5327 | u32 val; |
| 5328 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5329 | if (frag >= 2346) |
| 5330 | val = (u32) -1; |
| 5331 | else |
| 5332 | val = frag; |
| 5333 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5334 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5335 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 5336 | nlmsg_free(msg); |
| 5337 | return -ENOBUFS; |
| 5338 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5339 | |
| 5340 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5341 | if (!ret) |
| 5342 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5343 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 5344 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 5345 | return ret; |
| 5346 | } |
| 5347 | |
| 5348 | |
| 5349 | static int i802_flush(void *priv) |
| 5350 | { |
| 5351 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5352 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5353 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5354 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5355 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 5356 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5357 | |
| 5358 | /* |
| 5359 | * XXX: FIX! this needs to flush all VLANs too |
| 5360 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5361 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 5362 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5363 | if (res) { |
| 5364 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 5365 | "(%s)", res, strerror(-res)); |
| 5366 | } |
| 5367 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | |
| 5371 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 5372 | { |
| 5373 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5374 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5375 | struct hostap_sta_driver_data *data = arg; |
| 5376 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 5377 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 5378 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 5379 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 5380 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 5381 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 5382 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5383 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 5384 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 5385 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5386 | }; |
| 5387 | |
| 5388 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5389 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5390 | |
| 5391 | /* |
| 5392 | * TODO: validate the interface and mac address! |
| 5393 | * Otherwise, there's a race condition as soon as |
| 5394 | * the kernel starts sending station notifications. |
| 5395 | */ |
| 5396 | |
| 5397 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 5398 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 5399 | return NL_SKIP; |
| 5400 | } |
| 5401 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 5402 | tb[NL80211_ATTR_STA_INFO], |
| 5403 | stats_policy)) { |
| 5404 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 5405 | return NL_SKIP; |
| 5406 | } |
| 5407 | |
| 5408 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 5409 | data->inactive_msec = |
| 5410 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 5411 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5412 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 5413 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 5414 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 5415 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 5416 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 5417 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 5418 | /* |
| 5419 | * The driver supports 64-bit counters, so use them to override |
| 5420 | * the 32-bit values. |
| 5421 | */ |
| 5422 | data->rx_bytes = |
| 5423 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 5424 | data->tx_bytes = |
| 5425 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 5426 | data->bytes_64bit = 1; |
| 5427 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5428 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 5429 | data->rx_packets = |
| 5430 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 5431 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 5432 | data->tx_packets = |
| 5433 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5434 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 5435 | data->tx_retry_failed = |
| 5436 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5437 | |
| 5438 | return NL_SKIP; |
| 5439 | } |
| 5440 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5441 | static int i802_read_sta_data(struct i802_bss *bss, |
| 5442 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5443 | const u8 *addr) |
| 5444 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5445 | struct nl_msg *msg; |
| 5446 | |
| 5447 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5448 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5449 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 5450 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 5451 | nlmsg_free(msg); |
| 5452 | return -ENOBUFS; |
| 5453 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5454 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5455 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | |
| 5459 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 5460 | int cw_min, int cw_max, int burst_time) |
| 5461 | { |
| 5462 | struct i802_bss *bss = priv; |
| 5463 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5464 | struct nl_msg *msg; |
| 5465 | struct nlattr *txq, *params; |
| 5466 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5467 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5468 | if (!msg) |
| 5469 | return -1; |
| 5470 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5471 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 5472 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5473 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5474 | |
| 5475 | /* We are only sending parameters for a single TXQ at a time */ |
| 5476 | params = nla_nest_start(msg, 1); |
| 5477 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5478 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5479 | |
| 5480 | switch (queue) { |
| 5481 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5482 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 5483 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5484 | break; |
| 5485 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5486 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 5487 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5488 | break; |
| 5489 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5490 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 5491 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5492 | break; |
| 5493 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5494 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 5495 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5496 | break; |
| 5497 | } |
| 5498 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 5499 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5500 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 5501 | (burst_time * 100 + 16) / 32) || |
| 5502 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 5503 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 5504 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 5505 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5506 | |
| 5507 | nla_nest_end(msg, params); |
| 5508 | |
| 5509 | nla_nest_end(msg, txq); |
| 5510 | |
| 5511 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 5512 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5513 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5514 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5515 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5516 | return -1; |
| 5517 | } |
| 5518 | |
| 5519 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5520 | 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] | 5521 | const char *ifname, int vlan_id) |
| 5522 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5523 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5524 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5525 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5526 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5527 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 5528 | ", ifname=%s[%d], vlan_id=%d)", |
| 5529 | bss->ifname, if_nametoindex(bss->ifname), |
| 5530 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5531 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5532 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5533 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 5534 | nlmsg_free(msg); |
| 5535 | return -ENOBUFS; |
| 5536 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5537 | |
| 5538 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5539 | if (ret < 0) { |
| 5540 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 5541 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 5542 | MAC2STR(addr), ifname, vlan_id, ret, |
| 5543 | strerror(-ret)); |
| 5544 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5545 | return ret; |
| 5546 | } |
| 5547 | |
| 5548 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5549 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 5550 | { |
| 5551 | struct hostap_sta_driver_data data; |
| 5552 | int ret; |
| 5553 | |
| 5554 | data.inactive_msec = (unsigned long) -1; |
| 5555 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5556 | if (ret == -ENOENT) |
| 5557 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5558 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 5559 | return -1; |
| 5560 | return data.inactive_msec / 1000; |
| 5561 | } |
| 5562 | |
| 5563 | |
| 5564 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 5565 | { |
| 5566 | #if 0 |
| 5567 | /* TODO */ |
| 5568 | #endif |
| 5569 | return 0; |
| 5570 | } |
| 5571 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5572 | |
| 5573 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 5574 | int reason) |
| 5575 | { |
| 5576 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5577 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5578 | struct ieee80211_mgmt mgmt; |
| 5579 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5580 | if (is_mesh_interface(drv->nlmode)) |
| 5581 | return -1; |
| 5582 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5583 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5584 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5585 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5586 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5587 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5588 | WLAN_FC_STYPE_DEAUTH); |
| 5589 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5590 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5591 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5592 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 5593 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5594 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5595 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5596 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | |
| 5600 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 5601 | int reason) |
| 5602 | { |
| 5603 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5604 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5605 | struct ieee80211_mgmt mgmt; |
| 5606 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5607 | if (is_mesh_interface(drv->nlmode)) |
| 5608 | return -1; |
| 5609 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5610 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5611 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5612 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5613 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5614 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5615 | WLAN_FC_STYPE_DISASSOC); |
| 5616 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5617 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5618 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5619 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 5620 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5621 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5622 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5623 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5624 | } |
| 5625 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5626 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5627 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 5628 | { |
| 5629 | char buf[200], *pos, *end; |
| 5630 | int i, res; |
| 5631 | |
| 5632 | pos = buf; |
| 5633 | end = pos + sizeof(buf); |
| 5634 | |
| 5635 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5636 | if (!drv->if_indices[i]) |
| 5637 | continue; |
| 5638 | res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5639 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5640 | break; |
| 5641 | pos += res; |
| 5642 | } |
| 5643 | *pos = '\0'; |
| 5644 | |
| 5645 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 5646 | drv->num_if_indices, buf); |
| 5647 | } |
| 5648 | |
| 5649 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5650 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5651 | { |
| 5652 | int i; |
| 5653 | int *old; |
| 5654 | |
| 5655 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", |
| 5656 | ifidx); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5657 | if (have_ifidx(drv, ifidx)) { |
| 5658 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 5659 | ifidx); |
| 5660 | return; |
| 5661 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5662 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5663 | if (drv->if_indices[i] == 0) { |
| 5664 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5665 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5666 | return; |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | if (drv->if_indices != drv->default_if_indices) |
| 5671 | old = drv->if_indices; |
| 5672 | else |
| 5673 | old = NULL; |
| 5674 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5675 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 5676 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5677 | if (!drv->if_indices) { |
| 5678 | if (!old) |
| 5679 | drv->if_indices = drv->default_if_indices; |
| 5680 | else |
| 5681 | drv->if_indices = old; |
| 5682 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 5683 | "interfaces"); |
| 5684 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 5685 | return; |
| 5686 | } else if (!old) |
| 5687 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 5688 | sizeof(drv->default_if_indices)); |
| 5689 | drv->if_indices[drv->num_if_indices] = ifidx; |
| 5690 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5691 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | |
| 5695 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5696 | { |
| 5697 | int i; |
| 5698 | |
| 5699 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5700 | if (drv->if_indices[i] == ifidx) { |
| 5701 | drv->if_indices[i] = 0; |
| 5702 | break; |
| 5703 | } |
| 5704 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5705 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | |
| 5709 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5710 | { |
| 5711 | int i; |
| 5712 | |
| 5713 | for (i = 0; i < drv->num_if_indices; i++) |
| 5714 | if (drv->if_indices[i] == ifidx) |
| 5715 | return 1; |
| 5716 | |
| 5717 | return 0; |
| 5718 | } |
| 5719 | |
| 5720 | |
| 5721 | 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] | 5722 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5723 | { |
| 5724 | struct i802_bss *bss = priv; |
| 5725 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5726 | char name[IFNAMSIZ + 1]; |
| 5727 | |
| 5728 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5729 | if (ifname_wds) |
| 5730 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 5731 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5732 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 5733 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 5734 | if (val) { |
| 5735 | if (!if_nametoindex(name)) { |
| 5736 | if (nl80211_create_iface(drv, name, |
| 5737 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5738 | bss->addr, 1, NULL, NULL, 0) < |
| 5739 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5740 | return -1; |
| 5741 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5742 | linux_br_add_if(drv->global->ioctl_sock, |
| 5743 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5744 | return -1; |
| 5745 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5746 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 5747 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 5748 | "interface %s up", name); |
| 5749 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5750 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 5751 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5752 | if (bridge_ifname) |
| 5753 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 5754 | name); |
| 5755 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5756 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 5757 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 5758 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5759 | } |
| 5760 | } |
| 5761 | |
| 5762 | |
| 5763 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 5764 | { |
| 5765 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 5766 | struct sockaddr_ll lladdr; |
| 5767 | unsigned char buf[3000]; |
| 5768 | int len; |
| 5769 | socklen_t fromlen = sizeof(lladdr); |
| 5770 | |
| 5771 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 5772 | (struct sockaddr *)&lladdr, &fromlen); |
| 5773 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5774 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 5775 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5776 | return; |
| 5777 | } |
| 5778 | |
| 5779 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
| 5780 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 5781 | } |
| 5782 | |
| 5783 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5784 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 5785 | struct i802_bss *bss, |
| 5786 | const char *brname, const char *ifname) |
| 5787 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5788 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5789 | char in_br[IFNAMSIZ]; |
| 5790 | |
| 5791 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5792 | br_ifindex = if_nametoindex(brname); |
| 5793 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5794 | /* |
| 5795 | * Bridge was configured, but the bridge device does |
| 5796 | * not exist. Try to add it now. |
| 5797 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5798 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5799 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 5800 | "bridge interface %s: %s", |
| 5801 | brname, strerror(errno)); |
| 5802 | return -1; |
| 5803 | } |
| 5804 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5805 | br_ifindex = if_nametoindex(brname); |
| 5806 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5807 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5808 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5809 | |
| 5810 | if (linux_br_get(in_br, ifname) == 0) { |
| 5811 | if (os_strcmp(in_br, brname) == 0) |
| 5812 | return 0; /* already in the bridge */ |
| 5813 | |
| 5814 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 5815 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5816 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 5817 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5818 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 5819 | "remove interface %s from bridge " |
| 5820 | "%s: %s", |
| 5821 | ifname, brname, strerror(errno)); |
| 5822 | return -1; |
| 5823 | } |
| 5824 | } |
| 5825 | |
| 5826 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 5827 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5828 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5829 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 5830 | "into bridge %s: %s", |
| 5831 | ifname, brname, strerror(errno)); |
| 5832 | return -1; |
| 5833 | } |
| 5834 | bss->added_if_into_bridge = 1; |
| 5835 | |
| 5836 | return 0; |
| 5837 | } |
| 5838 | |
| 5839 | |
| 5840 | static void *i802_init(struct hostapd_data *hapd, |
| 5841 | struct wpa_init_params *params) |
| 5842 | { |
| 5843 | struct wpa_driver_nl80211_data *drv; |
| 5844 | struct i802_bss *bss; |
| 5845 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5846 | char master_ifname[IFNAMSIZ]; |
| 5847 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5848 | int br_added = 0; |
| 5849 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5850 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 5851 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5852 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5853 | if (bss == NULL) |
| 5854 | return NULL; |
| 5855 | |
| 5856 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5857 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5858 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5859 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5860 | params->ifname, master_ifname); |
| 5861 | br_ifindex = if_nametoindex(master_ifname); |
| 5862 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 5863 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 5864 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 5865 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 5866 | params->ifname, master_ifname); |
| 5867 | /* start listening for EAPOL on the master interface */ |
| 5868 | add_ifidx(drv, if_nametoindex(master_ifname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5869 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5870 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5871 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5872 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5873 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5874 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5875 | for (i = 0; i < params->num_bridge; i++) { |
| 5876 | if (params->bridge[i]) { |
| 5877 | ifindex = if_nametoindex(params->bridge[i]); |
| 5878 | if (ifindex) |
| 5879 | add_ifidx(drv, ifindex); |
| 5880 | if (ifindex == br_ifindex) |
| 5881 | br_added = 1; |
| 5882 | } |
| 5883 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5884 | |
| 5885 | /* start listening for EAPOL on the default AP interface */ |
| 5886 | add_ifidx(drv, drv->ifindex); |
| 5887 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5888 | if (params->num_bridge && params->bridge[0]) { |
| 5889 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 5890 | params->ifname) < 0) |
| 5891 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5892 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5893 | br_added = 1; |
| 5894 | } |
| 5895 | |
| 5896 | if (!br_added && br_ifindex && |
| 5897 | (params->num_bridge == 0 || !params->bridge[0])) |
| 5898 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5899 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5900 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5901 | if (bss->added_if_into_bridge) { |
| 5902 | drv->rtnl_sk = nl_socket_alloc(); |
| 5903 | if (drv->rtnl_sk == NULL) { |
| 5904 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 5905 | goto failed; |
| 5906 | } |
| 5907 | |
| 5908 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 5909 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 5910 | strerror(errno)); |
| 5911 | goto failed; |
| 5912 | } |
| 5913 | } |
| 5914 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5915 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5916 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 5917 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5918 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 5919 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5920 | goto failed; |
| 5921 | } |
| 5922 | |
| 5923 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 5924 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5925 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5926 | goto failed; |
| 5927 | } |
| 5928 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5929 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 5930 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5931 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5932 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5933 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5934 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 5935 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5936 | return bss; |
| 5937 | |
| 5938 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5939 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5940 | return NULL; |
| 5941 | } |
| 5942 | |
| 5943 | |
| 5944 | static void i802_deinit(void *priv) |
| 5945 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5946 | struct i802_bss *bss = priv; |
| 5947 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5948 | } |
| 5949 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5950 | |
| 5951 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 5952 | enum wpa_driver_if_type type) |
| 5953 | { |
| 5954 | switch (type) { |
| 5955 | case WPA_IF_STATION: |
| 5956 | return NL80211_IFTYPE_STATION; |
| 5957 | case WPA_IF_P2P_CLIENT: |
| 5958 | case WPA_IF_P2P_GROUP: |
| 5959 | return NL80211_IFTYPE_P2P_CLIENT; |
| 5960 | case WPA_IF_AP_VLAN: |
| 5961 | return NL80211_IFTYPE_AP_VLAN; |
| 5962 | case WPA_IF_AP_BSS: |
| 5963 | return NL80211_IFTYPE_AP; |
| 5964 | case WPA_IF_P2P_GO: |
| 5965 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5966 | case WPA_IF_P2P_DEVICE: |
| 5967 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5968 | case WPA_IF_MESH: |
| 5969 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5970 | default: |
| 5971 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5972 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5973 | } |
| 5974 | |
| 5975 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5976 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 5977 | { |
| 5978 | struct wpa_driver_nl80211_data *drv; |
| 5979 | dl_list_for_each(drv, &global->interfaces, |
| 5980 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5981 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5982 | return 1; |
| 5983 | } |
| 5984 | return 0; |
| 5985 | } |
| 5986 | |
| 5987 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5988 | 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] | 5989 | { |
| 5990 | unsigned int idx; |
| 5991 | |
| 5992 | if (!drv->global) |
| 5993 | return -1; |
| 5994 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5995 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5996 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5997 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5998 | new_addr[0] ^= idx << 2; |
| 5999 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 6000 | break; |
| 6001 | } |
| 6002 | if (idx == 64) |
| 6003 | return -1; |
| 6004 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6005 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6006 | MACSTR, MAC2STR(new_addr)); |
| 6007 | |
| 6008 | return 0; |
| 6009 | } |
| 6010 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6011 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6012 | struct wdev_info { |
| 6013 | u64 wdev_id; |
| 6014 | int wdev_id_set; |
| 6015 | u8 macaddr[ETH_ALEN]; |
| 6016 | }; |
| 6017 | |
| 6018 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 6019 | { |
| 6020 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6021 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6022 | struct wdev_info *wi = arg; |
| 6023 | |
| 6024 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6025 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6026 | if (tb[NL80211_ATTR_WDEV]) { |
| 6027 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 6028 | wi->wdev_id_set = 1; |
| 6029 | } |
| 6030 | |
| 6031 | if (tb[NL80211_ATTR_MAC]) |
| 6032 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 6033 | ETH_ALEN); |
| 6034 | |
| 6035 | return NL_SKIP; |
| 6036 | } |
| 6037 | |
| 6038 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6039 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 6040 | const char *ifname, const u8 *addr, |
| 6041 | void *bss_ctx, void **drv_priv, |
| 6042 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6043 | const char *bridge, int use_existing, |
| 6044 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6045 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6046 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6047 | struct i802_bss *bss = priv; |
| 6048 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6049 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6050 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6051 | |
| 6052 | if (addr) |
| 6053 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6054 | nlmode = wpa_driver_nl80211_if_type(type); |
| 6055 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 6056 | struct wdev_info p2pdev_info; |
| 6057 | |
| 6058 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 6059 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 6060 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6061 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6062 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 6063 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 6064 | ifname); |
| 6065 | return -1; |
| 6066 | } |
| 6067 | |
| 6068 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 6069 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 6070 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 6071 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 6072 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 6073 | ifname, |
| 6074 | (long long unsigned int) p2pdev_info.wdev_id); |
| 6075 | } else { |
| 6076 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6077 | 0, NULL, NULL, use_existing); |
| 6078 | if (use_existing && ifidx == -ENFILE) { |
| 6079 | added = 0; |
| 6080 | ifidx = if_nametoindex(ifname); |
| 6081 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6082 | return -1; |
| 6083 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6084 | } |
| 6085 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6086 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6087 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6088 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 6089 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6090 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6091 | if (added) |
| 6092 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6093 | return -1; |
| 6094 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6095 | } |
| 6096 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6097 | if (!addr && |
| 6098 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6099 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 6100 | type == WPA_IF_STATION)) { |
| 6101 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6102 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6103 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6104 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6105 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6106 | if (added) |
| 6107 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6108 | return -1; |
| 6109 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6110 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6111 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6112 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6113 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6114 | if (added) |
| 6115 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6116 | return -1; |
| 6117 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6118 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6119 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6120 | if (added) |
| 6121 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6122 | return -1; |
| 6123 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6124 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6125 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6126 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6127 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6128 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6129 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 6130 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6131 | if (added) |
| 6132 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6133 | return -1; |
| 6134 | } |
| 6135 | |
| 6136 | if (bridge && |
| 6137 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 6138 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 6139 | "interface %s to a bridge %s", |
| 6140 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6141 | if (added) |
| 6142 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6143 | os_free(new_bss); |
| 6144 | return -1; |
| 6145 | } |
| 6146 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6147 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 6148 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6149 | if (added) |
| 6150 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6151 | os_free(new_bss); |
| 6152 | return -1; |
| 6153 | } |
| 6154 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6155 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6156 | new_bss->ifindex = ifidx; |
| 6157 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6158 | new_bss->next = drv->first_bss->next; |
| 6159 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6160 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6161 | new_bss->added_if = added; |
| 6162 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6163 | if (drv_priv) |
| 6164 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6165 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6166 | |
| 6167 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 6168 | if (nl80211_setup_ap(new_bss)) |
| 6169 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6170 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6171 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6172 | if (drv->global) |
| 6173 | drv->global->if_add_ifindex = ifidx; |
| 6174 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6175 | /* |
| 6176 | * Some virtual interfaces need to process EAPOL packets and events on |
| 6177 | * the parent interface. This is used mainly with hostapd. |
| 6178 | */ |
| 6179 | if (ifidx > 0 && |
| 6180 | (drv->hostapd || |
| 6181 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 6182 | nlmode == NL80211_IFTYPE_WDS || |
| 6183 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6184 | add_ifidx(drv, ifidx); |
| 6185 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6186 | return 0; |
| 6187 | } |
| 6188 | |
| 6189 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6190 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6191 | enum wpa_driver_if_type type, |
| 6192 | const char *ifname) |
| 6193 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6194 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6195 | int ifindex = if_nametoindex(ifname); |
| 6196 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6197 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 6198 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6199 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6200 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6201 | else if (ifindex > 0 && !bss->added_if) { |
| 6202 | struct wpa_driver_nl80211_data *drv2; |
| 6203 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 6204 | struct wpa_driver_nl80211_data, list) |
| 6205 | del_ifidx(drv2, ifindex); |
| 6206 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6207 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6208 | if (type != WPA_IF_AP_BSS) |
| 6209 | return 0; |
| 6210 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6211 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6212 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 6213 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6214 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6215 | "interface %s from bridge %s: %s", |
| 6216 | bss->ifname, bss->brname, strerror(errno)); |
| 6217 | } |
| 6218 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6219 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6220 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6221 | "bridge %s: %s", |
| 6222 | bss->brname, strerror(errno)); |
| 6223 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6224 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6225 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6226 | struct i802_bss *tbss; |
| 6227 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6228 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 6229 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6230 | if (tbss->next == bss) { |
| 6231 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6232 | /* Unsubscribe management frames */ |
| 6233 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6234 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6235 | if (!bss->added_if) |
| 6236 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6237 | os_free(bss); |
| 6238 | bss = NULL; |
| 6239 | break; |
| 6240 | } |
| 6241 | } |
| 6242 | if (bss) |
| 6243 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 6244 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6245 | } else { |
| 6246 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 6247 | nl80211_teardown_ap(bss); |
| 6248 | if (!bss->added_if && !drv->first_bss->next) |
| 6249 | wpa_driver_nl80211_del_beacon(drv); |
| 6250 | nl80211_destroy_bss(bss); |
| 6251 | if (!bss->added_if) |
| 6252 | i802_set_iface_flags(bss, 0); |
| 6253 | if (drv->first_bss->next) { |
| 6254 | drv->first_bss = drv->first_bss->next; |
| 6255 | drv->ctx = drv->first_bss->ctx; |
| 6256 | os_free(bss); |
| 6257 | } else { |
| 6258 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 6259 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6260 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6261 | |
| 6262 | return 0; |
| 6263 | } |
| 6264 | |
| 6265 | |
| 6266 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 6267 | { |
| 6268 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6269 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6270 | u64 *cookie = arg; |
| 6271 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6272 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6273 | if (tb[NL80211_ATTR_COOKIE]) |
| 6274 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 6275 | return NL_SKIP; |
| 6276 | } |
| 6277 | |
| 6278 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6279 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6280 | unsigned int freq, unsigned int wait, |
| 6281 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6282 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6283 | int offchanok, const u16 *csa_offs, |
| 6284 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6285 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6286 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6287 | struct nl_msg *msg; |
| 6288 | u64 cookie; |
| 6289 | int ret = -1; |
| 6290 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6291 | 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] | 6292 | "no_ack=%d offchanok=%d", |
| 6293 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6294 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6295 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6296 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 6297 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 6298 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 6299 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6300 | drv->test_use_roc_tx) && |
| 6301 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 6302 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 6303 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6304 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 6305 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6306 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 6307 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6308 | |
| 6309 | cookie = 0; |
| 6310 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6311 | msg = NULL; |
| 6312 | if (ret) { |
| 6313 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6314 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 6315 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6316 | } else { |
| 6317 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 6318 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 6319 | (long long unsigned int) cookie); |
| 6320 | |
| 6321 | if (cookie_out) |
| 6322 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6323 | |
| 6324 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { |
| 6325 | wpa_printf(MSG_DEBUG, |
| 6326 | "nl80211: Drop oldest pending send action cookie 0x%llx", |
| 6327 | (long long unsigned int) |
| 6328 | drv->send_action_cookies[0]); |
| 6329 | os_memmove(&drv->send_action_cookies[0], |
| 6330 | &drv->send_action_cookies[1], |
| 6331 | (MAX_SEND_ACTION_COOKIES - 1) * |
| 6332 | sizeof(u64)); |
| 6333 | drv->num_send_action_cookies--; |
| 6334 | } |
| 6335 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; |
| 6336 | drv->num_send_action_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6337 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6338 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6339 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6340 | nlmsg_free(msg); |
| 6341 | return ret; |
| 6342 | } |
| 6343 | |
| 6344 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6345 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 6346 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6347 | unsigned int wait_time, |
| 6348 | const u8 *dst, const u8 *src, |
| 6349 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6350 | const u8 *data, size_t data_len, |
| 6351 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6352 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6353 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6354 | int ret = -1; |
| 6355 | u8 *buf; |
| 6356 | struct ieee80211_hdr *hdr; |
| 6357 | |
| 6358 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6359 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 6360 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6361 | |
| 6362 | buf = os_zalloc(24 + data_len); |
| 6363 | if (buf == NULL) |
| 6364 | return ret; |
| 6365 | os_memcpy(buf + 24, data, data_len); |
| 6366 | hdr = (struct ieee80211_hdr *) buf; |
| 6367 | hdr->frame_control = |
| 6368 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 6369 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 6370 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 6371 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 6372 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6373 | if (is_ap_interface(drv->nlmode) && |
| 6374 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6375 | (int) freq == bss->freq || drv->device_ap_sme || |
| 6376 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6377 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 6378 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6379 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6380 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6381 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6382 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6383 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6384 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6385 | |
| 6386 | os_free(buf); |
| 6387 | return ret; |
| 6388 | } |
| 6389 | |
| 6390 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6391 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6392 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6393 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6394 | struct nl_msg *msg; |
| 6395 | int ret; |
| 6396 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 6397 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6398 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6399 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6400 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6401 | nlmsg_free(msg); |
| 6402 | return; |
| 6403 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6404 | |
| 6405 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6406 | if (ret) |
| 6407 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 6408 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6409 | } |
| 6410 | |
| 6411 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6412 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 6413 | { |
| 6414 | struct i802_bss *bss = priv; |
| 6415 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6416 | unsigned int i; |
| 6417 | u64 cookie; |
| 6418 | |
| 6419 | /* Cancel the last pending TX cookie */ |
| 6420 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); |
| 6421 | |
| 6422 | /* |
| 6423 | * Cancel the other pending TX cookies, if any. This is needed since |
| 6424 | * the driver may keep a list of all pending offchannel TX operations |
| 6425 | * and free up the radio only once they have expired or cancelled. |
| 6426 | */ |
| 6427 | for (i = drv->num_send_action_cookies; i > 0; i--) { |
| 6428 | cookie = drv->send_action_cookies[i - 1]; |
| 6429 | if (cookie != drv->send_action_cookie) |
| 6430 | nl80211_frame_wait_cancel(bss, cookie); |
| 6431 | } |
| 6432 | drv->num_send_action_cookies = 0; |
| 6433 | } |
| 6434 | |
| 6435 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6436 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 6437 | unsigned int duration) |
| 6438 | { |
| 6439 | struct i802_bss *bss = priv; |
| 6440 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6441 | struct nl_msg *msg; |
| 6442 | int ret; |
| 6443 | u64 cookie; |
| 6444 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6445 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 6446 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 6447 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 6448 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6449 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6450 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6451 | |
| 6452 | cookie = 0; |
| 6453 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6454 | if (ret == 0) { |
| 6455 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 6456 | "0x%llx for freq=%u MHz duration=%u", |
| 6457 | (long long unsigned int) cookie, freq, duration); |
| 6458 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6459 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6460 | return 0; |
| 6461 | } |
| 6462 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 6463 | "(freq=%d duration=%u): %d (%s)", |
| 6464 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6465 | return -1; |
| 6466 | } |
| 6467 | |
| 6468 | |
| 6469 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 6470 | { |
| 6471 | struct i802_bss *bss = priv; |
| 6472 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6473 | struct nl_msg *msg; |
| 6474 | int ret; |
| 6475 | |
| 6476 | if (!drv->pending_remain_on_chan) { |
| 6477 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 6478 | "to cancel"); |
| 6479 | return -1; |
| 6480 | } |
| 6481 | |
| 6482 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 6483 | "0x%llx", |
| 6484 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 6485 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6486 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 6487 | if (!msg || |
| 6488 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 6489 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6490 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6491 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6492 | |
| 6493 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6494 | if (ret == 0) |
| 6495 | return 0; |
| 6496 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 6497 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6498 | return -1; |
| 6499 | } |
| 6500 | |
| 6501 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6502 | 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] | 6503 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6504 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6505 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6506 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6507 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 6508 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 6509 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6510 | /* |
| 6511 | * Do not disable Probe Request reporting that was |
| 6512 | * enabled in nl80211_setup_ap(). |
| 6513 | */ |
| 6514 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 6515 | "Probe Request reporting nl_preq=%p while " |
| 6516 | "in AP mode", bss->nl_preq); |
| 6517 | } else if (bss->nl_preq) { |
| 6518 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 6519 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6520 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6521 | } |
| 6522 | return 0; |
| 6523 | } |
| 6524 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6525 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6526 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6527 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6528 | return 0; |
| 6529 | } |
| 6530 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6531 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 6532 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6533 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6534 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 6535 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6536 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6537 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6538 | (WLAN_FC_TYPE_MGMT << 2) | |
| 6539 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6540 | NULL, 0) < 0) |
| 6541 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 6542 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6543 | nl80211_register_eloop_read(&bss->nl_preq, |
| 6544 | wpa_driver_nl80211_event_receive, |
| 6545 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6546 | |
| 6547 | return 0; |
| 6548 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6549 | out_err: |
| 6550 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6551 | return -1; |
| 6552 | } |
| 6553 | |
| 6554 | |
| 6555 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 6556 | int ifindex, int disabled) |
| 6557 | { |
| 6558 | struct nl_msg *msg; |
| 6559 | struct nlattr *bands, *band; |
| 6560 | int ret; |
| 6561 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6562 | wpa_printf(MSG_DEBUG, |
| 6563 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 6564 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 6565 | "no NL80211_TXRATE_LEGACY constraint"); |
| 6566 | |
| 6567 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 6568 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6569 | if (!msg) |
| 6570 | return -1; |
| 6571 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6572 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 6573 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6574 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6575 | |
| 6576 | /* |
| 6577 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 6578 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 6579 | * rates. All 5 GHz rates are left enabled. |
| 6580 | */ |
| 6581 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6582 | if (!band || |
| 6583 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 6584 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 6585 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6586 | nla_nest_end(msg, band); |
| 6587 | |
| 6588 | nla_nest_end(msg, bands); |
| 6589 | |
| 6590 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6591 | if (ret) { |
| 6592 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 6593 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6594 | } else |
| 6595 | drv->disabled_11b_rates = disabled; |
| 6596 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6597 | return ret; |
| 6598 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6599 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6600 | nlmsg_free(msg); |
| 6601 | return -1; |
| 6602 | } |
| 6603 | |
| 6604 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6605 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 6606 | { |
| 6607 | struct i802_bss *bss = priv; |
| 6608 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6609 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6610 | return -1; |
| 6611 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6612 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6613 | |
| 6614 | /* |
| 6615 | * If the P2P GO interface was dynamically added, then it is |
| 6616 | * possible that the interface change to station is not possible. |
| 6617 | */ |
| 6618 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 6619 | return 0; |
| 6620 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6621 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6625 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 6626 | { |
| 6627 | struct i802_bss *bss = priv; |
| 6628 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6629 | if (!is_ap_interface(drv->nlmode)) |
| 6630 | return -1; |
| 6631 | wpa_driver_nl80211_del_beacon(drv); |
| 6632 | bss->beacon_set = 0; |
| 6633 | return 0; |
| 6634 | } |
| 6635 | |
| 6636 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6637 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 6638 | { |
| 6639 | struct i802_bss *bss = priv; |
| 6640 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6641 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 6642 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6643 | |
| 6644 | /* |
| 6645 | * If the P2P Client interface was dynamically added, then it is |
| 6646 | * possible that the interface change to station is not possible. |
| 6647 | */ |
| 6648 | if (bss->if_dynamic) |
| 6649 | return 0; |
| 6650 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6651 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 6652 | } |
| 6653 | |
| 6654 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6655 | static void wpa_driver_nl80211_resume(void *priv) |
| 6656 | { |
| 6657 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6658 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6659 | |
| 6660 | if (i802_set_iface_flags(bss, 1)) |
| 6661 | 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] | 6662 | |
| 6663 | if (is_p2p_net_interface(nlmode)) |
| 6664 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6665 | } |
| 6666 | |
| 6667 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6668 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 6669 | { |
| 6670 | struct i802_bss *bss = priv; |
| 6671 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6672 | struct nl_msg *msg; |
| 6673 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6674 | |
| 6675 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 6676 | "hysteresis=%d", threshold, hysteresis); |
| 6677 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6678 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 6679 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 6680 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 6681 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 6682 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6683 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6684 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6685 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6686 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6687 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6691 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 6692 | { |
| 6693 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6694 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6695 | struct wpa_signal_info *sig_change = arg; |
| 6696 | |
| 6697 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6698 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6699 | |
| 6700 | sig_change->center_frq1 = -1; |
| 6701 | sig_change->center_frq2 = -1; |
| 6702 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 6703 | |
| 6704 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 6705 | sig_change->chanwidth = convert2width( |
| 6706 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 6707 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 6708 | sig_change->center_frq1 = |
| 6709 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 6710 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 6711 | sig_change->center_frq2 = |
| 6712 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 6713 | } |
| 6714 | |
| 6715 | return NL_SKIP; |
| 6716 | } |
| 6717 | |
| 6718 | |
| 6719 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 6720 | struct wpa_signal_info *sig) |
| 6721 | { |
| 6722 | struct nl_msg *msg; |
| 6723 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6724 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6725 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6729 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 6730 | { |
| 6731 | struct i802_bss *bss = priv; |
| 6732 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6733 | int res; |
| 6734 | |
| 6735 | os_memset(si, 0, sizeof(*si)); |
| 6736 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6737 | if (res) { |
| 6738 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 6739 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 6740 | return res; |
| 6741 | si->current_signal = 0; |
| 6742 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6743 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6744 | res = nl80211_get_channel_width(drv, si); |
| 6745 | if (res != 0) |
| 6746 | return res; |
| 6747 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6748 | return nl80211_get_link_noise(drv, si); |
| 6749 | } |
| 6750 | |
| 6751 | |
| 6752 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 6753 | int encrypt) |
| 6754 | { |
| 6755 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6756 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6757 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6758 | } |
| 6759 | |
| 6760 | |
| 6761 | static int nl80211_set_param(void *priv, const char *param) |
| 6762 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6763 | if (param == NULL) |
| 6764 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame^] | 6765 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6766 | |
| 6767 | #ifdef CONFIG_P2P |
| 6768 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 6769 | struct i802_bss *bss = priv; |
| 6770 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6771 | |
| 6772 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 6773 | "interface"); |
| 6774 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 6775 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 6776 | } |
| 6777 | #endif /* CONFIG_P2P */ |
| 6778 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6779 | if (os_strstr(param, "use_monitor=1")) { |
| 6780 | struct i802_bss *bss = priv; |
| 6781 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6782 | drv->use_monitor = 1; |
| 6783 | } |
| 6784 | |
| 6785 | if (os_strstr(param, "force_connect_cmd=1")) { |
| 6786 | struct i802_bss *bss = priv; |
| 6787 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6788 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6789 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6790 | } |
| 6791 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 6792 | if (os_strstr(param, "no_offchannel_tx=1")) { |
| 6793 | struct i802_bss *bss = priv; |
| 6794 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6795 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 6796 | drv->test_use_roc_tx = 1; |
| 6797 | } |
| 6798 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6799 | return 0; |
| 6800 | } |
| 6801 | |
| 6802 | |
| 6803 | static void * nl80211_global_init(void) |
| 6804 | { |
| 6805 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6806 | struct netlink_config *cfg; |
| 6807 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6808 | global = os_zalloc(sizeof(*global)); |
| 6809 | if (global == NULL) |
| 6810 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6811 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6812 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6813 | global->if_add_ifindex = -1; |
| 6814 | |
| 6815 | cfg = os_zalloc(sizeof(*cfg)); |
| 6816 | if (cfg == NULL) |
| 6817 | goto err; |
| 6818 | |
| 6819 | cfg->ctx = global; |
| 6820 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 6821 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 6822 | global->netlink = netlink_init(cfg); |
| 6823 | if (global->netlink == NULL) { |
| 6824 | os_free(cfg); |
| 6825 | goto err; |
| 6826 | } |
| 6827 | |
| 6828 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 6829 | goto err; |
| 6830 | |
| 6831 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 6832 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6833 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 6834 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6835 | goto err; |
| 6836 | } |
| 6837 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6838 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6839 | |
| 6840 | err: |
| 6841 | nl80211_global_deinit(global); |
| 6842 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6843 | } |
| 6844 | |
| 6845 | |
| 6846 | static void nl80211_global_deinit(void *priv) |
| 6847 | { |
| 6848 | struct nl80211_global *global = priv; |
| 6849 | if (global == NULL) |
| 6850 | return; |
| 6851 | if (!dl_list_empty(&global->interfaces)) { |
| 6852 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 6853 | "nl80211_global_deinit", |
| 6854 | dl_list_len(&global->interfaces)); |
| 6855 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6856 | |
| 6857 | if (global->netlink) |
| 6858 | netlink_deinit(global->netlink); |
| 6859 | |
| 6860 | nl_destroy_handles(&global->nl); |
| 6861 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6862 | if (global->nl_event) |
| 6863 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6864 | |
| 6865 | nl_cb_put(global->nl_cb); |
| 6866 | |
| 6867 | if (global->ioctl_sock >= 0) |
| 6868 | close(global->ioctl_sock); |
| 6869 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6870 | os_free(global); |
| 6871 | } |
| 6872 | |
| 6873 | |
| 6874 | static const char * nl80211_get_radio_name(void *priv) |
| 6875 | { |
| 6876 | struct i802_bss *bss = priv; |
| 6877 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6878 | return drv->phyname; |
| 6879 | } |
| 6880 | |
| 6881 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6882 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 6883 | const u8 *pmkid) |
| 6884 | { |
| 6885 | struct nl_msg *msg; |
| 6886 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6887 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 6888 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
| 6889 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { |
| 6890 | nlmsg_free(msg); |
| 6891 | return -ENOBUFS; |
| 6892 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6893 | |
| 6894 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | |
| 6898 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6899 | { |
| 6900 | struct i802_bss *bss = priv; |
| 6901 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 6902 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 6903 | } |
| 6904 | |
| 6905 | |
| 6906 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6907 | { |
| 6908 | struct i802_bss *bss = priv; |
| 6909 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 6910 | MAC2STR(bssid)); |
| 6911 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 6912 | } |
| 6913 | |
| 6914 | |
| 6915 | static int nl80211_flush_pmkid(void *priv) |
| 6916 | { |
| 6917 | struct i802_bss *bss = priv; |
| 6918 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 6919 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 6920 | } |
| 6921 | |
| 6922 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6923 | static void clean_survey_results(struct survey_results *survey_results) |
| 6924 | { |
| 6925 | struct freq_survey *survey, *tmp; |
| 6926 | |
| 6927 | if (dl_list_empty(&survey_results->survey_list)) |
| 6928 | return; |
| 6929 | |
| 6930 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 6931 | struct freq_survey, list) { |
| 6932 | dl_list_del(&survey->list); |
| 6933 | os_free(survey); |
| 6934 | } |
| 6935 | } |
| 6936 | |
| 6937 | |
| 6938 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 6939 | struct dl_list *survey_list) |
| 6940 | { |
| 6941 | struct freq_survey *survey; |
| 6942 | |
| 6943 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 6944 | if (!survey) |
| 6945 | return; |
| 6946 | |
| 6947 | survey->ifidx = ifidx; |
| 6948 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6949 | survey->filled = 0; |
| 6950 | |
| 6951 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 6952 | survey->nf = (int8_t) |
| 6953 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 6954 | survey->filled |= SURVEY_HAS_NF; |
| 6955 | } |
| 6956 | |
| 6957 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 6958 | survey->channel_time = |
| 6959 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 6960 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 6961 | } |
| 6962 | |
| 6963 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 6964 | survey->channel_time_busy = |
| 6965 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 6966 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 6967 | } |
| 6968 | |
| 6969 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 6970 | survey->channel_time_rx = |
| 6971 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 6972 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 6973 | } |
| 6974 | |
| 6975 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 6976 | survey->channel_time_tx = |
| 6977 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 6978 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 6979 | } |
| 6980 | |
| 6981 | 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)", |
| 6982 | survey->freq, |
| 6983 | survey->nf, |
| 6984 | (unsigned long int) survey->channel_time, |
| 6985 | (unsigned long int) survey->channel_time_busy, |
| 6986 | (unsigned long int) survey->channel_time_tx, |
| 6987 | (unsigned long int) survey->channel_time_rx, |
| 6988 | survey->filled); |
| 6989 | |
| 6990 | dl_list_add_tail(survey_list, &survey->list); |
| 6991 | } |
| 6992 | |
| 6993 | |
| 6994 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 6995 | unsigned int freq_filter) |
| 6996 | { |
| 6997 | if (!freq_filter) |
| 6998 | return 1; |
| 6999 | |
| 7000 | return freq_filter == surveyed_freq; |
| 7001 | } |
| 7002 | |
| 7003 | |
| 7004 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 7005 | { |
| 7006 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7007 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7008 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 7009 | struct survey_results *survey_results; |
| 7010 | u32 surveyed_freq = 0; |
| 7011 | u32 ifidx; |
| 7012 | |
| 7013 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 7014 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 7015 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 7016 | }; |
| 7017 | |
| 7018 | survey_results = (struct survey_results *) arg; |
| 7019 | |
| 7020 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7021 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7022 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 7023 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 7024 | return NL_SKIP; |
| 7025 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7026 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 7027 | |
| 7028 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 7029 | return NL_SKIP; |
| 7030 | |
| 7031 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 7032 | tb[NL80211_ATTR_SURVEY_INFO], |
| 7033 | survey_policy)) |
| 7034 | return NL_SKIP; |
| 7035 | |
| 7036 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 7037 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 7038 | return NL_SKIP; |
| 7039 | } |
| 7040 | |
| 7041 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7042 | |
| 7043 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 7044 | survey_results->freq_filter)) |
| 7045 | return NL_SKIP; |
| 7046 | |
| 7047 | if (survey_results->freq_filter && |
| 7048 | survey_results->freq_filter != surveyed_freq) { |
| 7049 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 7050 | surveyed_freq); |
| 7051 | return NL_SKIP; |
| 7052 | } |
| 7053 | |
| 7054 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 7055 | |
| 7056 | return NL_SKIP; |
| 7057 | } |
| 7058 | |
| 7059 | |
| 7060 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 7061 | { |
| 7062 | struct i802_bss *bss = priv; |
| 7063 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7064 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7065 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7066 | union wpa_event_data data; |
| 7067 | struct survey_results *survey_results; |
| 7068 | |
| 7069 | os_memset(&data, 0, sizeof(data)); |
| 7070 | survey_results = &data.survey_results; |
| 7071 | |
| 7072 | dl_list_init(&survey_results->survey_list); |
| 7073 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7074 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7075 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7076 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7077 | |
| 7078 | if (freq) |
| 7079 | data.survey_results.freq_filter = freq; |
| 7080 | |
| 7081 | do { |
| 7082 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 7083 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 7084 | survey_results); |
| 7085 | } while (err > 0); |
| 7086 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7087 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7088 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7089 | else |
| 7090 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7091 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7092 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7093 | return err; |
| 7094 | } |
| 7095 | |
| 7096 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7097 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 7098 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7099 | const u8 *replay_ctr) |
| 7100 | { |
| 7101 | struct i802_bss *bss = priv; |
| 7102 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7103 | struct nlattr *replay_nested; |
| 7104 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7105 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7106 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7107 | if (!drv->set_rekey_offload) |
| 7108 | return; |
| 7109 | |
| 7110 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7111 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 7112 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7113 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
| 7114 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7115 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 7116 | replay_ctr)) { |
| 7117 | nl80211_nlmsg_clear(msg); |
| 7118 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7119 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7120 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7121 | |
| 7122 | nla_nest_end(msg, replay_nested); |
| 7123 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7124 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 7125 | if (ret == -EOPNOTSUPP) { |
| 7126 | wpa_printf(MSG_DEBUG, |
| 7127 | "nl80211: Driver does not support rekey offload"); |
| 7128 | drv->set_rekey_offload = 0; |
| 7129 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7130 | } |
| 7131 | |
| 7132 | |
| 7133 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 7134 | const u8 *addr, int qos) |
| 7135 | { |
| 7136 | /* send data frame to poll STA and check whether |
| 7137 | * this frame is ACKed */ |
| 7138 | struct { |
| 7139 | struct ieee80211_hdr hdr; |
| 7140 | u16 qos_ctl; |
| 7141 | } STRUCT_PACKED nulldata; |
| 7142 | size_t size; |
| 7143 | |
| 7144 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 7145 | |
| 7146 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 7147 | |
| 7148 | if (qos) { |
| 7149 | nulldata.hdr.frame_control = |
| 7150 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 7151 | WLAN_FC_STYPE_QOS_NULL); |
| 7152 | size = sizeof(nulldata); |
| 7153 | } else { |
| 7154 | nulldata.hdr.frame_control = |
| 7155 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 7156 | WLAN_FC_STYPE_NULLFUNC); |
| 7157 | size = sizeof(struct ieee80211_hdr); |
| 7158 | } |
| 7159 | |
| 7160 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 7161 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 7162 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 7163 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 7164 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7165 | 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] | 7166 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7167 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 7168 | "send poll frame"); |
| 7169 | } |
| 7170 | |
| 7171 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 7172 | int qos) |
| 7173 | { |
| 7174 | struct i802_bss *bss = priv; |
| 7175 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7176 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7177 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7178 | |
| 7179 | if (!drv->poll_command_supported) { |
| 7180 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 7181 | return; |
| 7182 | } |
| 7183 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7184 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 7185 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7186 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7187 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7188 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7189 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7190 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7191 | if (ret < 0) { |
| 7192 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 7193 | MACSTR " failed: ret=%d (%s)", |
| 7194 | MAC2STR(addr), ret, strerror(-ret)); |
| 7195 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7196 | } |
| 7197 | |
| 7198 | |
| 7199 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 7200 | { |
| 7201 | struct nl_msg *msg; |
| 7202 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7203 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 7204 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 7205 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 7206 | nlmsg_free(msg); |
| 7207 | return -ENOBUFS; |
| 7208 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7209 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | |
| 7213 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 7214 | int ctwindow) |
| 7215 | { |
| 7216 | struct i802_bss *bss = priv; |
| 7217 | |
| 7218 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 7219 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 7220 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7221 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7222 | #ifdef ANDROID_P2P |
| 7223 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7224 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7225 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7226 | #endif /* ANDROID_P2P */ |
| 7227 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7228 | |
| 7229 | if (legacy_ps == -1) |
| 7230 | return 0; |
| 7231 | if (legacy_ps != 0 && legacy_ps != 1) |
| 7232 | return -1; /* Not yet supported */ |
| 7233 | |
| 7234 | return nl80211_set_power_save(bss, legacy_ps); |
| 7235 | } |
| 7236 | |
| 7237 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7238 | static int nl80211_start_radar_detection(void *priv, |
| 7239 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7240 | { |
| 7241 | struct i802_bss *bss = priv; |
| 7242 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7243 | struct nl_msg *msg; |
| 7244 | int ret; |
| 7245 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7246 | 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)", |
| 7247 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7248 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7249 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7250 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 7251 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 7252 | "detection"); |
| 7253 | return -1; |
| 7254 | } |
| 7255 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7256 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 7257 | nl80211_put_freq_params(msg, freq) < 0) { |
| 7258 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7259 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7260 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7261 | |
| 7262 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7263 | if (ret == 0) |
| 7264 | return 0; |
| 7265 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 7266 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7267 | return -1; |
| 7268 | } |
| 7269 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7270 | #ifdef CONFIG_TDLS |
| 7271 | |
| 7272 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 7273 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7274 | u32 peer_capab, int initiator, const u8 *buf, |
| 7275 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7276 | { |
| 7277 | struct i802_bss *bss = priv; |
| 7278 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7279 | struct nl_msg *msg; |
| 7280 | |
| 7281 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7282 | return -EOPNOTSUPP; |
| 7283 | |
| 7284 | if (!dst) |
| 7285 | return -EINVAL; |
| 7286 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7287 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 7288 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 7289 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 7290 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 7291 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 7292 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7293 | if (peer_capab) { |
| 7294 | /* |
| 7295 | * The internal enum tdls_peer_capability definition is |
| 7296 | * currently identical with the nl80211 enum |
| 7297 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 7298 | * here. |
| 7299 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7300 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 7301 | peer_capab)) |
| 7302 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7303 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7304 | if ((initiator && |
| 7305 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 7306 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 7307 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7308 | |
| 7309 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7310 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7311 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7312 | nlmsg_free(msg); |
| 7313 | return -ENOBUFS; |
| 7314 | } |
| 7315 | |
| 7316 | |
| 7317 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 7318 | { |
| 7319 | struct i802_bss *bss = priv; |
| 7320 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7321 | struct nl_msg *msg; |
| 7322 | enum nl80211_tdls_operation nl80211_oper; |
| 7323 | |
| 7324 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7325 | return -EOPNOTSUPP; |
| 7326 | |
| 7327 | switch (oper) { |
| 7328 | case TDLS_DISCOVERY_REQ: |
| 7329 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 7330 | break; |
| 7331 | case TDLS_SETUP: |
| 7332 | nl80211_oper = NL80211_TDLS_SETUP; |
| 7333 | break; |
| 7334 | case TDLS_TEARDOWN: |
| 7335 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 7336 | break; |
| 7337 | case TDLS_ENABLE_LINK: |
| 7338 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 7339 | break; |
| 7340 | case TDLS_DISABLE_LINK: |
| 7341 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 7342 | break; |
| 7343 | case TDLS_ENABLE: |
| 7344 | return 0; |
| 7345 | case TDLS_DISABLE: |
| 7346 | return 0; |
| 7347 | default: |
| 7348 | return -EINVAL; |
| 7349 | } |
| 7350 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7351 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 7352 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 7353 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 7354 | nlmsg_free(msg); |
| 7355 | return -ENOBUFS; |
| 7356 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7357 | |
| 7358 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7359 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7360 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7361 | |
| 7362 | static int |
| 7363 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 7364 | const struct hostapd_freq_params *params) |
| 7365 | { |
| 7366 | struct i802_bss *bss = priv; |
| 7367 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7368 | struct nl_msg *msg; |
| 7369 | int ret = -ENOBUFS; |
| 7370 | |
| 7371 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7372 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7373 | return -EOPNOTSUPP; |
| 7374 | |
| 7375 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 7376 | " oper_class=%u freq=%u", |
| 7377 | MAC2STR(addr), oper_class, params->freq); |
| 7378 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 7379 | if (!msg || |
| 7380 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7381 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 7382 | (ret = nl80211_put_freq_params(msg, params))) { |
| 7383 | nlmsg_free(msg); |
| 7384 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 7385 | return ret; |
| 7386 | } |
| 7387 | |
| 7388 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7389 | } |
| 7390 | |
| 7391 | |
| 7392 | static int |
| 7393 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 7394 | { |
| 7395 | struct i802_bss *bss = priv; |
| 7396 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7397 | struct nl_msg *msg; |
| 7398 | |
| 7399 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7400 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7401 | return -EOPNOTSUPP; |
| 7402 | |
| 7403 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 7404 | MAC2STR(addr)); |
| 7405 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 7406 | if (!msg || |
| 7407 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7408 | nlmsg_free(msg); |
| 7409 | wpa_printf(MSG_DEBUG, |
| 7410 | "nl80211: Could not build TDLS cancel chan switch"); |
| 7411 | return -ENOBUFS; |
| 7412 | } |
| 7413 | |
| 7414 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7415 | } |
| 7416 | |
| 7417 | #endif /* CONFIG TDLS */ |
| 7418 | |
| 7419 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7420 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 7421 | enum wpa_alg alg, const u8 *addr, |
| 7422 | int key_idx, int set_tx, |
| 7423 | const u8 *seq, size_t seq_len, |
| 7424 | const u8 *key, size_t key_len) |
| 7425 | { |
| 7426 | struct i802_bss *bss = priv; |
| 7427 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 7428 | set_tx, seq, seq_len, key, key_len); |
| 7429 | } |
| 7430 | |
| 7431 | |
| 7432 | static int driver_nl80211_scan2(void *priv, |
| 7433 | struct wpa_driver_scan_params *params) |
| 7434 | { |
| 7435 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7436 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 7437 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7438 | |
| 7439 | /* |
| 7440 | * Do a vendor specific scan if possible. If only_new_results is |
| 7441 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 7442 | * cannot be achieved through a vendor scan. The below condition may |
| 7443 | * need to be modified if new scan flags are added in the future whose |
| 7444 | * functionality can only be achieved through a normal scan. |
| 7445 | */ |
| 7446 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 7447 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 7448 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7449 | return wpa_driver_nl80211_scan(bss, params); |
| 7450 | } |
| 7451 | |
| 7452 | |
| 7453 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 7454 | int reason_code) |
| 7455 | { |
| 7456 | struct i802_bss *bss = priv; |
| 7457 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 7458 | } |
| 7459 | |
| 7460 | |
| 7461 | static int driver_nl80211_authenticate(void *priv, |
| 7462 | struct wpa_driver_auth_params *params) |
| 7463 | { |
| 7464 | struct i802_bss *bss = priv; |
| 7465 | return wpa_driver_nl80211_authenticate(bss, params); |
| 7466 | } |
| 7467 | |
| 7468 | |
| 7469 | static void driver_nl80211_deinit(void *priv) |
| 7470 | { |
| 7471 | struct i802_bss *bss = priv; |
| 7472 | wpa_driver_nl80211_deinit(bss); |
| 7473 | } |
| 7474 | |
| 7475 | |
| 7476 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 7477 | const char *ifname) |
| 7478 | { |
| 7479 | struct i802_bss *bss = priv; |
| 7480 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 7481 | } |
| 7482 | |
| 7483 | |
| 7484 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7485 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7486 | unsigned int freq, |
| 7487 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7488 | { |
| 7489 | struct i802_bss *bss = priv; |
| 7490 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7491 | freq, 0, 0, 0, csa_offs, |
| 7492 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | |
| 7496 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 7497 | { |
| 7498 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7499 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7503 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 7504 | const char *ifname, int vlan_id) |
| 7505 | { |
| 7506 | struct i802_bss *bss = priv; |
| 7507 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 7508 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7509 | |
| 7510 | |
| 7511 | static int driver_nl80211_read_sta_data(void *priv, |
| 7512 | struct hostap_sta_driver_data *data, |
| 7513 | const u8 *addr) |
| 7514 | { |
| 7515 | struct i802_bss *bss = priv; |
| 7516 | return i802_read_sta_data(bss, data, addr); |
| 7517 | } |
| 7518 | |
| 7519 | |
| 7520 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 7521 | unsigned int wait_time, |
| 7522 | const u8 *dst, const u8 *src, |
| 7523 | const u8 *bssid, |
| 7524 | const u8 *data, size_t data_len, |
| 7525 | int no_cck) |
| 7526 | { |
| 7527 | struct i802_bss *bss = priv; |
| 7528 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 7529 | bssid, data, data_len, no_cck); |
| 7530 | } |
| 7531 | |
| 7532 | |
| 7533 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 7534 | { |
| 7535 | struct i802_bss *bss = priv; |
| 7536 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 7537 | } |
| 7538 | |
| 7539 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7540 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 7541 | const u8 *ies, size_t ies_len) |
| 7542 | { |
| 7543 | int ret; |
| 7544 | struct nl_msg *msg; |
| 7545 | struct i802_bss *bss = priv; |
| 7546 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7547 | u16 mdid = WPA_GET_LE16(md); |
| 7548 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7549 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7550 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 7551 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 7552 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 7553 | nlmsg_free(msg); |
| 7554 | return -ENOBUFS; |
| 7555 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7556 | |
| 7557 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7558 | if (ret) { |
| 7559 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 7560 | "err=%d (%s)", ret, strerror(-ret)); |
| 7561 | } |
| 7562 | |
| 7563 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7564 | } |
| 7565 | |
| 7566 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7567 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
| 7568 | { |
| 7569 | struct i802_bss *bss = priv; |
| 7570 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7571 | |
| 7572 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 7573 | return NULL; |
| 7574 | |
| 7575 | return bss->addr; |
| 7576 | } |
| 7577 | |
| 7578 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7579 | static const char * scan_state_str(enum scan_states scan_state) |
| 7580 | { |
| 7581 | switch (scan_state) { |
| 7582 | case NO_SCAN: |
| 7583 | return "NO_SCAN"; |
| 7584 | case SCAN_REQUESTED: |
| 7585 | return "SCAN_REQUESTED"; |
| 7586 | case SCAN_STARTED: |
| 7587 | return "SCAN_STARTED"; |
| 7588 | case SCAN_COMPLETED: |
| 7589 | return "SCAN_COMPLETED"; |
| 7590 | case SCAN_ABORTED: |
| 7591 | return "SCAN_ABORTED"; |
| 7592 | case SCHED_SCAN_STARTED: |
| 7593 | return "SCHED_SCAN_STARTED"; |
| 7594 | case SCHED_SCAN_STOPPED: |
| 7595 | return "SCHED_SCAN_STOPPED"; |
| 7596 | case SCHED_SCAN_RESULTS: |
| 7597 | return "SCHED_SCAN_RESULTS"; |
| 7598 | } |
| 7599 | |
| 7600 | return "??"; |
| 7601 | } |
| 7602 | |
| 7603 | |
| 7604 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 7605 | { |
| 7606 | struct i802_bss *bss = priv; |
| 7607 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7608 | int res; |
| 7609 | char *pos, *end; |
| 7610 | |
| 7611 | pos = buf; |
| 7612 | end = buf + buflen; |
| 7613 | |
| 7614 | res = os_snprintf(pos, end - pos, |
| 7615 | "ifindex=%d\n" |
| 7616 | "ifname=%s\n" |
| 7617 | "brname=%s\n" |
| 7618 | "addr=" MACSTR "\n" |
| 7619 | "freq=%d\n" |
| 7620 | "%s%s%s%s%s", |
| 7621 | bss->ifindex, |
| 7622 | bss->ifname, |
| 7623 | bss->brname, |
| 7624 | MAC2STR(bss->addr), |
| 7625 | bss->freq, |
| 7626 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 7627 | bss->added_if_into_bridge ? |
| 7628 | "added_if_into_bridge=1\n" : "", |
| 7629 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 7630 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 7631 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7632 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7633 | return pos - buf; |
| 7634 | pos += res; |
| 7635 | |
| 7636 | if (bss->wdev_id_set) { |
| 7637 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 7638 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7639 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7640 | return pos - buf; |
| 7641 | pos += res; |
| 7642 | } |
| 7643 | |
| 7644 | res = os_snprintf(pos, end - pos, |
| 7645 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7646 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7647 | "drv_ifindex=%d\n" |
| 7648 | "operstate=%d\n" |
| 7649 | "scan_state=%s\n" |
| 7650 | "auth_bssid=" MACSTR "\n" |
| 7651 | "auth_attempt_bssid=" MACSTR "\n" |
| 7652 | "bssid=" MACSTR "\n" |
| 7653 | "prev_bssid=" MACSTR "\n" |
| 7654 | "associated=%d\n" |
| 7655 | "assoc_freq=%u\n" |
| 7656 | "monitor_sock=%d\n" |
| 7657 | "monitor_ifidx=%d\n" |
| 7658 | "monitor_refcount=%d\n" |
| 7659 | "last_mgmt_freq=%u\n" |
| 7660 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7661 | "%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] | 7662 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7663 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7664 | drv->ifindex, |
| 7665 | drv->operstate, |
| 7666 | scan_state_str(drv->scan_state), |
| 7667 | MAC2STR(drv->auth_bssid), |
| 7668 | MAC2STR(drv->auth_attempt_bssid), |
| 7669 | MAC2STR(drv->bssid), |
| 7670 | MAC2STR(drv->prev_bssid), |
| 7671 | drv->associated, |
| 7672 | drv->assoc_freq, |
| 7673 | drv->monitor_sock, |
| 7674 | drv->monitor_ifidx, |
| 7675 | drv->monitor_refcount, |
| 7676 | drv->last_mgmt_freq, |
| 7677 | drv->eapol_tx_sock, |
| 7678 | drv->ignore_if_down_event ? |
| 7679 | "ignore_if_down_event=1\n" : "", |
| 7680 | drv->scan_complete_events ? |
| 7681 | "scan_complete_events=1\n" : "", |
| 7682 | drv->disabled_11b_rates ? |
| 7683 | "disabled_11b_rates=1\n" : "", |
| 7684 | drv->pending_remain_on_chan ? |
| 7685 | "pending_remain_on_chan=1\n" : "", |
| 7686 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 7687 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 7688 | drv->poll_command_supported ? |
| 7689 | "poll_command_supported=1\n" : "", |
| 7690 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 7691 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 7692 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 7693 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 7694 | drv->ignore_next_local_disconnect ? |
| 7695 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 7696 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7697 | "ignore_next_local_deauth=1\n" : ""); |
| 7698 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7699 | return pos - buf; |
| 7700 | pos += res; |
| 7701 | |
| 7702 | if (drv->has_capability) { |
| 7703 | res = os_snprintf(pos, end - pos, |
| 7704 | "capa.key_mgmt=0x%x\n" |
| 7705 | "capa.enc=0x%x\n" |
| 7706 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7707 | "capa.flags=0x%llx\n" |
| 7708 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7709 | "capa.max_scan_ssids=%d\n" |
| 7710 | "capa.max_sched_scan_ssids=%d\n" |
| 7711 | "capa.sched_scan_supported=%d\n" |
| 7712 | "capa.max_match_sets=%d\n" |
| 7713 | "capa.max_remain_on_chan=%u\n" |
| 7714 | "capa.max_stations=%u\n" |
| 7715 | "capa.probe_resp_offloads=0x%x\n" |
| 7716 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7717 | "capa.num_multichan_concurrent=%u\n" |
| 7718 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7719 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 7720 | "capa.conc_capab=%u\n" |
| 7721 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7722 | "capa.max_conc_chan_5_0=%u\n" |
| 7723 | "capa.max_sched_scan_plans=%u\n" |
| 7724 | "capa.max_sched_scan_plan_interval=%u\n" |
| 7725 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7726 | drv->capa.key_mgmt, |
| 7727 | drv->capa.enc, |
| 7728 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7729 | (unsigned long long) drv->capa.flags, |
| 7730 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7731 | drv->capa.max_scan_ssids, |
| 7732 | drv->capa.max_sched_scan_ssids, |
| 7733 | drv->capa.sched_scan_supported, |
| 7734 | drv->capa.max_match_sets, |
| 7735 | drv->capa.max_remain_on_chan, |
| 7736 | drv->capa.max_stations, |
| 7737 | drv->capa.probe_resp_offloads, |
| 7738 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7739 | drv->capa.num_multichan_concurrent, |
| 7740 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7741 | drv->capa.mac_addr_rand_scan_supported, |
| 7742 | drv->capa.conc_capab, |
| 7743 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7744 | drv->capa.max_conc_chan_5_0, |
| 7745 | drv->capa.max_sched_scan_plans, |
| 7746 | drv->capa.max_sched_scan_plan_interval, |
| 7747 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7748 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7749 | return pos - buf; |
| 7750 | pos += res; |
| 7751 | } |
| 7752 | |
| 7753 | return pos - buf; |
| 7754 | } |
| 7755 | |
| 7756 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7757 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 7758 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7759 | if ((settings->head && |
| 7760 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 7761 | settings->head_len, settings->head)) || |
| 7762 | (settings->tail && |
| 7763 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 7764 | settings->tail_len, settings->tail)) || |
| 7765 | (settings->beacon_ies && |
| 7766 | nla_put(msg, NL80211_ATTR_IE, |
| 7767 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 7768 | (settings->proberesp_ies && |
| 7769 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 7770 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 7771 | (settings->assocresp_ies && |
| 7772 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 7773 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 7774 | (settings->probe_resp && |
| 7775 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 7776 | settings->probe_resp_len, settings->probe_resp))) |
| 7777 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7778 | |
| 7779 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7780 | } |
| 7781 | |
| 7782 | |
| 7783 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 7784 | { |
| 7785 | struct nl_msg *msg; |
| 7786 | struct i802_bss *bss = priv; |
| 7787 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7788 | struct nlattr *beacon_csa; |
| 7789 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7790 | int csa_off_len = 0; |
| 7791 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7792 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7793 | 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] | 7794 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7795 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 7796 | settings->freq_params.center_freq1, |
| 7797 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7798 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7799 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7800 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 7801 | return -EOPNOTSUPP; |
| 7802 | } |
| 7803 | |
| 7804 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 7805 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 7806 | return -EOPNOTSUPP; |
| 7807 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7808 | /* |
| 7809 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 7810 | * counters match. This implementation assumes that there are only two |
| 7811 | * counters. |
| 7812 | */ |
| 7813 | if (settings->counter_offset_beacon[0] && |
| 7814 | !settings->counter_offset_beacon[1]) { |
| 7815 | csa_off_len = 1; |
| 7816 | } else if (settings->counter_offset_beacon[1] && |
| 7817 | !settings->counter_offset_beacon[0]) { |
| 7818 | csa_off_len = 1; |
| 7819 | settings->counter_offset_beacon[0] = |
| 7820 | settings->counter_offset_beacon[1]; |
| 7821 | settings->counter_offset_presp[0] = |
| 7822 | settings->counter_offset_presp[1]; |
| 7823 | } else if (settings->counter_offset_beacon[1] && |
| 7824 | settings->counter_offset_beacon[0]) { |
| 7825 | csa_off_len = 2; |
| 7826 | } else { |
| 7827 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 7828 | return -EINVAL; |
| 7829 | } |
| 7830 | |
| 7831 | /* Check CSA counters validity */ |
| 7832 | if (drv->capa.max_csa_counters && |
| 7833 | csa_off_len > drv->capa.max_csa_counters) { |
| 7834 | wpa_printf(MSG_ERROR, |
| 7835 | "nl80211: Too many CSA counters provided"); |
| 7836 | return -EINVAL; |
| 7837 | } |
| 7838 | |
| 7839 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7840 | return -EINVAL; |
| 7841 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7842 | for (i = 0; i < csa_off_len; i++) { |
| 7843 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 7844 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 7845 | |
| 7846 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 7847 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 7848 | settings->cs_count)) |
| 7849 | return -EINVAL; |
| 7850 | |
| 7851 | if (settings->beacon_csa.probe_resp && |
| 7852 | ((settings->beacon_csa.probe_resp_len <= |
| 7853 | csa_c_off_presp) || |
| 7854 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 7855 | settings->cs_count))) |
| 7856 | return -EINVAL; |
| 7857 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7858 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7859 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 7860 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 7861 | settings->cs_count) || |
| 7862 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 7863 | (settings->block_tx && |
| 7864 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7865 | goto error; |
| 7866 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7867 | /* beacon_after params */ |
| 7868 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 7869 | if (ret) |
| 7870 | goto error; |
| 7871 | |
| 7872 | /* beacon_csa params */ |
| 7873 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 7874 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7875 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7876 | |
| 7877 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 7878 | if (ret) |
| 7879 | goto error; |
| 7880 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7881 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 7882 | csa_off_len * sizeof(u16), |
| 7883 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7884 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7885 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 7886 | csa_off_len * sizeof(u16), |
| 7887 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7888 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7889 | |
| 7890 | nla_nest_end(msg, beacon_csa); |
| 7891 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7892 | if (ret) { |
| 7893 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 7894 | ret, strerror(-ret)); |
| 7895 | } |
| 7896 | return ret; |
| 7897 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7898 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7899 | ret = -ENOBUFS; |
| 7900 | error: |
| 7901 | nlmsg_free(msg); |
| 7902 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 7903 | return ret; |
| 7904 | } |
| 7905 | |
| 7906 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7907 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 7908 | u8 user_priority, u16 admitted_time) |
| 7909 | { |
| 7910 | struct i802_bss *bss = priv; |
| 7911 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7912 | struct nl_msg *msg; |
| 7913 | int ret; |
| 7914 | |
| 7915 | wpa_printf(MSG_DEBUG, |
| 7916 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 7917 | tsid, admitted_time, user_priority); |
| 7918 | |
| 7919 | if (!is_sta_interface(drv->nlmode)) |
| 7920 | return -ENOTSUP; |
| 7921 | |
| 7922 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 7923 | if (!msg || |
| 7924 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7925 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7926 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 7927 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 7928 | nlmsg_free(msg); |
| 7929 | return -ENOBUFS; |
| 7930 | } |
| 7931 | |
| 7932 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7933 | if (ret) |
| 7934 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 7935 | ret, strerror(-ret)); |
| 7936 | return ret; |
| 7937 | } |
| 7938 | |
| 7939 | |
| 7940 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 7941 | { |
| 7942 | struct i802_bss *bss = priv; |
| 7943 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7944 | struct nl_msg *msg; |
| 7945 | int ret; |
| 7946 | |
| 7947 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 7948 | |
| 7949 | if (!is_sta_interface(drv->nlmode)) |
| 7950 | return -ENOTSUP; |
| 7951 | |
| 7952 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 7953 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7954 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7955 | nlmsg_free(msg); |
| 7956 | return -ENOBUFS; |
| 7957 | } |
| 7958 | |
| 7959 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7960 | if (ret) |
| 7961 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 7962 | ret, strerror(-ret)); |
| 7963 | return ret; |
| 7964 | } |
| 7965 | |
| 7966 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7967 | #ifdef CONFIG_TESTING_OPTIONS |
| 7968 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 7969 | { |
| 7970 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7971 | struct wpabuf *buf = arg; |
| 7972 | |
| 7973 | if (!buf) |
| 7974 | return NL_SKIP; |
| 7975 | |
| 7976 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 7977 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 7978 | return NL_SKIP; |
| 7979 | } |
| 7980 | |
| 7981 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 7982 | genlmsg_attrlen(gnlh, 0)); |
| 7983 | |
| 7984 | return NL_SKIP; |
| 7985 | } |
| 7986 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7987 | |
| 7988 | |
| 7989 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 7990 | { |
| 7991 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7992 | struct nlattr *nl_vendor_reply, *nl; |
| 7993 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7994 | struct wpabuf *buf = arg; |
| 7995 | int rem; |
| 7996 | |
| 7997 | if (!buf) |
| 7998 | return NL_SKIP; |
| 7999 | |
| 8000 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8001 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8002 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8003 | |
| 8004 | if (!nl_vendor_reply) |
| 8005 | return NL_SKIP; |
| 8006 | |
| 8007 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 8008 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 8009 | return NL_SKIP; |
| 8010 | } |
| 8011 | |
| 8012 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 8013 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 8014 | } |
| 8015 | |
| 8016 | return NL_SKIP; |
| 8017 | } |
| 8018 | |
| 8019 | |
| 8020 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 8021 | unsigned int subcmd, const u8 *data, |
| 8022 | size_t data_len, struct wpabuf *buf) |
| 8023 | { |
| 8024 | struct i802_bss *bss = priv; |
| 8025 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8026 | struct nl_msg *msg; |
| 8027 | int ret; |
| 8028 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8029 | #ifdef CONFIG_TESTING_OPTIONS |
| 8030 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8031 | msg = nlmsg_alloc(); |
| 8032 | if (!msg) |
| 8033 | return -ENOMEM; |
| 8034 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8035 | nl80211_cmd(drv, msg, 0, subcmd); |
| 8036 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 8037 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8038 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8039 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 8040 | if (ret) |
| 8041 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 8042 | ret); |
| 8043 | return ret; |
| 8044 | } |
| 8045 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8046 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8047 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 8048 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 8049 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 8050 | (data && |
| 8051 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 8052 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8053 | |
| 8054 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 8055 | if (ret) |
| 8056 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 8057 | ret); |
| 8058 | return ret; |
| 8059 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8060 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8061 | nlmsg_free(msg); |
| 8062 | return -ENOBUFS; |
| 8063 | } |
| 8064 | |
| 8065 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8066 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 8067 | u8 qos_map_set_len) |
| 8068 | { |
| 8069 | struct i802_bss *bss = priv; |
| 8070 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8071 | struct nl_msg *msg; |
| 8072 | int ret; |
| 8073 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8074 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 8075 | qos_map_set, qos_map_set_len); |
| 8076 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8077 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 8078 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 8079 | nlmsg_free(msg); |
| 8080 | return -ENOBUFS; |
| 8081 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8082 | |
| 8083 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8084 | if (ret) |
| 8085 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 8086 | |
| 8087 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8088 | } |
| 8089 | |
| 8090 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8091 | static int nl80211_set_wowlan(void *priv, |
| 8092 | const struct wowlan_triggers *triggers) |
| 8093 | { |
| 8094 | struct i802_bss *bss = priv; |
| 8095 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8096 | struct nl_msg *msg; |
| 8097 | struct nlattr *wowlan_triggers; |
| 8098 | int ret; |
| 8099 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8100 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 8101 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8102 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8103 | !(wowlan_triggers = nla_nest_start(msg, |
| 8104 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 8105 | (triggers->any && |
| 8106 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 8107 | (triggers->disconnect && |
| 8108 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 8109 | (triggers->magic_pkt && |
| 8110 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 8111 | (triggers->gtk_rekey_failure && |
| 8112 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 8113 | (triggers->eap_identity_req && |
| 8114 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 8115 | (triggers->four_way_handshake && |
| 8116 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 8117 | (triggers->rfkill_release && |
| 8118 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 8119 | nlmsg_free(msg); |
| 8120 | return -ENOBUFS; |
| 8121 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8122 | |
| 8123 | nla_nest_end(msg, wowlan_triggers); |
| 8124 | |
| 8125 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8126 | if (ret) |
| 8127 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 8128 | |
| 8129 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8130 | } |
| 8131 | |
| 8132 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8133 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8134 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 8135 | { |
| 8136 | struct i802_bss *bss = priv; |
| 8137 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8138 | struct nl_msg *msg; |
| 8139 | struct nlattr *params; |
| 8140 | |
| 8141 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 8142 | |
| 8143 | if (!drv->roaming_vendor_cmd_avail) { |
| 8144 | wpa_printf(MSG_DEBUG, |
| 8145 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 8146 | return -1; |
| 8147 | } |
| 8148 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8149 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8150 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8151 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8152 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 8153 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8154 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 8155 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 8156 | QCA_ROAMING_NOT_ALLOWED) || |
| 8157 | (bssid && |
| 8158 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 8159 | nlmsg_free(msg); |
| 8160 | return -1; |
| 8161 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8162 | nla_nest_end(msg, params); |
| 8163 | |
| 8164 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8165 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8166 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8167 | |
| 8168 | |
| 8169 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 8170 | { |
| 8171 | struct i802_bss *bss = priv; |
| 8172 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8173 | int new_addr = addr != NULL; |
| 8174 | |
| 8175 | if (!addr) |
| 8176 | addr = drv->perm_addr; |
| 8177 | |
| 8178 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 8179 | return -1; |
| 8180 | |
| 8181 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 8182 | { |
| 8183 | wpa_printf(MSG_DEBUG, |
| 8184 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 8185 | bss->ifname, MAC2STR(addr)); |
| 8186 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 8187 | 1) < 0) { |
| 8188 | wpa_printf(MSG_DEBUG, |
| 8189 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 8190 | } |
| 8191 | return -1; |
| 8192 | } |
| 8193 | |
| 8194 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 8195 | bss->ifname, MAC2STR(addr)); |
| 8196 | drv->addr_changed = new_addr; |
| 8197 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 8198 | |
| 8199 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 8200 | { |
| 8201 | wpa_printf(MSG_DEBUG, |
| 8202 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 8203 | } |
| 8204 | |
| 8205 | return 0; |
| 8206 | } |
| 8207 | |
| 8208 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8209 | #ifdef CONFIG_MESH |
| 8210 | |
| 8211 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 8212 | { |
| 8213 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 8214 | wpa_printf(MSG_INFO, |
| 8215 | "nl80211: Failed to set interface into mesh mode"); |
| 8216 | return -1; |
| 8217 | } |
| 8218 | return 0; |
| 8219 | } |
| 8220 | |
| 8221 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8222 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 8223 | size_t mesh_id_len) |
| 8224 | { |
| 8225 | if (mesh_id) { |
| 8226 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 8227 | mesh_id, mesh_id_len); |
| 8228 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 8229 | } |
| 8230 | |
| 8231 | return 0; |
| 8232 | } |
| 8233 | |
| 8234 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8235 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8236 | struct wpa_driver_mesh_join_params *params) |
| 8237 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8238 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8239 | struct nl_msg *msg; |
| 8240 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8241 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8242 | |
| 8243 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 8244 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8245 | if (!msg || |
| 8246 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 8247 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 8248 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
| 8249 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8250 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8251 | |
| 8252 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 8253 | |
| 8254 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 8255 | if (!container) |
| 8256 | goto fail; |
| 8257 | |
| 8258 | if (params->ies) { |
| 8259 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 8260 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 8261 | params->ies)) |
| 8262 | goto fail; |
| 8263 | } |
| 8264 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 8265 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 8266 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 8267 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 8268 | goto fail; |
| 8269 | } |
| 8270 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 8271 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 8272 | goto fail; |
| 8273 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 8274 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 8275 | goto fail; |
| 8276 | nla_nest_end(msg, container); |
| 8277 | |
| 8278 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 8279 | if (!container) |
| 8280 | goto fail; |
| 8281 | |
| 8282 | if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
| 8283 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0)) |
| 8284 | goto fail; |
| 8285 | if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) && |
| 8286 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 8287 | params->max_peer_links)) |
| 8288 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8289 | |
| 8290 | /* |
| 8291 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 8292 | * the timer could disconnect stations even in that case. |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8293 | */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8294 | if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 8295 | params->conf.peer_link_timeout)) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8296 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 8297 | goto fail; |
| 8298 | } |
| 8299 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8300 | nla_nest_end(msg, container); |
| 8301 | |
| 8302 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8303 | msg = NULL; |
| 8304 | if (ret) { |
| 8305 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 8306 | ret, strerror(-ret)); |
| 8307 | goto fail; |
| 8308 | } |
| 8309 | ret = 0; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8310 | bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8311 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 8312 | |
| 8313 | fail: |
| 8314 | nlmsg_free(msg); |
| 8315 | return ret; |
| 8316 | } |
| 8317 | |
| 8318 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8319 | static int |
| 8320 | wpa_driver_nl80211_join_mesh(void *priv, |
| 8321 | struct wpa_driver_mesh_join_params *params) |
| 8322 | { |
| 8323 | struct i802_bss *bss = priv; |
| 8324 | int ret, timeout; |
| 8325 | |
| 8326 | timeout = params->conf.peer_link_timeout; |
| 8327 | |
| 8328 | /* Disable kernel inactivity timer */ |
| 8329 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 8330 | params->conf.peer_link_timeout = 0; |
| 8331 | |
| 8332 | ret = nl80211_join_mesh(bss, params); |
| 8333 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 8334 | wpa_printf(MSG_DEBUG, |
| 8335 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 8336 | /* |
| 8337 | * Old kernel does not support setting |
| 8338 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 8339 | * into future from peer_link_timeout. |
| 8340 | */ |
| 8341 | params->conf.peer_link_timeout = timeout + 60; |
| 8342 | ret = nl80211_join_mesh(priv, params); |
| 8343 | } |
| 8344 | |
| 8345 | params->conf.peer_link_timeout = timeout; |
| 8346 | return ret; |
| 8347 | } |
| 8348 | |
| 8349 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8350 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 8351 | { |
| 8352 | struct i802_bss *bss = priv; |
| 8353 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8354 | struct nl_msg *msg; |
| 8355 | int ret; |
| 8356 | |
| 8357 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 8358 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 8359 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8360 | if (ret) { |
| 8361 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 8362 | ret, strerror(-ret)); |
| 8363 | } else { |
| 8364 | wpa_printf(MSG_DEBUG, |
| 8365 | "nl80211: mesh leave request send successfully"); |
| 8366 | } |
| 8367 | |
| 8368 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 8369 | NL80211_IFTYPE_STATION)) { |
| 8370 | wpa_printf(MSG_INFO, |
| 8371 | "nl80211: Failed to set interface into station mode"); |
| 8372 | } |
| 8373 | return ret; |
| 8374 | } |
| 8375 | |
| 8376 | #endif /* CONFIG_MESH */ |
| 8377 | |
| 8378 | |
| 8379 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 8380 | const u8 *ipaddr, int prefixlen, |
| 8381 | const u8 *addr) |
| 8382 | { |
| 8383 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8384 | struct i802_bss *bss = priv; |
| 8385 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8386 | struct rtnl_neigh *rn; |
| 8387 | struct nl_addr *nl_ipaddr = NULL; |
| 8388 | struct nl_addr *nl_lladdr = NULL; |
| 8389 | int family, addrsize; |
| 8390 | int res; |
| 8391 | |
| 8392 | if (!ipaddr || prefixlen == 0 || !addr) |
| 8393 | return -EINVAL; |
| 8394 | |
| 8395 | if (bss->br_ifindex == 0) { |
| 8396 | wpa_printf(MSG_DEBUG, |
| 8397 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 8398 | return -1; |
| 8399 | } |
| 8400 | |
| 8401 | if (!drv->rtnl_sk) { |
| 8402 | wpa_printf(MSG_DEBUG, |
| 8403 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8404 | return -1; |
| 8405 | } |
| 8406 | |
| 8407 | if (version == 4) { |
| 8408 | family = AF_INET; |
| 8409 | addrsize = 4; |
| 8410 | } else if (version == 6) { |
| 8411 | family = AF_INET6; |
| 8412 | addrsize = 16; |
| 8413 | } else { |
| 8414 | return -EINVAL; |
| 8415 | } |
| 8416 | |
| 8417 | rn = rtnl_neigh_alloc(); |
| 8418 | if (rn == NULL) |
| 8419 | return -ENOMEM; |
| 8420 | |
| 8421 | /* set the destination ip address for neigh */ |
| 8422 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8423 | if (nl_ipaddr == NULL) { |
| 8424 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8425 | res = -ENOMEM; |
| 8426 | goto errout; |
| 8427 | } |
| 8428 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 8429 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8430 | if (res) { |
| 8431 | wpa_printf(MSG_DEBUG, |
| 8432 | "nl80211: neigh set destination addr failed"); |
| 8433 | goto errout; |
| 8434 | } |
| 8435 | |
| 8436 | /* set the corresponding lladdr for neigh */ |
| 8437 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 8438 | if (nl_lladdr == NULL) { |
| 8439 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 8440 | res = -ENOMEM; |
| 8441 | goto errout; |
| 8442 | } |
| 8443 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 8444 | |
| 8445 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8446 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 8447 | |
| 8448 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 8449 | if (res) { |
| 8450 | wpa_printf(MSG_DEBUG, |
| 8451 | "nl80211: Adding bridge ip neigh failed: %s", |
| 8452 | strerror(errno)); |
| 8453 | } |
| 8454 | errout: |
| 8455 | if (nl_lladdr) |
| 8456 | nl_addr_put(nl_lladdr); |
| 8457 | if (nl_ipaddr) |
| 8458 | nl_addr_put(nl_ipaddr); |
| 8459 | if (rn) |
| 8460 | rtnl_neigh_put(rn); |
| 8461 | return res; |
| 8462 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8463 | return -1; |
| 8464 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8465 | } |
| 8466 | |
| 8467 | |
| 8468 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 8469 | const u8 *ipaddr) |
| 8470 | { |
| 8471 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8472 | struct i802_bss *bss = priv; |
| 8473 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8474 | struct rtnl_neigh *rn; |
| 8475 | struct nl_addr *nl_ipaddr; |
| 8476 | int family, addrsize; |
| 8477 | int res; |
| 8478 | |
| 8479 | if (!ipaddr) |
| 8480 | return -EINVAL; |
| 8481 | |
| 8482 | if (version == 4) { |
| 8483 | family = AF_INET; |
| 8484 | addrsize = 4; |
| 8485 | } else if (version == 6) { |
| 8486 | family = AF_INET6; |
| 8487 | addrsize = 16; |
| 8488 | } else { |
| 8489 | return -EINVAL; |
| 8490 | } |
| 8491 | |
| 8492 | if (bss->br_ifindex == 0) { |
| 8493 | wpa_printf(MSG_DEBUG, |
| 8494 | "nl80211: bridge must be set to delete an ip neigh"); |
| 8495 | return -1; |
| 8496 | } |
| 8497 | |
| 8498 | if (!drv->rtnl_sk) { |
| 8499 | wpa_printf(MSG_DEBUG, |
| 8500 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8501 | return -1; |
| 8502 | } |
| 8503 | |
| 8504 | rn = rtnl_neigh_alloc(); |
| 8505 | if (rn == NULL) |
| 8506 | return -ENOMEM; |
| 8507 | |
| 8508 | /* set the destination ip address for neigh */ |
| 8509 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8510 | if (nl_ipaddr == NULL) { |
| 8511 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8512 | res = -ENOMEM; |
| 8513 | goto errout; |
| 8514 | } |
| 8515 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8516 | if (res) { |
| 8517 | wpa_printf(MSG_DEBUG, |
| 8518 | "nl80211: neigh set destination addr failed"); |
| 8519 | goto errout; |
| 8520 | } |
| 8521 | |
| 8522 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8523 | |
| 8524 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 8525 | if (res) { |
| 8526 | wpa_printf(MSG_DEBUG, |
| 8527 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 8528 | strerror(errno)); |
| 8529 | } |
| 8530 | errout: |
| 8531 | if (nl_ipaddr) |
| 8532 | nl_addr_put(nl_ipaddr); |
| 8533 | if (rn) |
| 8534 | rtnl_neigh_put(rn); |
| 8535 | return res; |
| 8536 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8537 | return -1; |
| 8538 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8539 | } |
| 8540 | |
| 8541 | |
| 8542 | static int linux_write_system_file(const char *path, unsigned int val) |
| 8543 | { |
| 8544 | char buf[50]; |
| 8545 | int fd, len; |
| 8546 | |
| 8547 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 8548 | if (os_snprintf_error(sizeof(buf), len)) |
| 8549 | return -1; |
| 8550 | |
| 8551 | fd = open(path, O_WRONLY); |
| 8552 | if (fd < 0) |
| 8553 | return -1; |
| 8554 | |
| 8555 | if (write(fd, buf, len) < 0) { |
| 8556 | wpa_printf(MSG_DEBUG, |
| 8557 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 8558 | path, val); |
| 8559 | close(fd); |
| 8560 | return -1; |
| 8561 | } |
| 8562 | close(fd); |
| 8563 | |
| 8564 | return 0; |
| 8565 | } |
| 8566 | |
| 8567 | |
| 8568 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 8569 | { |
| 8570 | switch (attr) { |
| 8571 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 8572 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8573 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 8574 | return "hairpin_mode"; |
| 8575 | } |
| 8576 | |
| 8577 | return NULL; |
| 8578 | } |
| 8579 | |
| 8580 | |
| 8581 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 8582 | unsigned int val) |
| 8583 | { |
| 8584 | struct i802_bss *bss = priv; |
| 8585 | char path[128]; |
| 8586 | const char *attr_txt; |
| 8587 | |
| 8588 | attr_txt = drv_br_port_attr_str(attr); |
| 8589 | if (attr_txt == NULL) |
| 8590 | return -EINVAL; |
| 8591 | |
| 8592 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 8593 | bss->ifname, attr_txt); |
| 8594 | |
| 8595 | if (linux_write_system_file(path, val)) |
| 8596 | return -1; |
| 8597 | |
| 8598 | return 0; |
| 8599 | } |
| 8600 | |
| 8601 | |
| 8602 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 8603 | { |
| 8604 | switch (param) { |
| 8605 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8606 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8607 | default: |
| 8608 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8609 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8610 | } |
| 8611 | |
| 8612 | |
| 8613 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 8614 | unsigned int val) |
| 8615 | { |
| 8616 | struct i802_bss *bss = priv; |
| 8617 | char path[128]; |
| 8618 | const char *param_txt; |
| 8619 | int ip_version = 4; |
| 8620 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8621 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 8622 | os_snprintf(path, sizeof(path), |
| 8623 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 8624 | bss->brname); |
| 8625 | goto set_val; |
| 8626 | } |
| 8627 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8628 | param_txt = drv_br_net_param_str(param); |
| 8629 | if (param_txt == NULL) |
| 8630 | return -EINVAL; |
| 8631 | |
| 8632 | switch (param) { |
| 8633 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8634 | ip_version = 4; |
| 8635 | break; |
| 8636 | default: |
| 8637 | return -EINVAL; |
| 8638 | } |
| 8639 | |
| 8640 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 8641 | ip_version, bss->brname, param_txt); |
| 8642 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8643 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8644 | if (linux_write_system_file(path, val)) |
| 8645 | return -1; |
| 8646 | |
| 8647 | return 0; |
| 8648 | } |
| 8649 | |
| 8650 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8651 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8652 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8653 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 8654 | { |
| 8655 | switch (hw_mode) { |
| 8656 | case HOSTAPD_MODE_IEEE80211B: |
| 8657 | return QCA_ACS_MODE_IEEE80211B; |
| 8658 | case HOSTAPD_MODE_IEEE80211G: |
| 8659 | return QCA_ACS_MODE_IEEE80211G; |
| 8660 | case HOSTAPD_MODE_IEEE80211A: |
| 8661 | return QCA_ACS_MODE_IEEE80211A; |
| 8662 | case HOSTAPD_MODE_IEEE80211AD: |
| 8663 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 8664 | case HOSTAPD_MODE_IEEE80211ANY: |
| 8665 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8666 | default: |
| 8667 | return -1; |
| 8668 | } |
| 8669 | } |
| 8670 | |
| 8671 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8672 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 8673 | { |
| 8674 | int i, len, ret; |
| 8675 | u32 *freqs; |
| 8676 | |
| 8677 | if (!freq_list) |
| 8678 | return 0; |
| 8679 | len = int_array_len(freq_list); |
| 8680 | freqs = os_malloc(sizeof(u32) * len); |
| 8681 | if (!freqs) |
| 8682 | return -1; |
| 8683 | for (i = 0; i < len; i++) |
| 8684 | freqs[i] = freq_list[i]; |
| 8685 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 8686 | sizeof(u32) * len, freqs); |
| 8687 | os_free(freqs); |
| 8688 | return ret; |
| 8689 | } |
| 8690 | |
| 8691 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8692 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 8693 | { |
| 8694 | struct i802_bss *bss = priv; |
| 8695 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8696 | struct nl_msg *msg; |
| 8697 | struct nlattr *data; |
| 8698 | int ret; |
| 8699 | int mode; |
| 8700 | |
| 8701 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 8702 | if (mode < 0) |
| 8703 | return -1; |
| 8704 | |
| 8705 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8706 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8707 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8708 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 8709 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8710 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 8711 | (params->ht_enabled && |
| 8712 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 8713 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8714 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 8715 | (params->vht_enabled && |
| 8716 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 8717 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 8718 | params->ch_width) || |
| 8719 | (params->ch_list_len && |
| 8720 | 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] | 8721 | params->ch_list)) || |
| 8722 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8723 | nlmsg_free(msg); |
| 8724 | return -ENOBUFS; |
| 8725 | } |
| 8726 | nla_nest_end(msg, data); |
| 8727 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8728 | wpa_printf(MSG_DEBUG, |
| 8729 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 8730 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 8731 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 8732 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8733 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8734 | if (ret) { |
| 8735 | wpa_printf(MSG_DEBUG, |
| 8736 | "nl80211: Failed to invoke driver ACS function: %s", |
| 8737 | strerror(errno)); |
| 8738 | } |
| 8739 | return ret; |
| 8740 | } |
| 8741 | |
| 8742 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 8743 | static int nl80211_set_band(void *priv, enum set_band band) |
| 8744 | { |
| 8745 | struct i802_bss *bss = priv; |
| 8746 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8747 | struct nl_msg *msg; |
| 8748 | struct nlattr *data; |
| 8749 | int ret; |
| 8750 | enum qca_set_band qca_band; |
| 8751 | |
| 8752 | if (!drv->setband_vendor_cmd_avail) |
| 8753 | return -1; |
| 8754 | |
| 8755 | switch (band) { |
| 8756 | case WPA_SETBAND_AUTO: |
| 8757 | qca_band = QCA_SETBAND_AUTO; |
| 8758 | break; |
| 8759 | case WPA_SETBAND_5G: |
| 8760 | qca_band = QCA_SETBAND_5G; |
| 8761 | break; |
| 8762 | case WPA_SETBAND_2G: |
| 8763 | qca_band = QCA_SETBAND_2G; |
| 8764 | break; |
| 8765 | default: |
| 8766 | return -1; |
| 8767 | } |
| 8768 | |
| 8769 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8770 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8771 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8772 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 8773 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8774 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 8775 | nlmsg_free(msg); |
| 8776 | return -ENOBUFS; |
| 8777 | } |
| 8778 | nla_nest_end(msg, data); |
| 8779 | |
| 8780 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8781 | if (ret) { |
| 8782 | wpa_printf(MSG_DEBUG, |
| 8783 | "nl80211: Driver setband function failed: %s", |
| 8784 | strerror(errno)); |
| 8785 | } |
| 8786 | return ret; |
| 8787 | } |
| 8788 | |
| 8789 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8790 | struct nl80211_pcl { |
| 8791 | unsigned int num; |
| 8792 | unsigned int *freq_list; |
| 8793 | }; |
| 8794 | |
| 8795 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 8796 | { |
| 8797 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8798 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8799 | struct nl80211_pcl *param = arg; |
| 8800 | struct nlattr *nl_vend, *attr; |
| 8801 | enum qca_iface_type iface_type; |
| 8802 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 8803 | unsigned int num, max_num; |
| 8804 | u32 *freqs; |
| 8805 | |
| 8806 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8807 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8808 | |
| 8809 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8810 | if (!nl_vend) |
| 8811 | return NL_SKIP; |
| 8812 | |
| 8813 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 8814 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 8815 | |
| 8816 | attr = tb_vendor[ |
| 8817 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 8818 | if (!attr) { |
| 8819 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 8820 | param->num = 0; |
| 8821 | return NL_SKIP; |
| 8822 | } |
| 8823 | |
| 8824 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 8825 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 8826 | iface_type); |
| 8827 | |
| 8828 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 8829 | if (!attr) { |
| 8830 | wpa_printf(MSG_ERROR, |
| 8831 | "nl80211: preferred_freq_list couldn't be found"); |
| 8832 | param->num = 0; |
| 8833 | return NL_SKIP; |
| 8834 | } |
| 8835 | |
| 8836 | /* |
| 8837 | * param->num has the maximum number of entries for which there |
| 8838 | * is room in the freq_list provided by the caller. |
| 8839 | */ |
| 8840 | freqs = nla_data(attr); |
| 8841 | max_num = nla_len(attr) / sizeof(u32); |
| 8842 | if (max_num > param->num) |
| 8843 | max_num = param->num; |
| 8844 | for (num = 0; num < max_num; num++) |
| 8845 | param->freq_list[num] = freqs[num]; |
| 8846 | param->num = num; |
| 8847 | |
| 8848 | return NL_SKIP; |
| 8849 | } |
| 8850 | |
| 8851 | |
| 8852 | static int nl80211_get_pref_freq_list(void *priv, |
| 8853 | enum wpa_driver_if_type if_type, |
| 8854 | unsigned int *num, |
| 8855 | unsigned int *freq_list) |
| 8856 | { |
| 8857 | struct i802_bss *bss = priv; |
| 8858 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8859 | struct nl_msg *msg; |
| 8860 | int ret; |
| 8861 | unsigned int i; |
| 8862 | struct nlattr *params; |
| 8863 | struct nl80211_pcl param; |
| 8864 | enum qca_iface_type iface_type; |
| 8865 | |
| 8866 | if (!drv->get_pref_freq_list) |
| 8867 | return -1; |
| 8868 | |
| 8869 | switch (if_type) { |
| 8870 | case WPA_IF_STATION: |
| 8871 | iface_type = QCA_IFACE_TYPE_STA; |
| 8872 | break; |
| 8873 | case WPA_IF_AP_BSS: |
| 8874 | iface_type = QCA_IFACE_TYPE_AP; |
| 8875 | break; |
| 8876 | case WPA_IF_P2P_GO: |
| 8877 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 8878 | break; |
| 8879 | case WPA_IF_P2P_CLIENT: |
| 8880 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 8881 | break; |
| 8882 | case WPA_IF_IBSS: |
| 8883 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 8884 | break; |
| 8885 | case WPA_IF_TDLS: |
| 8886 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 8887 | break; |
| 8888 | default: |
| 8889 | return -1; |
| 8890 | } |
| 8891 | |
| 8892 | param.num = *num; |
| 8893 | param.freq_list = freq_list; |
| 8894 | |
| 8895 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8896 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 8897 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8898 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8899 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 8900 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8901 | nla_put_u32(msg, |
| 8902 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 8903 | iface_type)) { |
| 8904 | wpa_printf(MSG_ERROR, |
| 8905 | "%s: err in adding vendor_cmd and vendor_data", |
| 8906 | __func__); |
| 8907 | nlmsg_free(msg); |
| 8908 | return -1; |
| 8909 | } |
| 8910 | nla_nest_end(msg, params); |
| 8911 | |
| 8912 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 8913 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 8914 | if (ret) { |
| 8915 | wpa_printf(MSG_ERROR, |
| 8916 | "%s: err in send_and_recv_msgs", __func__); |
| 8917 | return ret; |
| 8918 | } |
| 8919 | |
| 8920 | *num = param.num; |
| 8921 | |
| 8922 | for (i = 0; i < *num; i++) { |
| 8923 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 8924 | i, freq_list[i]); |
| 8925 | } |
| 8926 | |
| 8927 | return 0; |
| 8928 | } |
| 8929 | |
| 8930 | |
| 8931 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 8932 | { |
| 8933 | struct i802_bss *bss = priv; |
| 8934 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8935 | struct nl_msg *msg; |
| 8936 | int ret; |
| 8937 | struct nlattr *params; |
| 8938 | |
| 8939 | if (!drv->set_prob_oper_freq) |
| 8940 | return -1; |
| 8941 | |
| 8942 | wpa_printf(MSG_DEBUG, |
| 8943 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 8944 | freq, bss->ifindex); |
| 8945 | |
| 8946 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8947 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8948 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8949 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 8950 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8951 | nla_put_u32(msg, |
| 8952 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 8953 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 8954 | nla_put_u32(msg, |
| 8955 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 8956 | freq)) { |
| 8957 | wpa_printf(MSG_ERROR, |
| 8958 | "%s: err in adding vendor_cmd and vendor_data", |
| 8959 | __func__); |
| 8960 | nlmsg_free(msg); |
| 8961 | return -1; |
| 8962 | } |
| 8963 | nla_nest_end(msg, params); |
| 8964 | |
| 8965 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8966 | msg = NULL; |
| 8967 | if (ret) { |
| 8968 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 8969 | __func__); |
| 8970 | return ret; |
| 8971 | } |
| 8972 | nlmsg_free(msg); |
| 8973 | return 0; |
| 8974 | } |
| 8975 | |
| 8976 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 8977 | |
| 8978 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8979 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 8980 | .name = "nl80211", |
| 8981 | .desc = "Linux nl80211/cfg80211", |
| 8982 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 8983 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8984 | .set_key = driver_nl80211_set_key, |
| 8985 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8986 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 8987 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8988 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8989 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8990 | .deauthenticate = driver_nl80211_deauthenticate, |
| 8991 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8992 | .associate = wpa_driver_nl80211_associate, |
| 8993 | .global_init = nl80211_global_init, |
| 8994 | .global_deinit = nl80211_global_deinit, |
| 8995 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8996 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8997 | .get_capa = wpa_driver_nl80211_get_capa, |
| 8998 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 8999 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 9000 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9001 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9002 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 9003 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9004 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9005 | .if_remove = driver_nl80211_if_remove, |
| 9006 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9007 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9008 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9009 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9010 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 9011 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9012 | .hapd_init = i802_init, |
| 9013 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9014 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9015 | .get_seqnum = i802_get_seqnum, |
| 9016 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9017 | .get_inact_sec = i802_get_inact_sec, |
| 9018 | .sta_clear_stats = i802_sta_clear_stats, |
| 9019 | .set_rts = i802_set_rts, |
| 9020 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9021 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9022 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9023 | .sta_deauth = i802_sta_deauth, |
| 9024 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9025 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9026 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9027 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9028 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 9029 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 9030 | .cancel_remain_on_channel = |
| 9031 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9032 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9033 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9034 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9035 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9036 | .signal_monitor = nl80211_signal_monitor, |
| 9037 | .signal_poll = nl80211_signal_poll, |
| 9038 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9039 | .set_param = nl80211_set_param, |
| 9040 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9041 | .add_pmkid = nl80211_add_pmkid, |
| 9042 | .remove_pmkid = nl80211_remove_pmkid, |
| 9043 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9044 | .set_rekey_info = nl80211_set_rekey_info, |
| 9045 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9046 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9047 | .start_dfs_cac = nl80211_start_radar_detection, |
| 9048 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9049 | #ifdef CONFIG_TDLS |
| 9050 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 9051 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9052 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 9053 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9054 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9055 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9056 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9057 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9058 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9059 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9060 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9061 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9062 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9063 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9064 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9065 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 9066 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9067 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 9068 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9069 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9070 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9071 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9072 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9073 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9074 | .roaming = nl80211_roaming, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9075 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9076 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9077 | #ifdef CONFIG_MESH |
| 9078 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 9079 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 9080 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 9081 | #endif /* CONFIG_MESH */ |
| 9082 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 9083 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 9084 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 9085 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 9086 | .add_tx_ts = nl80211_add_ts, |
| 9087 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9088 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9089 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9090 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9091 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 9092 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
| 9093 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9094 | }; |