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 | { |
| 1523 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
| 1524 | /* |
| 1525 | * This may be for any interface; use ifdown event to disable |
| 1526 | * interface. |
| 1527 | */ |
| 1528 | } |
| 1529 | |
| 1530 | |
| 1531 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1532 | { |
| 1533 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1534 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1535 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1536 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1537 | "after rfkill unblock"); |
| 1538 | return; |
| 1539 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 1540 | |
| 1541 | if (is_p2p_net_interface(drv->nlmode)) |
| 1542 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1543 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1544 | /* rtnetlink ifup handler will report interface as enabled */ |
| 1545 | } |
| 1546 | |
| 1547 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1548 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1549 | void *eloop_ctx, |
| 1550 | void *handle) |
| 1551 | { |
| 1552 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1553 | u8 data[2048]; |
| 1554 | struct msghdr msg; |
| 1555 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1556 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1557 | struct cmsghdr *cmsg; |
| 1558 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1559 | union wpa_event_data event; |
| 1560 | |
| 1561 | memset(&msg, 0, sizeof(msg)); |
| 1562 | msg.msg_iov = &entry; |
| 1563 | msg.msg_iovlen = 1; |
| 1564 | entry.iov_base = data; |
| 1565 | entry.iov_len = sizeof(data); |
| 1566 | msg.msg_control = &control; |
| 1567 | msg.msg_controllen = sizeof(control); |
| 1568 | |
| 1569 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1570 | /* if error or not fitting 802.3 header, return */ |
| 1571 | if (res < 14) |
| 1572 | return; |
| 1573 | |
| 1574 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1575 | { |
| 1576 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1577 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1578 | int *ack; |
| 1579 | |
| 1580 | found_wifi = 1; |
| 1581 | ack = (void *)CMSG_DATA(cmsg); |
| 1582 | acked = *ack; |
| 1583 | } |
| 1584 | |
| 1585 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1586 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1587 | struct sock_extended_err *err = |
| 1588 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1589 | |
| 1590 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1591 | found_ee = 1; |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | if (!found_ee || !found_wifi) |
| 1596 | return; |
| 1597 | |
| 1598 | memset(&event, 0, sizeof(event)); |
| 1599 | event.eapol_tx_status.dst = data; |
| 1600 | event.eapol_tx_status.data = data + 14; |
| 1601 | event.eapol_tx_status.data_len = res - 14; |
| 1602 | event.eapol_tx_status.ack = acked; |
| 1603 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1604 | } |
| 1605 | |
| 1606 | |
| 1607 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1608 | { |
| 1609 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1610 | if (!bss->nl_cb) |
| 1611 | return -1; |
| 1612 | |
| 1613 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1614 | no_seq_check, NULL); |
| 1615 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1616 | process_bss_event, bss); |
| 1617 | |
| 1618 | return 0; |
| 1619 | } |
| 1620 | |
| 1621 | |
| 1622 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1623 | { |
| 1624 | nl_cb_put(bss->nl_cb); |
| 1625 | bss->nl_cb = NULL; |
| 1626 | } |
| 1627 | |
| 1628 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1629 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1630 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1631 | const u8 *set_addr, |
| 1632 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1633 | { |
| 1634 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1635 | struct rfkill_config *rcfg; |
| 1636 | struct i802_bss *bss; |
| 1637 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1638 | if (global_priv == NULL) |
| 1639 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1640 | drv = os_zalloc(sizeof(*drv)); |
| 1641 | if (drv == NULL) |
| 1642 | return NULL; |
| 1643 | drv->global = global_priv; |
| 1644 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1645 | drv->hostapd = !!hostapd; |
| 1646 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1647 | |
| 1648 | /* |
| 1649 | * There is no driver capability flag for this, so assume it is |
| 1650 | * supported and disable this on first attempt to use if the driver |
| 1651 | * rejects the command due to missing support. |
| 1652 | */ |
| 1653 | drv->set_rekey_offload = 1; |
| 1654 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1655 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1656 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1657 | |
| 1658 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1659 | if (!drv->first_bss) { |
| 1660 | os_free(drv); |
| 1661 | return NULL; |
| 1662 | } |
| 1663 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1664 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1665 | bss->ctx = ctx; |
| 1666 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1667 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1668 | drv->monitor_ifidx = -1; |
| 1669 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1670 | drv->eapol_tx_sock = -1; |
| 1671 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1672 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1673 | if (nl80211_init_bss(bss)) |
| 1674 | goto failed; |
| 1675 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1676 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1677 | if (rcfg == NULL) |
| 1678 | goto failed; |
| 1679 | rcfg->ctx = drv; |
| 1680 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); |
| 1681 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1682 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1683 | drv->rfkill = rfkill_init(rcfg); |
| 1684 | if (drv->rfkill == NULL) { |
| 1685 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1686 | os_free(rcfg); |
| 1687 | } |
| 1688 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1689 | if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0) |
| 1690 | drv->start_iface_up = 1; |
| 1691 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1692 | 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] | 1693 | goto failed; |
| 1694 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1695 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1696 | if (drv->eapol_tx_sock < 0) |
| 1697 | goto failed; |
| 1698 | |
| 1699 | if (drv->data_tx_status) { |
| 1700 | int enabled = 1; |
| 1701 | |
| 1702 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1703 | &enabled, sizeof(enabled)) < 0) { |
| 1704 | wpa_printf(MSG_DEBUG, |
| 1705 | "nl80211: wifi status sockopt failed\n"); |
| 1706 | drv->data_tx_status = 0; |
| 1707 | if (!drv->use_monitor) |
| 1708 | drv->capa.flags &= |
| 1709 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1710 | } else { |
| 1711 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1712 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1713 | drv, NULL); |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1718 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1719 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1720 | drv->in_interface_list = 1; |
| 1721 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1722 | |
| 1723 | return bss; |
| 1724 | |
| 1725 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1726 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1727 | return NULL; |
| 1728 | } |
| 1729 | |
| 1730 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1731 | /** |
| 1732 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1733 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1734 | * e.g., wpa_supplicant_event() |
| 1735 | * @ifname: interface name, e.g., wlan0 |
| 1736 | * @global_priv: private driver global data from global_init() |
| 1737 | * Returns: Pointer to private data, %NULL on failure |
| 1738 | */ |
| 1739 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1740 | void *global_priv) |
| 1741 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1742 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1743 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1747 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1748 | struct nl_handle *nl_handle, |
| 1749 | u16 type, const u8 *match, size_t match_len) |
| 1750 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1751 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1752 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1753 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1754 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1755 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1756 | buf[0] = '\0'; |
| 1757 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1758 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1759 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1760 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1761 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1762 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1763 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1764 | nlmsg_free(msg); |
| 1765 | return -1; |
| 1766 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1767 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1768 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1769 | if (ret) { |
| 1770 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1771 | "failed (type=%u): ret=%d (%s)", |
| 1772 | type, ret, strerror(-ret)); |
| 1773 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1774 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1775 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1776 | return ret; |
| 1777 | } |
| 1778 | |
| 1779 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1780 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1781 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1782 | if (bss->nl_mgmt) { |
| 1783 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1784 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 1785 | return -1; |
| 1786 | } |
| 1787 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1788 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1789 | if (bss->nl_mgmt == NULL) |
| 1790 | return -1; |
| 1791 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1792 | return 0; |
| 1793 | } |
| 1794 | |
| 1795 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1796 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 1797 | { |
| 1798 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 1799 | wpa_driver_nl80211_event_receive, |
| 1800 | bss->nl_cb); |
| 1801 | } |
| 1802 | |
| 1803 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1804 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1805 | const u8 *match, size_t match_len) |
| 1806 | { |
| 1807 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1808 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1809 | type, match, match_len); |
| 1810 | } |
| 1811 | |
| 1812 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1813 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1814 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1815 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1816 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1817 | |
| 1818 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1819 | return -1; |
| 1820 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 1821 | "handle %p", bss->nl_mgmt); |
| 1822 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1823 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 1824 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 1825 | |
| 1826 | /* register for any AUTH message */ |
| 1827 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 1828 | } |
| 1829 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1830 | #ifdef CONFIG_INTERWORKING |
| 1831 | /* QoS Map Configure */ |
| 1832 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1833 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1834 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1835 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1836 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1837 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1838 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1839 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1840 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1841 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1842 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1843 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1844 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1845 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1846 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1847 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1848 | /* Protected GAS Initial Request */ |
| 1849 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 1850 | ret = -1; |
| 1851 | /* Protected GAS Initial Response */ |
| 1852 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 1853 | ret = -1; |
| 1854 | /* Protected GAS Comeback Request */ |
| 1855 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 1856 | ret = -1; |
| 1857 | /* Protected GAS Comeback Response */ |
| 1858 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 1859 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1860 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 1861 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1862 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1863 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1864 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 1865 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1866 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1867 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1868 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1869 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 1870 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1871 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1872 | #endif /* CONFIG_P2P */ |
| 1873 | #ifdef CONFIG_IEEE80211W |
| 1874 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1875 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1876 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1877 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1878 | #ifdef CONFIG_TDLS |
| 1879 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 1880 | /* TDLS Discovery Response */ |
| 1881 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 1882 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1883 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1884 | } |
| 1885 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 1886 | #ifdef CONFIG_FST |
| 1887 | /* FST Action frames */ |
| 1888 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 1889 | ret = -1; |
| 1890 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1891 | |
| 1892 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1893 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1894 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1895 | else |
| 1896 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 1897 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 1898 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1899 | /* WNM - BSS Transition Management Request */ |
| 1900 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1901 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1902 | /* WNM-Sleep Mode Response */ |
| 1903 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1904 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1905 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1906 | #ifdef CONFIG_HS20 |
| 1907 | /* WNM-Notification */ |
| 1908 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1909 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1910 | #endif /* CONFIG_HS20 */ |
| 1911 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1912 | /* WMM-AC ADDTS Response */ |
| 1913 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 1914 | ret = -1; |
| 1915 | |
| 1916 | /* WMM-AC DELTS */ |
| 1917 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 1918 | ret = -1; |
| 1919 | |
| 1920 | /* Radio Measurement - Neighbor Report Response */ |
| 1921 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 1922 | ret = -1; |
| 1923 | |
| 1924 | /* Radio Measurement - Link Measurement Request */ |
| 1925 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 1926 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 1927 | ret = -1; |
| 1928 | |
| 1929 | nl80211_mgmt_handle_register_eloop(bss); |
| 1930 | |
| 1931 | return ret; |
| 1932 | } |
| 1933 | |
| 1934 | |
| 1935 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 1936 | { |
| 1937 | int ret = 0; |
| 1938 | |
| 1939 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1940 | return -1; |
| 1941 | |
| 1942 | wpa_printf(MSG_DEBUG, |
| 1943 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 1944 | bss->nl_mgmt); |
| 1945 | |
| 1946 | /* Auth frames for mesh SAE */ |
| 1947 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 1948 | (WLAN_FC_TYPE_MGMT << 2) | |
| 1949 | (WLAN_FC_STYPE_AUTH << 4), |
| 1950 | NULL, 0) < 0) |
| 1951 | ret = -1; |
| 1952 | |
| 1953 | /* Mesh peering open */ |
| 1954 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 1955 | ret = -1; |
| 1956 | /* Mesh peering confirm */ |
| 1957 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 1958 | ret = -1; |
| 1959 | /* Mesh peering close */ |
| 1960 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 1961 | ret = -1; |
| 1962 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1963 | nl80211_mgmt_handle_register_eloop(bss); |
| 1964 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1965 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1969 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 1970 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1971 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1972 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1973 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1974 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 1975 | 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] | 1976 | if (ret) { |
| 1977 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 1978 | "failed: ret=%d (%s)", |
| 1979 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1980 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1981 | return ret; |
| 1982 | } |
| 1983 | |
| 1984 | |
| 1985 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 1986 | { |
| 1987 | static const int stypes[] = { |
| 1988 | WLAN_FC_STYPE_AUTH, |
| 1989 | WLAN_FC_STYPE_ASSOC_REQ, |
| 1990 | WLAN_FC_STYPE_REASSOC_REQ, |
| 1991 | WLAN_FC_STYPE_DISASSOC, |
| 1992 | WLAN_FC_STYPE_DEAUTH, |
| 1993 | WLAN_FC_STYPE_ACTION, |
| 1994 | WLAN_FC_STYPE_PROBE_REQ, |
| 1995 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 1996 | * it, but it wouldn't really be the right thing anyway as |
| 1997 | * it isn't per interface ... maybe just dump the scan |
| 1998 | * results periodically for OLBC? |
| 1999 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2000 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2001 | }; |
| 2002 | unsigned int i; |
| 2003 | |
| 2004 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2005 | return -1; |
| 2006 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2007 | "handle %p", bss->nl_mgmt); |
| 2008 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2009 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2010 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2011 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2012 | (stypes[i] << 4), |
| 2013 | NULL, 0) < 0) { |
| 2014 | goto out_err; |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | if (nl80211_register_spurious_class3(bss)) |
| 2019 | goto out_err; |
| 2020 | |
| 2021 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 2022 | goto out_err; |
| 2023 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2024 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2025 | return 0; |
| 2026 | |
| 2027 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2028 | nl_destroy_handles(&bss->nl_mgmt); |
| 2029 | return -1; |
| 2030 | } |
| 2031 | |
| 2032 | |
| 2033 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2034 | { |
| 2035 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2036 | return -1; |
| 2037 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2038 | "handle %p (device SME)", bss->nl_mgmt); |
| 2039 | |
| 2040 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2041 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2042 | (WLAN_FC_STYPE_ACTION << 4), |
| 2043 | NULL, 0) < 0) |
| 2044 | goto out_err; |
| 2045 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2046 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2047 | return 0; |
| 2048 | |
| 2049 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2050 | nl_destroy_handles(&bss->nl_mgmt); |
| 2051 | return -1; |
| 2052 | } |
| 2053 | |
| 2054 | |
| 2055 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2056 | { |
| 2057 | if (bss->nl_mgmt == NULL) |
| 2058 | return; |
| 2059 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2060 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2061 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2062 | |
| 2063 | nl80211_put_wiphy_data_ap(bss); |
| 2064 | } |
| 2065 | |
| 2066 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2067 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2068 | { |
| 2069 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2070 | } |
| 2071 | |
| 2072 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2073 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2074 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2075 | struct nl_msg *msg; |
| 2076 | int ret; |
| 2077 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2078 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2079 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2080 | |
| 2081 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2082 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2083 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | |
| 2087 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2088 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2089 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2090 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2091 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2092 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2093 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2094 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2095 | |
| 2096 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2097 | start ? "Start" : "Stop", |
| 2098 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2099 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2100 | return ret; |
| 2101 | } |
| 2102 | |
| 2103 | |
| 2104 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2105 | { |
| 2106 | enum nl80211_iftype nlmode; |
| 2107 | |
| 2108 | nlmode = nl80211_get_ifmode(bss); |
| 2109 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2110 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2111 | bss->ifname, up); |
| 2112 | } |
| 2113 | |
| 2114 | /* P2P Device has start/stop which is equivalent */ |
| 2115 | return nl80211_set_p2pdev(bss, up); |
| 2116 | } |
| 2117 | |
| 2118 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2119 | #ifdef CONFIG_TESTING_OPTIONS |
| 2120 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2121 | { |
| 2122 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2123 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2124 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2125 | |
| 2126 | |
| 2127 | wpa_printf(MSG_DEBUG, |
| 2128 | "nl80211: QCA vendor test command response received"); |
| 2129 | |
| 2130 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2131 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2132 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2133 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2134 | return NL_SKIP; |
| 2135 | } |
| 2136 | |
| 2137 | wpa_hexdump(MSG_DEBUG, |
| 2138 | "nl80211: Received QCA vendor test command response", |
| 2139 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2140 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2141 | |
| 2142 | return NL_SKIP; |
| 2143 | } |
| 2144 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2145 | |
| 2146 | |
| 2147 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2148 | { |
| 2149 | #ifdef CONFIG_TESTING_OPTIONS |
| 2150 | struct nl_msg *msg; |
| 2151 | struct nlattr *params; |
| 2152 | int ret; |
| 2153 | |
| 2154 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2155 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2156 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2157 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2158 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2159 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2160 | nlmsg_free(msg); |
| 2161 | return; |
| 2162 | } |
| 2163 | nla_nest_end(msg, params); |
| 2164 | |
| 2165 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2166 | wpa_printf(MSG_DEBUG, |
| 2167 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2168 | ret, strerror(-ret)); |
| 2169 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2170 | } |
| 2171 | |
| 2172 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2173 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2174 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2175 | const u8 *set_addr, int first, |
| 2176 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2177 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2178 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2179 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2180 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2181 | |
| 2182 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2183 | bss->ifindex = drv->ifindex; |
| 2184 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2185 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2186 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2187 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2188 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2189 | drv->global->if_add_wdevid_set = 0; |
| 2190 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2191 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2192 | bss->static_ap = 1; |
| 2193 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2194 | if (wpa_driver_nl80211_capa(drv)) |
| 2195 | return -1; |
| 2196 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2197 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2198 | return -1; |
| 2199 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2200 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2201 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2202 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2203 | if (set_addr && |
| 2204 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2205 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2206 | set_addr))) |
| 2207 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2208 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2209 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2210 | drv->start_mode_ap = 1; |
| 2211 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2212 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2213 | nlmode = NL80211_IFTYPE_AP; |
| 2214 | else if (bss->if_dynamic) |
| 2215 | nlmode = nl80211_get_ifmode(bss); |
| 2216 | else |
| 2217 | nlmode = NL80211_IFTYPE_STATION; |
| 2218 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2219 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2220 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2221 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2222 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2223 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2224 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2225 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2226 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2227 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2228 | int ret = i802_set_iface_flags(bss, 1); |
| 2229 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2230 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2231 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2232 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2233 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 2234 | |
| 2235 | if (is_p2p_net_interface(nlmode)) |
| 2236 | nl80211_disable_11b_rates(bss->drv, |
| 2237 | bss->drv->ifindex, 1); |
| 2238 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2239 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2240 | return ret; |
| 2241 | } else { |
| 2242 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2243 | "interface '%s' due to rfkill", bss->ifname); |
| 2244 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2245 | return 0; |
| 2246 | drv->if_disabled = 1; |
| 2247 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2250 | if (!drv->hostapd) |
| 2251 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2252 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2253 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2254 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2255 | bss->addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2256 | return -1; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2257 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2258 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2259 | if (send_rfkill_event) { |
| 2260 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2261 | drv, drv->ctx); |
| 2262 | } |
| 2263 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2264 | if (drv->vendor_cmd_test_avail) |
| 2265 | qca_vendor_test(drv); |
| 2266 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2267 | return 0; |
| 2268 | } |
| 2269 | |
| 2270 | |
| 2271 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 2272 | { |
| 2273 | struct nl_msg *msg; |
| 2274 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2275 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2276 | drv->ifindex); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2277 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2278 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | |
| 2282 | /** |
| 2283 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2284 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2285 | * |
| 2286 | * Shut down driver interface and processing of driver events. Free |
| 2287 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2288 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2289 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2290 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2291 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2292 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2293 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2294 | bss->ifname, drv->disabled_11b_rates); |
| 2295 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2296 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2297 | if (drv->data_tx_status) |
| 2298 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2299 | if (drv->eapol_tx_sock >= 0) |
| 2300 | close(drv->eapol_tx_sock); |
| 2301 | |
| 2302 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2303 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2304 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2305 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2306 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2307 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2308 | "interface %s from bridge %s: %s", |
| 2309 | bss->ifname, bss->brname, strerror(errno)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2310 | if (drv->rtnl_sk) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2311 | nl80211_handle_destroy(drv->rtnl_sk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2312 | } |
| 2313 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2314 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2315 | 0) < 0) |
| 2316 | wpa_printf(MSG_INFO, |
| 2317 | "nl80211: Could not set bridge %s down", |
| 2318 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2319 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2320 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2321 | "bridge %s: %s", |
| 2322 | bss->brname, strerror(errno)); |
| 2323 | } |
| 2324 | |
| 2325 | nl80211_remove_monitor_interface(drv); |
| 2326 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2327 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2328 | wpa_driver_nl80211_del_beacon(drv); |
| 2329 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2330 | if (drv->eapol_sock >= 0) { |
| 2331 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2332 | close(drv->eapol_sock); |
| 2333 | } |
| 2334 | |
| 2335 | if (drv->if_indices != drv->default_if_indices) |
| 2336 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2337 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2338 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2339 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2340 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2341 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2342 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2343 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2344 | rfkill_deinit(drv->rfkill); |
| 2345 | |
| 2346 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2347 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2348 | if (!drv->start_iface_up) |
| 2349 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2350 | |
| 2351 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2352 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2353 | 0) < 0) { |
| 2354 | wpa_printf(MSG_DEBUG, |
| 2355 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2356 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2357 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2358 | drv->perm_addr) < 0) { |
| 2359 | wpa_printf(MSG_DEBUG, |
| 2360 | "nl80211: Could not restore permanent MAC address"); |
| 2361 | } |
| 2362 | } |
| 2363 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2364 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2365 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2366 | wpa_driver_nl80211_set_mode(bss, |
| 2367 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2368 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2369 | } else { |
| 2370 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2371 | nl80211_del_p2pdev(bss); |
| 2372 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2373 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2374 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2375 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2376 | os_free(drv->filter_ssids); |
| 2377 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2378 | os_free(drv->auth_ie); |
| 2379 | |
| 2380 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | dl_list_del(&drv->list); |
| 2382 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2383 | os_free(drv->extended_capa); |
| 2384 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2385 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2386 | os_free(drv); |
| 2387 | } |
| 2388 | |
| 2389 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2390 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2391 | { |
| 2392 | switch (alg) { |
| 2393 | case WPA_ALG_WEP: |
| 2394 | if (key_len == 5) |
| 2395 | return WLAN_CIPHER_SUITE_WEP40; |
| 2396 | return WLAN_CIPHER_SUITE_WEP104; |
| 2397 | case WPA_ALG_TKIP: |
| 2398 | return WLAN_CIPHER_SUITE_TKIP; |
| 2399 | case WPA_ALG_CCMP: |
| 2400 | return WLAN_CIPHER_SUITE_CCMP; |
| 2401 | case WPA_ALG_GCMP: |
| 2402 | return WLAN_CIPHER_SUITE_GCMP; |
| 2403 | case WPA_ALG_CCMP_256: |
| 2404 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2405 | case WPA_ALG_GCMP_256: |
| 2406 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2407 | case WPA_ALG_IGTK: |
| 2408 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 2409 | case WPA_ALG_BIP_GMAC_128: |
| 2410 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 2411 | case WPA_ALG_BIP_GMAC_256: |
| 2412 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 2413 | case WPA_ALG_BIP_CMAC_256: |
| 2414 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 2415 | case WPA_ALG_SMS4: |
| 2416 | return WLAN_CIPHER_SUITE_SMS4; |
| 2417 | case WPA_ALG_KRK: |
| 2418 | return WLAN_CIPHER_SUITE_KRK; |
| 2419 | case WPA_ALG_NONE: |
| 2420 | case WPA_ALG_PMK: |
| 2421 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2422 | alg); |
| 2423 | return 0; |
| 2424 | } |
| 2425 | |
| 2426 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2427 | alg); |
| 2428 | return 0; |
| 2429 | } |
| 2430 | |
| 2431 | |
| 2432 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2433 | { |
| 2434 | switch (cipher) { |
| 2435 | case WPA_CIPHER_CCMP_256: |
| 2436 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2437 | case WPA_CIPHER_GCMP_256: |
| 2438 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2439 | case WPA_CIPHER_CCMP: |
| 2440 | return WLAN_CIPHER_SUITE_CCMP; |
| 2441 | case WPA_CIPHER_GCMP: |
| 2442 | return WLAN_CIPHER_SUITE_GCMP; |
| 2443 | case WPA_CIPHER_TKIP: |
| 2444 | return WLAN_CIPHER_SUITE_TKIP; |
| 2445 | case WPA_CIPHER_WEP104: |
| 2446 | return WLAN_CIPHER_SUITE_WEP104; |
| 2447 | case WPA_CIPHER_WEP40: |
| 2448 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2449 | case WPA_CIPHER_GTK_NOT_USED: |
| 2450 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | return 0; |
| 2454 | } |
| 2455 | |
| 2456 | |
| 2457 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2458 | int max_suites) |
| 2459 | { |
| 2460 | int num_suites = 0; |
| 2461 | |
| 2462 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 2463 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 2464 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 2465 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 2466 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 2467 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 2468 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 2469 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 2470 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 2471 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 2472 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 2473 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 2474 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 2475 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 2476 | |
| 2477 | return num_suites; |
| 2478 | } |
| 2479 | |
| 2480 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 2481 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2482 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2483 | const u8 *key, size_t key_len) |
| 2484 | { |
| 2485 | struct nl_msg *msg; |
| 2486 | int ret; |
| 2487 | |
| 2488 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2489 | return 0; |
| 2490 | |
| 2491 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2492 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2493 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2494 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2495 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2496 | nl80211_nlmsg_clear(msg); |
| 2497 | nlmsg_free(msg); |
| 2498 | return -1; |
| 2499 | } |
| 2500 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2501 | if (ret) { |
| 2502 | wpa_printf(MSG_DEBUG, |
| 2503 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2504 | ret, strerror(-ret)); |
| 2505 | } |
| 2506 | |
| 2507 | return ret; |
| 2508 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 2509 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2510 | |
| 2511 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2512 | 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] | 2513 | enum wpa_alg alg, const u8 *addr, |
| 2514 | int key_idx, int set_tx, |
| 2515 | const u8 *seq, size_t seq_len, |
| 2516 | const u8 *key, size_t key_len) |
| 2517 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2518 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2519 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2520 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2521 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2522 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2523 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2524 | /* Ignore for P2P Device */ |
| 2525 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2526 | return 0; |
| 2527 | |
| 2528 | ifindex = if_nametoindex(ifname); |
| 2529 | 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] | 2530 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2531 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2532 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2533 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2534 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2535 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2536 | tdls = 1; |
| 2537 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2538 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2539 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 2540 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2541 | if (alg == WPA_ALG_PMK && |
| 2542 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2543 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2544 | __func__); |
| 2545 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2546 | return ret; |
| 2547 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 2548 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2549 | |
| 2550 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2551 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2552 | if (!msg) |
| 2553 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2554 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2555 | u32 suite; |
| 2556 | |
| 2557 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2558 | if (!suite) |
| 2559 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2560 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2561 | if (!msg || |
| 2562 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2563 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2564 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2565 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2568 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2569 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2570 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2571 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2572 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2573 | |
| 2574 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2575 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2576 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2577 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2578 | |
| 2579 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2580 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2581 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2582 | NL80211_KEYTYPE_GROUP)) |
| 2583 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2584 | } |
| 2585 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2586 | struct nlattr *types; |
| 2587 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2588 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2589 | |
| 2590 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2591 | if (!types || |
| 2592 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2593 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2594 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2595 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2596 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2597 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2598 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2599 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2600 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2601 | ret = 0; |
| 2602 | if (ret) |
| 2603 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2604 | ret, strerror(-ret)); |
| 2605 | |
| 2606 | /* |
| 2607 | * If we failed or don't need to set the default TX key (below), |
| 2608 | * we're done here. |
| 2609 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2610 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2611 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2612 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2613 | !is_broadcast_ether_addr(addr)) |
| 2614 | return ret; |
| 2615 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2616 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2617 | if (!msg || |
| 2618 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2619 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2620 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2621 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2622 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2623 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2624 | NL80211_ATTR_KEY_DEFAULT)) |
| 2625 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2626 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2627 | struct nlattr *types; |
| 2628 | |
| 2629 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2630 | if (!types || |
| 2631 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2632 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2633 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2634 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2635 | struct nlattr *types; |
| 2636 | |
| 2637 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2638 | if (!types || |
| 2639 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2640 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2641 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2645 | if (ret == -ENOENT) |
| 2646 | ret = 0; |
| 2647 | if (ret) |
| 2648 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2649 | "err=%d %s)", ret, strerror(-ret)); |
| 2650 | return ret; |
| 2651 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2652 | fail: |
| 2653 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2654 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2655 | return -ENOBUFS; |
| 2656 | } |
| 2657 | |
| 2658 | |
| 2659 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 2660 | int key_idx, int defkey, |
| 2661 | const u8 *seq, size_t seq_len, |
| 2662 | const u8 *key, size_t key_len) |
| 2663 | { |
| 2664 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2665 | u32 suite; |
| 2666 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2667 | if (!key_attr) |
| 2668 | return -1; |
| 2669 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2670 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2671 | if (!suite) |
| 2672 | return -1; |
| 2673 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2674 | if (defkey && alg == WPA_ALG_IGTK) { |
| 2675 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 2676 | return -1; |
| 2677 | } else if (defkey) { |
| 2678 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 2679 | return -1; |
| 2680 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2681 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2682 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2683 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2684 | (seq && seq_len && |
| 2685 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 2686 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 2687 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2688 | |
| 2689 | nla_nest_end(msg, key_attr); |
| 2690 | |
| 2691 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | |
| 2695 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 2696 | struct nl_msg *msg) |
| 2697 | { |
| 2698 | int i, privacy = 0; |
| 2699 | struct nlattr *nl_keys, *nl_key; |
| 2700 | |
| 2701 | for (i = 0; i < 4; i++) { |
| 2702 | if (!params->wep_key[i]) |
| 2703 | continue; |
| 2704 | privacy = 1; |
| 2705 | break; |
| 2706 | } |
| 2707 | if (params->wps == WPS_MODE_PRIVACY) |
| 2708 | privacy = 1; |
| 2709 | if (params->pairwise_suite && |
| 2710 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 2711 | privacy = 1; |
| 2712 | |
| 2713 | if (!privacy) |
| 2714 | return 0; |
| 2715 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2716 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 2717 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2718 | |
| 2719 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 2720 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2721 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2722 | |
| 2723 | for (i = 0; i < 4; i++) { |
| 2724 | if (!params->wep_key[i]) |
| 2725 | continue; |
| 2726 | |
| 2727 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2728 | if (!nl_key || |
| 2729 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 2730 | params->wep_key[i]) || |
| 2731 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2732 | params->wep_key_len[i] == 5 ? |
| 2733 | WLAN_CIPHER_SUITE_WEP40 : |
| 2734 | WLAN_CIPHER_SUITE_WEP104) || |
| 2735 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 2736 | (i == params->wep_tx_keyidx && |
| 2737 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 2738 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2739 | |
| 2740 | nla_nest_end(msg, nl_key); |
| 2741 | } |
| 2742 | nla_nest_end(msg, nl_keys); |
| 2743 | |
| 2744 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2748 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 2749 | const u8 *addr, int cmd, u16 reason_code, |
| 2750 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2751 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2752 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2753 | struct nl_msg *msg; |
| 2754 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2755 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 2756 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 2757 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 2758 | (local_state_change && |
| 2759 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 2760 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2761 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2762 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2763 | |
| 2764 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2765 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2766 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2767 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 2768 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2769 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2770 | return ret; |
| 2771 | } |
| 2772 | |
| 2773 | |
| 2774 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2775 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2776 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2777 | int ret; |
| 2778 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2779 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2780 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2781 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2782 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 2783 | reason_code, 0); |
| 2784 | /* |
| 2785 | * For locally generated disconnect, supplicant already generates a |
| 2786 | * DEAUTH event, so ignore the event from NL80211. |
| 2787 | */ |
| 2788 | drv->ignore_next_local_disconnect = ret == 0; |
| 2789 | |
| 2790 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2794 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 2795 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2796 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2797 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2798 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2799 | |
| 2800 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 2801 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2802 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2803 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2804 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2805 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2806 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 2807 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2808 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2809 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 2810 | reason_code, 0); |
| 2811 | /* |
| 2812 | * For locally generated deauthenticate, supplicant already generates a |
| 2813 | * DEAUTH event, so ignore the event from NL80211. |
| 2814 | */ |
| 2815 | drv->ignore_next_local_deauth = ret == 0; |
| 2816 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2820 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 2821 | struct wpa_driver_auth_params *params) |
| 2822 | { |
| 2823 | int i; |
| 2824 | |
| 2825 | drv->auth_freq = params->freq; |
| 2826 | drv->auth_alg = params->auth_alg; |
| 2827 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 2828 | drv->auth_local_state_change = params->local_state_change; |
| 2829 | drv->auth_p2p = params->p2p; |
| 2830 | |
| 2831 | if (params->bssid) |
| 2832 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 2833 | else |
| 2834 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 2835 | |
| 2836 | if (params->ssid) { |
| 2837 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 2838 | drv->auth_ssid_len = params->ssid_len; |
| 2839 | } else |
| 2840 | drv->auth_ssid_len = 0; |
| 2841 | |
| 2842 | |
| 2843 | os_free(drv->auth_ie); |
| 2844 | drv->auth_ie = NULL; |
| 2845 | drv->auth_ie_len = 0; |
| 2846 | if (params->ie) { |
| 2847 | drv->auth_ie = os_malloc(params->ie_len); |
| 2848 | if (drv->auth_ie) { |
| 2849 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 2850 | drv->auth_ie_len = params->ie_len; |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | for (i = 0; i < 4; i++) { |
| 2855 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 2856 | params->wep_key_len[i] <= 16) { |
| 2857 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 2858 | params->wep_key_len[i]); |
| 2859 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 2860 | } else |
| 2861 | drv->auth_wep_key_len[i] = 0; |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2866 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 2867 | { |
| 2868 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2869 | |
| 2870 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 2871 | return; |
| 2872 | |
| 2873 | /* |
| 2874 | * Looks like we failed to unmask 11b rates previously. This could |
| 2875 | * happen, e.g., if the interface was down at the point in time when a |
| 2876 | * P2P group was terminated. |
| 2877 | */ |
| 2878 | wpa_printf(MSG_DEBUG, |
| 2879 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 2880 | bss->ifname); |
| 2881 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2882 | } |
| 2883 | |
| 2884 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2885 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2886 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2887 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2888 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2889 | int ret = -1, i; |
| 2890 | struct nl_msg *msg; |
| 2891 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2892 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2893 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2894 | int is_retry; |
| 2895 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2896 | nl80211_unmask_11b_rates(bss); |
| 2897 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2898 | is_retry = drv->retry_auth; |
| 2899 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2900 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2901 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2902 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2903 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2904 | if (params->bssid) |
| 2905 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 2906 | else |
| 2907 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2908 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2909 | nlmode = params->p2p ? |
| 2910 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 2911 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2912 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2913 | return -1; |
| 2914 | |
| 2915 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2916 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 2917 | drv->ifindex); |
| 2918 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2919 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 2920 | if (!msg) |
| 2921 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2922 | |
| 2923 | for (i = 0; i < 4; i++) { |
| 2924 | if (!params->wep_key[i]) |
| 2925 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2926 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2927 | NULL, i, |
| 2928 | i == params->wep_tx_keyidx, NULL, 0, |
| 2929 | params->wep_key[i], |
| 2930 | params->wep_key_len[i]); |
| 2931 | if (params->wep_tx_keyidx != i) |
| 2932 | continue; |
| 2933 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2934 | params->wep_key[i], params->wep_key_len[i])) |
| 2935 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2938 | if (params->bssid) { |
| 2939 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 2940 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2941 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 2942 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2943 | } |
| 2944 | if (params->freq) { |
| 2945 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2946 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 2947 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2948 | } |
| 2949 | if (params->ssid) { |
| 2950 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 2951 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2952 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 2953 | params->ssid)) |
| 2954 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2955 | } |
| 2956 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2957 | if (params->ie && |
| 2958 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 2959 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2960 | if (params->sae_data) { |
| 2961 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 2962 | params->sae_data_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2963 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 2964 | params->sae_data)) |
| 2965 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2966 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2967 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 2968 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 2969 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 2970 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 2971 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 2972 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 2973 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 2974 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2975 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 2976 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2977 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2978 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2979 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2980 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 2981 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2982 | if (params->local_state_change) { |
| 2983 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2984 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 2985 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2989 | msg = NULL; |
| 2990 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2991 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2992 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 2993 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2994 | count++; |
| 2995 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 2996 | !params->local_state_change) { |
| 2997 | /* |
| 2998 | * mac80211 does not currently accept new |
| 2999 | * authentication if we are already authenticated. As a |
| 3000 | * workaround, force deauthentication and try again. |
| 3001 | */ |
| 3002 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3003 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3004 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3005 | wpa_driver_nl80211_deauthenticate( |
| 3006 | bss, params->bssid, |
| 3007 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3008 | nlmsg_free(msg); |
| 3009 | goto retry; |
| 3010 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3011 | |
| 3012 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3013 | /* |
| 3014 | * cfg80211 has likely expired the BSS entry even |
| 3015 | * though it was previously available in our internal |
| 3016 | * BSS table. To recover quickly, start a single |
| 3017 | * channel scan on the specified channel. |
| 3018 | */ |
| 3019 | struct wpa_driver_scan_params scan; |
| 3020 | int freqs[2]; |
| 3021 | |
| 3022 | os_memset(&scan, 0, sizeof(scan)); |
| 3023 | scan.num_ssids = 1; |
| 3024 | if (params->ssid) { |
| 3025 | scan.ssids[0].ssid = params->ssid; |
| 3026 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3027 | } |
| 3028 | freqs[0] = params->freq; |
| 3029 | freqs[1] = 0; |
| 3030 | scan.freqs = freqs; |
| 3031 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3032 | "channel scan to refresh cfg80211 BSS " |
| 3033 | "entry"); |
| 3034 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3035 | if (ret == 0) { |
| 3036 | nl80211_copy_auth_params(drv, params); |
| 3037 | drv->scan_for_auth = 1; |
| 3038 | } |
| 3039 | } else if (is_retry) { |
| 3040 | /* |
| 3041 | * Need to indicate this with an event since the return |
| 3042 | * value from the retry is not delivered to core code. |
| 3043 | */ |
| 3044 | union wpa_event_data event; |
| 3045 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3046 | "failed"); |
| 3047 | os_memset(&event, 0, sizeof(event)); |
| 3048 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3049 | ETH_ALEN); |
| 3050 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3051 | &event); |
| 3052 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3053 | } else { |
| 3054 | wpa_printf(MSG_DEBUG, |
| 3055 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3056 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3057 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3058 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3059 | nlmsg_free(msg); |
| 3060 | return ret; |
| 3061 | } |
| 3062 | |
| 3063 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3064 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3065 | { |
| 3066 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3067 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3068 | int i; |
| 3069 | |
| 3070 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3071 | |
| 3072 | os_memset(¶ms, 0, sizeof(params)); |
| 3073 | params.freq = drv->auth_freq; |
| 3074 | params.auth_alg = drv->auth_alg; |
| 3075 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3076 | params.local_state_change = drv->auth_local_state_change; |
| 3077 | params.p2p = drv->auth_p2p; |
| 3078 | |
| 3079 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3080 | params.bssid = drv->auth_bssid_; |
| 3081 | |
| 3082 | if (drv->auth_ssid_len) { |
| 3083 | params.ssid = drv->auth_ssid; |
| 3084 | params.ssid_len = drv->auth_ssid_len; |
| 3085 | } |
| 3086 | |
| 3087 | params.ie = drv->auth_ie; |
| 3088 | params.ie_len = drv->auth_ie_len; |
| 3089 | |
| 3090 | for (i = 0; i < 4; i++) { |
| 3091 | if (drv->auth_wep_key_len[i]) { |
| 3092 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3093 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | drv->retry_auth = 1; |
| 3098 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3099 | } |
| 3100 | |
| 3101 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3102 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3103 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3104 | int encrypt, int noack, |
| 3105 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3106 | int offchanok, unsigned int wait_time, |
| 3107 | const u16 *csa_offs, |
| 3108 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3109 | { |
| 3110 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3111 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3112 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3113 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3114 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3115 | freq = nl80211_get_assoc_freq(drv); |
| 3116 | wpa_printf(MSG_DEBUG, |
| 3117 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3118 | freq); |
| 3119 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3120 | if (freq == 0) { |
| 3121 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3122 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3123 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3124 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3125 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3126 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3127 | 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] | 3128 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3129 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3130 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3131 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3132 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3133 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3134 | &cookie, no_cck, noack, offchanok, |
| 3135 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3136 | if (res == 0 && !noack) { |
| 3137 | const struct ieee80211_mgmt *mgmt; |
| 3138 | u16 fc; |
| 3139 | |
| 3140 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3141 | fc = le_to_host16(mgmt->frame_control); |
| 3142 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3143 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3144 | wpa_printf(MSG_MSGDUMP, |
| 3145 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3146 | (long long unsigned int) |
| 3147 | drv->send_action_cookie, |
| 3148 | (long long unsigned int) cookie); |
| 3149 | drv->send_action_cookie = cookie; |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3157 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3158 | size_t data_len, int noack, |
| 3159 | unsigned int freq, int no_cck, |
| 3160 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3161 | unsigned int wait_time, |
| 3162 | const u16 *csa_offs, |
| 3163 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3164 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3165 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3166 | struct ieee80211_mgmt *mgmt; |
| 3167 | int encrypt = 1; |
| 3168 | u16 fc; |
| 3169 | |
| 3170 | mgmt = (struct ieee80211_mgmt *) data; |
| 3171 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3172 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3173 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3174 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3175 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3176 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3177 | if ((is_sta_interface(drv->nlmode) || |
| 3178 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3179 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3180 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3181 | /* |
| 3182 | * The use of last_mgmt_freq is a bit of a hack, |
| 3183 | * but it works due to the single-threaded nature |
| 3184 | * of wpa_supplicant. |
| 3185 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3186 | if (freq == 0) { |
| 3187 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3188 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3189 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3190 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3191 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3192 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3193 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3194 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3195 | |
| 3196 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3197 | if (freq == 0) { |
| 3198 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3199 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3200 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3201 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3202 | return nl80211_send_frame_cmd(bss, freq, |
| 3203 | (int) freq == bss->freq ? 0 : |
| 3204 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3205 | data, data_len, |
| 3206 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3207 | no_cck, noack, offchanok, |
| 3208 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3209 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3210 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3211 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3212 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3213 | /* |
| 3214 | * Only one of the authentication frame types is encrypted. |
| 3215 | * In order for static WEP encryption to work properly (i.e., |
| 3216 | * to not encrypt the frame), we need to tell mac80211 about |
| 3217 | * the frames that must not be encrypted. |
| 3218 | */ |
| 3219 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3220 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3221 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3222 | encrypt = 0; |
| 3223 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3224 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3225 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3226 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3227 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3228 | wait_time, csa_offs, |
| 3229 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3233 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3234 | { |
| 3235 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3236 | u8 rates_len = 0; |
| 3237 | int i; |
| 3238 | |
| 3239 | if (!basic_rates) |
| 3240 | return 0; |
| 3241 | |
| 3242 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3243 | rates[rates_len++] = basic_rates[i] / 5; |
| 3244 | |
| 3245 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3246 | } |
| 3247 | |
| 3248 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3249 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3250 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3251 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3252 | { |
| 3253 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3254 | struct nl_msg *msg; |
| 3255 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3256 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3257 | (cts >= 0 && |
| 3258 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3259 | (preamble >= 0 && |
| 3260 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3261 | (slot >= 0 && |
| 3262 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3263 | (ht_opmode >= 0 && |
| 3264 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3265 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3266 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3267 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3268 | nlmsg_free(msg); |
| 3269 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3270 | } |
| 3271 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3272 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3273 | } |
| 3274 | |
| 3275 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3276 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3277 | struct hostapd_acl_params *params) |
| 3278 | { |
| 3279 | struct i802_bss *bss = priv; |
| 3280 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3281 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3282 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3283 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3284 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3285 | |
| 3286 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3287 | return -ENOTSUP; |
| 3288 | |
| 3289 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3290 | return -ENOTSUP; |
| 3291 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3292 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3293 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3294 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3295 | acl = nlmsg_alloc(); |
| 3296 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3297 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3298 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3299 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3300 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3301 | return -ENOMEM; |
| 3302 | } |
| 3303 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3304 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 3305 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3306 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3307 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3308 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3309 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3310 | nlmsg_free(msg); |
| 3311 | nlmsg_free(acl); |
| 3312 | return -ENOMEM; |
| 3313 | } |
| 3314 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3315 | |
| 3316 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3317 | if (ret) { |
| 3318 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3319 | ret, strerror(-ret)); |
| 3320 | } |
| 3321 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3322 | return ret; |
| 3323 | } |
| 3324 | |
| 3325 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3326 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3327 | { |
| 3328 | if (beacon_int > 0) { |
| 3329 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3330 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3331 | beacon_int); |
| 3332 | } |
| 3333 | |
| 3334 | return 0; |
| 3335 | } |
| 3336 | |
| 3337 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3338 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3339 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3340 | { |
| 3341 | struct i802_bss *bss = priv; |
| 3342 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3343 | struct nl_msg *msg; |
| 3344 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3345 | int ret; |
| 3346 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3347 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3348 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3349 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3350 | u32 ver; |
| 3351 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3352 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3353 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3354 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3355 | beacon_set); |
| 3356 | if (beacon_set) |
| 3357 | cmd = NL80211_CMD_SET_BEACON; |
| 3358 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3359 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3360 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3361 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3362 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3363 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3364 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3365 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3366 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3367 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3368 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3369 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3370 | params->head) || |
| 3371 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3372 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3373 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3374 | nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) || |
| 3375 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3376 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3377 | if (params->proberesp && params->proberesp_len) { |
| 3378 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3379 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3380 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3381 | params->proberesp)) |
| 3382 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3383 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3384 | switch (params->hide_ssid) { |
| 3385 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3386 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3387 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3388 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3389 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3390 | break; |
| 3391 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3392 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3393 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3394 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3395 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3396 | break; |
| 3397 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3398 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3399 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3400 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3401 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3402 | break; |
| 3403 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3404 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3405 | if (params->privacy && |
| 3406 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3407 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3408 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3409 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3410 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3411 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3412 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3413 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3414 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3415 | goto fail; |
| 3416 | } else { |
| 3417 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3418 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3419 | goto fail; |
| 3420 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3421 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3422 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3423 | ver = 0; |
| 3424 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3425 | ver |= NL80211_WPA_VERSION_1; |
| 3426 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3427 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3428 | if (ver && |
| 3429 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3430 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3431 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3432 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3433 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3434 | num_suites = 0; |
| 3435 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 3436 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 3437 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 3438 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3439 | if (num_suites && |
| 3440 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3441 | suites)) |
| 3442 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3443 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3444 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 3445 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) && |
| 3446 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) |
| 3447 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3448 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3449 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 3450 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3451 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 3452 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3453 | if (num_suites && |
| 3454 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 3455 | num_suites * sizeof(u32), suites)) |
| 3456 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3457 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3458 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 3459 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3460 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3461 | if (suite && |
| 3462 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 3463 | goto fail; |
| 3464 | |
| 3465 | switch (params->smps_mode) { |
| 3466 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 3467 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 3468 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 3469 | break; |
| 3470 | case HT_CAP_INFO_SMPS_STATIC: |
| 3471 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 3472 | smps_mode = NL80211_SMPS_STATIC; |
| 3473 | break; |
| 3474 | default: |
| 3475 | /* invalid - fallback to smps off */ |
| 3476 | case HT_CAP_INFO_SMPS_DISABLED: |
| 3477 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 3478 | smps_mode = NL80211_SMPS_OFF; |
| 3479 | break; |
| 3480 | } |
| 3481 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
| 3482 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3483 | |
| 3484 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3485 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 3486 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3487 | if (nla_put(msg, NL80211_ATTR_IE, |
| 3488 | wpabuf_len(params->beacon_ies), |
| 3489 | wpabuf_head(params->beacon_ies))) |
| 3490 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3491 | } |
| 3492 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3493 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 3494 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3495 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 3496 | wpabuf_len(params->proberesp_ies), |
| 3497 | wpabuf_head(params->proberesp_ies))) |
| 3498 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3499 | } |
| 3500 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3501 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 3502 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3503 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 3504 | wpabuf_len(params->assocresp_ies), |
| 3505 | wpabuf_head(params->assocresp_ies))) |
| 3506 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3507 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3508 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3509 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3510 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 3511 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3512 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 3513 | params->ap_max_inactivity)) |
| 3514 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3517 | #ifdef CONFIG_P2P |
| 3518 | if (params->p2p_go_ctwindow > 0) { |
| 3519 | if (drv->p2p_go_ctwindow_supported) { |
| 3520 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 3521 | params->p2p_go_ctwindow); |
| 3522 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 3523 | params->p2p_go_ctwindow)) |
| 3524 | goto fail; |
| 3525 | } else { |
| 3526 | wpa_printf(MSG_INFO, |
| 3527 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 3528 | } |
| 3529 | } |
| 3530 | #endif /* CONFIG_P2P */ |
| 3531 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3532 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3533 | if (ret) { |
| 3534 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 3535 | ret, strerror(-ret)); |
| 3536 | } else { |
| 3537 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3538 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 3539 | params->short_slot_time, params->ht_opmode, |
| 3540 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3541 | if (beacon_set && params->freq && |
| 3542 | params->freq->bandwidth != bss->bandwidth) { |
| 3543 | wpa_printf(MSG_DEBUG, |
| 3544 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 3545 | bss->ifname, bss->bandwidth, |
| 3546 | params->freq->bandwidth); |
| 3547 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 3548 | if (ret) { |
| 3549 | wpa_printf(MSG_DEBUG, |
| 3550 | "nl80211: Frequency set failed: %d (%s)", |
| 3551 | ret, strerror(-ret)); |
| 3552 | } else { |
| 3553 | wpa_printf(MSG_DEBUG, |
| 3554 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 3555 | bss->bandwidth = params->freq->bandwidth; |
| 3556 | } |
| 3557 | } else if (!beacon_set) { |
| 3558 | /* |
| 3559 | * cfg80211 updates the driver on frequence change in AP |
| 3560 | * mode only at the point when beaconing is started, so |
| 3561 | * set the initial value here. |
| 3562 | */ |
| 3563 | bss->bandwidth = params->freq->bandwidth; |
| 3564 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3565 | } |
| 3566 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3567 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3568 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3569 | return -ENOBUFS; |
| 3570 | } |
| 3571 | |
| 3572 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3573 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3574 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3575 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3576 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3577 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 3578 | return -ENOBUFS; |
| 3579 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3580 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 3581 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 3582 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3583 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3584 | enum nl80211_chan_width cw; |
| 3585 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3586 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3587 | switch (freq->bandwidth) { |
| 3588 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3589 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3590 | break; |
| 3591 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3592 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3593 | break; |
| 3594 | case 80: |
| 3595 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3596 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3597 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3598 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3599 | break; |
| 3600 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3601 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3602 | break; |
| 3603 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3604 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3605 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3606 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3607 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 3608 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 3609 | freq->center_freq1); |
| 3610 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 3611 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3612 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 3613 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 3614 | freq->center_freq1) || |
| 3615 | (freq->center_freq2 && |
| 3616 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 3617 | freq->center_freq2))) |
| 3618 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3619 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3620 | enum nl80211_channel_type ct; |
| 3621 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3622 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 3623 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3624 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3625 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3626 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3627 | break; |
| 3628 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3629 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3630 | break; |
| 3631 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3632 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3633 | break; |
| 3634 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3635 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3636 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3637 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 3638 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3639 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3640 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3644 | static int nl80211_set_channel(struct i802_bss *bss, |
| 3645 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3646 | { |
| 3647 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3648 | struct nl_msg *msg; |
| 3649 | int ret; |
| 3650 | |
| 3651 | wpa_printf(MSG_DEBUG, |
| 3652 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 3653 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 3654 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3655 | |
| 3656 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 3657 | NL80211_CMD_SET_WIPHY); |
| 3658 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 3659 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3660 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3661 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3662 | |
| 3663 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3664 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3665 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3666 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3667 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3668 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3669 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3670 | return -1; |
| 3671 | } |
| 3672 | |
| 3673 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3674 | static u32 sta_flags_nl80211(int flags) |
| 3675 | { |
| 3676 | u32 f = 0; |
| 3677 | |
| 3678 | if (flags & WPA_STA_AUTHORIZED) |
| 3679 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3680 | if (flags & WPA_STA_WMM) |
| 3681 | f |= BIT(NL80211_STA_FLAG_WME); |
| 3682 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 3683 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 3684 | if (flags & WPA_STA_MFP) |
| 3685 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 3686 | if (flags & WPA_STA_TDLS_PEER) |
| 3687 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3688 | if (flags & WPA_STA_AUTHENTICATED) |
| 3689 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3690 | |
| 3691 | return f; |
| 3692 | } |
| 3693 | |
| 3694 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3695 | #ifdef CONFIG_MESH |
| 3696 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 3697 | { |
| 3698 | switch (state) { |
| 3699 | case PLINK_LISTEN: |
| 3700 | return NL80211_PLINK_LISTEN; |
| 3701 | case PLINK_OPEN_SENT: |
| 3702 | return NL80211_PLINK_OPN_SNT; |
| 3703 | case PLINK_OPEN_RCVD: |
| 3704 | return NL80211_PLINK_OPN_RCVD; |
| 3705 | case PLINK_CNF_RCVD: |
| 3706 | return NL80211_PLINK_CNF_RCVD; |
| 3707 | case PLINK_ESTAB: |
| 3708 | return NL80211_PLINK_ESTAB; |
| 3709 | case PLINK_HOLDING: |
| 3710 | return NL80211_PLINK_HOLDING; |
| 3711 | case PLINK_BLOCKED: |
| 3712 | return NL80211_PLINK_BLOCKED; |
| 3713 | default: |
| 3714 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 3715 | state); |
| 3716 | } |
| 3717 | return -1; |
| 3718 | } |
| 3719 | #endif /* CONFIG_MESH */ |
| 3720 | |
| 3721 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3722 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 3723 | struct hostapd_sta_add_params *params) |
| 3724 | { |
| 3725 | struct i802_bss *bss = priv; |
| 3726 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3727 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3728 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3729 | int ret = -ENOBUFS; |
| 3730 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3731 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 3732 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 3733 | return -EOPNOTSUPP; |
| 3734 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3735 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 3736 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3737 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 3738 | NL80211_CMD_NEW_STATION); |
| 3739 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 3740 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3741 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3742 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) { |
| 3743 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 3744 | params->supp_rates, params->supp_rates_len); |
| 3745 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 3746 | params->capability); |
| 3747 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 3748 | params->supp_rates_len, params->supp_rates) || |
| 3749 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 3750 | params->capability)) |
| 3751 | goto fail; |
| 3752 | |
| 3753 | if (params->ht_capabilities) { |
| 3754 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 3755 | (u8 *) params->ht_capabilities, |
| 3756 | sizeof(*params->ht_capabilities)); |
| 3757 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 3758 | sizeof(*params->ht_capabilities), |
| 3759 | params->ht_capabilities)) |
| 3760 | goto fail; |
| 3761 | } |
| 3762 | |
| 3763 | if (params->vht_capabilities) { |
| 3764 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 3765 | (u8 *) params->vht_capabilities, |
| 3766 | sizeof(*params->vht_capabilities)); |
| 3767 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 3768 | sizeof(*params->vht_capabilities), |
| 3769 | params->vht_capabilities)) |
| 3770 | goto fail; |
| 3771 | } |
| 3772 | |
| 3773 | if (params->ext_capab) { |
| 3774 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 3775 | params->ext_capab, params->ext_capab_len); |
| 3776 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 3777 | params->ext_capab_len, params->ext_capab)) |
| 3778 | goto fail; |
| 3779 | } |
| 3780 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3781 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3782 | if (params->aid) { |
| 3783 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3784 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 3785 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3786 | } else { |
| 3787 | /* |
| 3788 | * cfg80211 validates that AID is non-zero, so we have |
| 3789 | * to make this a non-zero value for the TDLS case where |
| 3790 | * a dummy STA entry is used for now. |
| 3791 | */ |
| 3792 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3793 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 3794 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3795 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3796 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 3797 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3798 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 3799 | params->listen_interval)) |
| 3800 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3801 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 3802 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3803 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 3804 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3805 | } |
| 3806 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3807 | if (params->vht_opmode_enabled) { |
| 3808 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3809 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 3810 | params->vht_opmode)) |
| 3811 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3812 | } |
| 3813 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3814 | if (params->supp_channels) { |
| 3815 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 3816 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3817 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 3818 | params->supp_channels_len, params->supp_channels)) |
| 3819 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | if (params->supp_oper_classes) { |
| 3823 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 3824 | params->supp_oper_classes, |
| 3825 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3826 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 3827 | params->supp_oper_classes_len, |
| 3828 | params->supp_oper_classes)) |
| 3829 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3830 | } |
| 3831 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3832 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3833 | upd.set = sta_flags_nl80211(params->flags); |
| 3834 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3835 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 3836 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3837 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 3838 | goto fail; |
| 3839 | |
| 3840 | #ifdef CONFIG_MESH |
| 3841 | if (params->plink_state && |
| 3842 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 3843 | sta_plink_state_nl80211(params->plink_state))) |
| 3844 | goto fail; |
| 3845 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3846 | |
| 3847 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3848 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 3849 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3850 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3851 | if (!wme || |
| 3852 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 3853 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 3854 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 3855 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 3856 | WMM_QOSINFO_STA_SP_MASK)) |
| 3857 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3858 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3859 | } |
| 3860 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3861 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3862 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3863 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3864 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 3865 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 3866 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3867 | if (ret == -EEXIST) |
| 3868 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3869 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3870 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3871 | return ret; |
| 3872 | } |
| 3873 | |
| 3874 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3875 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 3876 | { |
| 3877 | #ifdef CONFIG_LIBNL3_ROUTE |
| 3878 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3879 | struct rtnl_neigh *rn; |
| 3880 | struct nl_addr *nl_addr; |
| 3881 | int err; |
| 3882 | |
| 3883 | rn = rtnl_neigh_alloc(); |
| 3884 | if (!rn) |
| 3885 | return; |
| 3886 | |
| 3887 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 3888 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 3889 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 3890 | if (!nl_addr) { |
| 3891 | rtnl_neigh_put(rn); |
| 3892 | return; |
| 3893 | } |
| 3894 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 3895 | |
| 3896 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 3897 | if (err < 0) { |
| 3898 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 3899 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 3900 | bss->ifindex, nl_geterror(err)); |
| 3901 | } else { |
| 3902 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 3903 | MACSTR, MAC2STR(addr)); |
| 3904 | } |
| 3905 | |
| 3906 | nl_addr_put(nl_addr); |
| 3907 | rtnl_neigh_put(rn); |
| 3908 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 3909 | } |
| 3910 | |
| 3911 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3912 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 3913 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3914 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3915 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3916 | struct nl_msg *msg; |
| 3917 | int ret; |
| 3918 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3919 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 3920 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3921 | (deauth == 0 && |
| 3922 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 3923 | WLAN_FC_STYPE_DISASSOC)) || |
| 3924 | (deauth == 1 && |
| 3925 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 3926 | WLAN_FC_STYPE_DEAUTH)) || |
| 3927 | (reason_code && |
| 3928 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 3929 | nlmsg_free(msg); |
| 3930 | return -ENOBUFS; |
| 3931 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3932 | |
| 3933 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 3934 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 3935 | " --> %d (%s)", |
| 3936 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3937 | |
| 3938 | if (drv->rtnl_sk) |
| 3939 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 3940 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3941 | if (ret == -ENOENT) |
| 3942 | return 0; |
| 3943 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3947 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3948 | { |
| 3949 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3950 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3951 | |
| 3952 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 3953 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3954 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3955 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 3956 | struct wpa_driver_nl80211_data, list) |
| 3957 | del_ifidx(drv2, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3958 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3959 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3960 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 3961 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3962 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 3963 | } |
| 3964 | |
| 3965 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3966 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 3967 | { |
| 3968 | switch (mode) { |
| 3969 | case NL80211_IFTYPE_ADHOC: |
| 3970 | return "ADHOC"; |
| 3971 | case NL80211_IFTYPE_STATION: |
| 3972 | return "STATION"; |
| 3973 | case NL80211_IFTYPE_AP: |
| 3974 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3975 | case NL80211_IFTYPE_AP_VLAN: |
| 3976 | return "AP_VLAN"; |
| 3977 | case NL80211_IFTYPE_WDS: |
| 3978 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3979 | case NL80211_IFTYPE_MONITOR: |
| 3980 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3981 | case NL80211_IFTYPE_MESH_POINT: |
| 3982 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3983 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3984 | return "P2P_CLIENT"; |
| 3985 | case NL80211_IFTYPE_P2P_GO: |
| 3986 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3987 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3988 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3989 | default: |
| 3990 | return "unknown"; |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3995 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 3996 | const char *ifname, |
| 3997 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3998 | const u8 *addr, int wds, |
| 3999 | int (*handler)(struct nl_msg *, void *), |
| 4000 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4001 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4002 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4003 | int ifidx; |
| 4004 | int ret = -ENOBUFS; |
| 4005 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4006 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4007 | iftype, nl80211_iftype_str(iftype)); |
| 4008 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4009 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4010 | if (!msg || |
| 4011 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4012 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4013 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4014 | |
| 4015 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4016 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4017 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4018 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4019 | if (!flags || |
| 4020 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4021 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4022 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4023 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4024 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4025 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4026 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4029 | /* |
| 4030 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4031 | * it, and the interface should be deleted when the socket is closed. |
| 4032 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4033 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4034 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4035 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4036 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4037 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4038 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4039 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4040 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4041 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4042 | ifname, ret, strerror(-ret)); |
| 4043 | return ret; |
| 4044 | } |
| 4045 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4046 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4047 | return 0; |
| 4048 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4049 | ifidx = if_nametoindex(ifname); |
| 4050 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4051 | ifname, ifidx); |
| 4052 | |
| 4053 | if (ifidx <= 0) |
| 4054 | return -1; |
| 4055 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4056 | /* |
| 4057 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4058 | * the parent interface. This is used mainly with hostapd. |
| 4059 | */ |
| 4060 | if (drv->hostapd || |
| 4061 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4062 | iftype == NL80211_IFTYPE_WDS || |
| 4063 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4064 | /* start listening for EAPOL on this interface */ |
| 4065 | add_ifidx(drv, ifidx); |
| 4066 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4067 | |
| 4068 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4069 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4070 | nl80211_remove_iface(drv, ifidx); |
| 4071 | return -1; |
| 4072 | } |
| 4073 | |
| 4074 | return ifidx; |
| 4075 | } |
| 4076 | |
| 4077 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4078 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4079 | const char *ifname, enum nl80211_iftype iftype, |
| 4080 | const u8 *addr, int wds, |
| 4081 | int (*handler)(struct nl_msg *, void *), |
| 4082 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4083 | { |
| 4084 | int ret; |
| 4085 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4086 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4087 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4088 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4089 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4090 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4091 | if (use_existing) { |
| 4092 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4093 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4094 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4095 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4096 | addr) < 0 && |
| 4097 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4098 | ifname, 0) < 0 || |
| 4099 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4100 | addr) < 0 || |
| 4101 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4102 | ifname, 1) < 0)) |
| 4103 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4104 | return -ENFILE; |
| 4105 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4106 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4107 | |
| 4108 | /* Try to remove the interface that was already there. */ |
| 4109 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4110 | |
| 4111 | /* Try to create the interface again */ |
| 4112 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4113 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4114 | } |
| 4115 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4116 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4117 | wpa_printf(MSG_DEBUG, |
| 4118 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4119 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4120 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4121 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4122 | |
| 4123 | return ret; |
| 4124 | } |
| 4125 | |
| 4126 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4127 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4128 | { |
| 4129 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4130 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4131 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4132 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4133 | |
| 4134 | /* |
| 4135 | * Disable Probe Request reporting unless we need it in this way for |
| 4136 | * devices that include the AP SME, in the other case (unless using |
| 4137 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4138 | */ |
| 4139 | if (!drv->device_ap_sme) |
| 4140 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4141 | |
| 4142 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4143 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4144 | return -1; |
| 4145 | |
| 4146 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4147 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 4148 | return -1; |
| 4149 | |
| 4150 | if (!drv->device_ap_sme && drv->use_monitor && |
| 4151 | nl80211_create_monitor_interface(drv) && |
| 4152 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4153 | return -1; |
| 4154 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4155 | if (drv->device_ap_sme && |
| 4156 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4157 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4158 | "Probe Request frame reporting in AP mode"); |
| 4159 | /* Try to survive without this */ |
| 4160 | } |
| 4161 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4162 | return 0; |
| 4163 | } |
| 4164 | |
| 4165 | |
| 4166 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4167 | { |
| 4168 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4169 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4170 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4171 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4172 | if (drv->device_ap_sme) { |
| 4173 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4174 | if (!drv->use_monitor) |
| 4175 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4176 | } else if (drv->use_monitor) |
| 4177 | nl80211_remove_monitor_interface(drv); |
| 4178 | else |
| 4179 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4180 | |
| 4181 | bss->beacon_set = 0; |
| 4182 | } |
| 4183 | |
| 4184 | |
| 4185 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4186 | const u8 *addr, const u8 *data, |
| 4187 | size_t data_len) |
| 4188 | { |
| 4189 | struct sockaddr_ll ll; |
| 4190 | int ret; |
| 4191 | |
| 4192 | if (bss->drv->eapol_tx_sock < 0) { |
| 4193 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4194 | return -1; |
| 4195 | } |
| 4196 | |
| 4197 | os_memset(&ll, 0, sizeof(ll)); |
| 4198 | ll.sll_family = AF_PACKET; |
| 4199 | ll.sll_ifindex = bss->ifindex; |
| 4200 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4201 | ll.sll_halen = ETH_ALEN; |
| 4202 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4203 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4204 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4205 | if (ret < 0) |
| 4206 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4207 | strerror(errno)); |
| 4208 | |
| 4209 | return ret; |
| 4210 | } |
| 4211 | |
| 4212 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4213 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4214 | |
| 4215 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4216 | void *priv, const u8 *addr, const u8 *data, |
| 4217 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4218 | { |
| 4219 | struct i802_bss *bss = priv; |
| 4220 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4221 | struct ieee80211_hdr *hdr; |
| 4222 | size_t len; |
| 4223 | u8 *pos; |
| 4224 | int res; |
| 4225 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4226 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4227 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4228 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4229 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4230 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4231 | data_len; |
| 4232 | hdr = os_zalloc(len); |
| 4233 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4234 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4235 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4236 | return -1; |
| 4237 | } |
| 4238 | |
| 4239 | hdr->frame_control = |
| 4240 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4241 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4242 | if (encrypt) |
| 4243 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4244 | if (qos) { |
| 4245 | hdr->frame_control |= |
| 4246 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4247 | } |
| 4248 | |
| 4249 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4250 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4251 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4252 | pos = (u8 *) (hdr + 1); |
| 4253 | |
| 4254 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4255 | /* Set highest priority in QoS header */ |
| 4256 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4257 | pos[1] = 0; |
| 4258 | pos += 2; |
| 4259 | } |
| 4260 | |
| 4261 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4262 | pos += sizeof(rfc1042_header); |
| 4263 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4264 | pos += 2; |
| 4265 | memcpy(pos, data, data_len); |
| 4266 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4267 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 4268 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4269 | if (res < 0) { |
| 4270 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4271 | "failed: %d (%s)", |
| 4272 | (unsigned long) len, errno, strerror(errno)); |
| 4273 | } |
| 4274 | os_free(hdr); |
| 4275 | |
| 4276 | return res; |
| 4277 | } |
| 4278 | |
| 4279 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4280 | 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^] | 4281 | unsigned int total_flags, |
| 4282 | unsigned int flags_or, |
| 4283 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4284 | { |
| 4285 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4286 | struct nl_msg *msg; |
| 4287 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4288 | struct nl80211_sta_flag_update upd; |
| 4289 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4290 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4291 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4292 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4293 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4294 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4295 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4296 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4297 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4298 | |
| 4299 | /* |
| 4300 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4301 | * can be removed eventually. |
| 4302 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4303 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4304 | if (!flags || |
| 4305 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4306 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4307 | ((total_flags & WPA_STA_WMM) && |
| 4308 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4309 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4310 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4311 | ((total_flags & WPA_STA_MFP) && |
| 4312 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4313 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4314 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4315 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4316 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4317 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4318 | |
| 4319 | os_memset(&upd, 0, sizeof(upd)); |
| 4320 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4321 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4322 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4323 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4324 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4325 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4326 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4327 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4328 | return -ENOBUFS; |
| 4329 | } |
| 4330 | |
| 4331 | |
| 4332 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4333 | struct wpa_driver_associate_params *params) |
| 4334 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4335 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4336 | |
| 4337 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4338 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4339 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4340 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4341 | } else |
| 4342 | nlmode = NL80211_IFTYPE_AP; |
| 4343 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4344 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4345 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4346 | nl80211_remove_monitor_interface(drv); |
| 4347 | return -1; |
| 4348 | } |
| 4349 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4350 | if (params->freq.freq && |
| 4351 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4352 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4353 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4354 | nl80211_remove_monitor_interface(drv); |
| 4355 | return -1; |
| 4356 | } |
| 4357 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4358 | return 0; |
| 4359 | } |
| 4360 | |
| 4361 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4362 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 4363 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4364 | { |
| 4365 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4366 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4367 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4368 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4369 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4370 | if (ret) { |
| 4371 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 4372 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4373 | } else { |
| 4374 | wpa_printf(MSG_DEBUG, |
| 4375 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4376 | } |
| 4377 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4378 | if (reset_mode && |
| 4379 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4380 | NL80211_IFTYPE_STATION)) { |
| 4381 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4382 | "station mode"); |
| 4383 | } |
| 4384 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4385 | return ret; |
| 4386 | } |
| 4387 | |
| 4388 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4389 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 4390 | struct wpa_driver_associate_params *params) |
| 4391 | { |
| 4392 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 4393 | return -1; |
| 4394 | |
| 4395 | if (params->htcaps && params->htcaps_mask) { |
| 4396 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 4397 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 4398 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 4399 | params->htcaps_mask, sz); |
| 4400 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 4401 | params->htcaps) || |
| 4402 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 4403 | params->htcaps_mask)) |
| 4404 | return -1; |
| 4405 | } |
| 4406 | |
| 4407 | #ifdef CONFIG_VHT_OVERRIDES |
| 4408 | if (params->disable_vht) { |
| 4409 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 4410 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 4411 | return -1; |
| 4412 | } |
| 4413 | |
| 4414 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 4415 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 4416 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 4417 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 4418 | params->vhtcaps_mask, sz); |
| 4419 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 4420 | params->vhtcaps) || |
| 4421 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 4422 | params->vhtcaps_mask)) |
| 4423 | return -1; |
| 4424 | } |
| 4425 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 4426 | |
| 4427 | return 0; |
| 4428 | } |
| 4429 | |
| 4430 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4431 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 4432 | struct wpa_driver_associate_params *params) |
| 4433 | { |
| 4434 | struct nl_msg *msg; |
| 4435 | int ret = -1; |
| 4436 | int count = 0; |
| 4437 | |
| 4438 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 4439 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4440 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4441 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4442 | "IBSS mode"); |
| 4443 | return -1; |
| 4444 | } |
| 4445 | |
| 4446 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4447 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 4448 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 4449 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4450 | |
| 4451 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4452 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4453 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4454 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4455 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4456 | drv->ssid_len = params->ssid_len; |
| 4457 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4458 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 4459 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4460 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4461 | |
| 4462 | ret = nl80211_set_conn_keys(params, msg); |
| 4463 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4464 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4465 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4466 | if (params->bssid && params->fixed_bssid) { |
| 4467 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 4468 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4469 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4470 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4471 | } |
| 4472 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4473 | if (params->fixed_freq) { |
| 4474 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 4475 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 4476 | goto fail; |
| 4477 | } |
| 4478 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4479 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4480 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4481 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 4482 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4483 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4484 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4485 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4486 | } |
| 4487 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4488 | if (params->wpa_ie) { |
| 4489 | wpa_hexdump(MSG_DEBUG, |
| 4490 | " * Extra IEs for Beacon/Probe Response frames", |
| 4491 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4492 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 4493 | params->wpa_ie)) |
| 4494 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4497 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
| 4498 | return -1; |
| 4499 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4500 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4501 | msg = NULL; |
| 4502 | if (ret) { |
| 4503 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 4504 | ret, strerror(-ret)); |
| 4505 | count++; |
| 4506 | if (ret == -EALREADY && count == 1) { |
| 4507 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 4508 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4509 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4510 | nlmsg_free(msg); |
| 4511 | goto retry; |
| 4512 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4513 | } else { |
| 4514 | wpa_printf(MSG_DEBUG, |
| 4515 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4516 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4517 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4518 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4519 | nlmsg_free(msg); |
| 4520 | return ret; |
| 4521 | } |
| 4522 | |
| 4523 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4524 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 4525 | struct wpa_driver_associate_params *params, |
| 4526 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4527 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4528 | if (params->bssid) { |
| 4529 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4530 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4531 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4532 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4533 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4534 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4535 | if (params->bssid_hint) { |
| 4536 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 4537 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4538 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 4539 | params->bssid_hint)) |
| 4540 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4541 | } |
| 4542 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4543 | if (params->freq.freq) { |
| 4544 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4545 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 4546 | params->freq.freq)) |
| 4547 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4548 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4549 | } else |
| 4550 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4551 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4552 | if (params->freq_hint) { |
| 4553 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4554 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 4555 | params->freq_hint)) |
| 4556 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4557 | } |
| 4558 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4559 | if (params->bg_scan_period >= 0) { |
| 4560 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 4561 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4562 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 4563 | params->bg_scan_period)) |
| 4564 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4565 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4566 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4567 | if (params->ssid) { |
| 4568 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4569 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4570 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4571 | params->ssid)) |
| 4572 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4573 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4574 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4575 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4576 | drv->ssid_len = params->ssid_len; |
| 4577 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4578 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4579 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4580 | if (params->wpa_ie && |
| 4581 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 4582 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4583 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4584 | if (params->wpa_proto) { |
| 4585 | enum nl80211_wpa_versions ver = 0; |
| 4586 | |
| 4587 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 4588 | ver |= NL80211_WPA_VERSION_1; |
| 4589 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 4590 | ver |= NL80211_WPA_VERSION_2; |
| 4591 | |
| 4592 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4593 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4594 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 4598 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 4599 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4600 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4601 | cipher)) |
| 4602 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4603 | } |
| 4604 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4605 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 4606 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 4607 | /* |
| 4608 | * This is likely to work even though many drivers do not |
| 4609 | * advertise support for operations without GTK. |
| 4610 | */ |
| 4611 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 4612 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4613 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 4614 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4615 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 4616 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4620 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4621 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 4622 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4623 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4624 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 4625 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4626 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4627 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
| 4628 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4629 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 4630 | |
| 4631 | switch (params->key_mgmt_suite) { |
| 4632 | case WPA_KEY_MGMT_CCKM: |
| 4633 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 4634 | break; |
| 4635 | case WPA_KEY_MGMT_IEEE8021X: |
| 4636 | mgmt = WLAN_AKM_SUITE_8021X; |
| 4637 | break; |
| 4638 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 4639 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 4640 | break; |
| 4641 | case WPA_KEY_MGMT_FT_PSK: |
| 4642 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 4643 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4644 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 4645 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; |
| 4646 | break; |
| 4647 | case WPA_KEY_MGMT_PSK_SHA256: |
| 4648 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; |
| 4649 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4650 | case WPA_KEY_MGMT_OSEN: |
| 4651 | mgmt = WLAN_AKM_SUITE_OSEN; |
| 4652 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4653 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 4654 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; |
| 4655 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4656 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
| 4657 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; |
| 4658 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4659 | case WPA_KEY_MGMT_PSK: |
| 4660 | default: |
| 4661 | mgmt = WLAN_AKM_SUITE_PSK; |
| 4662 | break; |
| 4663 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4664 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4665 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 4666 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4667 | } |
| 4668 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4669 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4670 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4671 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4672 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 4673 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 4674 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4675 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4676 | if (params->rrm_used) { |
| 4677 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
| 4678 | if (!(drv_rrm_flags & |
| 4679 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) || |
| 4680 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) || |
| 4681 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 4682 | return -1; |
| 4683 | } |
| 4684 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4685 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4686 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4687 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4688 | if (params->p2p) |
| 4689 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 4690 | |
| 4691 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | |
| 4695 | static int wpa_driver_nl80211_try_connect( |
| 4696 | struct wpa_driver_nl80211_data *drv, |
| 4697 | struct wpa_driver_associate_params *params) |
| 4698 | { |
| 4699 | struct nl_msg *msg; |
| 4700 | enum nl80211_auth_type type; |
| 4701 | int ret; |
| 4702 | int algs; |
| 4703 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 4704 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4705 | if (params->req_key_mgmt_offload && params->psk && |
| 4706 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4707 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 4708 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 4709 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 4710 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 4711 | if (ret) |
| 4712 | return ret; |
| 4713 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 4714 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4715 | |
| 4716 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 4717 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4718 | if (!msg) |
| 4719 | return -1; |
| 4720 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4721 | ret = nl80211_connect_common(drv, params, msg); |
| 4722 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4723 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4724 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4725 | algs = 0; |
| 4726 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4727 | algs++; |
| 4728 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4729 | algs++; |
| 4730 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4731 | algs++; |
| 4732 | if (algs > 1) { |
| 4733 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 4734 | "selection"); |
| 4735 | goto skip_auth_type; |
| 4736 | } |
| 4737 | |
| 4738 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4739 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 4740 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4741 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 4742 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4743 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 4744 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 4745 | type = NL80211_AUTHTYPE_FT; |
| 4746 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4747 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4748 | |
| 4749 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4750 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 4751 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4752 | |
| 4753 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4754 | ret = nl80211_set_conn_keys(params, msg); |
| 4755 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4756 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4757 | |
| 4758 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4759 | msg = NULL; |
| 4760 | if (ret) { |
| 4761 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 4762 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4763 | } else { |
| 4764 | wpa_printf(MSG_DEBUG, |
| 4765 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4766 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4767 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4768 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4769 | nlmsg_free(msg); |
| 4770 | return ret; |
| 4771 | |
| 4772 | } |
| 4773 | |
| 4774 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4775 | static int wpa_driver_nl80211_connect( |
| 4776 | struct wpa_driver_nl80211_data *drv, |
| 4777 | struct wpa_driver_associate_params *params) |
| 4778 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 4779 | int ret; |
| 4780 | |
| 4781 | /* Store the connection attempted bssid for future use */ |
| 4782 | if (params->bssid) |
| 4783 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 4784 | else |
| 4785 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 4786 | |
| 4787 | ret = wpa_driver_nl80211_try_connect(drv, params); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4788 | if (ret == -EALREADY) { |
| 4789 | /* |
| 4790 | * cfg80211 does not currently accept new connections if |
| 4791 | * we are already connected. As a workaround, force |
| 4792 | * disconnection and try again. |
| 4793 | */ |
| 4794 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 4795 | "disconnecting before reassociation " |
| 4796 | "attempt"); |
| 4797 | if (wpa_driver_nl80211_disconnect( |
| 4798 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 4799 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4800 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 4801 | } |
| 4802 | return ret; |
| 4803 | } |
| 4804 | |
| 4805 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4806 | static int wpa_driver_nl80211_associate( |
| 4807 | void *priv, struct wpa_driver_associate_params *params) |
| 4808 | { |
| 4809 | struct i802_bss *bss = priv; |
| 4810 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4811 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4812 | struct nl_msg *msg; |
| 4813 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4814 | nl80211_unmask_11b_rates(bss); |
| 4815 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4816 | if (params->mode == IEEE80211_MODE_AP) |
| 4817 | return wpa_driver_nl80211_ap(drv, params); |
| 4818 | |
| 4819 | if (params->mode == IEEE80211_MODE_IBSS) |
| 4820 | return wpa_driver_nl80211_ibss(drv, params); |
| 4821 | |
| 4822 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4823 | enum nl80211_iftype nlmode = params->p2p ? |
| 4824 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 4825 | |
| 4826 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4827 | return -1; |
| 4828 | return wpa_driver_nl80211_connect(drv, params); |
| 4829 | } |
| 4830 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4831 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4832 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4833 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 4834 | drv->ifindex); |
| 4835 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4836 | if (!msg) |
| 4837 | return -1; |
| 4838 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4839 | ret = nl80211_connect_common(drv, params, msg); |
| 4840 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4841 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4842 | |
| 4843 | if (params->prev_bssid) { |
| 4844 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 4845 | MAC2STR(params->prev_bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4846 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 4847 | params->prev_bssid)) |
| 4848 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4849 | } |
| 4850 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4851 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4852 | msg = NULL; |
| 4853 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4854 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 4855 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 4856 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4857 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4858 | } else { |
| 4859 | wpa_printf(MSG_DEBUG, |
| 4860 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4861 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4862 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4863 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4864 | nlmsg_free(msg); |
| 4865 | return ret; |
| 4866 | } |
| 4867 | |
| 4868 | |
| 4869 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4870 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4871 | { |
| 4872 | struct nl_msg *msg; |
| 4873 | int ret = -ENOBUFS; |
| 4874 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4875 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 4876 | ifindex, mode, nl80211_iftype_str(mode)); |
| 4877 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4878 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 4879 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 4880 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4881 | |
| 4882 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4883 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4884 | if (!ret) |
| 4885 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4886 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4887 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4888 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 4889 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 4890 | return ret; |
| 4891 | } |
| 4892 | |
| 4893 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4894 | static int wpa_driver_nl80211_set_mode_impl( |
| 4895 | struct i802_bss *bss, |
| 4896 | enum nl80211_iftype nlmode, |
| 4897 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4898 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4899 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4900 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4901 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4902 | int was_ap = is_ap_interface(drv->nlmode); |
| 4903 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4904 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4905 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4906 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 4907 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 4908 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4909 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4910 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4911 | drv->nlmode = nlmode; |
| 4912 | ret = 0; |
| 4913 | goto done; |
| 4914 | } |
| 4915 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4916 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4917 | return -1; |
| 4918 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4919 | if (nlmode == drv->nlmode) { |
| 4920 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 4921 | "requested mode - ignore error"); |
| 4922 | ret = 0; |
| 4923 | goto done; /* Already in the requested mode */ |
| 4924 | } |
| 4925 | |
| 4926 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 4927 | * take the device down, try to set the mode again, and bring the |
| 4928 | * device back up. |
| 4929 | */ |
| 4930 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 4931 | "interface down"); |
| 4932 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4933 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4934 | if (res == -EACCES || res == -ENODEV) |
| 4935 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4936 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4937 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 4938 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4939 | os_sleep(0, 100000); |
| 4940 | continue; |
| 4941 | } |
| 4942 | |
| 4943 | /* |
| 4944 | * Setting the mode will fail for some drivers if the phy is |
| 4945 | * on a frequency that the mode is disallowed in. |
| 4946 | */ |
| 4947 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4948 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4949 | if (res) { |
| 4950 | wpa_printf(MSG_DEBUG, |
| 4951 | "nl80211: Failed to set frequency on interface"); |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | /* Try to set the mode again while the interface is down */ |
| 4956 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 4957 | if (mode_switch_res == -EBUSY) { |
| 4958 | wpa_printf(MSG_DEBUG, |
| 4959 | "nl80211: Delaying mode set while interface going down"); |
| 4960 | os_sleep(0, 100000); |
| 4961 | continue; |
| 4962 | } |
| 4963 | ret = mode_switch_res; |
| 4964 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | if (!ret) { |
| 4968 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 4969 | "interface is down"); |
| 4970 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4971 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4972 | } |
| 4973 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4974 | /* Bring the interface back up */ |
| 4975 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 4976 | if (res != 0) { |
| 4977 | wpa_printf(MSG_DEBUG, |
| 4978 | "nl80211: Failed to set interface up after switching mode"); |
| 4979 | ret = -1; |
| 4980 | } |
| 4981 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4982 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4983 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4984 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 4985 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4986 | return ret; |
| 4987 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4988 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4989 | if (is_p2p_net_interface(nlmode)) { |
| 4990 | wpa_printf(MSG_DEBUG, |
| 4991 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 4992 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4993 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4994 | } else if (drv->disabled_11b_rates) { |
| 4995 | wpa_printf(MSG_DEBUG, |
| 4996 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 4997 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4998 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4999 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5000 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5001 | if (is_ap_interface(nlmode)) { |
| 5002 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 5003 | /* Setup additional AP mode functionality if needed */ |
| 5004 | if (nl80211_setup_ap(bss)) |
| 5005 | return -1; |
| 5006 | } else if (was_ap) { |
| 5007 | /* Remove additional AP mode functionality */ |
| 5008 | nl80211_teardown_ap(bss); |
| 5009 | } else { |
| 5010 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 5011 | } |
| 5012 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5013 | if (is_mesh_interface(nlmode) && |
| 5014 | nl80211_mgmt_subscribe_mesh(bss)) |
| 5015 | return -1; |
| 5016 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5017 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5018 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5019 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 5020 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 5021 | "frame processing - ignore for now"); |
| 5022 | |
| 5023 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5027 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 5028 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5029 | { |
| 5030 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5031 | } |
| 5032 | |
| 5033 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5034 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5035 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5036 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5037 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5038 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5039 | } |
| 5040 | |
| 5041 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5042 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5043 | struct wpa_driver_capa *capa) |
| 5044 | { |
| 5045 | struct i802_bss *bss = priv; |
| 5046 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5047 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5048 | if (!drv->has_capability) |
| 5049 | return -1; |
| 5050 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5051 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5052 | capa->extended_capa = drv->extended_capa; |
| 5053 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5054 | capa->extended_capa_len = drv->extended_capa_len; |
| 5055 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5056 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5057 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | |
| 5061 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5062 | { |
| 5063 | struct i802_bss *bss = priv; |
| 5064 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5065 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5066 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5067 | bss->ifname, drv->operstate, state, |
| 5068 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5069 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5070 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5071 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5072 | } |
| 5073 | |
| 5074 | |
| 5075 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5076 | { |
| 5077 | struct i802_bss *bss = priv; |
| 5078 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5079 | struct nl_msg *msg; |
| 5080 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5081 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5082 | |
| 5083 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5084 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5085 | return 0; |
| 5086 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5087 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5088 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5089 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5090 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5091 | os_memset(&upd, 0, sizeof(upd)); |
| 5092 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5093 | if (authorized) |
| 5094 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5095 | |
| 5096 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5097 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5098 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5099 | nlmsg_free(msg); |
| 5100 | return -ENOBUFS; |
| 5101 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5102 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5103 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5104 | if (!ret) |
| 5105 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5106 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5107 | ret, strerror(-ret)); |
| 5108 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5112 | /* Set kernel driver on given frequency (MHz) */ |
| 5113 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5114 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5115 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5116 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5120 | static inline int min_int(int a, int b) |
| 5121 | { |
| 5122 | if (a < b) |
| 5123 | return a; |
| 5124 | return b; |
| 5125 | } |
| 5126 | |
| 5127 | |
| 5128 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5129 | { |
| 5130 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5131 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5132 | |
| 5133 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5134 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5135 | |
| 5136 | /* |
| 5137 | * TODO: validate the key index and mac address! |
| 5138 | * Otherwise, there's a race condition as soon as |
| 5139 | * the kernel starts sending key notifications. |
| 5140 | */ |
| 5141 | |
| 5142 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5143 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5144 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5145 | return NL_SKIP; |
| 5146 | } |
| 5147 | |
| 5148 | |
| 5149 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5150 | int idx, u8 *seq) |
| 5151 | { |
| 5152 | struct i802_bss *bss = priv; |
| 5153 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5154 | struct nl_msg *msg; |
| 5155 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5156 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5157 | NL80211_CMD_GET_KEY); |
| 5158 | if (!msg || |
| 5159 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5160 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5161 | nlmsg_free(msg); |
| 5162 | return -ENOBUFS; |
| 5163 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5164 | |
| 5165 | memset(seq, 0, 6); |
| 5166 | |
| 5167 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5168 | } |
| 5169 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5170 | |
| 5171 | static int i802_set_rts(void *priv, int rts) |
| 5172 | { |
| 5173 | struct i802_bss *bss = priv; |
| 5174 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5175 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5176 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5177 | u32 val; |
| 5178 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5179 | if (rts >= 2347) |
| 5180 | val = (u32) -1; |
| 5181 | else |
| 5182 | val = rts; |
| 5183 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5184 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5185 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5186 | nlmsg_free(msg); |
| 5187 | return -ENOBUFS; |
| 5188 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5189 | |
| 5190 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5191 | if (!ret) |
| 5192 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5193 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5194 | "%d (%s)", rts, ret, strerror(-ret)); |
| 5195 | return ret; |
| 5196 | } |
| 5197 | |
| 5198 | |
| 5199 | static int i802_set_frag(void *priv, int frag) |
| 5200 | { |
| 5201 | struct i802_bss *bss = priv; |
| 5202 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5203 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5204 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5205 | u32 val; |
| 5206 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5207 | if (frag >= 2346) |
| 5208 | val = (u32) -1; |
| 5209 | else |
| 5210 | val = frag; |
| 5211 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5212 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5213 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 5214 | nlmsg_free(msg); |
| 5215 | return -ENOBUFS; |
| 5216 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5217 | |
| 5218 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5219 | if (!ret) |
| 5220 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5221 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 5222 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 5223 | return ret; |
| 5224 | } |
| 5225 | |
| 5226 | |
| 5227 | static int i802_flush(void *priv) |
| 5228 | { |
| 5229 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5230 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5231 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5232 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5233 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 5234 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5235 | |
| 5236 | /* |
| 5237 | * XXX: FIX! this needs to flush all VLANs too |
| 5238 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5239 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 5240 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5241 | if (res) { |
| 5242 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 5243 | "(%s)", res, strerror(-res)); |
| 5244 | } |
| 5245 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | |
| 5249 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 5250 | { |
| 5251 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5252 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5253 | struct hostap_sta_driver_data *data = arg; |
| 5254 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 5255 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 5256 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 5257 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 5258 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 5259 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 5260 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5261 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5262 | }; |
| 5263 | |
| 5264 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5265 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5266 | |
| 5267 | /* |
| 5268 | * TODO: validate the interface and mac address! |
| 5269 | * Otherwise, there's a race condition as soon as |
| 5270 | * the kernel starts sending station notifications. |
| 5271 | */ |
| 5272 | |
| 5273 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 5274 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 5275 | return NL_SKIP; |
| 5276 | } |
| 5277 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 5278 | tb[NL80211_ATTR_STA_INFO], |
| 5279 | stats_policy)) { |
| 5280 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 5281 | return NL_SKIP; |
| 5282 | } |
| 5283 | |
| 5284 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 5285 | data->inactive_msec = |
| 5286 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
| 5287 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 5288 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 5289 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 5290 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
| 5291 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 5292 | data->rx_packets = |
| 5293 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 5294 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 5295 | data->tx_packets = |
| 5296 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5297 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 5298 | data->tx_retry_failed = |
| 5299 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5300 | |
| 5301 | return NL_SKIP; |
| 5302 | } |
| 5303 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5304 | static int i802_read_sta_data(struct i802_bss *bss, |
| 5305 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5306 | const u8 *addr) |
| 5307 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5308 | struct nl_msg *msg; |
| 5309 | |
| 5310 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5311 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5312 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 5313 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 5314 | nlmsg_free(msg); |
| 5315 | return -ENOBUFS; |
| 5316 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5317 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5318 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | |
| 5322 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 5323 | int cw_min, int cw_max, int burst_time) |
| 5324 | { |
| 5325 | struct i802_bss *bss = priv; |
| 5326 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5327 | struct nl_msg *msg; |
| 5328 | struct nlattr *txq, *params; |
| 5329 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5330 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5331 | if (!msg) |
| 5332 | return -1; |
| 5333 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5334 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 5335 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5336 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5337 | |
| 5338 | /* We are only sending parameters for a single TXQ at a time */ |
| 5339 | params = nla_nest_start(msg, 1); |
| 5340 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5341 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5342 | |
| 5343 | switch (queue) { |
| 5344 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5345 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 5346 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5347 | break; |
| 5348 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5349 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 5350 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5351 | break; |
| 5352 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5353 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 5354 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5355 | break; |
| 5356 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5357 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 5358 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5359 | break; |
| 5360 | } |
| 5361 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 5362 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5363 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 5364 | (burst_time * 100 + 16) / 32) || |
| 5365 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 5366 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 5367 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 5368 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5369 | |
| 5370 | nla_nest_end(msg, params); |
| 5371 | |
| 5372 | nla_nest_end(msg, txq); |
| 5373 | |
| 5374 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 5375 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5376 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5377 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5378 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5379 | return -1; |
| 5380 | } |
| 5381 | |
| 5382 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5383 | 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] | 5384 | const char *ifname, int vlan_id) |
| 5385 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5386 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5387 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5388 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5389 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5390 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 5391 | ", ifname=%s[%d], vlan_id=%d)", |
| 5392 | bss->ifname, if_nametoindex(bss->ifname), |
| 5393 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5394 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5395 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5396 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 5397 | nlmsg_free(msg); |
| 5398 | return -ENOBUFS; |
| 5399 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5400 | |
| 5401 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5402 | if (ret < 0) { |
| 5403 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 5404 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 5405 | MAC2STR(addr), ifname, vlan_id, ret, |
| 5406 | strerror(-ret)); |
| 5407 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5408 | return ret; |
| 5409 | } |
| 5410 | |
| 5411 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5412 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 5413 | { |
| 5414 | struct hostap_sta_driver_data data; |
| 5415 | int ret; |
| 5416 | |
| 5417 | data.inactive_msec = (unsigned long) -1; |
| 5418 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5419 | if (ret == -ENOENT) |
| 5420 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5421 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 5422 | return -1; |
| 5423 | return data.inactive_msec / 1000; |
| 5424 | } |
| 5425 | |
| 5426 | |
| 5427 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 5428 | { |
| 5429 | #if 0 |
| 5430 | /* TODO */ |
| 5431 | #endif |
| 5432 | return 0; |
| 5433 | } |
| 5434 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5435 | |
| 5436 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 5437 | int reason) |
| 5438 | { |
| 5439 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5440 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5441 | struct ieee80211_mgmt mgmt; |
| 5442 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5443 | if (is_mesh_interface(drv->nlmode)) |
| 5444 | return -1; |
| 5445 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5446 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5447 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5448 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5449 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5450 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5451 | WLAN_FC_STYPE_DEAUTH); |
| 5452 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5453 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5454 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5455 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 5456 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5457 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5458 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5459 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | |
| 5463 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 5464 | int reason) |
| 5465 | { |
| 5466 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5467 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5468 | struct ieee80211_mgmt mgmt; |
| 5469 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5470 | if (is_mesh_interface(drv->nlmode)) |
| 5471 | return -1; |
| 5472 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5473 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5474 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5475 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5476 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5477 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5478 | WLAN_FC_STYPE_DISASSOC); |
| 5479 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5480 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5481 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5482 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 5483 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5484 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5485 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5486 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5487 | } |
| 5488 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5489 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5490 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 5491 | { |
| 5492 | char buf[200], *pos, *end; |
| 5493 | int i, res; |
| 5494 | |
| 5495 | pos = buf; |
| 5496 | end = pos + sizeof(buf); |
| 5497 | |
| 5498 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5499 | if (!drv->if_indices[i]) |
| 5500 | continue; |
| 5501 | res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5502 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5503 | break; |
| 5504 | pos += res; |
| 5505 | } |
| 5506 | *pos = '\0'; |
| 5507 | |
| 5508 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 5509 | drv->num_if_indices, buf); |
| 5510 | } |
| 5511 | |
| 5512 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5513 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5514 | { |
| 5515 | int i; |
| 5516 | int *old; |
| 5517 | |
| 5518 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", |
| 5519 | ifidx); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5520 | if (have_ifidx(drv, ifidx)) { |
| 5521 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 5522 | ifidx); |
| 5523 | return; |
| 5524 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5525 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5526 | if (drv->if_indices[i] == 0) { |
| 5527 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5528 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5529 | return; |
| 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | if (drv->if_indices != drv->default_if_indices) |
| 5534 | old = drv->if_indices; |
| 5535 | else |
| 5536 | old = NULL; |
| 5537 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5538 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 5539 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5540 | if (!drv->if_indices) { |
| 5541 | if (!old) |
| 5542 | drv->if_indices = drv->default_if_indices; |
| 5543 | else |
| 5544 | drv->if_indices = old; |
| 5545 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 5546 | "interfaces"); |
| 5547 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 5548 | return; |
| 5549 | } else if (!old) |
| 5550 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 5551 | sizeof(drv->default_if_indices)); |
| 5552 | drv->if_indices[drv->num_if_indices] = ifidx; |
| 5553 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5554 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | |
| 5558 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5559 | { |
| 5560 | int i; |
| 5561 | |
| 5562 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5563 | if (drv->if_indices[i] == ifidx) { |
| 5564 | drv->if_indices[i] = 0; |
| 5565 | break; |
| 5566 | } |
| 5567 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5568 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | |
| 5572 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5573 | { |
| 5574 | int i; |
| 5575 | |
| 5576 | for (i = 0; i < drv->num_if_indices; i++) |
| 5577 | if (drv->if_indices[i] == ifidx) |
| 5578 | return 1; |
| 5579 | |
| 5580 | return 0; |
| 5581 | } |
| 5582 | |
| 5583 | |
| 5584 | 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] | 5585 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5586 | { |
| 5587 | struct i802_bss *bss = priv; |
| 5588 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5589 | char name[IFNAMSIZ + 1]; |
| 5590 | |
| 5591 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5592 | if (ifname_wds) |
| 5593 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 5594 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5595 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 5596 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 5597 | if (val) { |
| 5598 | if (!if_nametoindex(name)) { |
| 5599 | if (nl80211_create_iface(drv, name, |
| 5600 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5601 | bss->addr, 1, NULL, NULL, 0) < |
| 5602 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5603 | return -1; |
| 5604 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5605 | linux_br_add_if(drv->global->ioctl_sock, |
| 5606 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5607 | return -1; |
| 5608 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5609 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 5610 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 5611 | "interface %s up", name); |
| 5612 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5613 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 5614 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5615 | if (bridge_ifname) |
| 5616 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 5617 | name); |
| 5618 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5619 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 5620 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 5621 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | |
| 5626 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 5627 | { |
| 5628 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 5629 | struct sockaddr_ll lladdr; |
| 5630 | unsigned char buf[3000]; |
| 5631 | int len; |
| 5632 | socklen_t fromlen = sizeof(lladdr); |
| 5633 | |
| 5634 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 5635 | (struct sockaddr *)&lladdr, &fromlen); |
| 5636 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5637 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 5638 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5639 | return; |
| 5640 | } |
| 5641 | |
| 5642 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
| 5643 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 5644 | } |
| 5645 | |
| 5646 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5647 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 5648 | struct i802_bss *bss, |
| 5649 | const char *brname, const char *ifname) |
| 5650 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5651 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5652 | char in_br[IFNAMSIZ]; |
| 5653 | |
| 5654 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5655 | br_ifindex = if_nametoindex(brname); |
| 5656 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5657 | /* |
| 5658 | * Bridge was configured, but the bridge device does |
| 5659 | * not exist. Try to add it now. |
| 5660 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5661 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5662 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 5663 | "bridge interface %s: %s", |
| 5664 | brname, strerror(errno)); |
| 5665 | return -1; |
| 5666 | } |
| 5667 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5668 | br_ifindex = if_nametoindex(brname); |
| 5669 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5670 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5671 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5672 | |
| 5673 | if (linux_br_get(in_br, ifname) == 0) { |
| 5674 | if (os_strcmp(in_br, brname) == 0) |
| 5675 | return 0; /* already in the bridge */ |
| 5676 | |
| 5677 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 5678 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5679 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 5680 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5681 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 5682 | "remove interface %s from bridge " |
| 5683 | "%s: %s", |
| 5684 | ifname, brname, strerror(errno)); |
| 5685 | return -1; |
| 5686 | } |
| 5687 | } |
| 5688 | |
| 5689 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 5690 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5691 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5692 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 5693 | "into bridge %s: %s", |
| 5694 | ifname, brname, strerror(errno)); |
| 5695 | return -1; |
| 5696 | } |
| 5697 | bss->added_if_into_bridge = 1; |
| 5698 | |
| 5699 | return 0; |
| 5700 | } |
| 5701 | |
| 5702 | |
| 5703 | static void *i802_init(struct hostapd_data *hapd, |
| 5704 | struct wpa_init_params *params) |
| 5705 | { |
| 5706 | struct wpa_driver_nl80211_data *drv; |
| 5707 | struct i802_bss *bss; |
| 5708 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5709 | char master_ifname[IFNAMSIZ]; |
| 5710 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5711 | int br_added = 0; |
| 5712 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5713 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 5714 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5715 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5716 | if (bss == NULL) |
| 5717 | return NULL; |
| 5718 | |
| 5719 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5720 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5721 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5722 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5723 | params->ifname, master_ifname); |
| 5724 | br_ifindex = if_nametoindex(master_ifname); |
| 5725 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 5726 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 5727 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 5728 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 5729 | params->ifname, master_ifname); |
| 5730 | /* start listening for EAPOL on the master interface */ |
| 5731 | add_ifidx(drv, if_nametoindex(master_ifname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5732 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5733 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5734 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5735 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5736 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5737 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5738 | for (i = 0; i < params->num_bridge; i++) { |
| 5739 | if (params->bridge[i]) { |
| 5740 | ifindex = if_nametoindex(params->bridge[i]); |
| 5741 | if (ifindex) |
| 5742 | add_ifidx(drv, ifindex); |
| 5743 | if (ifindex == br_ifindex) |
| 5744 | br_added = 1; |
| 5745 | } |
| 5746 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5747 | |
| 5748 | /* start listening for EAPOL on the default AP interface */ |
| 5749 | add_ifidx(drv, drv->ifindex); |
| 5750 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5751 | if (params->num_bridge && params->bridge[0]) { |
| 5752 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 5753 | params->ifname) < 0) |
| 5754 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5755 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5756 | br_added = 1; |
| 5757 | } |
| 5758 | |
| 5759 | if (!br_added && br_ifindex && |
| 5760 | (params->num_bridge == 0 || !params->bridge[0])) |
| 5761 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5762 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5763 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5764 | if (bss->added_if_into_bridge) { |
| 5765 | drv->rtnl_sk = nl_socket_alloc(); |
| 5766 | if (drv->rtnl_sk == NULL) { |
| 5767 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 5768 | goto failed; |
| 5769 | } |
| 5770 | |
| 5771 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 5772 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 5773 | strerror(errno)); |
| 5774 | goto failed; |
| 5775 | } |
| 5776 | } |
| 5777 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5778 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5779 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 5780 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5781 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 5782 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5783 | goto failed; |
| 5784 | } |
| 5785 | |
| 5786 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 5787 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5788 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5789 | goto failed; |
| 5790 | } |
| 5791 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5792 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 5793 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5794 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5795 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5796 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5797 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 5798 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5799 | return bss; |
| 5800 | |
| 5801 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5802 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5803 | return NULL; |
| 5804 | } |
| 5805 | |
| 5806 | |
| 5807 | static void i802_deinit(void *priv) |
| 5808 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5809 | struct i802_bss *bss = priv; |
| 5810 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5813 | |
| 5814 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 5815 | enum wpa_driver_if_type type) |
| 5816 | { |
| 5817 | switch (type) { |
| 5818 | case WPA_IF_STATION: |
| 5819 | return NL80211_IFTYPE_STATION; |
| 5820 | case WPA_IF_P2P_CLIENT: |
| 5821 | case WPA_IF_P2P_GROUP: |
| 5822 | return NL80211_IFTYPE_P2P_CLIENT; |
| 5823 | case WPA_IF_AP_VLAN: |
| 5824 | return NL80211_IFTYPE_AP_VLAN; |
| 5825 | case WPA_IF_AP_BSS: |
| 5826 | return NL80211_IFTYPE_AP; |
| 5827 | case WPA_IF_P2P_GO: |
| 5828 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5829 | case WPA_IF_P2P_DEVICE: |
| 5830 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5831 | case WPA_IF_MESH: |
| 5832 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 5833 | default: |
| 5834 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5835 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5839 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 5840 | { |
| 5841 | struct wpa_driver_nl80211_data *drv; |
| 5842 | dl_list_for_each(drv, &global->interfaces, |
| 5843 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5844 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5845 | return 1; |
| 5846 | } |
| 5847 | return 0; |
| 5848 | } |
| 5849 | |
| 5850 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5851 | 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] | 5852 | { |
| 5853 | unsigned int idx; |
| 5854 | |
| 5855 | if (!drv->global) |
| 5856 | return -1; |
| 5857 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5858 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5859 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5860 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5861 | new_addr[0] ^= idx << 2; |
| 5862 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 5863 | break; |
| 5864 | } |
| 5865 | if (idx == 64) |
| 5866 | return -1; |
| 5867 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5868 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5869 | MACSTR, MAC2STR(new_addr)); |
| 5870 | |
| 5871 | return 0; |
| 5872 | } |
| 5873 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5874 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5875 | struct wdev_info { |
| 5876 | u64 wdev_id; |
| 5877 | int wdev_id_set; |
| 5878 | u8 macaddr[ETH_ALEN]; |
| 5879 | }; |
| 5880 | |
| 5881 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 5882 | { |
| 5883 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5884 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5885 | struct wdev_info *wi = arg; |
| 5886 | |
| 5887 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5888 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5889 | if (tb[NL80211_ATTR_WDEV]) { |
| 5890 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 5891 | wi->wdev_id_set = 1; |
| 5892 | } |
| 5893 | |
| 5894 | if (tb[NL80211_ATTR_MAC]) |
| 5895 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 5896 | ETH_ALEN); |
| 5897 | |
| 5898 | return NL_SKIP; |
| 5899 | } |
| 5900 | |
| 5901 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5902 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 5903 | const char *ifname, const u8 *addr, |
| 5904 | void *bss_ctx, void **drv_priv, |
| 5905 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5906 | const char *bridge, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5907 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5908 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5909 | struct i802_bss *bss = priv; |
| 5910 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5911 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5912 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5913 | |
| 5914 | if (addr) |
| 5915 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5916 | nlmode = wpa_driver_nl80211_if_type(type); |
| 5917 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 5918 | struct wdev_info p2pdev_info; |
| 5919 | |
| 5920 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 5921 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 5922 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5923 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5924 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 5925 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 5926 | ifname); |
| 5927 | return -1; |
| 5928 | } |
| 5929 | |
| 5930 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 5931 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 5932 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 5933 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 5934 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 5935 | ifname, |
| 5936 | (long long unsigned int) p2pdev_info.wdev_id); |
| 5937 | } else { |
| 5938 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5939 | 0, NULL, NULL, use_existing); |
| 5940 | if (use_existing && ifidx == -ENFILE) { |
| 5941 | added = 0; |
| 5942 | ifidx = if_nametoindex(ifname); |
| 5943 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5944 | return -1; |
| 5945 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5946 | } |
| 5947 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5948 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 5949 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5950 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 5951 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 5952 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5953 | if (added) |
| 5954 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5955 | return -1; |
| 5956 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5957 | } |
| 5958 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5959 | if (!addr && |
| 5960 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 5961 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 5962 | type == WPA_IF_STATION)) { |
| 5963 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5964 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5965 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5966 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5967 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5968 | if (added) |
| 5969 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5970 | return -1; |
| 5971 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5972 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5973 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 5974 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5975 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5976 | if (added) |
| 5977 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5978 | return -1; |
| 5979 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5980 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5981 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5982 | if (added) |
| 5983 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5984 | return -1; |
| 5985 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5986 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 5987 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5988 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5989 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5990 | if (type == WPA_IF_AP_BSS) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5991 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 5992 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5993 | if (added) |
| 5994 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5995 | return -1; |
| 5996 | } |
| 5997 | |
| 5998 | if (bridge && |
| 5999 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 6000 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 6001 | "interface %s to a bridge %s", |
| 6002 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6003 | if (added) |
| 6004 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6005 | os_free(new_bss); |
| 6006 | return -1; |
| 6007 | } |
| 6008 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6009 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 6010 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6011 | if (added) |
| 6012 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6013 | os_free(new_bss); |
| 6014 | return -1; |
| 6015 | } |
| 6016 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6017 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6018 | new_bss->ifindex = ifidx; |
| 6019 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6020 | new_bss->next = drv->first_bss->next; |
| 6021 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6022 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6023 | new_bss->added_if = added; |
| 6024 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6025 | if (drv_priv) |
| 6026 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6027 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6028 | |
| 6029 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 6030 | if (nl80211_setup_ap(new_bss)) |
| 6031 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6032 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6033 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6034 | if (drv->global) |
| 6035 | drv->global->if_add_ifindex = ifidx; |
| 6036 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6037 | /* |
| 6038 | * Some virtual interfaces need to process EAPOL packets and events on |
| 6039 | * the parent interface. This is used mainly with hostapd. |
| 6040 | */ |
| 6041 | if (ifidx > 0 && |
| 6042 | (drv->hostapd || |
| 6043 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 6044 | nlmode == NL80211_IFTYPE_WDS || |
| 6045 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6046 | add_ifidx(drv, ifidx); |
| 6047 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6048 | return 0; |
| 6049 | } |
| 6050 | |
| 6051 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6052 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6053 | enum wpa_driver_if_type type, |
| 6054 | const char *ifname) |
| 6055 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6056 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6057 | int ifindex = if_nametoindex(ifname); |
| 6058 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6059 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 6060 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6061 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6062 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6063 | else if (ifindex > 0 && !bss->added_if) { |
| 6064 | struct wpa_driver_nl80211_data *drv2; |
| 6065 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 6066 | struct wpa_driver_nl80211_data, list) |
| 6067 | del_ifidx(drv2, ifindex); |
| 6068 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6069 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6070 | if (type != WPA_IF_AP_BSS) |
| 6071 | return 0; |
| 6072 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6073 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6074 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 6075 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6076 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6077 | "interface %s from bridge %s: %s", |
| 6078 | bss->ifname, bss->brname, strerror(errno)); |
| 6079 | } |
| 6080 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6081 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6082 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6083 | "bridge %s: %s", |
| 6084 | bss->brname, strerror(errno)); |
| 6085 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6086 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6087 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6088 | struct i802_bss *tbss; |
| 6089 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6090 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 6091 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6092 | if (tbss->next == bss) { |
| 6093 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6094 | /* Unsubscribe management frames */ |
| 6095 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6096 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6097 | if (!bss->added_if) |
| 6098 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6099 | os_free(bss); |
| 6100 | bss = NULL; |
| 6101 | break; |
| 6102 | } |
| 6103 | } |
| 6104 | if (bss) |
| 6105 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 6106 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6107 | } else { |
| 6108 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 6109 | nl80211_teardown_ap(bss); |
| 6110 | if (!bss->added_if && !drv->first_bss->next) |
| 6111 | wpa_driver_nl80211_del_beacon(drv); |
| 6112 | nl80211_destroy_bss(bss); |
| 6113 | if (!bss->added_if) |
| 6114 | i802_set_iface_flags(bss, 0); |
| 6115 | if (drv->first_bss->next) { |
| 6116 | drv->first_bss = drv->first_bss->next; |
| 6117 | drv->ctx = drv->first_bss->ctx; |
| 6118 | os_free(bss); |
| 6119 | } else { |
| 6120 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 6121 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6122 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6123 | |
| 6124 | return 0; |
| 6125 | } |
| 6126 | |
| 6127 | |
| 6128 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 6129 | { |
| 6130 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6131 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6132 | u64 *cookie = arg; |
| 6133 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6134 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6135 | if (tb[NL80211_ATTR_COOKIE]) |
| 6136 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 6137 | return NL_SKIP; |
| 6138 | } |
| 6139 | |
| 6140 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6141 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6142 | unsigned int freq, unsigned int wait, |
| 6143 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6144 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 6145 | int offchanok, const u16 *csa_offs, |
| 6146 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6147 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6148 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6149 | struct nl_msg *msg; |
| 6150 | u64 cookie; |
| 6151 | int ret = -1; |
| 6152 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6153 | 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] | 6154 | "no_ack=%d offchanok=%d", |
| 6155 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6156 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6157 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6158 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 6159 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 6160 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 6161 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6162 | drv->test_use_roc_tx) && |
| 6163 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 6164 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 6165 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 6166 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 6167 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6168 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 6169 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6170 | |
| 6171 | cookie = 0; |
| 6172 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6173 | msg = NULL; |
| 6174 | if (ret) { |
| 6175 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6176 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 6177 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6178 | } else { |
| 6179 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 6180 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 6181 | (long long unsigned int) cookie); |
| 6182 | |
| 6183 | if (cookie_out) |
| 6184 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6185 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6186 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6187 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6188 | nlmsg_free(msg); |
| 6189 | return ret; |
| 6190 | } |
| 6191 | |
| 6192 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6193 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 6194 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6195 | unsigned int wait_time, |
| 6196 | const u8 *dst, const u8 *src, |
| 6197 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6198 | const u8 *data, size_t data_len, |
| 6199 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6200 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6201 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6202 | int ret = -1; |
| 6203 | u8 *buf; |
| 6204 | struct ieee80211_hdr *hdr; |
| 6205 | |
| 6206 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6207 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 6208 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6209 | |
| 6210 | buf = os_zalloc(24 + data_len); |
| 6211 | if (buf == NULL) |
| 6212 | return ret; |
| 6213 | os_memcpy(buf + 24, data, data_len); |
| 6214 | hdr = (struct ieee80211_hdr *) buf; |
| 6215 | hdr->frame_control = |
| 6216 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 6217 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 6218 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 6219 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 6220 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6221 | if (is_ap_interface(drv->nlmode) && |
| 6222 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6223 | (int) freq == bss->freq || drv->device_ap_sme || |
| 6224 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6225 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 6226 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 6227 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6228 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6229 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6230 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6231 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 6232 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6233 | |
| 6234 | os_free(buf); |
| 6235 | return ret; |
| 6236 | } |
| 6237 | |
| 6238 | |
| 6239 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 6240 | { |
| 6241 | struct i802_bss *bss = priv; |
| 6242 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6243 | struct nl_msg *msg; |
| 6244 | int ret; |
| 6245 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 6246 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
| 6247 | (long long unsigned int) drv->send_action_cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6248 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
| 6249 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) { |
| 6250 | nlmsg_free(msg); |
| 6251 | return; |
| 6252 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6253 | |
| 6254 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6255 | if (ret) |
| 6256 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 6257 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | |
| 6261 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 6262 | unsigned int duration) |
| 6263 | { |
| 6264 | struct i802_bss *bss = priv; |
| 6265 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6266 | struct nl_msg *msg; |
| 6267 | int ret; |
| 6268 | u64 cookie; |
| 6269 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6270 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 6271 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 6272 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 6273 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6274 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6275 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6276 | |
| 6277 | cookie = 0; |
| 6278 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6279 | if (ret == 0) { |
| 6280 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 6281 | "0x%llx for freq=%u MHz duration=%u", |
| 6282 | (long long unsigned int) cookie, freq, duration); |
| 6283 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6284 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6285 | return 0; |
| 6286 | } |
| 6287 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 6288 | "(freq=%d duration=%u): %d (%s)", |
| 6289 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6290 | return -1; |
| 6291 | } |
| 6292 | |
| 6293 | |
| 6294 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 6295 | { |
| 6296 | struct i802_bss *bss = priv; |
| 6297 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6298 | struct nl_msg *msg; |
| 6299 | int ret; |
| 6300 | |
| 6301 | if (!drv->pending_remain_on_chan) { |
| 6302 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 6303 | "to cancel"); |
| 6304 | return -1; |
| 6305 | } |
| 6306 | |
| 6307 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 6308 | "0x%llx", |
| 6309 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 6310 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6311 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 6312 | if (!msg || |
| 6313 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 6314 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6315 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6316 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6317 | |
| 6318 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6319 | if (ret == 0) |
| 6320 | return 0; |
| 6321 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 6322 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6323 | return -1; |
| 6324 | } |
| 6325 | |
| 6326 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6327 | 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] | 6328 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6329 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6330 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6331 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6332 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 6333 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 6334 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6335 | /* |
| 6336 | * Do not disable Probe Request reporting that was |
| 6337 | * enabled in nl80211_setup_ap(). |
| 6338 | */ |
| 6339 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 6340 | "Probe Request reporting nl_preq=%p while " |
| 6341 | "in AP mode", bss->nl_preq); |
| 6342 | } else if (bss->nl_preq) { |
| 6343 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 6344 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6345 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6346 | } |
| 6347 | return 0; |
| 6348 | } |
| 6349 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6350 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6351 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6352 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6353 | return 0; |
| 6354 | } |
| 6355 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6356 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 6357 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6358 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6359 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 6360 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6361 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6362 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6363 | (WLAN_FC_TYPE_MGMT << 2) | |
| 6364 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6365 | NULL, 0) < 0) |
| 6366 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 6367 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6368 | nl80211_register_eloop_read(&bss->nl_preq, |
| 6369 | wpa_driver_nl80211_event_receive, |
| 6370 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6371 | |
| 6372 | return 0; |
| 6373 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6374 | out_err: |
| 6375 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6376 | return -1; |
| 6377 | } |
| 6378 | |
| 6379 | |
| 6380 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 6381 | int ifindex, int disabled) |
| 6382 | { |
| 6383 | struct nl_msg *msg; |
| 6384 | struct nlattr *bands, *band; |
| 6385 | int ret; |
| 6386 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6387 | wpa_printf(MSG_DEBUG, |
| 6388 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 6389 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 6390 | "no NL80211_TXRATE_LEGACY constraint"); |
| 6391 | |
| 6392 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 6393 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6394 | if (!msg) |
| 6395 | return -1; |
| 6396 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6397 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 6398 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6399 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6400 | |
| 6401 | /* |
| 6402 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 6403 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 6404 | * rates. All 5 GHz rates are left enabled. |
| 6405 | */ |
| 6406 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6407 | if (!band || |
| 6408 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 6409 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 6410 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6411 | nla_nest_end(msg, band); |
| 6412 | |
| 6413 | nla_nest_end(msg, bands); |
| 6414 | |
| 6415 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6416 | if (ret) { |
| 6417 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 6418 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6419 | } else |
| 6420 | drv->disabled_11b_rates = disabled; |
| 6421 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6422 | return ret; |
| 6423 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6424 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6425 | nlmsg_free(msg); |
| 6426 | return -1; |
| 6427 | } |
| 6428 | |
| 6429 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6430 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 6431 | { |
| 6432 | struct i802_bss *bss = priv; |
| 6433 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6434 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6435 | return -1; |
| 6436 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6437 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6438 | |
| 6439 | /* |
| 6440 | * If the P2P GO interface was dynamically added, then it is |
| 6441 | * possible that the interface change to station is not possible. |
| 6442 | */ |
| 6443 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 6444 | return 0; |
| 6445 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6446 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6447 | } |
| 6448 | |
| 6449 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6450 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 6451 | { |
| 6452 | struct i802_bss *bss = priv; |
| 6453 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6454 | if (!is_ap_interface(drv->nlmode)) |
| 6455 | return -1; |
| 6456 | wpa_driver_nl80211_del_beacon(drv); |
| 6457 | bss->beacon_set = 0; |
| 6458 | return 0; |
| 6459 | } |
| 6460 | |
| 6461 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6462 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 6463 | { |
| 6464 | struct i802_bss *bss = priv; |
| 6465 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6466 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 6467 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6468 | |
| 6469 | /* |
| 6470 | * If the P2P Client interface was dynamically added, then it is |
| 6471 | * possible that the interface change to station is not possible. |
| 6472 | */ |
| 6473 | if (bss->if_dynamic) |
| 6474 | return 0; |
| 6475 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6476 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 6477 | } |
| 6478 | |
| 6479 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6480 | static void wpa_driver_nl80211_resume(void *priv) |
| 6481 | { |
| 6482 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 6483 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6484 | |
| 6485 | if (i802_set_iface_flags(bss, 1)) |
| 6486 | 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^] | 6487 | |
| 6488 | if (is_p2p_net_interface(nlmode)) |
| 6489 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6493 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 6494 | { |
| 6495 | struct i802_bss *bss = priv; |
| 6496 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6497 | struct nl_msg *msg; |
| 6498 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6499 | |
| 6500 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 6501 | "hysteresis=%d", threshold, hysteresis); |
| 6502 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6503 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 6504 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 6505 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 6506 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 6507 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6508 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6509 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6510 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6511 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6512 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6513 | } |
| 6514 | |
| 6515 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6516 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 6517 | { |
| 6518 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6519 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6520 | struct wpa_signal_info *sig_change = arg; |
| 6521 | |
| 6522 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6523 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6524 | |
| 6525 | sig_change->center_frq1 = -1; |
| 6526 | sig_change->center_frq2 = -1; |
| 6527 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 6528 | |
| 6529 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 6530 | sig_change->chanwidth = convert2width( |
| 6531 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 6532 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 6533 | sig_change->center_frq1 = |
| 6534 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 6535 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 6536 | sig_change->center_frq2 = |
| 6537 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 6538 | } |
| 6539 | |
| 6540 | return NL_SKIP; |
| 6541 | } |
| 6542 | |
| 6543 | |
| 6544 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 6545 | struct wpa_signal_info *sig) |
| 6546 | { |
| 6547 | struct nl_msg *msg; |
| 6548 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6549 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6550 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6551 | } |
| 6552 | |
| 6553 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6554 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 6555 | { |
| 6556 | struct i802_bss *bss = priv; |
| 6557 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6558 | int res; |
| 6559 | |
| 6560 | os_memset(si, 0, sizeof(*si)); |
| 6561 | res = nl80211_get_link_signal(drv, si); |
| 6562 | if (res != 0) |
| 6563 | return res; |
| 6564 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6565 | res = nl80211_get_channel_width(drv, si); |
| 6566 | if (res != 0) |
| 6567 | return res; |
| 6568 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6569 | return nl80211_get_link_noise(drv, si); |
| 6570 | } |
| 6571 | |
| 6572 | |
| 6573 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 6574 | int encrypt) |
| 6575 | { |
| 6576 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6577 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 6578 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6579 | } |
| 6580 | |
| 6581 | |
| 6582 | static int nl80211_set_param(void *priv, const char *param) |
| 6583 | { |
| 6584 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
| 6585 | if (param == NULL) |
| 6586 | return 0; |
| 6587 | |
| 6588 | #ifdef CONFIG_P2P |
| 6589 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 6590 | struct i802_bss *bss = priv; |
| 6591 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6592 | |
| 6593 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 6594 | "interface"); |
| 6595 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 6596 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 6597 | } |
| 6598 | #endif /* CONFIG_P2P */ |
| 6599 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6600 | if (os_strstr(param, "use_monitor=1")) { |
| 6601 | struct i802_bss *bss = priv; |
| 6602 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6603 | drv->use_monitor = 1; |
| 6604 | } |
| 6605 | |
| 6606 | if (os_strstr(param, "force_connect_cmd=1")) { |
| 6607 | struct i802_bss *bss = priv; |
| 6608 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6609 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6610 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6611 | } |
| 6612 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 6613 | if (os_strstr(param, "no_offchannel_tx=1")) { |
| 6614 | struct i802_bss *bss = priv; |
| 6615 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6616 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 6617 | drv->test_use_roc_tx = 1; |
| 6618 | } |
| 6619 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6620 | return 0; |
| 6621 | } |
| 6622 | |
| 6623 | |
| 6624 | static void * nl80211_global_init(void) |
| 6625 | { |
| 6626 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6627 | struct netlink_config *cfg; |
| 6628 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6629 | global = os_zalloc(sizeof(*global)); |
| 6630 | if (global == NULL) |
| 6631 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6632 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6633 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6634 | global->if_add_ifindex = -1; |
| 6635 | |
| 6636 | cfg = os_zalloc(sizeof(*cfg)); |
| 6637 | if (cfg == NULL) |
| 6638 | goto err; |
| 6639 | |
| 6640 | cfg->ctx = global; |
| 6641 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 6642 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 6643 | global->netlink = netlink_init(cfg); |
| 6644 | if (global->netlink == NULL) { |
| 6645 | os_free(cfg); |
| 6646 | goto err; |
| 6647 | } |
| 6648 | |
| 6649 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 6650 | goto err; |
| 6651 | |
| 6652 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 6653 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6654 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 6655 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6656 | goto err; |
| 6657 | } |
| 6658 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6659 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6660 | |
| 6661 | err: |
| 6662 | nl80211_global_deinit(global); |
| 6663 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6664 | } |
| 6665 | |
| 6666 | |
| 6667 | static void nl80211_global_deinit(void *priv) |
| 6668 | { |
| 6669 | struct nl80211_global *global = priv; |
| 6670 | if (global == NULL) |
| 6671 | return; |
| 6672 | if (!dl_list_empty(&global->interfaces)) { |
| 6673 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 6674 | "nl80211_global_deinit", |
| 6675 | dl_list_len(&global->interfaces)); |
| 6676 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6677 | |
| 6678 | if (global->netlink) |
| 6679 | netlink_deinit(global->netlink); |
| 6680 | |
| 6681 | nl_destroy_handles(&global->nl); |
| 6682 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6683 | if (global->nl_event) |
| 6684 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6685 | |
| 6686 | nl_cb_put(global->nl_cb); |
| 6687 | |
| 6688 | if (global->ioctl_sock >= 0) |
| 6689 | close(global->ioctl_sock); |
| 6690 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6691 | os_free(global); |
| 6692 | } |
| 6693 | |
| 6694 | |
| 6695 | static const char * nl80211_get_radio_name(void *priv) |
| 6696 | { |
| 6697 | struct i802_bss *bss = priv; |
| 6698 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6699 | return drv->phyname; |
| 6700 | } |
| 6701 | |
| 6702 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6703 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 6704 | const u8 *pmkid) |
| 6705 | { |
| 6706 | struct nl_msg *msg; |
| 6707 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6708 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 6709 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
| 6710 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { |
| 6711 | nlmsg_free(msg); |
| 6712 | return -ENOBUFS; |
| 6713 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6714 | |
| 6715 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6716 | } |
| 6717 | |
| 6718 | |
| 6719 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6720 | { |
| 6721 | struct i802_bss *bss = priv; |
| 6722 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 6723 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 6724 | } |
| 6725 | |
| 6726 | |
| 6727 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6728 | { |
| 6729 | struct i802_bss *bss = priv; |
| 6730 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 6731 | MAC2STR(bssid)); |
| 6732 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 6733 | } |
| 6734 | |
| 6735 | |
| 6736 | static int nl80211_flush_pmkid(void *priv) |
| 6737 | { |
| 6738 | struct i802_bss *bss = priv; |
| 6739 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 6740 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 6741 | } |
| 6742 | |
| 6743 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6744 | static void clean_survey_results(struct survey_results *survey_results) |
| 6745 | { |
| 6746 | struct freq_survey *survey, *tmp; |
| 6747 | |
| 6748 | if (dl_list_empty(&survey_results->survey_list)) |
| 6749 | return; |
| 6750 | |
| 6751 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 6752 | struct freq_survey, list) { |
| 6753 | dl_list_del(&survey->list); |
| 6754 | os_free(survey); |
| 6755 | } |
| 6756 | } |
| 6757 | |
| 6758 | |
| 6759 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 6760 | struct dl_list *survey_list) |
| 6761 | { |
| 6762 | struct freq_survey *survey; |
| 6763 | |
| 6764 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 6765 | if (!survey) |
| 6766 | return; |
| 6767 | |
| 6768 | survey->ifidx = ifidx; |
| 6769 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6770 | survey->filled = 0; |
| 6771 | |
| 6772 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 6773 | survey->nf = (int8_t) |
| 6774 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 6775 | survey->filled |= SURVEY_HAS_NF; |
| 6776 | } |
| 6777 | |
| 6778 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 6779 | survey->channel_time = |
| 6780 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 6781 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 6782 | } |
| 6783 | |
| 6784 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 6785 | survey->channel_time_busy = |
| 6786 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 6787 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 6788 | } |
| 6789 | |
| 6790 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 6791 | survey->channel_time_rx = |
| 6792 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 6793 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 6794 | } |
| 6795 | |
| 6796 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 6797 | survey->channel_time_tx = |
| 6798 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 6799 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 6800 | } |
| 6801 | |
| 6802 | 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)", |
| 6803 | survey->freq, |
| 6804 | survey->nf, |
| 6805 | (unsigned long int) survey->channel_time, |
| 6806 | (unsigned long int) survey->channel_time_busy, |
| 6807 | (unsigned long int) survey->channel_time_tx, |
| 6808 | (unsigned long int) survey->channel_time_rx, |
| 6809 | survey->filled); |
| 6810 | |
| 6811 | dl_list_add_tail(survey_list, &survey->list); |
| 6812 | } |
| 6813 | |
| 6814 | |
| 6815 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 6816 | unsigned int freq_filter) |
| 6817 | { |
| 6818 | if (!freq_filter) |
| 6819 | return 1; |
| 6820 | |
| 6821 | return freq_filter == surveyed_freq; |
| 6822 | } |
| 6823 | |
| 6824 | |
| 6825 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 6826 | { |
| 6827 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6828 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6829 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 6830 | struct survey_results *survey_results; |
| 6831 | u32 surveyed_freq = 0; |
| 6832 | u32 ifidx; |
| 6833 | |
| 6834 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 6835 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 6836 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 6837 | }; |
| 6838 | |
| 6839 | survey_results = (struct survey_results *) arg; |
| 6840 | |
| 6841 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6842 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6843 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 6844 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 6845 | return NL_SKIP; |
| 6846 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6847 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 6848 | |
| 6849 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 6850 | return NL_SKIP; |
| 6851 | |
| 6852 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 6853 | tb[NL80211_ATTR_SURVEY_INFO], |
| 6854 | survey_policy)) |
| 6855 | return NL_SKIP; |
| 6856 | |
| 6857 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 6858 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 6859 | return NL_SKIP; |
| 6860 | } |
| 6861 | |
| 6862 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6863 | |
| 6864 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 6865 | survey_results->freq_filter)) |
| 6866 | return NL_SKIP; |
| 6867 | |
| 6868 | if (survey_results->freq_filter && |
| 6869 | survey_results->freq_filter != surveyed_freq) { |
| 6870 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 6871 | surveyed_freq); |
| 6872 | return NL_SKIP; |
| 6873 | } |
| 6874 | |
| 6875 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 6876 | |
| 6877 | return NL_SKIP; |
| 6878 | } |
| 6879 | |
| 6880 | |
| 6881 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 6882 | { |
| 6883 | struct i802_bss *bss = priv; |
| 6884 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6885 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6886 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6887 | union wpa_event_data data; |
| 6888 | struct survey_results *survey_results; |
| 6889 | |
| 6890 | os_memset(&data, 0, sizeof(data)); |
| 6891 | survey_results = &data.survey_results; |
| 6892 | |
| 6893 | dl_list_init(&survey_results->survey_list); |
| 6894 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6895 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6896 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6897 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6898 | |
| 6899 | if (freq) |
| 6900 | data.survey_results.freq_filter = freq; |
| 6901 | |
| 6902 | do { |
| 6903 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 6904 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 6905 | survey_results); |
| 6906 | } while (err > 0); |
| 6907 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6908 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6909 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6910 | else |
| 6911 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6912 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6913 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6914 | return err; |
| 6915 | } |
| 6916 | |
| 6917 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6918 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 6919 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6920 | const u8 *replay_ctr) |
| 6921 | { |
| 6922 | struct i802_bss *bss = priv; |
| 6923 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6924 | struct nlattr *replay_nested; |
| 6925 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6926 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6927 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6928 | if (!drv->set_rekey_offload) |
| 6929 | return; |
| 6930 | |
| 6931 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6932 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 6933 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6934 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
| 6935 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6936 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 6937 | replay_ctr)) { |
| 6938 | nl80211_nlmsg_clear(msg); |
| 6939 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6940 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6941 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6942 | |
| 6943 | nla_nest_end(msg, replay_nested); |
| 6944 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6945 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 6946 | if (ret == -EOPNOTSUPP) { |
| 6947 | wpa_printf(MSG_DEBUG, |
| 6948 | "nl80211: Driver does not support rekey offload"); |
| 6949 | drv->set_rekey_offload = 0; |
| 6950 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6951 | } |
| 6952 | |
| 6953 | |
| 6954 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 6955 | const u8 *addr, int qos) |
| 6956 | { |
| 6957 | /* send data frame to poll STA and check whether |
| 6958 | * this frame is ACKed */ |
| 6959 | struct { |
| 6960 | struct ieee80211_hdr hdr; |
| 6961 | u16 qos_ctl; |
| 6962 | } STRUCT_PACKED nulldata; |
| 6963 | size_t size; |
| 6964 | |
| 6965 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 6966 | |
| 6967 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 6968 | |
| 6969 | if (qos) { |
| 6970 | nulldata.hdr.frame_control = |
| 6971 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 6972 | WLAN_FC_STYPE_QOS_NULL); |
| 6973 | size = sizeof(nulldata); |
| 6974 | } else { |
| 6975 | nulldata.hdr.frame_control = |
| 6976 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 6977 | WLAN_FC_STYPE_NULLFUNC); |
| 6978 | size = sizeof(struct ieee80211_hdr); |
| 6979 | } |
| 6980 | |
| 6981 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 6982 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 6983 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 6984 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 6985 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6986 | 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^] | 6987 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6988 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 6989 | "send poll frame"); |
| 6990 | } |
| 6991 | |
| 6992 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 6993 | int qos) |
| 6994 | { |
| 6995 | struct i802_bss *bss = priv; |
| 6996 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6997 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6998 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6999 | |
| 7000 | if (!drv->poll_command_supported) { |
| 7001 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 7002 | return; |
| 7003 | } |
| 7004 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7005 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 7006 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7007 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7008 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7009 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7010 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7011 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7012 | if (ret < 0) { |
| 7013 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 7014 | MACSTR " failed: ret=%d (%s)", |
| 7015 | MAC2STR(addr), ret, strerror(-ret)); |
| 7016 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7017 | } |
| 7018 | |
| 7019 | |
| 7020 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 7021 | { |
| 7022 | struct nl_msg *msg; |
| 7023 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7024 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 7025 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 7026 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 7027 | nlmsg_free(msg); |
| 7028 | return -ENOBUFS; |
| 7029 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7030 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | |
| 7034 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 7035 | int ctwindow) |
| 7036 | { |
| 7037 | struct i802_bss *bss = priv; |
| 7038 | |
| 7039 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 7040 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 7041 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7042 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7043 | #ifdef ANDROID_P2P |
| 7044 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7045 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7046 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7047 | #endif /* ANDROID_P2P */ |
| 7048 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7049 | |
| 7050 | if (legacy_ps == -1) |
| 7051 | return 0; |
| 7052 | if (legacy_ps != 0 && legacy_ps != 1) |
| 7053 | return -1; /* Not yet supported */ |
| 7054 | |
| 7055 | return nl80211_set_power_save(bss, legacy_ps); |
| 7056 | } |
| 7057 | |
| 7058 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7059 | static int nl80211_start_radar_detection(void *priv, |
| 7060 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7061 | { |
| 7062 | struct i802_bss *bss = priv; |
| 7063 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7064 | struct nl_msg *msg; |
| 7065 | int ret; |
| 7066 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7067 | 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)", |
| 7068 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7069 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7070 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7071 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 7072 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 7073 | "detection"); |
| 7074 | return -1; |
| 7075 | } |
| 7076 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7077 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 7078 | nl80211_put_freq_params(msg, freq) < 0) { |
| 7079 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7080 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7081 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7082 | |
| 7083 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7084 | if (ret == 0) |
| 7085 | return 0; |
| 7086 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 7087 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7088 | return -1; |
| 7089 | } |
| 7090 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7091 | #ifdef CONFIG_TDLS |
| 7092 | |
| 7093 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 7094 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7095 | u32 peer_capab, int initiator, const u8 *buf, |
| 7096 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7097 | { |
| 7098 | struct i802_bss *bss = priv; |
| 7099 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7100 | struct nl_msg *msg; |
| 7101 | |
| 7102 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7103 | return -EOPNOTSUPP; |
| 7104 | |
| 7105 | if (!dst) |
| 7106 | return -EINVAL; |
| 7107 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7108 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 7109 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 7110 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 7111 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 7112 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 7113 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7114 | if (peer_capab) { |
| 7115 | /* |
| 7116 | * The internal enum tdls_peer_capability definition is |
| 7117 | * currently identical with the nl80211 enum |
| 7118 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 7119 | * here. |
| 7120 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7121 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 7122 | peer_capab)) |
| 7123 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7124 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7125 | if ((initiator && |
| 7126 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 7127 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 7128 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7129 | |
| 7130 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7131 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7132 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7133 | nlmsg_free(msg); |
| 7134 | return -ENOBUFS; |
| 7135 | } |
| 7136 | |
| 7137 | |
| 7138 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 7139 | { |
| 7140 | struct i802_bss *bss = priv; |
| 7141 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7142 | struct nl_msg *msg; |
| 7143 | enum nl80211_tdls_operation nl80211_oper; |
| 7144 | |
| 7145 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7146 | return -EOPNOTSUPP; |
| 7147 | |
| 7148 | switch (oper) { |
| 7149 | case TDLS_DISCOVERY_REQ: |
| 7150 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 7151 | break; |
| 7152 | case TDLS_SETUP: |
| 7153 | nl80211_oper = NL80211_TDLS_SETUP; |
| 7154 | break; |
| 7155 | case TDLS_TEARDOWN: |
| 7156 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 7157 | break; |
| 7158 | case TDLS_ENABLE_LINK: |
| 7159 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 7160 | break; |
| 7161 | case TDLS_DISABLE_LINK: |
| 7162 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 7163 | break; |
| 7164 | case TDLS_ENABLE: |
| 7165 | return 0; |
| 7166 | case TDLS_DISABLE: |
| 7167 | return 0; |
| 7168 | default: |
| 7169 | return -EINVAL; |
| 7170 | } |
| 7171 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7172 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 7173 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 7174 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 7175 | nlmsg_free(msg); |
| 7176 | return -ENOBUFS; |
| 7177 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7178 | |
| 7179 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7180 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7181 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7182 | |
| 7183 | static int |
| 7184 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 7185 | const struct hostapd_freq_params *params) |
| 7186 | { |
| 7187 | struct i802_bss *bss = priv; |
| 7188 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7189 | struct nl_msg *msg; |
| 7190 | int ret = -ENOBUFS; |
| 7191 | |
| 7192 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7193 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7194 | return -EOPNOTSUPP; |
| 7195 | |
| 7196 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 7197 | " oper_class=%u freq=%u", |
| 7198 | MAC2STR(addr), oper_class, params->freq); |
| 7199 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 7200 | if (!msg || |
| 7201 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7202 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 7203 | (ret = nl80211_put_freq_params(msg, params))) { |
| 7204 | nlmsg_free(msg); |
| 7205 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 7206 | return ret; |
| 7207 | } |
| 7208 | |
| 7209 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7210 | } |
| 7211 | |
| 7212 | |
| 7213 | static int |
| 7214 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 7215 | { |
| 7216 | struct i802_bss *bss = priv; |
| 7217 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7218 | struct nl_msg *msg; |
| 7219 | |
| 7220 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7221 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7222 | return -EOPNOTSUPP; |
| 7223 | |
| 7224 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 7225 | MAC2STR(addr)); |
| 7226 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 7227 | if (!msg || |
| 7228 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7229 | nlmsg_free(msg); |
| 7230 | wpa_printf(MSG_DEBUG, |
| 7231 | "nl80211: Could not build TDLS cancel chan switch"); |
| 7232 | return -ENOBUFS; |
| 7233 | } |
| 7234 | |
| 7235 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7236 | } |
| 7237 | |
| 7238 | #endif /* CONFIG TDLS */ |
| 7239 | |
| 7240 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7241 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 7242 | enum wpa_alg alg, const u8 *addr, |
| 7243 | int key_idx, int set_tx, |
| 7244 | const u8 *seq, size_t seq_len, |
| 7245 | const u8 *key, size_t key_len) |
| 7246 | { |
| 7247 | struct i802_bss *bss = priv; |
| 7248 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 7249 | set_tx, seq, seq_len, key, key_len); |
| 7250 | } |
| 7251 | |
| 7252 | |
| 7253 | static int driver_nl80211_scan2(void *priv, |
| 7254 | struct wpa_driver_scan_params *params) |
| 7255 | { |
| 7256 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7257 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 7258 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7259 | |
| 7260 | /* |
| 7261 | * Do a vendor specific scan if possible. If only_new_results is |
| 7262 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 7263 | * cannot be achieved through a vendor scan. The below condition may |
| 7264 | * need to be modified if new scan flags are added in the future whose |
| 7265 | * functionality can only be achieved through a normal scan. |
| 7266 | */ |
| 7267 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 7268 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 7269 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7270 | return wpa_driver_nl80211_scan(bss, params); |
| 7271 | } |
| 7272 | |
| 7273 | |
| 7274 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 7275 | int reason_code) |
| 7276 | { |
| 7277 | struct i802_bss *bss = priv; |
| 7278 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 7279 | } |
| 7280 | |
| 7281 | |
| 7282 | static int driver_nl80211_authenticate(void *priv, |
| 7283 | struct wpa_driver_auth_params *params) |
| 7284 | { |
| 7285 | struct i802_bss *bss = priv; |
| 7286 | return wpa_driver_nl80211_authenticate(bss, params); |
| 7287 | } |
| 7288 | |
| 7289 | |
| 7290 | static void driver_nl80211_deinit(void *priv) |
| 7291 | { |
| 7292 | struct i802_bss *bss = priv; |
| 7293 | wpa_driver_nl80211_deinit(bss); |
| 7294 | } |
| 7295 | |
| 7296 | |
| 7297 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 7298 | const char *ifname) |
| 7299 | { |
| 7300 | struct i802_bss *bss = priv; |
| 7301 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 7302 | } |
| 7303 | |
| 7304 | |
| 7305 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7306 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7307 | unsigned int freq, |
| 7308 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7309 | { |
| 7310 | struct i802_bss *bss = priv; |
| 7311 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7312 | freq, 0, 0, 0, csa_offs, |
| 7313 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7314 | } |
| 7315 | |
| 7316 | |
| 7317 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 7318 | { |
| 7319 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7320 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7321 | } |
| 7322 | |
| 7323 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7324 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 7325 | const char *ifname, int vlan_id) |
| 7326 | { |
| 7327 | struct i802_bss *bss = priv; |
| 7328 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 7329 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7330 | |
| 7331 | |
| 7332 | static int driver_nl80211_read_sta_data(void *priv, |
| 7333 | struct hostap_sta_driver_data *data, |
| 7334 | const u8 *addr) |
| 7335 | { |
| 7336 | struct i802_bss *bss = priv; |
| 7337 | return i802_read_sta_data(bss, data, addr); |
| 7338 | } |
| 7339 | |
| 7340 | |
| 7341 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 7342 | unsigned int wait_time, |
| 7343 | const u8 *dst, const u8 *src, |
| 7344 | const u8 *bssid, |
| 7345 | const u8 *data, size_t data_len, |
| 7346 | int no_cck) |
| 7347 | { |
| 7348 | struct i802_bss *bss = priv; |
| 7349 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 7350 | bssid, data, data_len, no_cck); |
| 7351 | } |
| 7352 | |
| 7353 | |
| 7354 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 7355 | { |
| 7356 | struct i802_bss *bss = priv; |
| 7357 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 7358 | } |
| 7359 | |
| 7360 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7361 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 7362 | const u8 *ies, size_t ies_len) |
| 7363 | { |
| 7364 | int ret; |
| 7365 | struct nl_msg *msg; |
| 7366 | struct i802_bss *bss = priv; |
| 7367 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7368 | u16 mdid = WPA_GET_LE16(md); |
| 7369 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7370 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7371 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 7372 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 7373 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 7374 | nlmsg_free(msg); |
| 7375 | return -ENOBUFS; |
| 7376 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7377 | |
| 7378 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7379 | if (ret) { |
| 7380 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 7381 | "err=%d (%s)", ret, strerror(-ret)); |
| 7382 | } |
| 7383 | |
| 7384 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7385 | } |
| 7386 | |
| 7387 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7388 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
| 7389 | { |
| 7390 | struct i802_bss *bss = priv; |
| 7391 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7392 | |
| 7393 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 7394 | return NULL; |
| 7395 | |
| 7396 | return bss->addr; |
| 7397 | } |
| 7398 | |
| 7399 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7400 | static const char * scan_state_str(enum scan_states scan_state) |
| 7401 | { |
| 7402 | switch (scan_state) { |
| 7403 | case NO_SCAN: |
| 7404 | return "NO_SCAN"; |
| 7405 | case SCAN_REQUESTED: |
| 7406 | return "SCAN_REQUESTED"; |
| 7407 | case SCAN_STARTED: |
| 7408 | return "SCAN_STARTED"; |
| 7409 | case SCAN_COMPLETED: |
| 7410 | return "SCAN_COMPLETED"; |
| 7411 | case SCAN_ABORTED: |
| 7412 | return "SCAN_ABORTED"; |
| 7413 | case SCHED_SCAN_STARTED: |
| 7414 | return "SCHED_SCAN_STARTED"; |
| 7415 | case SCHED_SCAN_STOPPED: |
| 7416 | return "SCHED_SCAN_STOPPED"; |
| 7417 | case SCHED_SCAN_RESULTS: |
| 7418 | return "SCHED_SCAN_RESULTS"; |
| 7419 | } |
| 7420 | |
| 7421 | return "??"; |
| 7422 | } |
| 7423 | |
| 7424 | |
| 7425 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 7426 | { |
| 7427 | struct i802_bss *bss = priv; |
| 7428 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7429 | int res; |
| 7430 | char *pos, *end; |
| 7431 | |
| 7432 | pos = buf; |
| 7433 | end = buf + buflen; |
| 7434 | |
| 7435 | res = os_snprintf(pos, end - pos, |
| 7436 | "ifindex=%d\n" |
| 7437 | "ifname=%s\n" |
| 7438 | "brname=%s\n" |
| 7439 | "addr=" MACSTR "\n" |
| 7440 | "freq=%d\n" |
| 7441 | "%s%s%s%s%s", |
| 7442 | bss->ifindex, |
| 7443 | bss->ifname, |
| 7444 | bss->brname, |
| 7445 | MAC2STR(bss->addr), |
| 7446 | bss->freq, |
| 7447 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 7448 | bss->added_if_into_bridge ? |
| 7449 | "added_if_into_bridge=1\n" : "", |
| 7450 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 7451 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 7452 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7453 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7454 | return pos - buf; |
| 7455 | pos += res; |
| 7456 | |
| 7457 | if (bss->wdev_id_set) { |
| 7458 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 7459 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7460 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7461 | return pos - buf; |
| 7462 | pos += res; |
| 7463 | } |
| 7464 | |
| 7465 | res = os_snprintf(pos, end - pos, |
| 7466 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7467 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7468 | "drv_ifindex=%d\n" |
| 7469 | "operstate=%d\n" |
| 7470 | "scan_state=%s\n" |
| 7471 | "auth_bssid=" MACSTR "\n" |
| 7472 | "auth_attempt_bssid=" MACSTR "\n" |
| 7473 | "bssid=" MACSTR "\n" |
| 7474 | "prev_bssid=" MACSTR "\n" |
| 7475 | "associated=%d\n" |
| 7476 | "assoc_freq=%u\n" |
| 7477 | "monitor_sock=%d\n" |
| 7478 | "monitor_ifidx=%d\n" |
| 7479 | "monitor_refcount=%d\n" |
| 7480 | "last_mgmt_freq=%u\n" |
| 7481 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7482 | "%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] | 7483 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7484 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7485 | drv->ifindex, |
| 7486 | drv->operstate, |
| 7487 | scan_state_str(drv->scan_state), |
| 7488 | MAC2STR(drv->auth_bssid), |
| 7489 | MAC2STR(drv->auth_attempt_bssid), |
| 7490 | MAC2STR(drv->bssid), |
| 7491 | MAC2STR(drv->prev_bssid), |
| 7492 | drv->associated, |
| 7493 | drv->assoc_freq, |
| 7494 | drv->monitor_sock, |
| 7495 | drv->monitor_ifidx, |
| 7496 | drv->monitor_refcount, |
| 7497 | drv->last_mgmt_freq, |
| 7498 | drv->eapol_tx_sock, |
| 7499 | drv->ignore_if_down_event ? |
| 7500 | "ignore_if_down_event=1\n" : "", |
| 7501 | drv->scan_complete_events ? |
| 7502 | "scan_complete_events=1\n" : "", |
| 7503 | drv->disabled_11b_rates ? |
| 7504 | "disabled_11b_rates=1\n" : "", |
| 7505 | drv->pending_remain_on_chan ? |
| 7506 | "pending_remain_on_chan=1\n" : "", |
| 7507 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 7508 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 7509 | drv->poll_command_supported ? |
| 7510 | "poll_command_supported=1\n" : "", |
| 7511 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 7512 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 7513 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 7514 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 7515 | drv->ignore_next_local_disconnect ? |
| 7516 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 7517 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7518 | "ignore_next_local_deauth=1\n" : ""); |
| 7519 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7520 | return pos - buf; |
| 7521 | pos += res; |
| 7522 | |
| 7523 | if (drv->has_capability) { |
| 7524 | res = os_snprintf(pos, end - pos, |
| 7525 | "capa.key_mgmt=0x%x\n" |
| 7526 | "capa.enc=0x%x\n" |
| 7527 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7528 | "capa.flags=0x%llx\n" |
| 7529 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7530 | "capa.max_scan_ssids=%d\n" |
| 7531 | "capa.max_sched_scan_ssids=%d\n" |
| 7532 | "capa.sched_scan_supported=%d\n" |
| 7533 | "capa.max_match_sets=%d\n" |
| 7534 | "capa.max_remain_on_chan=%u\n" |
| 7535 | "capa.max_stations=%u\n" |
| 7536 | "capa.probe_resp_offloads=0x%x\n" |
| 7537 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7538 | "capa.num_multichan_concurrent=%u\n" |
| 7539 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7540 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 7541 | "capa.conc_capab=%u\n" |
| 7542 | "capa.max_conc_chan_2_4=%u\n" |
| 7543 | "capa.max_conc_chan_5_0=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7544 | drv->capa.key_mgmt, |
| 7545 | drv->capa.enc, |
| 7546 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7547 | (unsigned long long) drv->capa.flags, |
| 7548 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7549 | drv->capa.max_scan_ssids, |
| 7550 | drv->capa.max_sched_scan_ssids, |
| 7551 | drv->capa.sched_scan_supported, |
| 7552 | drv->capa.max_match_sets, |
| 7553 | drv->capa.max_remain_on_chan, |
| 7554 | drv->capa.max_stations, |
| 7555 | drv->capa.probe_resp_offloads, |
| 7556 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7557 | drv->capa.num_multichan_concurrent, |
| 7558 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7559 | drv->capa.mac_addr_rand_scan_supported, |
| 7560 | drv->capa.conc_capab, |
| 7561 | drv->capa.max_conc_chan_2_4, |
| 7562 | drv->capa.max_conc_chan_5_0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7563 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7564 | return pos - buf; |
| 7565 | pos += res; |
| 7566 | } |
| 7567 | |
| 7568 | return pos - buf; |
| 7569 | } |
| 7570 | |
| 7571 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7572 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 7573 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7574 | if ((settings->head && |
| 7575 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 7576 | settings->head_len, settings->head)) || |
| 7577 | (settings->tail && |
| 7578 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 7579 | settings->tail_len, settings->tail)) || |
| 7580 | (settings->beacon_ies && |
| 7581 | nla_put(msg, NL80211_ATTR_IE, |
| 7582 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 7583 | (settings->proberesp_ies && |
| 7584 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 7585 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 7586 | (settings->assocresp_ies && |
| 7587 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 7588 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 7589 | (settings->probe_resp && |
| 7590 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 7591 | settings->probe_resp_len, settings->probe_resp))) |
| 7592 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7593 | |
| 7594 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7595 | } |
| 7596 | |
| 7597 | |
| 7598 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 7599 | { |
| 7600 | struct nl_msg *msg; |
| 7601 | struct i802_bss *bss = priv; |
| 7602 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7603 | struct nlattr *beacon_csa; |
| 7604 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7605 | int csa_off_len = 0; |
| 7606 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7607 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7608 | 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] | 7609 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7610 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 7611 | settings->freq_params.center_freq1, |
| 7612 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7613 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7614 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7615 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 7616 | return -EOPNOTSUPP; |
| 7617 | } |
| 7618 | |
| 7619 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 7620 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 7621 | return -EOPNOTSUPP; |
| 7622 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7623 | /* |
| 7624 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 7625 | * counters match. This implementation assumes that there are only two |
| 7626 | * counters. |
| 7627 | */ |
| 7628 | if (settings->counter_offset_beacon[0] && |
| 7629 | !settings->counter_offset_beacon[1]) { |
| 7630 | csa_off_len = 1; |
| 7631 | } else if (settings->counter_offset_beacon[1] && |
| 7632 | !settings->counter_offset_beacon[0]) { |
| 7633 | csa_off_len = 1; |
| 7634 | settings->counter_offset_beacon[0] = |
| 7635 | settings->counter_offset_beacon[1]; |
| 7636 | settings->counter_offset_presp[0] = |
| 7637 | settings->counter_offset_presp[1]; |
| 7638 | } else if (settings->counter_offset_beacon[1] && |
| 7639 | settings->counter_offset_beacon[0]) { |
| 7640 | csa_off_len = 2; |
| 7641 | } else { |
| 7642 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 7643 | return -EINVAL; |
| 7644 | } |
| 7645 | |
| 7646 | /* Check CSA counters validity */ |
| 7647 | if (drv->capa.max_csa_counters && |
| 7648 | csa_off_len > drv->capa.max_csa_counters) { |
| 7649 | wpa_printf(MSG_ERROR, |
| 7650 | "nl80211: Too many CSA counters provided"); |
| 7651 | return -EINVAL; |
| 7652 | } |
| 7653 | |
| 7654 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7655 | return -EINVAL; |
| 7656 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7657 | for (i = 0; i < csa_off_len; i++) { |
| 7658 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 7659 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 7660 | |
| 7661 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 7662 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 7663 | settings->cs_count)) |
| 7664 | return -EINVAL; |
| 7665 | |
| 7666 | if (settings->beacon_csa.probe_resp && |
| 7667 | ((settings->beacon_csa.probe_resp_len <= |
| 7668 | csa_c_off_presp) || |
| 7669 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 7670 | settings->cs_count))) |
| 7671 | return -EINVAL; |
| 7672 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7673 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7674 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 7675 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 7676 | settings->cs_count) || |
| 7677 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 7678 | (settings->block_tx && |
| 7679 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7680 | goto error; |
| 7681 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7682 | /* beacon_after params */ |
| 7683 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 7684 | if (ret) |
| 7685 | goto error; |
| 7686 | |
| 7687 | /* beacon_csa params */ |
| 7688 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 7689 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7690 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7691 | |
| 7692 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 7693 | if (ret) |
| 7694 | goto error; |
| 7695 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7696 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 7697 | csa_off_len * sizeof(u16), |
| 7698 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7699 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7700 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 7701 | csa_off_len * sizeof(u16), |
| 7702 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7703 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7704 | |
| 7705 | nla_nest_end(msg, beacon_csa); |
| 7706 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7707 | if (ret) { |
| 7708 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 7709 | ret, strerror(-ret)); |
| 7710 | } |
| 7711 | return ret; |
| 7712 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7713 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7714 | ret = -ENOBUFS; |
| 7715 | error: |
| 7716 | nlmsg_free(msg); |
| 7717 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 7718 | return ret; |
| 7719 | } |
| 7720 | |
| 7721 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7722 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 7723 | u8 user_priority, u16 admitted_time) |
| 7724 | { |
| 7725 | struct i802_bss *bss = priv; |
| 7726 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7727 | struct nl_msg *msg; |
| 7728 | int ret; |
| 7729 | |
| 7730 | wpa_printf(MSG_DEBUG, |
| 7731 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 7732 | tsid, admitted_time, user_priority); |
| 7733 | |
| 7734 | if (!is_sta_interface(drv->nlmode)) |
| 7735 | return -ENOTSUP; |
| 7736 | |
| 7737 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 7738 | if (!msg || |
| 7739 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7740 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7741 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 7742 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 7743 | nlmsg_free(msg); |
| 7744 | return -ENOBUFS; |
| 7745 | } |
| 7746 | |
| 7747 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7748 | if (ret) |
| 7749 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 7750 | ret, strerror(-ret)); |
| 7751 | return ret; |
| 7752 | } |
| 7753 | |
| 7754 | |
| 7755 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 7756 | { |
| 7757 | struct i802_bss *bss = priv; |
| 7758 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7759 | struct nl_msg *msg; |
| 7760 | int ret; |
| 7761 | |
| 7762 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 7763 | |
| 7764 | if (!is_sta_interface(drv->nlmode)) |
| 7765 | return -ENOTSUP; |
| 7766 | |
| 7767 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 7768 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7769 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7770 | nlmsg_free(msg); |
| 7771 | return -ENOBUFS; |
| 7772 | } |
| 7773 | |
| 7774 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7775 | if (ret) |
| 7776 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 7777 | ret, strerror(-ret)); |
| 7778 | return ret; |
| 7779 | } |
| 7780 | |
| 7781 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7782 | #ifdef CONFIG_TESTING_OPTIONS |
| 7783 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 7784 | { |
| 7785 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7786 | struct wpabuf *buf = arg; |
| 7787 | |
| 7788 | if (!buf) |
| 7789 | return NL_SKIP; |
| 7790 | |
| 7791 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 7792 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 7793 | return NL_SKIP; |
| 7794 | } |
| 7795 | |
| 7796 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 7797 | genlmsg_attrlen(gnlh, 0)); |
| 7798 | |
| 7799 | return NL_SKIP; |
| 7800 | } |
| 7801 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7802 | |
| 7803 | |
| 7804 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 7805 | { |
| 7806 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7807 | struct nlattr *nl_vendor_reply, *nl; |
| 7808 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7809 | struct wpabuf *buf = arg; |
| 7810 | int rem; |
| 7811 | |
| 7812 | if (!buf) |
| 7813 | return NL_SKIP; |
| 7814 | |
| 7815 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7816 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7817 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 7818 | |
| 7819 | if (!nl_vendor_reply) |
| 7820 | return NL_SKIP; |
| 7821 | |
| 7822 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 7823 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 7824 | return NL_SKIP; |
| 7825 | } |
| 7826 | |
| 7827 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 7828 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 7829 | } |
| 7830 | |
| 7831 | return NL_SKIP; |
| 7832 | } |
| 7833 | |
| 7834 | |
| 7835 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 7836 | unsigned int subcmd, const u8 *data, |
| 7837 | size_t data_len, struct wpabuf *buf) |
| 7838 | { |
| 7839 | struct i802_bss *bss = priv; |
| 7840 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7841 | struct nl_msg *msg; |
| 7842 | int ret; |
| 7843 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7844 | #ifdef CONFIG_TESTING_OPTIONS |
| 7845 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7846 | msg = nlmsg_alloc(); |
| 7847 | if (!msg) |
| 7848 | return -ENOMEM; |
| 7849 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7850 | nl80211_cmd(drv, msg, 0, subcmd); |
| 7851 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 7852 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7853 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7854 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 7855 | if (ret) |
| 7856 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 7857 | ret); |
| 7858 | return ret; |
| 7859 | } |
| 7860 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7861 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7862 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 7863 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 7864 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 7865 | (data && |
| 7866 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 7867 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7868 | |
| 7869 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 7870 | if (ret) |
| 7871 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 7872 | ret); |
| 7873 | return ret; |
| 7874 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7875 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7876 | nlmsg_free(msg); |
| 7877 | return -ENOBUFS; |
| 7878 | } |
| 7879 | |
| 7880 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7881 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 7882 | u8 qos_map_set_len) |
| 7883 | { |
| 7884 | struct i802_bss *bss = priv; |
| 7885 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7886 | struct nl_msg *msg; |
| 7887 | int ret; |
| 7888 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7889 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 7890 | qos_map_set, qos_map_set_len); |
| 7891 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7892 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 7893 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 7894 | nlmsg_free(msg); |
| 7895 | return -ENOBUFS; |
| 7896 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7897 | |
| 7898 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7899 | if (ret) |
| 7900 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 7901 | |
| 7902 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7903 | } |
| 7904 | |
| 7905 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7906 | static int nl80211_set_wowlan(void *priv, |
| 7907 | const struct wowlan_triggers *triggers) |
| 7908 | { |
| 7909 | struct i802_bss *bss = priv; |
| 7910 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7911 | struct nl_msg *msg; |
| 7912 | struct nlattr *wowlan_triggers; |
| 7913 | int ret; |
| 7914 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7915 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 7916 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7917 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7918 | !(wowlan_triggers = nla_nest_start(msg, |
| 7919 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 7920 | (triggers->any && |
| 7921 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7922 | (triggers->disconnect && |
| 7923 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7924 | (triggers->magic_pkt && |
| 7925 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7926 | (triggers->gtk_rekey_failure && |
| 7927 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7928 | (triggers->eap_identity_req && |
| 7929 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7930 | (triggers->four_way_handshake && |
| 7931 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7932 | (triggers->rfkill_release && |
| 7933 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 7934 | nlmsg_free(msg); |
| 7935 | return -ENOBUFS; |
| 7936 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7937 | |
| 7938 | nla_nest_end(msg, wowlan_triggers); |
| 7939 | |
| 7940 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7941 | if (ret) |
| 7942 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 7943 | |
| 7944 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7945 | } |
| 7946 | |
| 7947 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7948 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7949 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 7950 | { |
| 7951 | struct i802_bss *bss = priv; |
| 7952 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7953 | struct nl_msg *msg; |
| 7954 | struct nlattr *params; |
| 7955 | |
| 7956 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 7957 | |
| 7958 | if (!drv->roaming_vendor_cmd_avail) { |
| 7959 | wpa_printf(MSG_DEBUG, |
| 7960 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 7961 | return -1; |
| 7962 | } |
| 7963 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7964 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 7965 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7966 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7967 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 7968 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7969 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 7970 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 7971 | QCA_ROAMING_NOT_ALLOWED) || |
| 7972 | (bssid && |
| 7973 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 7974 | nlmsg_free(msg); |
| 7975 | return -1; |
| 7976 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7977 | nla_nest_end(msg, params); |
| 7978 | |
| 7979 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7980 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 7981 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7982 | |
| 7983 | |
| 7984 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 7985 | { |
| 7986 | struct i802_bss *bss = priv; |
| 7987 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7988 | int new_addr = addr != NULL; |
| 7989 | |
| 7990 | if (!addr) |
| 7991 | addr = drv->perm_addr; |
| 7992 | |
| 7993 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 7994 | return -1; |
| 7995 | |
| 7996 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 7997 | { |
| 7998 | wpa_printf(MSG_DEBUG, |
| 7999 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 8000 | bss->ifname, MAC2STR(addr)); |
| 8001 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 8002 | 1) < 0) { |
| 8003 | wpa_printf(MSG_DEBUG, |
| 8004 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 8005 | } |
| 8006 | return -1; |
| 8007 | } |
| 8008 | |
| 8009 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 8010 | bss->ifname, MAC2STR(addr)); |
| 8011 | drv->addr_changed = new_addr; |
| 8012 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 8013 | |
| 8014 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 8015 | { |
| 8016 | wpa_printf(MSG_DEBUG, |
| 8017 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 8018 | } |
| 8019 | |
| 8020 | return 0; |
| 8021 | } |
| 8022 | |
| 8023 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8024 | #ifdef CONFIG_MESH |
| 8025 | |
| 8026 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 8027 | { |
| 8028 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 8029 | wpa_printf(MSG_INFO, |
| 8030 | "nl80211: Failed to set interface into mesh mode"); |
| 8031 | return -1; |
| 8032 | } |
| 8033 | return 0; |
| 8034 | } |
| 8035 | |
| 8036 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8037 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 8038 | size_t mesh_id_len) |
| 8039 | { |
| 8040 | if (mesh_id) { |
| 8041 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 8042 | mesh_id, mesh_id_len); |
| 8043 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 8044 | } |
| 8045 | |
| 8046 | return 0; |
| 8047 | } |
| 8048 | |
| 8049 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8050 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8051 | struct wpa_driver_mesh_join_params *params) |
| 8052 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8053 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8054 | struct nl_msg *msg; |
| 8055 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8056 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8057 | |
| 8058 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 8059 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8060 | if (!msg || |
| 8061 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 8062 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 8063 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
| 8064 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8065 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8066 | |
| 8067 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 8068 | |
| 8069 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 8070 | if (!container) |
| 8071 | goto fail; |
| 8072 | |
| 8073 | if (params->ies) { |
| 8074 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 8075 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 8076 | params->ies)) |
| 8077 | goto fail; |
| 8078 | } |
| 8079 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 8080 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 8081 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 8082 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 8083 | goto fail; |
| 8084 | } |
| 8085 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 8086 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 8087 | goto fail; |
| 8088 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 8089 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 8090 | goto fail; |
| 8091 | nla_nest_end(msg, container); |
| 8092 | |
| 8093 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 8094 | if (!container) |
| 8095 | goto fail; |
| 8096 | |
| 8097 | if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
| 8098 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0)) |
| 8099 | goto fail; |
| 8100 | if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) && |
| 8101 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 8102 | params->max_peer_links)) |
| 8103 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8104 | |
| 8105 | /* |
| 8106 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 8107 | * the timer could disconnect stations even in that case. |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8108 | */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8109 | if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 8110 | params->conf.peer_link_timeout)) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8111 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 8112 | goto fail; |
| 8113 | } |
| 8114 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8115 | nla_nest_end(msg, container); |
| 8116 | |
| 8117 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8118 | msg = NULL; |
| 8119 | if (ret) { |
| 8120 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 8121 | ret, strerror(-ret)); |
| 8122 | goto fail; |
| 8123 | } |
| 8124 | ret = 0; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8125 | bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8126 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 8127 | |
| 8128 | fail: |
| 8129 | nlmsg_free(msg); |
| 8130 | return ret; |
| 8131 | } |
| 8132 | |
| 8133 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8134 | static int |
| 8135 | wpa_driver_nl80211_join_mesh(void *priv, |
| 8136 | struct wpa_driver_mesh_join_params *params) |
| 8137 | { |
| 8138 | struct i802_bss *bss = priv; |
| 8139 | int ret, timeout; |
| 8140 | |
| 8141 | timeout = params->conf.peer_link_timeout; |
| 8142 | |
| 8143 | /* Disable kernel inactivity timer */ |
| 8144 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 8145 | params->conf.peer_link_timeout = 0; |
| 8146 | |
| 8147 | ret = nl80211_join_mesh(bss, params); |
| 8148 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 8149 | wpa_printf(MSG_DEBUG, |
| 8150 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 8151 | /* |
| 8152 | * Old kernel does not support setting |
| 8153 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 8154 | * into future from peer_link_timeout. |
| 8155 | */ |
| 8156 | params->conf.peer_link_timeout = timeout + 60; |
| 8157 | ret = nl80211_join_mesh(priv, params); |
| 8158 | } |
| 8159 | |
| 8160 | params->conf.peer_link_timeout = timeout; |
| 8161 | return ret; |
| 8162 | } |
| 8163 | |
| 8164 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8165 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 8166 | { |
| 8167 | struct i802_bss *bss = priv; |
| 8168 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8169 | struct nl_msg *msg; |
| 8170 | int ret; |
| 8171 | |
| 8172 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 8173 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 8174 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8175 | if (ret) { |
| 8176 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 8177 | ret, strerror(-ret)); |
| 8178 | } else { |
| 8179 | wpa_printf(MSG_DEBUG, |
| 8180 | "nl80211: mesh leave request send successfully"); |
| 8181 | } |
| 8182 | |
| 8183 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 8184 | NL80211_IFTYPE_STATION)) { |
| 8185 | wpa_printf(MSG_INFO, |
| 8186 | "nl80211: Failed to set interface into station mode"); |
| 8187 | } |
| 8188 | return ret; |
| 8189 | } |
| 8190 | |
| 8191 | #endif /* CONFIG_MESH */ |
| 8192 | |
| 8193 | |
| 8194 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 8195 | const u8 *ipaddr, int prefixlen, |
| 8196 | const u8 *addr) |
| 8197 | { |
| 8198 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8199 | struct i802_bss *bss = priv; |
| 8200 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8201 | struct rtnl_neigh *rn; |
| 8202 | struct nl_addr *nl_ipaddr = NULL; |
| 8203 | struct nl_addr *nl_lladdr = NULL; |
| 8204 | int family, addrsize; |
| 8205 | int res; |
| 8206 | |
| 8207 | if (!ipaddr || prefixlen == 0 || !addr) |
| 8208 | return -EINVAL; |
| 8209 | |
| 8210 | if (bss->br_ifindex == 0) { |
| 8211 | wpa_printf(MSG_DEBUG, |
| 8212 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 8213 | return -1; |
| 8214 | } |
| 8215 | |
| 8216 | if (!drv->rtnl_sk) { |
| 8217 | wpa_printf(MSG_DEBUG, |
| 8218 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8219 | return -1; |
| 8220 | } |
| 8221 | |
| 8222 | if (version == 4) { |
| 8223 | family = AF_INET; |
| 8224 | addrsize = 4; |
| 8225 | } else if (version == 6) { |
| 8226 | family = AF_INET6; |
| 8227 | addrsize = 16; |
| 8228 | } else { |
| 8229 | return -EINVAL; |
| 8230 | } |
| 8231 | |
| 8232 | rn = rtnl_neigh_alloc(); |
| 8233 | if (rn == NULL) |
| 8234 | return -ENOMEM; |
| 8235 | |
| 8236 | /* set the destination ip address for neigh */ |
| 8237 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8238 | if (nl_ipaddr == NULL) { |
| 8239 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8240 | res = -ENOMEM; |
| 8241 | goto errout; |
| 8242 | } |
| 8243 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 8244 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8245 | if (res) { |
| 8246 | wpa_printf(MSG_DEBUG, |
| 8247 | "nl80211: neigh set destination addr failed"); |
| 8248 | goto errout; |
| 8249 | } |
| 8250 | |
| 8251 | /* set the corresponding lladdr for neigh */ |
| 8252 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 8253 | if (nl_lladdr == NULL) { |
| 8254 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 8255 | res = -ENOMEM; |
| 8256 | goto errout; |
| 8257 | } |
| 8258 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 8259 | |
| 8260 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8261 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 8262 | |
| 8263 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 8264 | if (res) { |
| 8265 | wpa_printf(MSG_DEBUG, |
| 8266 | "nl80211: Adding bridge ip neigh failed: %s", |
| 8267 | strerror(errno)); |
| 8268 | } |
| 8269 | errout: |
| 8270 | if (nl_lladdr) |
| 8271 | nl_addr_put(nl_lladdr); |
| 8272 | if (nl_ipaddr) |
| 8273 | nl_addr_put(nl_ipaddr); |
| 8274 | if (rn) |
| 8275 | rtnl_neigh_put(rn); |
| 8276 | return res; |
| 8277 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8278 | return -1; |
| 8279 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8280 | } |
| 8281 | |
| 8282 | |
| 8283 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 8284 | const u8 *ipaddr) |
| 8285 | { |
| 8286 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8287 | struct i802_bss *bss = priv; |
| 8288 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8289 | struct rtnl_neigh *rn; |
| 8290 | struct nl_addr *nl_ipaddr; |
| 8291 | int family, addrsize; |
| 8292 | int res; |
| 8293 | |
| 8294 | if (!ipaddr) |
| 8295 | return -EINVAL; |
| 8296 | |
| 8297 | if (version == 4) { |
| 8298 | family = AF_INET; |
| 8299 | addrsize = 4; |
| 8300 | } else if (version == 6) { |
| 8301 | family = AF_INET6; |
| 8302 | addrsize = 16; |
| 8303 | } else { |
| 8304 | return -EINVAL; |
| 8305 | } |
| 8306 | |
| 8307 | if (bss->br_ifindex == 0) { |
| 8308 | wpa_printf(MSG_DEBUG, |
| 8309 | "nl80211: bridge must be set to delete an ip neigh"); |
| 8310 | return -1; |
| 8311 | } |
| 8312 | |
| 8313 | if (!drv->rtnl_sk) { |
| 8314 | wpa_printf(MSG_DEBUG, |
| 8315 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8316 | return -1; |
| 8317 | } |
| 8318 | |
| 8319 | rn = rtnl_neigh_alloc(); |
| 8320 | if (rn == NULL) |
| 8321 | return -ENOMEM; |
| 8322 | |
| 8323 | /* set the destination ip address for neigh */ |
| 8324 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8325 | if (nl_ipaddr == NULL) { |
| 8326 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8327 | res = -ENOMEM; |
| 8328 | goto errout; |
| 8329 | } |
| 8330 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8331 | if (res) { |
| 8332 | wpa_printf(MSG_DEBUG, |
| 8333 | "nl80211: neigh set destination addr failed"); |
| 8334 | goto errout; |
| 8335 | } |
| 8336 | |
| 8337 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8338 | |
| 8339 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 8340 | if (res) { |
| 8341 | wpa_printf(MSG_DEBUG, |
| 8342 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 8343 | strerror(errno)); |
| 8344 | } |
| 8345 | errout: |
| 8346 | if (nl_ipaddr) |
| 8347 | nl_addr_put(nl_ipaddr); |
| 8348 | if (rn) |
| 8349 | rtnl_neigh_put(rn); |
| 8350 | return res; |
| 8351 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8352 | return -1; |
| 8353 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8354 | } |
| 8355 | |
| 8356 | |
| 8357 | static int linux_write_system_file(const char *path, unsigned int val) |
| 8358 | { |
| 8359 | char buf[50]; |
| 8360 | int fd, len; |
| 8361 | |
| 8362 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 8363 | if (os_snprintf_error(sizeof(buf), len)) |
| 8364 | return -1; |
| 8365 | |
| 8366 | fd = open(path, O_WRONLY); |
| 8367 | if (fd < 0) |
| 8368 | return -1; |
| 8369 | |
| 8370 | if (write(fd, buf, len) < 0) { |
| 8371 | wpa_printf(MSG_DEBUG, |
| 8372 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 8373 | path, val); |
| 8374 | close(fd); |
| 8375 | return -1; |
| 8376 | } |
| 8377 | close(fd); |
| 8378 | |
| 8379 | return 0; |
| 8380 | } |
| 8381 | |
| 8382 | |
| 8383 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 8384 | { |
| 8385 | switch (attr) { |
| 8386 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 8387 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8388 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 8389 | return "hairpin_mode"; |
| 8390 | } |
| 8391 | |
| 8392 | return NULL; |
| 8393 | } |
| 8394 | |
| 8395 | |
| 8396 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 8397 | unsigned int val) |
| 8398 | { |
| 8399 | struct i802_bss *bss = priv; |
| 8400 | char path[128]; |
| 8401 | const char *attr_txt; |
| 8402 | |
| 8403 | attr_txt = drv_br_port_attr_str(attr); |
| 8404 | if (attr_txt == NULL) |
| 8405 | return -EINVAL; |
| 8406 | |
| 8407 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 8408 | bss->ifname, attr_txt); |
| 8409 | |
| 8410 | if (linux_write_system_file(path, val)) |
| 8411 | return -1; |
| 8412 | |
| 8413 | return 0; |
| 8414 | } |
| 8415 | |
| 8416 | |
| 8417 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 8418 | { |
| 8419 | switch (param) { |
| 8420 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8421 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8422 | default: |
| 8423 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8424 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8425 | } |
| 8426 | |
| 8427 | |
| 8428 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 8429 | unsigned int val) |
| 8430 | { |
| 8431 | struct i802_bss *bss = priv; |
| 8432 | char path[128]; |
| 8433 | const char *param_txt; |
| 8434 | int ip_version = 4; |
| 8435 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8436 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 8437 | os_snprintf(path, sizeof(path), |
| 8438 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 8439 | bss->brname); |
| 8440 | goto set_val; |
| 8441 | } |
| 8442 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8443 | param_txt = drv_br_net_param_str(param); |
| 8444 | if (param_txt == NULL) |
| 8445 | return -EINVAL; |
| 8446 | |
| 8447 | switch (param) { |
| 8448 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8449 | ip_version = 4; |
| 8450 | break; |
| 8451 | default: |
| 8452 | return -EINVAL; |
| 8453 | } |
| 8454 | |
| 8455 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 8456 | ip_version, bss->brname, param_txt); |
| 8457 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8458 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8459 | if (linux_write_system_file(path, val)) |
| 8460 | return -1; |
| 8461 | |
| 8462 | return 0; |
| 8463 | } |
| 8464 | |
| 8465 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 8466 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8467 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8468 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 8469 | { |
| 8470 | switch (hw_mode) { |
| 8471 | case HOSTAPD_MODE_IEEE80211B: |
| 8472 | return QCA_ACS_MODE_IEEE80211B; |
| 8473 | case HOSTAPD_MODE_IEEE80211G: |
| 8474 | return QCA_ACS_MODE_IEEE80211G; |
| 8475 | case HOSTAPD_MODE_IEEE80211A: |
| 8476 | return QCA_ACS_MODE_IEEE80211A; |
| 8477 | case HOSTAPD_MODE_IEEE80211AD: |
| 8478 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 8479 | case HOSTAPD_MODE_IEEE80211ANY: |
| 8480 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8481 | default: |
| 8482 | return -1; |
| 8483 | } |
| 8484 | } |
| 8485 | |
| 8486 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 8487 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 8488 | { |
| 8489 | int i, len, ret; |
| 8490 | u32 *freqs; |
| 8491 | |
| 8492 | if (!freq_list) |
| 8493 | return 0; |
| 8494 | len = int_array_len(freq_list); |
| 8495 | freqs = os_malloc(sizeof(u32) * len); |
| 8496 | if (!freqs) |
| 8497 | return -1; |
| 8498 | for (i = 0; i < len; i++) |
| 8499 | freqs[i] = freq_list[i]; |
| 8500 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 8501 | sizeof(u32) * len, freqs); |
| 8502 | os_free(freqs); |
| 8503 | return ret; |
| 8504 | } |
| 8505 | |
| 8506 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8507 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 8508 | { |
| 8509 | struct i802_bss *bss = priv; |
| 8510 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8511 | struct nl_msg *msg; |
| 8512 | struct nlattr *data; |
| 8513 | int ret; |
| 8514 | int mode; |
| 8515 | |
| 8516 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 8517 | if (mode < 0) |
| 8518 | return -1; |
| 8519 | |
| 8520 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8521 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8522 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8523 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 8524 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8525 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 8526 | (params->ht_enabled && |
| 8527 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 8528 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8529 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 8530 | (params->vht_enabled && |
| 8531 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 8532 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 8533 | params->ch_width) || |
| 8534 | (params->ch_list_len && |
| 8535 | 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^] | 8536 | params->ch_list)) || |
| 8537 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8538 | nlmsg_free(msg); |
| 8539 | return -ENOBUFS; |
| 8540 | } |
| 8541 | nla_nest_end(msg, data); |
| 8542 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8543 | wpa_printf(MSG_DEBUG, |
| 8544 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 8545 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 8546 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 8547 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8548 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8549 | if (ret) { |
| 8550 | wpa_printf(MSG_DEBUG, |
| 8551 | "nl80211: Failed to invoke driver ACS function: %s", |
| 8552 | strerror(errno)); |
| 8553 | } |
| 8554 | return ret; |
| 8555 | } |
| 8556 | |
| 8557 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 8558 | static int nl80211_set_band(void *priv, enum set_band band) |
| 8559 | { |
| 8560 | struct i802_bss *bss = priv; |
| 8561 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8562 | struct nl_msg *msg; |
| 8563 | struct nlattr *data; |
| 8564 | int ret; |
| 8565 | enum qca_set_band qca_band; |
| 8566 | |
| 8567 | if (!drv->setband_vendor_cmd_avail) |
| 8568 | return -1; |
| 8569 | |
| 8570 | switch (band) { |
| 8571 | case WPA_SETBAND_AUTO: |
| 8572 | qca_band = QCA_SETBAND_AUTO; |
| 8573 | break; |
| 8574 | case WPA_SETBAND_5G: |
| 8575 | qca_band = QCA_SETBAND_5G; |
| 8576 | break; |
| 8577 | case WPA_SETBAND_2G: |
| 8578 | qca_band = QCA_SETBAND_2G; |
| 8579 | break; |
| 8580 | default: |
| 8581 | return -1; |
| 8582 | } |
| 8583 | |
| 8584 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8585 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8586 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8587 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 8588 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8589 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 8590 | nlmsg_free(msg); |
| 8591 | return -ENOBUFS; |
| 8592 | } |
| 8593 | nla_nest_end(msg, data); |
| 8594 | |
| 8595 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8596 | if (ret) { |
| 8597 | wpa_printf(MSG_DEBUG, |
| 8598 | "nl80211: Driver setband function failed: %s", |
| 8599 | strerror(errno)); |
| 8600 | } |
| 8601 | return ret; |
| 8602 | } |
| 8603 | |
| 8604 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 8605 | struct nl80211_pcl { |
| 8606 | unsigned int num; |
| 8607 | unsigned int *freq_list; |
| 8608 | }; |
| 8609 | |
| 8610 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 8611 | { |
| 8612 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8613 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8614 | struct nl80211_pcl *param = arg; |
| 8615 | struct nlattr *nl_vend, *attr; |
| 8616 | enum qca_iface_type iface_type; |
| 8617 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 8618 | unsigned int num, max_num; |
| 8619 | u32 *freqs; |
| 8620 | |
| 8621 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8622 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8623 | |
| 8624 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8625 | if (!nl_vend) |
| 8626 | return NL_SKIP; |
| 8627 | |
| 8628 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 8629 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 8630 | |
| 8631 | attr = tb_vendor[ |
| 8632 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 8633 | if (!attr) { |
| 8634 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 8635 | param->num = 0; |
| 8636 | return NL_SKIP; |
| 8637 | } |
| 8638 | |
| 8639 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 8640 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 8641 | iface_type); |
| 8642 | |
| 8643 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 8644 | if (!attr) { |
| 8645 | wpa_printf(MSG_ERROR, |
| 8646 | "nl80211: preferred_freq_list couldn't be found"); |
| 8647 | param->num = 0; |
| 8648 | return NL_SKIP; |
| 8649 | } |
| 8650 | |
| 8651 | /* |
| 8652 | * param->num has the maximum number of entries for which there |
| 8653 | * is room in the freq_list provided by the caller. |
| 8654 | */ |
| 8655 | freqs = nla_data(attr); |
| 8656 | max_num = nla_len(attr) / sizeof(u32); |
| 8657 | if (max_num > param->num) |
| 8658 | max_num = param->num; |
| 8659 | for (num = 0; num < max_num; num++) |
| 8660 | param->freq_list[num] = freqs[num]; |
| 8661 | param->num = num; |
| 8662 | |
| 8663 | return NL_SKIP; |
| 8664 | } |
| 8665 | |
| 8666 | |
| 8667 | static int nl80211_get_pref_freq_list(void *priv, |
| 8668 | enum wpa_driver_if_type if_type, |
| 8669 | unsigned int *num, |
| 8670 | unsigned int *freq_list) |
| 8671 | { |
| 8672 | struct i802_bss *bss = priv; |
| 8673 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8674 | struct nl_msg *msg; |
| 8675 | int ret; |
| 8676 | unsigned int i; |
| 8677 | struct nlattr *params; |
| 8678 | struct nl80211_pcl param; |
| 8679 | enum qca_iface_type iface_type; |
| 8680 | |
| 8681 | if (!drv->get_pref_freq_list) |
| 8682 | return -1; |
| 8683 | |
| 8684 | switch (if_type) { |
| 8685 | case WPA_IF_STATION: |
| 8686 | iface_type = QCA_IFACE_TYPE_STA; |
| 8687 | break; |
| 8688 | case WPA_IF_AP_BSS: |
| 8689 | iface_type = QCA_IFACE_TYPE_AP; |
| 8690 | break; |
| 8691 | case WPA_IF_P2P_GO: |
| 8692 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 8693 | break; |
| 8694 | case WPA_IF_P2P_CLIENT: |
| 8695 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 8696 | break; |
| 8697 | case WPA_IF_IBSS: |
| 8698 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 8699 | break; |
| 8700 | case WPA_IF_TDLS: |
| 8701 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 8702 | break; |
| 8703 | default: |
| 8704 | return -1; |
| 8705 | } |
| 8706 | |
| 8707 | param.num = *num; |
| 8708 | param.freq_list = freq_list; |
| 8709 | |
| 8710 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8711 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 8712 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8713 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8714 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 8715 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8716 | nla_put_u32(msg, |
| 8717 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 8718 | iface_type)) { |
| 8719 | wpa_printf(MSG_ERROR, |
| 8720 | "%s: err in adding vendor_cmd and vendor_data", |
| 8721 | __func__); |
| 8722 | nlmsg_free(msg); |
| 8723 | return -1; |
| 8724 | } |
| 8725 | nla_nest_end(msg, params); |
| 8726 | |
| 8727 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 8728 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 8729 | if (ret) { |
| 8730 | wpa_printf(MSG_ERROR, |
| 8731 | "%s: err in send_and_recv_msgs", __func__); |
| 8732 | return ret; |
| 8733 | } |
| 8734 | |
| 8735 | *num = param.num; |
| 8736 | |
| 8737 | for (i = 0; i < *num; i++) { |
| 8738 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 8739 | i, freq_list[i]); |
| 8740 | } |
| 8741 | |
| 8742 | return 0; |
| 8743 | } |
| 8744 | |
| 8745 | |
| 8746 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 8747 | { |
| 8748 | struct i802_bss *bss = priv; |
| 8749 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8750 | struct nl_msg *msg; |
| 8751 | int ret; |
| 8752 | struct nlattr *params; |
| 8753 | |
| 8754 | if (!drv->set_prob_oper_freq) |
| 8755 | return -1; |
| 8756 | |
| 8757 | wpa_printf(MSG_DEBUG, |
| 8758 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 8759 | freq, bss->ifindex); |
| 8760 | |
| 8761 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8762 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8763 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8764 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 8765 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8766 | nla_put_u32(msg, |
| 8767 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 8768 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 8769 | nla_put_u32(msg, |
| 8770 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 8771 | freq)) { |
| 8772 | wpa_printf(MSG_ERROR, |
| 8773 | "%s: err in adding vendor_cmd and vendor_data", |
| 8774 | __func__); |
| 8775 | nlmsg_free(msg); |
| 8776 | return -1; |
| 8777 | } |
| 8778 | nla_nest_end(msg, params); |
| 8779 | |
| 8780 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8781 | msg = NULL; |
| 8782 | if (ret) { |
| 8783 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 8784 | __func__); |
| 8785 | return ret; |
| 8786 | } |
| 8787 | nlmsg_free(msg); |
| 8788 | return 0; |
| 8789 | } |
| 8790 | |
| 8791 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 8792 | |
| 8793 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8794 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 8795 | .name = "nl80211", |
| 8796 | .desc = "Linux nl80211/cfg80211", |
| 8797 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 8798 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8799 | .set_key = driver_nl80211_set_key, |
| 8800 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8801 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 8802 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8803 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8804 | .deauthenticate = driver_nl80211_deauthenticate, |
| 8805 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8806 | .associate = wpa_driver_nl80211_associate, |
| 8807 | .global_init = nl80211_global_init, |
| 8808 | .global_deinit = nl80211_global_deinit, |
| 8809 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8810 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8811 | .get_capa = wpa_driver_nl80211_get_capa, |
| 8812 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 8813 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 8814 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8815 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8816 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8817 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8818 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8819 | .if_remove = driver_nl80211_if_remove, |
| 8820 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8821 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8822 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8823 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8824 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 8825 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8826 | .hapd_init = i802_init, |
| 8827 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8828 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8829 | .get_seqnum = i802_get_seqnum, |
| 8830 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8831 | .get_inact_sec = i802_get_inact_sec, |
| 8832 | .sta_clear_stats = i802_sta_clear_stats, |
| 8833 | .set_rts = i802_set_rts, |
| 8834 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8835 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8836 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8837 | .sta_deauth = i802_sta_deauth, |
| 8838 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8839 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8840 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8841 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8842 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 8843 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 8844 | .cancel_remain_on_channel = |
| 8845 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8846 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8847 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8848 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8849 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8850 | .signal_monitor = nl80211_signal_monitor, |
| 8851 | .signal_poll = nl80211_signal_poll, |
| 8852 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8853 | .set_param = nl80211_set_param, |
| 8854 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8855 | .add_pmkid = nl80211_add_pmkid, |
| 8856 | .remove_pmkid = nl80211_remove_pmkid, |
| 8857 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8858 | .set_rekey_info = nl80211_set_rekey_info, |
| 8859 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8860 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8861 | .start_dfs_cac = nl80211_start_radar_detection, |
| 8862 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8863 | #ifdef CONFIG_TDLS |
| 8864 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 8865 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8866 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 8867 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8868 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8869 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8870 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8871 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8872 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8873 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8874 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8875 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8876 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8877 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8878 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 8879 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 8880 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 8881 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 8882 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8883 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8884 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8885 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8886 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 8887 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8888 | .roaming = nl80211_roaming, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 8889 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8890 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8891 | #ifdef CONFIG_MESH |
| 8892 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 8893 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 8894 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 8895 | #endif /* CONFIG_MESH */ |
| 8896 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 8897 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 8898 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 8899 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 8900 | .add_tx_ts = nl80211_add_ts, |
| 8901 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 8902 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8903 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 8904 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame^] | 8905 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 8906 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
| 8907 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8908 | }; |