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 | |
| 90 | #define genl_ctrl_resolve android_genl_ctrl_resolve |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 91 | #endif /* ANDROID */ |
| 92 | |
| 93 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 94 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 95 | { |
| 96 | struct nl_handle *handle; |
| 97 | |
| 98 | handle = nl80211_handle_alloc(cb); |
| 99 | if (handle == NULL) { |
| 100 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 101 | "callbacks (%s)", dbg); |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | if (genl_connect(handle)) { |
| 106 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 107 | "netlink (%s)", dbg); |
| 108 | nl80211_handle_destroy(handle); |
| 109 | return NULL; |
| 110 | } |
| 111 | |
| 112 | return handle; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | static void nl_destroy_handles(struct nl_handle **handle) |
| 117 | { |
| 118 | if (*handle == NULL) |
| 119 | return; |
| 120 | nl80211_handle_destroy(*handle); |
| 121 | *handle = NULL; |
| 122 | } |
| 123 | |
| 124 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 125 | #if __WORDSIZE == 64 |
| 126 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 127 | #else |
| 128 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 129 | #endif |
| 130 | |
| 131 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
| 132 | eloop_sock_handler handler, |
| 133 | void *eloop_data) |
| 134 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 135 | #ifdef CONFIG_LIBNL20 |
| 136 | /* |
| 137 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 138 | * by default. It is possible to hit that limit in some cases where |
| 139 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 140 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 141 | * this less likely to occur. |
| 142 | */ |
| 143 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { |
| 144 | wpa_printf(MSG_DEBUG, |
| 145 | "nl80211: Could not set nl_socket RX buffer size: %s", |
| 146 | strerror(errno)); |
| 147 | /* continue anyway with the default (smaller) buffer */ |
| 148 | } |
| 149 | #endif /* CONFIG_LIBNL20 */ |
| 150 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 151 | nl_socket_set_nonblocking(*handle); |
| 152 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 153 | eloop_data, *handle); |
| 154 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle) |
| 159 | { |
| 160 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
| 161 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 162 | nl_destroy_handles(handle); |
| 163 | } |
| 164 | |
| 165 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 166 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 167 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 168 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 169 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 170 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 171 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 172 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 173 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 174 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 175 | const u8 *set_addr, int first, |
| 176 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 177 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 178 | unsigned int freq, unsigned int wait, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 179 | const u8 *buf, size_t buf_len, u64 *cookie, |
| 180 | int no_cck, int no_ack, int offchanok); |
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 | } |
| 1540 | /* rtnetlink ifup handler will report interface as enabled */ |
| 1541 | } |
| 1542 | |
| 1543 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1544 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1545 | void *eloop_ctx, |
| 1546 | void *handle) |
| 1547 | { |
| 1548 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1549 | u8 data[2048]; |
| 1550 | struct msghdr msg; |
| 1551 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1552 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1553 | struct cmsghdr *cmsg; |
| 1554 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1555 | union wpa_event_data event; |
| 1556 | |
| 1557 | memset(&msg, 0, sizeof(msg)); |
| 1558 | msg.msg_iov = &entry; |
| 1559 | msg.msg_iovlen = 1; |
| 1560 | entry.iov_base = data; |
| 1561 | entry.iov_len = sizeof(data); |
| 1562 | msg.msg_control = &control; |
| 1563 | msg.msg_controllen = sizeof(control); |
| 1564 | |
| 1565 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1566 | /* if error or not fitting 802.3 header, return */ |
| 1567 | if (res < 14) |
| 1568 | return; |
| 1569 | |
| 1570 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1571 | { |
| 1572 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1573 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1574 | int *ack; |
| 1575 | |
| 1576 | found_wifi = 1; |
| 1577 | ack = (void *)CMSG_DATA(cmsg); |
| 1578 | acked = *ack; |
| 1579 | } |
| 1580 | |
| 1581 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1582 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1583 | struct sock_extended_err *err = |
| 1584 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1585 | |
| 1586 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1587 | found_ee = 1; |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | if (!found_ee || !found_wifi) |
| 1592 | return; |
| 1593 | |
| 1594 | memset(&event, 0, sizeof(event)); |
| 1595 | event.eapol_tx_status.dst = data; |
| 1596 | event.eapol_tx_status.data = data + 14; |
| 1597 | event.eapol_tx_status.data_len = res - 14; |
| 1598 | event.eapol_tx_status.ack = acked; |
| 1599 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1600 | } |
| 1601 | |
| 1602 | |
| 1603 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1604 | { |
| 1605 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1606 | if (!bss->nl_cb) |
| 1607 | return -1; |
| 1608 | |
| 1609 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1610 | no_seq_check, NULL); |
| 1611 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1612 | process_bss_event, bss); |
| 1613 | |
| 1614 | return 0; |
| 1615 | } |
| 1616 | |
| 1617 | |
| 1618 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1619 | { |
| 1620 | nl_cb_put(bss->nl_cb); |
| 1621 | bss->nl_cb = NULL; |
| 1622 | } |
| 1623 | |
| 1624 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1625 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1626 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1627 | const u8 *set_addr, |
| 1628 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1629 | { |
| 1630 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1631 | struct rfkill_config *rcfg; |
| 1632 | struct i802_bss *bss; |
| 1633 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1634 | if (global_priv == NULL) |
| 1635 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1636 | drv = os_zalloc(sizeof(*drv)); |
| 1637 | if (drv == NULL) |
| 1638 | return NULL; |
| 1639 | drv->global = global_priv; |
| 1640 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1641 | drv->hostapd = !!hostapd; |
| 1642 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1643 | |
| 1644 | /* |
| 1645 | * There is no driver capability flag for this, so assume it is |
| 1646 | * supported and disable this on first attempt to use if the driver |
| 1647 | * rejects the command due to missing support. |
| 1648 | */ |
| 1649 | drv->set_rekey_offload = 1; |
| 1650 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1651 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1652 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1653 | |
| 1654 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1655 | if (!drv->first_bss) { |
| 1656 | os_free(drv); |
| 1657 | return NULL; |
| 1658 | } |
| 1659 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1660 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1661 | bss->ctx = ctx; |
| 1662 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1663 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1664 | drv->monitor_ifidx = -1; |
| 1665 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1666 | drv->eapol_tx_sock = -1; |
| 1667 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1668 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1669 | if (nl80211_init_bss(bss)) |
| 1670 | goto failed; |
| 1671 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1672 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1673 | if (rcfg == NULL) |
| 1674 | goto failed; |
| 1675 | rcfg->ctx = drv; |
| 1676 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); |
| 1677 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1678 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1679 | drv->rfkill = rfkill_init(rcfg); |
| 1680 | if (drv->rfkill == NULL) { |
| 1681 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1682 | os_free(rcfg); |
| 1683 | } |
| 1684 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1685 | if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0) |
| 1686 | drv->start_iface_up = 1; |
| 1687 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1688 | 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] | 1689 | goto failed; |
| 1690 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1691 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1692 | if (drv->eapol_tx_sock < 0) |
| 1693 | goto failed; |
| 1694 | |
| 1695 | if (drv->data_tx_status) { |
| 1696 | int enabled = 1; |
| 1697 | |
| 1698 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1699 | &enabled, sizeof(enabled)) < 0) { |
| 1700 | wpa_printf(MSG_DEBUG, |
| 1701 | "nl80211: wifi status sockopt failed\n"); |
| 1702 | drv->data_tx_status = 0; |
| 1703 | if (!drv->use_monitor) |
| 1704 | drv->capa.flags &= |
| 1705 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1706 | } else { |
| 1707 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1708 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1709 | drv, NULL); |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1714 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1715 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1716 | drv->in_interface_list = 1; |
| 1717 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1718 | |
| 1719 | return bss; |
| 1720 | |
| 1721 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1722 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1723 | return NULL; |
| 1724 | } |
| 1725 | |
| 1726 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1727 | /** |
| 1728 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1729 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1730 | * e.g., wpa_supplicant_event() |
| 1731 | * @ifname: interface name, e.g., wlan0 |
| 1732 | * @global_priv: private driver global data from global_init() |
| 1733 | * Returns: Pointer to private data, %NULL on failure |
| 1734 | */ |
| 1735 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1736 | void *global_priv) |
| 1737 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1738 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1739 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1743 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1744 | struct nl_handle *nl_handle, |
| 1745 | u16 type, const u8 *match, size_t match_len) |
| 1746 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1747 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1748 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1749 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1750 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1751 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1752 | buf[0] = '\0'; |
| 1753 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1754 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1755 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1756 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1757 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1758 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1759 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1760 | nlmsg_free(msg); |
| 1761 | return -1; |
| 1762 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1763 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1764 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1765 | if (ret) { |
| 1766 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1767 | "failed (type=%u): ret=%d (%s)", |
| 1768 | type, ret, strerror(-ret)); |
| 1769 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1770 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1771 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1772 | return ret; |
| 1773 | } |
| 1774 | |
| 1775 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1776 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1777 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1778 | if (bss->nl_mgmt) { |
| 1779 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1780 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 1781 | return -1; |
| 1782 | } |
| 1783 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1784 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1785 | if (bss->nl_mgmt == NULL) |
| 1786 | return -1; |
| 1787 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1788 | return 0; |
| 1789 | } |
| 1790 | |
| 1791 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1792 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 1793 | { |
| 1794 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 1795 | wpa_driver_nl80211_event_receive, |
| 1796 | bss->nl_cb); |
| 1797 | } |
| 1798 | |
| 1799 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1800 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1801 | const u8 *match, size_t match_len) |
| 1802 | { |
| 1803 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1804 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1805 | type, match, match_len); |
| 1806 | } |
| 1807 | |
| 1808 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1809 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1810 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1811 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1812 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1813 | |
| 1814 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1815 | return -1; |
| 1816 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 1817 | "handle %p", bss->nl_mgmt); |
| 1818 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1819 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 1820 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 1821 | |
| 1822 | /* register for any AUTH message */ |
| 1823 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 1824 | } |
| 1825 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1826 | #ifdef CONFIG_INTERWORKING |
| 1827 | /* QoS Map Configure */ |
| 1828 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1829 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1830 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1831 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1832 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1833 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1834 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1835 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1836 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1837 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1838 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1839 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1840 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1841 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1842 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1843 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1844 | /* Protected GAS Initial Request */ |
| 1845 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 1846 | ret = -1; |
| 1847 | /* Protected GAS Initial Response */ |
| 1848 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 1849 | ret = -1; |
| 1850 | /* Protected GAS Comeback Request */ |
| 1851 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 1852 | ret = -1; |
| 1853 | /* Protected GAS Comeback Response */ |
| 1854 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 1855 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1856 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 1857 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1858 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1859 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1860 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 1861 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1862 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1863 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1864 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1865 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 1866 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1867 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1868 | #endif /* CONFIG_P2P */ |
| 1869 | #ifdef CONFIG_IEEE80211W |
| 1870 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1871 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1872 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1873 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1874 | #ifdef CONFIG_TDLS |
| 1875 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 1876 | /* TDLS Discovery Response */ |
| 1877 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 1878 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1879 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1880 | } |
| 1881 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1882 | |
| 1883 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1884 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1885 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1886 | else |
| 1887 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 1888 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 1889 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1890 | /* WNM - BSS Transition Management Request */ |
| 1891 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1892 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1893 | /* WNM-Sleep Mode Response */ |
| 1894 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1895 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1896 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1897 | #ifdef CONFIG_HS20 |
| 1898 | /* WNM-Notification */ |
| 1899 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1900 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1901 | #endif /* CONFIG_HS20 */ |
| 1902 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1903 | /* WMM-AC ADDTS Response */ |
| 1904 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 1905 | ret = -1; |
| 1906 | |
| 1907 | /* WMM-AC DELTS */ |
| 1908 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 1909 | ret = -1; |
| 1910 | |
| 1911 | /* Radio Measurement - Neighbor Report Response */ |
| 1912 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 1913 | ret = -1; |
| 1914 | |
| 1915 | /* Radio Measurement - Link Measurement Request */ |
| 1916 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 1917 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 1918 | ret = -1; |
| 1919 | |
| 1920 | nl80211_mgmt_handle_register_eloop(bss); |
| 1921 | |
| 1922 | return ret; |
| 1923 | } |
| 1924 | |
| 1925 | |
| 1926 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 1927 | { |
| 1928 | int ret = 0; |
| 1929 | |
| 1930 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1931 | return -1; |
| 1932 | |
| 1933 | wpa_printf(MSG_DEBUG, |
| 1934 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 1935 | bss->nl_mgmt); |
| 1936 | |
| 1937 | /* Auth frames for mesh SAE */ |
| 1938 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 1939 | (WLAN_FC_TYPE_MGMT << 2) | |
| 1940 | (WLAN_FC_STYPE_AUTH << 4), |
| 1941 | NULL, 0) < 0) |
| 1942 | ret = -1; |
| 1943 | |
| 1944 | /* Mesh peering open */ |
| 1945 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 1946 | ret = -1; |
| 1947 | /* Mesh peering confirm */ |
| 1948 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 1949 | ret = -1; |
| 1950 | /* Mesh peering close */ |
| 1951 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 1952 | ret = -1; |
| 1953 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1954 | nl80211_mgmt_handle_register_eloop(bss); |
| 1955 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1956 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1960 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 1961 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1962 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1963 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1964 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1965 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 1966 | 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] | 1967 | if (ret) { |
| 1968 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 1969 | "failed: ret=%d (%s)", |
| 1970 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1971 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1972 | return ret; |
| 1973 | } |
| 1974 | |
| 1975 | |
| 1976 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 1977 | { |
| 1978 | static const int stypes[] = { |
| 1979 | WLAN_FC_STYPE_AUTH, |
| 1980 | WLAN_FC_STYPE_ASSOC_REQ, |
| 1981 | WLAN_FC_STYPE_REASSOC_REQ, |
| 1982 | WLAN_FC_STYPE_DISASSOC, |
| 1983 | WLAN_FC_STYPE_DEAUTH, |
| 1984 | WLAN_FC_STYPE_ACTION, |
| 1985 | WLAN_FC_STYPE_PROBE_REQ, |
| 1986 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 1987 | * it, but it wouldn't really be the right thing anyway as |
| 1988 | * it isn't per interface ... maybe just dump the scan |
| 1989 | * results periodically for OLBC? |
| 1990 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1991 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1992 | }; |
| 1993 | unsigned int i; |
| 1994 | |
| 1995 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1996 | return -1; |
| 1997 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 1998 | "handle %p", bss->nl_mgmt); |
| 1999 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2000 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2001 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2002 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2003 | (stypes[i] << 4), |
| 2004 | NULL, 0) < 0) { |
| 2005 | goto out_err; |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | if (nl80211_register_spurious_class3(bss)) |
| 2010 | goto out_err; |
| 2011 | |
| 2012 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 2013 | goto out_err; |
| 2014 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2015 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2016 | return 0; |
| 2017 | |
| 2018 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2019 | nl_destroy_handles(&bss->nl_mgmt); |
| 2020 | return -1; |
| 2021 | } |
| 2022 | |
| 2023 | |
| 2024 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2025 | { |
| 2026 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2027 | return -1; |
| 2028 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2029 | "handle %p (device SME)", bss->nl_mgmt); |
| 2030 | |
| 2031 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2032 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2033 | (WLAN_FC_STYPE_ACTION << 4), |
| 2034 | NULL, 0) < 0) |
| 2035 | goto out_err; |
| 2036 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2037 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2038 | return 0; |
| 2039 | |
| 2040 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2041 | nl_destroy_handles(&bss->nl_mgmt); |
| 2042 | return -1; |
| 2043 | } |
| 2044 | |
| 2045 | |
| 2046 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2047 | { |
| 2048 | if (bss->nl_mgmt == NULL) |
| 2049 | return; |
| 2050 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2051 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2052 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2053 | |
| 2054 | nl80211_put_wiphy_data_ap(bss); |
| 2055 | } |
| 2056 | |
| 2057 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2058 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2059 | { |
| 2060 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2061 | } |
| 2062 | |
| 2063 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2064 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2065 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2066 | struct nl_msg *msg; |
| 2067 | int ret; |
| 2068 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2069 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2070 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2071 | |
| 2072 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2073 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2074 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | |
| 2078 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2079 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2080 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2081 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2082 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2083 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2084 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2085 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2086 | |
| 2087 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2088 | start ? "Start" : "Stop", |
| 2089 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2090 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2091 | return ret; |
| 2092 | } |
| 2093 | |
| 2094 | |
| 2095 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2096 | { |
| 2097 | enum nl80211_iftype nlmode; |
| 2098 | |
| 2099 | nlmode = nl80211_get_ifmode(bss); |
| 2100 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2101 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2102 | bss->ifname, up); |
| 2103 | } |
| 2104 | |
| 2105 | /* P2P Device has start/stop which is equivalent */ |
| 2106 | return nl80211_set_p2pdev(bss, up); |
| 2107 | } |
| 2108 | |
| 2109 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2110 | #ifdef CONFIG_TESTING_OPTIONS |
| 2111 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2112 | { |
| 2113 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2114 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2115 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2116 | |
| 2117 | |
| 2118 | wpa_printf(MSG_DEBUG, |
| 2119 | "nl80211: QCA vendor test command response received"); |
| 2120 | |
| 2121 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2122 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2123 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2124 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2125 | return NL_SKIP; |
| 2126 | } |
| 2127 | |
| 2128 | wpa_hexdump(MSG_DEBUG, |
| 2129 | "nl80211: Received QCA vendor test command response", |
| 2130 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2131 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2132 | |
| 2133 | return NL_SKIP; |
| 2134 | } |
| 2135 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2136 | |
| 2137 | |
| 2138 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2139 | { |
| 2140 | #ifdef CONFIG_TESTING_OPTIONS |
| 2141 | struct nl_msg *msg; |
| 2142 | struct nlattr *params; |
| 2143 | int ret; |
| 2144 | |
| 2145 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2146 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2147 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2148 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2149 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2150 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2151 | nlmsg_free(msg); |
| 2152 | return; |
| 2153 | } |
| 2154 | nla_nest_end(msg, params); |
| 2155 | |
| 2156 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2157 | wpa_printf(MSG_DEBUG, |
| 2158 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2159 | ret, strerror(-ret)); |
| 2160 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2161 | } |
| 2162 | |
| 2163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2164 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2165 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2166 | const u8 *set_addr, int first, |
| 2167 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2168 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2169 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2170 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2171 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2172 | |
| 2173 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2174 | bss->ifindex = drv->ifindex; |
| 2175 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2176 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2177 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2178 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2179 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2180 | drv->global->if_add_wdevid_set = 0; |
| 2181 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2182 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2183 | bss->static_ap = 1; |
| 2184 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2185 | if (wpa_driver_nl80211_capa(drv)) |
| 2186 | return -1; |
| 2187 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2188 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2189 | return -1; |
| 2190 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2191 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2192 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2193 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2194 | if (set_addr && |
| 2195 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2196 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2197 | set_addr))) |
| 2198 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2199 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2200 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2201 | drv->start_mode_ap = 1; |
| 2202 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2203 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2204 | nlmode = NL80211_IFTYPE_AP; |
| 2205 | else if (bss->if_dynamic) |
| 2206 | nlmode = nl80211_get_ifmode(bss); |
| 2207 | else |
| 2208 | nlmode = NL80211_IFTYPE_STATION; |
| 2209 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2210 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2211 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2212 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2213 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2214 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2215 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2216 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2217 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2218 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2219 | int ret = i802_set_iface_flags(bss, 1); |
| 2220 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2221 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2222 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2223 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2224 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2225 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2226 | return ret; |
| 2227 | } else { |
| 2228 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2229 | "interface '%s' due to rfkill", bss->ifname); |
| 2230 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2231 | return 0; |
| 2232 | drv->if_disabled = 1; |
| 2233 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2236 | if (!drv->hostapd) |
| 2237 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2238 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2239 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2240 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2241 | bss->addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2242 | return -1; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2243 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2244 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2245 | if (send_rfkill_event) { |
| 2246 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2247 | drv, drv->ctx); |
| 2248 | } |
| 2249 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2250 | if (drv->vendor_cmd_test_avail) |
| 2251 | qca_vendor_test(drv); |
| 2252 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2253 | return 0; |
| 2254 | } |
| 2255 | |
| 2256 | |
| 2257 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 2258 | { |
| 2259 | struct nl_msg *msg; |
| 2260 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2261 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2262 | drv->ifindex); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2263 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2264 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | |
| 2268 | /** |
| 2269 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2270 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2271 | * |
| 2272 | * Shut down driver interface and processing of driver events. Free |
| 2273 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2274 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2275 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2276 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2277 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2278 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2279 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2280 | bss->ifname, drv->disabled_11b_rates); |
| 2281 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2282 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2283 | if (drv->data_tx_status) |
| 2284 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2285 | if (drv->eapol_tx_sock >= 0) |
| 2286 | close(drv->eapol_tx_sock); |
| 2287 | |
| 2288 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2289 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2290 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2291 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2292 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2293 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2294 | "interface %s from bridge %s: %s", |
| 2295 | bss->ifname, bss->brname, strerror(errno)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2296 | if (drv->rtnl_sk) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2297 | nl80211_handle_destroy(drv->rtnl_sk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2298 | } |
| 2299 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2300 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2301 | 0) < 0) |
| 2302 | wpa_printf(MSG_INFO, |
| 2303 | "nl80211: Could not set bridge %s down", |
| 2304 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2305 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2306 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2307 | "bridge %s: %s", |
| 2308 | bss->brname, strerror(errno)); |
| 2309 | } |
| 2310 | |
| 2311 | nl80211_remove_monitor_interface(drv); |
| 2312 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2313 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2314 | wpa_driver_nl80211_del_beacon(drv); |
| 2315 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2316 | if (drv->eapol_sock >= 0) { |
| 2317 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2318 | close(drv->eapol_sock); |
| 2319 | } |
| 2320 | |
| 2321 | if (drv->if_indices != drv->default_if_indices) |
| 2322 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2323 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2324 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2325 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2326 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2327 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2328 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2329 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2330 | rfkill_deinit(drv->rfkill); |
| 2331 | |
| 2332 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2333 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2334 | if (!drv->start_iface_up) |
| 2335 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2336 | |
| 2337 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2338 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2339 | 0) < 0) { |
| 2340 | wpa_printf(MSG_DEBUG, |
| 2341 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2342 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2343 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2344 | drv->perm_addr) < 0) { |
| 2345 | wpa_printf(MSG_DEBUG, |
| 2346 | "nl80211: Could not restore permanent MAC address"); |
| 2347 | } |
| 2348 | } |
| 2349 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2350 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2351 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2352 | wpa_driver_nl80211_set_mode(bss, |
| 2353 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2354 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2355 | } else { |
| 2356 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2357 | nl80211_del_p2pdev(bss); |
| 2358 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2359 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2360 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2361 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2362 | os_free(drv->filter_ssids); |
| 2363 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2364 | os_free(drv->auth_ie); |
| 2365 | |
| 2366 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2367 | dl_list_del(&drv->list); |
| 2368 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2369 | os_free(drv->extended_capa); |
| 2370 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2371 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2372 | os_free(drv); |
| 2373 | } |
| 2374 | |
| 2375 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2376 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2377 | { |
| 2378 | switch (alg) { |
| 2379 | case WPA_ALG_WEP: |
| 2380 | if (key_len == 5) |
| 2381 | return WLAN_CIPHER_SUITE_WEP40; |
| 2382 | return WLAN_CIPHER_SUITE_WEP104; |
| 2383 | case WPA_ALG_TKIP: |
| 2384 | return WLAN_CIPHER_SUITE_TKIP; |
| 2385 | case WPA_ALG_CCMP: |
| 2386 | return WLAN_CIPHER_SUITE_CCMP; |
| 2387 | case WPA_ALG_GCMP: |
| 2388 | return WLAN_CIPHER_SUITE_GCMP; |
| 2389 | case WPA_ALG_CCMP_256: |
| 2390 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2391 | case WPA_ALG_GCMP_256: |
| 2392 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2393 | case WPA_ALG_IGTK: |
| 2394 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 2395 | case WPA_ALG_BIP_GMAC_128: |
| 2396 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 2397 | case WPA_ALG_BIP_GMAC_256: |
| 2398 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 2399 | case WPA_ALG_BIP_CMAC_256: |
| 2400 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 2401 | case WPA_ALG_SMS4: |
| 2402 | return WLAN_CIPHER_SUITE_SMS4; |
| 2403 | case WPA_ALG_KRK: |
| 2404 | return WLAN_CIPHER_SUITE_KRK; |
| 2405 | case WPA_ALG_NONE: |
| 2406 | case WPA_ALG_PMK: |
| 2407 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2408 | alg); |
| 2409 | return 0; |
| 2410 | } |
| 2411 | |
| 2412 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2413 | alg); |
| 2414 | return 0; |
| 2415 | } |
| 2416 | |
| 2417 | |
| 2418 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2419 | { |
| 2420 | switch (cipher) { |
| 2421 | case WPA_CIPHER_CCMP_256: |
| 2422 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2423 | case WPA_CIPHER_GCMP_256: |
| 2424 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2425 | case WPA_CIPHER_CCMP: |
| 2426 | return WLAN_CIPHER_SUITE_CCMP; |
| 2427 | case WPA_CIPHER_GCMP: |
| 2428 | return WLAN_CIPHER_SUITE_GCMP; |
| 2429 | case WPA_CIPHER_TKIP: |
| 2430 | return WLAN_CIPHER_SUITE_TKIP; |
| 2431 | case WPA_CIPHER_WEP104: |
| 2432 | return WLAN_CIPHER_SUITE_WEP104; |
| 2433 | case WPA_CIPHER_WEP40: |
| 2434 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2435 | case WPA_CIPHER_GTK_NOT_USED: |
| 2436 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | return 0; |
| 2440 | } |
| 2441 | |
| 2442 | |
| 2443 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2444 | int max_suites) |
| 2445 | { |
| 2446 | int num_suites = 0; |
| 2447 | |
| 2448 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 2449 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 2450 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 2451 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 2452 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 2453 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 2454 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 2455 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 2456 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 2457 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 2458 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 2459 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 2460 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 2461 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 2462 | |
| 2463 | return num_suites; |
| 2464 | } |
| 2465 | |
| 2466 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2467 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2468 | const u8 *key, size_t key_len) |
| 2469 | { |
| 2470 | struct nl_msg *msg; |
| 2471 | int ret; |
| 2472 | |
| 2473 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2474 | return 0; |
| 2475 | |
| 2476 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2477 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2478 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2479 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2480 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2481 | nl80211_nlmsg_clear(msg); |
| 2482 | nlmsg_free(msg); |
| 2483 | return -1; |
| 2484 | } |
| 2485 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2486 | if (ret) { |
| 2487 | wpa_printf(MSG_DEBUG, |
| 2488 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2489 | ret, strerror(-ret)); |
| 2490 | } |
| 2491 | |
| 2492 | return ret; |
| 2493 | } |
| 2494 | |
| 2495 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2496 | 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] | 2497 | enum wpa_alg alg, const u8 *addr, |
| 2498 | int key_idx, int set_tx, |
| 2499 | const u8 *seq, size_t seq_len, |
| 2500 | const u8 *key, size_t key_len) |
| 2501 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2502 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2503 | int ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2504 | struct nl_msg *msg; |
| 2505 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2506 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2507 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2508 | /* Ignore for P2P Device */ |
| 2509 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2510 | return 0; |
| 2511 | |
| 2512 | ifindex = if_nametoindex(ifname); |
| 2513 | 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] | 2514 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2515 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2516 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2517 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2518 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2519 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2520 | tdls = 1; |
| 2521 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2522 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2523 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2524 | if (alg == WPA_ALG_PMK && |
| 2525 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2526 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2527 | __func__); |
| 2528 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2529 | return ret; |
| 2530 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2531 | |
| 2532 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2533 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2534 | if (!msg) |
| 2535 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2536 | } else { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2537 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2538 | if (!msg || |
| 2539 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
| 2540 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, |
| 2541 | wpa_alg_to_cipher_suite(alg, key_len))) |
| 2542 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2543 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2546 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2547 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2548 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2549 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2550 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2551 | |
| 2552 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2553 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2554 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2555 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2556 | |
| 2557 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2558 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2559 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2560 | NL80211_KEYTYPE_GROUP)) |
| 2561 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2562 | } |
| 2563 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2564 | struct nlattr *types; |
| 2565 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2566 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2567 | |
| 2568 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2569 | if (!types || |
| 2570 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2571 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2572 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2573 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2574 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2575 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2576 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2577 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2578 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2579 | ret = 0; |
| 2580 | if (ret) |
| 2581 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2582 | ret, strerror(-ret)); |
| 2583 | |
| 2584 | /* |
| 2585 | * If we failed or don't need to set the default TX key (below), |
| 2586 | * we're done here. |
| 2587 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2588 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2589 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2590 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2591 | !is_broadcast_ether_addr(addr)) |
| 2592 | return ret; |
| 2593 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2594 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2595 | if (!msg || |
| 2596 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2597 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2598 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2599 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2600 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2601 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2602 | NL80211_ATTR_KEY_DEFAULT)) |
| 2603 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2604 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2605 | struct nlattr *types; |
| 2606 | |
| 2607 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2608 | if (!types || |
| 2609 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2610 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2611 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2612 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2613 | struct nlattr *types; |
| 2614 | |
| 2615 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2616 | if (!types || |
| 2617 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2618 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2619 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2623 | if (ret == -ENOENT) |
| 2624 | ret = 0; |
| 2625 | if (ret) |
| 2626 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2627 | "err=%d %s)", ret, strerror(-ret)); |
| 2628 | return ret; |
| 2629 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2630 | fail: |
| 2631 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2632 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2633 | return -ENOBUFS; |
| 2634 | } |
| 2635 | |
| 2636 | |
| 2637 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 2638 | int key_idx, int defkey, |
| 2639 | const u8 *seq, size_t seq_len, |
| 2640 | const u8 *key, size_t key_len) |
| 2641 | { |
| 2642 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
| 2643 | if (!key_attr) |
| 2644 | return -1; |
| 2645 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2646 | if (defkey && alg == WPA_ALG_IGTK) { |
| 2647 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 2648 | return -1; |
| 2649 | } else if (defkey) { |
| 2650 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 2651 | return -1; |
| 2652 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2653 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2654 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
| 2655 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2656 | wpa_alg_to_cipher_suite(alg, key_len)) || |
| 2657 | (seq && seq_len && |
| 2658 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 2659 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 2660 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2661 | |
| 2662 | nla_nest_end(msg, key_attr); |
| 2663 | |
| 2664 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | |
| 2668 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 2669 | struct nl_msg *msg) |
| 2670 | { |
| 2671 | int i, privacy = 0; |
| 2672 | struct nlattr *nl_keys, *nl_key; |
| 2673 | |
| 2674 | for (i = 0; i < 4; i++) { |
| 2675 | if (!params->wep_key[i]) |
| 2676 | continue; |
| 2677 | privacy = 1; |
| 2678 | break; |
| 2679 | } |
| 2680 | if (params->wps == WPS_MODE_PRIVACY) |
| 2681 | privacy = 1; |
| 2682 | if (params->pairwise_suite && |
| 2683 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 2684 | privacy = 1; |
| 2685 | |
| 2686 | if (!privacy) |
| 2687 | return 0; |
| 2688 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2689 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 2690 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2691 | |
| 2692 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 2693 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2694 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2695 | |
| 2696 | for (i = 0; i < 4; i++) { |
| 2697 | if (!params->wep_key[i]) |
| 2698 | continue; |
| 2699 | |
| 2700 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2701 | if (!nl_key || |
| 2702 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 2703 | params->wep_key[i]) || |
| 2704 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2705 | params->wep_key_len[i] == 5 ? |
| 2706 | WLAN_CIPHER_SUITE_WEP40 : |
| 2707 | WLAN_CIPHER_SUITE_WEP104) || |
| 2708 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 2709 | (i == params->wep_tx_keyidx && |
| 2710 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 2711 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2712 | |
| 2713 | nla_nest_end(msg, nl_key); |
| 2714 | } |
| 2715 | nla_nest_end(msg, nl_keys); |
| 2716 | |
| 2717 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2721 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 2722 | const u8 *addr, int cmd, u16 reason_code, |
| 2723 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2724 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2725 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2726 | struct nl_msg *msg; |
| 2727 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2728 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 2729 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 2730 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 2731 | (local_state_change && |
| 2732 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 2733 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2734 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2735 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2736 | |
| 2737 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2738 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2739 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2740 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 2741 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2742 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2743 | return ret; |
| 2744 | } |
| 2745 | |
| 2746 | |
| 2747 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2748 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2749 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2750 | int ret; |
| 2751 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2752 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2753 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2754 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2755 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 2756 | reason_code, 0); |
| 2757 | /* |
| 2758 | * For locally generated disconnect, supplicant already generates a |
| 2759 | * DEAUTH event, so ignore the event from NL80211. |
| 2760 | */ |
| 2761 | drv->ignore_next_local_disconnect = ret == 0; |
| 2762 | |
| 2763 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2767 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 2768 | const u8 *addr, int reason_code) |
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 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2771 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2772 | |
| 2773 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 2774 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2775 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2776 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2777 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2778 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2779 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 2780 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2781 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2782 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 2783 | reason_code, 0); |
| 2784 | /* |
| 2785 | * For locally generated deauthenticate, supplicant already generates a |
| 2786 | * DEAUTH event, so ignore the event from NL80211. |
| 2787 | */ |
| 2788 | drv->ignore_next_local_deauth = ret == 0; |
| 2789 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2793 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 2794 | struct wpa_driver_auth_params *params) |
| 2795 | { |
| 2796 | int i; |
| 2797 | |
| 2798 | drv->auth_freq = params->freq; |
| 2799 | drv->auth_alg = params->auth_alg; |
| 2800 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 2801 | drv->auth_local_state_change = params->local_state_change; |
| 2802 | drv->auth_p2p = params->p2p; |
| 2803 | |
| 2804 | if (params->bssid) |
| 2805 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 2806 | else |
| 2807 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 2808 | |
| 2809 | if (params->ssid) { |
| 2810 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 2811 | drv->auth_ssid_len = params->ssid_len; |
| 2812 | } else |
| 2813 | drv->auth_ssid_len = 0; |
| 2814 | |
| 2815 | |
| 2816 | os_free(drv->auth_ie); |
| 2817 | drv->auth_ie = NULL; |
| 2818 | drv->auth_ie_len = 0; |
| 2819 | if (params->ie) { |
| 2820 | drv->auth_ie = os_malloc(params->ie_len); |
| 2821 | if (drv->auth_ie) { |
| 2822 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 2823 | drv->auth_ie_len = params->ie_len; |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | for (i = 0; i < 4; i++) { |
| 2828 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 2829 | params->wep_key_len[i] <= 16) { |
| 2830 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 2831 | params->wep_key_len[i]); |
| 2832 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 2833 | } else |
| 2834 | drv->auth_wep_key_len[i] = 0; |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2839 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 2840 | { |
| 2841 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2842 | |
| 2843 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 2844 | return; |
| 2845 | |
| 2846 | /* |
| 2847 | * Looks like we failed to unmask 11b rates previously. This could |
| 2848 | * happen, e.g., if the interface was down at the point in time when a |
| 2849 | * P2P group was terminated. |
| 2850 | */ |
| 2851 | wpa_printf(MSG_DEBUG, |
| 2852 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 2853 | bss->ifname); |
| 2854 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2855 | } |
| 2856 | |
| 2857 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2858 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2859 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2860 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2861 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2862 | int ret = -1, i; |
| 2863 | struct nl_msg *msg; |
| 2864 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2865 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2866 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2867 | int is_retry; |
| 2868 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2869 | nl80211_unmask_11b_rates(bss); |
| 2870 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2871 | is_retry = drv->retry_auth; |
| 2872 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2873 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2874 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2875 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2876 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2877 | if (params->bssid) |
| 2878 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 2879 | else |
| 2880 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2881 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2882 | nlmode = params->p2p ? |
| 2883 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 2884 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2885 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2886 | return -1; |
| 2887 | |
| 2888 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2889 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 2890 | drv->ifindex); |
| 2891 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2892 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 2893 | if (!msg) |
| 2894 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2895 | |
| 2896 | for (i = 0; i < 4; i++) { |
| 2897 | if (!params->wep_key[i]) |
| 2898 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2899 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2900 | NULL, i, |
| 2901 | i == params->wep_tx_keyidx, NULL, 0, |
| 2902 | params->wep_key[i], |
| 2903 | params->wep_key_len[i]); |
| 2904 | if (params->wep_tx_keyidx != i) |
| 2905 | continue; |
| 2906 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2907 | params->wep_key[i], params->wep_key_len[i])) |
| 2908 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2911 | if (params->bssid) { |
| 2912 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 2913 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2914 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 2915 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2916 | } |
| 2917 | if (params->freq) { |
| 2918 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2919 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 2920 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2921 | } |
| 2922 | if (params->ssid) { |
| 2923 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 2924 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2925 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 2926 | params->ssid)) |
| 2927 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2928 | } |
| 2929 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2930 | if (params->ie && |
| 2931 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 2932 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2933 | if (params->sae_data) { |
| 2934 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 2935 | params->sae_data_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2936 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 2937 | params->sae_data)) |
| 2938 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2939 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 2941 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 2942 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 2943 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 2944 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 2945 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 2946 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 2947 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2948 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 2949 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2950 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2951 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2952 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2953 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 2954 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2955 | if (params->local_state_change) { |
| 2956 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2957 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 2958 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2962 | msg = NULL; |
| 2963 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2964 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2965 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 2966 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2967 | count++; |
| 2968 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 2969 | !params->local_state_change) { |
| 2970 | /* |
| 2971 | * mac80211 does not currently accept new |
| 2972 | * authentication if we are already authenticated. As a |
| 2973 | * workaround, force deauthentication and try again. |
| 2974 | */ |
| 2975 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 2976 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2977 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2978 | wpa_driver_nl80211_deauthenticate( |
| 2979 | bss, params->bssid, |
| 2980 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 2981 | nlmsg_free(msg); |
| 2982 | goto retry; |
| 2983 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2984 | |
| 2985 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 2986 | /* |
| 2987 | * cfg80211 has likely expired the BSS entry even |
| 2988 | * though it was previously available in our internal |
| 2989 | * BSS table. To recover quickly, start a single |
| 2990 | * channel scan on the specified channel. |
| 2991 | */ |
| 2992 | struct wpa_driver_scan_params scan; |
| 2993 | int freqs[2]; |
| 2994 | |
| 2995 | os_memset(&scan, 0, sizeof(scan)); |
| 2996 | scan.num_ssids = 1; |
| 2997 | if (params->ssid) { |
| 2998 | scan.ssids[0].ssid = params->ssid; |
| 2999 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3000 | } |
| 3001 | freqs[0] = params->freq; |
| 3002 | freqs[1] = 0; |
| 3003 | scan.freqs = freqs; |
| 3004 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3005 | "channel scan to refresh cfg80211 BSS " |
| 3006 | "entry"); |
| 3007 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3008 | if (ret == 0) { |
| 3009 | nl80211_copy_auth_params(drv, params); |
| 3010 | drv->scan_for_auth = 1; |
| 3011 | } |
| 3012 | } else if (is_retry) { |
| 3013 | /* |
| 3014 | * Need to indicate this with an event since the return |
| 3015 | * value from the retry is not delivered to core code. |
| 3016 | */ |
| 3017 | union wpa_event_data event; |
| 3018 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3019 | "failed"); |
| 3020 | os_memset(&event, 0, sizeof(event)); |
| 3021 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3022 | ETH_ALEN); |
| 3023 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3024 | &event); |
| 3025 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3026 | } else { |
| 3027 | wpa_printf(MSG_DEBUG, |
| 3028 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3029 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3030 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3031 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3032 | nlmsg_free(msg); |
| 3033 | return ret; |
| 3034 | } |
| 3035 | |
| 3036 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3037 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3038 | { |
| 3039 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3040 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3041 | int i; |
| 3042 | |
| 3043 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3044 | |
| 3045 | os_memset(¶ms, 0, sizeof(params)); |
| 3046 | params.freq = drv->auth_freq; |
| 3047 | params.auth_alg = drv->auth_alg; |
| 3048 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3049 | params.local_state_change = drv->auth_local_state_change; |
| 3050 | params.p2p = drv->auth_p2p; |
| 3051 | |
| 3052 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3053 | params.bssid = drv->auth_bssid_; |
| 3054 | |
| 3055 | if (drv->auth_ssid_len) { |
| 3056 | params.ssid = drv->auth_ssid; |
| 3057 | params.ssid_len = drv->auth_ssid_len; |
| 3058 | } |
| 3059 | |
| 3060 | params.ie = drv->auth_ie; |
| 3061 | params.ie_len = drv->auth_ie_len; |
| 3062 | |
| 3063 | for (i = 0; i < 4; i++) { |
| 3064 | if (drv->auth_wep_key_len[i]) { |
| 3065 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3066 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | drv->retry_auth = 1; |
| 3071 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3072 | } |
| 3073 | |
| 3074 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3075 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3076 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3077 | int encrypt, int noack, |
| 3078 | unsigned int freq, int no_cck, |
| 3079 | int offchanok, unsigned int wait_time) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3080 | { |
| 3081 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3082 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3083 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3084 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3085 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3086 | freq = nl80211_get_assoc_freq(drv); |
| 3087 | wpa_printf(MSG_DEBUG, |
| 3088 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3089 | freq); |
| 3090 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3091 | if (freq == 0) { |
| 3092 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3093 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3094 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3095 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3096 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3097 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3098 | 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] | 3099 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3100 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3101 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3102 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3103 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3104 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
| 3105 | &cookie, no_cck, noack, offchanok); |
| 3106 | if (res == 0 && !noack) { |
| 3107 | const struct ieee80211_mgmt *mgmt; |
| 3108 | u16 fc; |
| 3109 | |
| 3110 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3111 | fc = le_to_host16(mgmt->frame_control); |
| 3112 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3113 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3114 | wpa_printf(MSG_MSGDUMP, |
| 3115 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3116 | (long long unsigned int) |
| 3117 | drv->send_action_cookie, |
| 3118 | (long long unsigned int) cookie); |
| 3119 | drv->send_action_cookie = cookie; |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3127 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3128 | size_t data_len, int noack, |
| 3129 | unsigned int freq, int no_cck, |
| 3130 | int offchanok, |
| 3131 | unsigned int wait_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3132 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3133 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3134 | struct ieee80211_mgmt *mgmt; |
| 3135 | int encrypt = 1; |
| 3136 | u16 fc; |
| 3137 | |
| 3138 | mgmt = (struct ieee80211_mgmt *) data; |
| 3139 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3140 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3141 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3142 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3143 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3144 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3145 | if ((is_sta_interface(drv->nlmode) || |
| 3146 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3147 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3148 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3149 | /* |
| 3150 | * The use of last_mgmt_freq is a bit of a hack, |
| 3151 | * but it works due to the single-threaded nature |
| 3152 | * of wpa_supplicant. |
| 3153 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3154 | if (freq == 0) { |
| 3155 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3156 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3157 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3158 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3159 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3160 | data, data_len, NULL, 1, noack, |
| 3161 | 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3162 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3163 | |
| 3164 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3165 | if (freq == 0) { |
| 3166 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3167 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3168 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3169 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3170 | return nl80211_send_frame_cmd(bss, freq, |
| 3171 | (int) freq == bss->freq ? 0 : |
| 3172 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3173 | data, data_len, |
| 3174 | &drv->send_action_cookie, |
| 3175 | no_cck, noack, offchanok); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3176 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3177 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3178 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3179 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3180 | /* |
| 3181 | * Only one of the authentication frame types is encrypted. |
| 3182 | * In order for static WEP encryption to work properly (i.e., |
| 3183 | * to not encrypt the frame), we need to tell mac80211 about |
| 3184 | * the frames that must not be encrypted. |
| 3185 | */ |
| 3186 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3187 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3188 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3189 | encrypt = 0; |
| 3190 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3191 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3192 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3193 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3194 | noack, freq, no_cck, offchanok, |
| 3195 | wait_time); |
| 3196 | } |
| 3197 | |
| 3198 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3199 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3200 | { |
| 3201 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3202 | u8 rates_len = 0; |
| 3203 | int i; |
| 3204 | |
| 3205 | if (!basic_rates) |
| 3206 | return 0; |
| 3207 | |
| 3208 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3209 | rates[rates_len++] = basic_rates[i] / 5; |
| 3210 | |
| 3211 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3212 | } |
| 3213 | |
| 3214 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3215 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3216 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3217 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3218 | { |
| 3219 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3220 | struct nl_msg *msg; |
| 3221 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3222 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3223 | (cts >= 0 && |
| 3224 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3225 | (preamble >= 0 && |
| 3226 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3227 | (slot >= 0 && |
| 3228 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3229 | (ht_opmode >= 0 && |
| 3230 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3231 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3232 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3233 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3234 | nlmsg_free(msg); |
| 3235 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3236 | } |
| 3237 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3238 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3242 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3243 | struct hostapd_acl_params *params) |
| 3244 | { |
| 3245 | struct i802_bss *bss = priv; |
| 3246 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3247 | struct nl_msg *msg; |
| 3248 | struct nlattr *acl; |
| 3249 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3250 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3251 | |
| 3252 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3253 | return -ENOTSUP; |
| 3254 | |
| 3255 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3256 | return -ENOTSUP; |
| 3257 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3258 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3259 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3260 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3261 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3262 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3263 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3264 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3265 | (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) { |
| 3266 | nlmsg_free(msg); |
| 3267 | return -ENOMEM; |
| 3268 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3269 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3270 | for (i = 0; i < params->num_mac_acl; i++) { |
| 3271 | if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3272 | nlmsg_free(msg); |
| 3273 | return -ENOMEM; |
| 3274 | } |
| 3275 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3276 | |
| 3277 | nla_nest_end(msg, acl); |
| 3278 | |
| 3279 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3280 | if (ret) { |
| 3281 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3282 | ret, strerror(-ret)); |
| 3283 | } |
| 3284 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3285 | return ret; |
| 3286 | } |
| 3287 | |
| 3288 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3289 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3290 | { |
| 3291 | if (beacon_int > 0) { |
| 3292 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3293 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3294 | beacon_int); |
| 3295 | } |
| 3296 | |
| 3297 | return 0; |
| 3298 | } |
| 3299 | |
| 3300 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3301 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3302 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3303 | { |
| 3304 | struct i802_bss *bss = priv; |
| 3305 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3306 | struct nl_msg *msg; |
| 3307 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3308 | int ret; |
| 3309 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3310 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3311 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3312 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3313 | u32 ver; |
| 3314 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3315 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3316 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3317 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3318 | beacon_set); |
| 3319 | if (beacon_set) |
| 3320 | cmd = NL80211_CMD_SET_BEACON; |
| 3321 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3322 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3323 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3324 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3325 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3326 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3327 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3328 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3329 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3330 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3331 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3332 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3333 | params->head) || |
| 3334 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3335 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3336 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3337 | nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) || |
| 3338 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3339 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3340 | if (params->proberesp && params->proberesp_len) { |
| 3341 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3342 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3343 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3344 | params->proberesp)) |
| 3345 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3346 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3347 | switch (params->hide_ssid) { |
| 3348 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3349 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3350 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3351 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3352 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3353 | break; |
| 3354 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3355 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3356 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3357 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3358 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3359 | break; |
| 3360 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3361 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3362 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3363 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3364 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3365 | break; |
| 3366 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3367 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3368 | if (params->privacy && |
| 3369 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3370 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3371 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3372 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3373 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3374 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3375 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3376 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3377 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3378 | goto fail; |
| 3379 | } else { |
| 3380 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3381 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3382 | goto fail; |
| 3383 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3384 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3385 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3386 | ver = 0; |
| 3387 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3388 | ver |= NL80211_WPA_VERSION_1; |
| 3389 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3390 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3391 | if (ver && |
| 3392 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3393 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3394 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3395 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3396 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3397 | num_suites = 0; |
| 3398 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 3399 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 3400 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 3401 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3402 | if (num_suites && |
| 3403 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3404 | suites)) |
| 3405 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3406 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3407 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 3408 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) && |
| 3409 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) |
| 3410 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3411 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3412 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 3413 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3414 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 3415 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3416 | if (num_suites && |
| 3417 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 3418 | num_suites * sizeof(u32), suites)) |
| 3419 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3420 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3421 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 3422 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3423 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3424 | if (suite && |
| 3425 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 3426 | goto fail; |
| 3427 | |
| 3428 | switch (params->smps_mode) { |
| 3429 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 3430 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 3431 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 3432 | break; |
| 3433 | case HT_CAP_INFO_SMPS_STATIC: |
| 3434 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 3435 | smps_mode = NL80211_SMPS_STATIC; |
| 3436 | break; |
| 3437 | default: |
| 3438 | /* invalid - fallback to smps off */ |
| 3439 | case HT_CAP_INFO_SMPS_DISABLED: |
| 3440 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 3441 | smps_mode = NL80211_SMPS_OFF; |
| 3442 | break; |
| 3443 | } |
| 3444 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
| 3445 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3446 | |
| 3447 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3448 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 3449 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3450 | if (nla_put(msg, NL80211_ATTR_IE, |
| 3451 | wpabuf_len(params->beacon_ies), |
| 3452 | wpabuf_head(params->beacon_ies))) |
| 3453 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3454 | } |
| 3455 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3456 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 3457 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3458 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 3459 | wpabuf_len(params->proberesp_ies), |
| 3460 | wpabuf_head(params->proberesp_ies))) |
| 3461 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3462 | } |
| 3463 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3464 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 3465 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3466 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 3467 | wpabuf_len(params->assocresp_ies), |
| 3468 | wpabuf_head(params->assocresp_ies))) |
| 3469 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3470 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3471 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3472 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3473 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 3474 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3475 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 3476 | params->ap_max_inactivity)) |
| 3477 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3480 | #ifdef CONFIG_P2P |
| 3481 | if (params->p2p_go_ctwindow > 0) { |
| 3482 | if (drv->p2p_go_ctwindow_supported) { |
| 3483 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 3484 | params->p2p_go_ctwindow); |
| 3485 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 3486 | params->p2p_go_ctwindow)) |
| 3487 | goto fail; |
| 3488 | } else { |
| 3489 | wpa_printf(MSG_INFO, |
| 3490 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 3491 | } |
| 3492 | } |
| 3493 | #endif /* CONFIG_P2P */ |
| 3494 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3495 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3496 | if (ret) { |
| 3497 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 3498 | ret, strerror(-ret)); |
| 3499 | } else { |
| 3500 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3501 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 3502 | params->short_slot_time, params->ht_opmode, |
| 3503 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3504 | if (beacon_set && params->freq && |
| 3505 | params->freq->bandwidth != bss->bandwidth) { |
| 3506 | wpa_printf(MSG_DEBUG, |
| 3507 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 3508 | bss->ifname, bss->bandwidth, |
| 3509 | params->freq->bandwidth); |
| 3510 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 3511 | if (ret) { |
| 3512 | wpa_printf(MSG_DEBUG, |
| 3513 | "nl80211: Frequency set failed: %d (%s)", |
| 3514 | ret, strerror(-ret)); |
| 3515 | } else { |
| 3516 | wpa_printf(MSG_DEBUG, |
| 3517 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 3518 | bss->bandwidth = params->freq->bandwidth; |
| 3519 | } |
| 3520 | } else if (!beacon_set) { |
| 3521 | /* |
| 3522 | * cfg80211 updates the driver on frequence change in AP |
| 3523 | * mode only at the point when beaconing is started, so |
| 3524 | * set the initial value here. |
| 3525 | */ |
| 3526 | bss->bandwidth = params->freq->bandwidth; |
| 3527 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3528 | } |
| 3529 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3530 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3531 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3532 | return -ENOBUFS; |
| 3533 | } |
| 3534 | |
| 3535 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3536 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3537 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3538 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3539 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3540 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 3541 | return -ENOBUFS; |
| 3542 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3543 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 3544 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 3545 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3546 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3547 | enum nl80211_chan_width cw; |
| 3548 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3549 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3550 | switch (freq->bandwidth) { |
| 3551 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3552 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3553 | break; |
| 3554 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3555 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3556 | break; |
| 3557 | case 80: |
| 3558 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3559 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3560 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3561 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3562 | break; |
| 3563 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3564 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3565 | break; |
| 3566 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3567 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3568 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3569 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3570 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 3571 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 3572 | freq->center_freq1); |
| 3573 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 3574 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3575 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 3576 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 3577 | freq->center_freq1) || |
| 3578 | (freq->center_freq2 && |
| 3579 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 3580 | freq->center_freq2))) |
| 3581 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3582 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3583 | enum nl80211_channel_type ct; |
| 3584 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3585 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 3586 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3587 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3588 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3589 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3590 | break; |
| 3591 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3592 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3593 | break; |
| 3594 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3595 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3596 | break; |
| 3597 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3598 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3599 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3600 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 3601 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3602 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3603 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3607 | static int nl80211_set_channel(struct i802_bss *bss, |
| 3608 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3609 | { |
| 3610 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3611 | struct nl_msg *msg; |
| 3612 | int ret; |
| 3613 | |
| 3614 | wpa_printf(MSG_DEBUG, |
| 3615 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 3616 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 3617 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3618 | |
| 3619 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 3620 | NL80211_CMD_SET_WIPHY); |
| 3621 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 3622 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3623 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3624 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3625 | |
| 3626 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3627 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3628 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3629 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3630 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3631 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3632 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3633 | return -1; |
| 3634 | } |
| 3635 | |
| 3636 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3637 | static u32 sta_flags_nl80211(int flags) |
| 3638 | { |
| 3639 | u32 f = 0; |
| 3640 | |
| 3641 | if (flags & WPA_STA_AUTHORIZED) |
| 3642 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3643 | if (flags & WPA_STA_WMM) |
| 3644 | f |= BIT(NL80211_STA_FLAG_WME); |
| 3645 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 3646 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 3647 | if (flags & WPA_STA_MFP) |
| 3648 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 3649 | if (flags & WPA_STA_TDLS_PEER) |
| 3650 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3651 | if (flags & WPA_STA_AUTHENTICATED) |
| 3652 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3653 | |
| 3654 | return f; |
| 3655 | } |
| 3656 | |
| 3657 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3658 | #ifdef CONFIG_MESH |
| 3659 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 3660 | { |
| 3661 | switch (state) { |
| 3662 | case PLINK_LISTEN: |
| 3663 | return NL80211_PLINK_LISTEN; |
| 3664 | case PLINK_OPEN_SENT: |
| 3665 | return NL80211_PLINK_OPN_SNT; |
| 3666 | case PLINK_OPEN_RCVD: |
| 3667 | return NL80211_PLINK_OPN_RCVD; |
| 3668 | case PLINK_CNF_RCVD: |
| 3669 | return NL80211_PLINK_CNF_RCVD; |
| 3670 | case PLINK_ESTAB: |
| 3671 | return NL80211_PLINK_ESTAB; |
| 3672 | case PLINK_HOLDING: |
| 3673 | return NL80211_PLINK_HOLDING; |
| 3674 | case PLINK_BLOCKED: |
| 3675 | return NL80211_PLINK_BLOCKED; |
| 3676 | default: |
| 3677 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 3678 | state); |
| 3679 | } |
| 3680 | return -1; |
| 3681 | } |
| 3682 | #endif /* CONFIG_MESH */ |
| 3683 | |
| 3684 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3685 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 3686 | struct hostapd_sta_add_params *params) |
| 3687 | { |
| 3688 | struct i802_bss *bss = priv; |
| 3689 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3690 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3691 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3692 | int ret = -ENOBUFS; |
| 3693 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3694 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 3695 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 3696 | return -EOPNOTSUPP; |
| 3697 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3698 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 3699 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3700 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 3701 | NL80211_CMD_NEW_STATION); |
| 3702 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 3703 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3704 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3705 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) { |
| 3706 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 3707 | params->supp_rates, params->supp_rates_len); |
| 3708 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 3709 | params->capability); |
| 3710 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 3711 | params->supp_rates_len, params->supp_rates) || |
| 3712 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 3713 | params->capability)) |
| 3714 | goto fail; |
| 3715 | |
| 3716 | if (params->ht_capabilities) { |
| 3717 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 3718 | (u8 *) params->ht_capabilities, |
| 3719 | sizeof(*params->ht_capabilities)); |
| 3720 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 3721 | sizeof(*params->ht_capabilities), |
| 3722 | params->ht_capabilities)) |
| 3723 | goto fail; |
| 3724 | } |
| 3725 | |
| 3726 | if (params->vht_capabilities) { |
| 3727 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 3728 | (u8 *) params->vht_capabilities, |
| 3729 | sizeof(*params->vht_capabilities)); |
| 3730 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 3731 | sizeof(*params->vht_capabilities), |
| 3732 | params->vht_capabilities)) |
| 3733 | goto fail; |
| 3734 | } |
| 3735 | |
| 3736 | if (params->ext_capab) { |
| 3737 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 3738 | params->ext_capab, params->ext_capab_len); |
| 3739 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 3740 | params->ext_capab_len, params->ext_capab)) |
| 3741 | goto fail; |
| 3742 | } |
| 3743 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3744 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3745 | if (params->aid) { |
| 3746 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3747 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 3748 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3749 | } else { |
| 3750 | /* |
| 3751 | * cfg80211 validates that AID is non-zero, so we have |
| 3752 | * to make this a non-zero value for the TDLS case where |
| 3753 | * a dummy STA entry is used for now. |
| 3754 | */ |
| 3755 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3756 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 3757 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3758 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3759 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 3760 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3761 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 3762 | params->listen_interval)) |
| 3763 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3764 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 3765 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3766 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 3767 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3768 | } |
| 3769 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3770 | if (params->vht_opmode_enabled) { |
| 3771 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3772 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 3773 | params->vht_opmode)) |
| 3774 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3775 | } |
| 3776 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3777 | if (params->supp_channels) { |
| 3778 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 3779 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3780 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 3781 | params->supp_channels_len, params->supp_channels)) |
| 3782 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | if (params->supp_oper_classes) { |
| 3786 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 3787 | params->supp_oper_classes, |
| 3788 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3789 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 3790 | params->supp_oper_classes_len, |
| 3791 | params->supp_oper_classes)) |
| 3792 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3793 | } |
| 3794 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3795 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3796 | upd.set = sta_flags_nl80211(params->flags); |
| 3797 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3798 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 3799 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3800 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 3801 | goto fail; |
| 3802 | |
| 3803 | #ifdef CONFIG_MESH |
| 3804 | if (params->plink_state && |
| 3805 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 3806 | sta_plink_state_nl80211(params->plink_state))) |
| 3807 | goto fail; |
| 3808 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3809 | |
| 3810 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3811 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 3812 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3813 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3814 | if (!wme || |
| 3815 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 3816 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 3817 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 3818 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 3819 | WMM_QOSINFO_STA_SP_MASK)) |
| 3820 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3821 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3822 | } |
| 3823 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3824 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3825 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3826 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3827 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 3828 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 3829 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3830 | if (ret == -EEXIST) |
| 3831 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3832 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3833 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3834 | return ret; |
| 3835 | } |
| 3836 | |
| 3837 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3838 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 3839 | { |
| 3840 | #ifdef CONFIG_LIBNL3_ROUTE |
| 3841 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3842 | struct rtnl_neigh *rn; |
| 3843 | struct nl_addr *nl_addr; |
| 3844 | int err; |
| 3845 | |
| 3846 | rn = rtnl_neigh_alloc(); |
| 3847 | if (!rn) |
| 3848 | return; |
| 3849 | |
| 3850 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 3851 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 3852 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 3853 | if (!nl_addr) { |
| 3854 | rtnl_neigh_put(rn); |
| 3855 | return; |
| 3856 | } |
| 3857 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 3858 | |
| 3859 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 3860 | if (err < 0) { |
| 3861 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 3862 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 3863 | bss->ifindex, nl_geterror(err)); |
| 3864 | } else { |
| 3865 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 3866 | MACSTR, MAC2STR(addr)); |
| 3867 | } |
| 3868 | |
| 3869 | nl_addr_put(nl_addr); |
| 3870 | rtnl_neigh_put(rn); |
| 3871 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 3872 | } |
| 3873 | |
| 3874 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3875 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 3876 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3877 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3878 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3879 | struct nl_msg *msg; |
| 3880 | int ret; |
| 3881 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3882 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 3883 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3884 | (deauth == 0 && |
| 3885 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 3886 | WLAN_FC_STYPE_DISASSOC)) || |
| 3887 | (deauth == 1 && |
| 3888 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 3889 | WLAN_FC_STYPE_DEAUTH)) || |
| 3890 | (reason_code && |
| 3891 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 3892 | nlmsg_free(msg); |
| 3893 | return -ENOBUFS; |
| 3894 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3895 | |
| 3896 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 3897 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 3898 | " --> %d (%s)", |
| 3899 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3900 | |
| 3901 | if (drv->rtnl_sk) |
| 3902 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 3903 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3904 | if (ret == -ENOENT) |
| 3905 | return 0; |
| 3906 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3910 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3911 | { |
| 3912 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3913 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3914 | |
| 3915 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 3916 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3917 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3918 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 3919 | struct wpa_driver_nl80211_data, list) |
| 3920 | del_ifidx(drv2, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3921 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3922 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3923 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 3924 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3925 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 3926 | } |
| 3927 | |
| 3928 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3929 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 3930 | { |
| 3931 | switch (mode) { |
| 3932 | case NL80211_IFTYPE_ADHOC: |
| 3933 | return "ADHOC"; |
| 3934 | case NL80211_IFTYPE_STATION: |
| 3935 | return "STATION"; |
| 3936 | case NL80211_IFTYPE_AP: |
| 3937 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3938 | case NL80211_IFTYPE_AP_VLAN: |
| 3939 | return "AP_VLAN"; |
| 3940 | case NL80211_IFTYPE_WDS: |
| 3941 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3942 | case NL80211_IFTYPE_MONITOR: |
| 3943 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3944 | case NL80211_IFTYPE_MESH_POINT: |
| 3945 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3946 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3947 | return "P2P_CLIENT"; |
| 3948 | case NL80211_IFTYPE_P2P_GO: |
| 3949 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3950 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3951 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3952 | default: |
| 3953 | return "unknown"; |
| 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3958 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 3959 | const char *ifname, |
| 3960 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3961 | const u8 *addr, int wds, |
| 3962 | int (*handler)(struct nl_msg *, void *), |
| 3963 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3964 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3965 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3966 | int ifidx; |
| 3967 | int ret = -ENOBUFS; |
| 3968 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3969 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 3970 | iftype, nl80211_iftype_str(iftype)); |
| 3971 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3972 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 3973 | if (!msg || |
| 3974 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 3975 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 3976 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3977 | |
| 3978 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3979 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3980 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3981 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3982 | if (!flags || |
| 3983 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 3984 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3985 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3986 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3987 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3988 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 3989 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3992 | /* |
| 3993 | * Tell cfg80211 that the interface belongs to the socket that created |
| 3994 | * it, and the interface should be deleted when the socket is closed. |
| 3995 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3996 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 3997 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3998 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3999 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4000 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4001 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4002 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4003 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4004 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4005 | ifname, ret, strerror(-ret)); |
| 4006 | return ret; |
| 4007 | } |
| 4008 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4009 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4010 | return 0; |
| 4011 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4012 | ifidx = if_nametoindex(ifname); |
| 4013 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4014 | ifname, ifidx); |
| 4015 | |
| 4016 | if (ifidx <= 0) |
| 4017 | return -1; |
| 4018 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4019 | /* |
| 4020 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4021 | * the parent interface. This is used mainly with hostapd. |
| 4022 | */ |
| 4023 | if (drv->hostapd || |
| 4024 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4025 | iftype == NL80211_IFTYPE_WDS || |
| 4026 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4027 | /* start listening for EAPOL on this interface */ |
| 4028 | add_ifidx(drv, ifidx); |
| 4029 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4030 | |
| 4031 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4032 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4033 | nl80211_remove_iface(drv, ifidx); |
| 4034 | return -1; |
| 4035 | } |
| 4036 | |
| 4037 | return ifidx; |
| 4038 | } |
| 4039 | |
| 4040 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4041 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4042 | const char *ifname, enum nl80211_iftype iftype, |
| 4043 | const u8 *addr, int wds, |
| 4044 | int (*handler)(struct nl_msg *, void *), |
| 4045 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4046 | { |
| 4047 | int ret; |
| 4048 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4049 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4050 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4051 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4052 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4053 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4054 | if (use_existing) { |
| 4055 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4056 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4057 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4058 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4059 | addr) < 0 && |
| 4060 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4061 | ifname, 0) < 0 || |
| 4062 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4063 | addr) < 0 || |
| 4064 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4065 | ifname, 1) < 0)) |
| 4066 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4067 | return -ENFILE; |
| 4068 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4069 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4070 | |
| 4071 | /* Try to remove the interface that was already there. */ |
| 4072 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4073 | |
| 4074 | /* Try to create the interface again */ |
| 4075 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4076 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4077 | } |
| 4078 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4079 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4080 | wpa_printf(MSG_DEBUG, |
| 4081 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4082 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4083 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4084 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4085 | |
| 4086 | return ret; |
| 4087 | } |
| 4088 | |
| 4089 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4090 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4091 | { |
| 4092 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4093 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4094 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4095 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4096 | |
| 4097 | /* |
| 4098 | * Disable Probe Request reporting unless we need it in this way for |
| 4099 | * devices that include the AP SME, in the other case (unless using |
| 4100 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4101 | */ |
| 4102 | if (!drv->device_ap_sme) |
| 4103 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4104 | |
| 4105 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4106 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4107 | return -1; |
| 4108 | |
| 4109 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4110 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 4111 | return -1; |
| 4112 | |
| 4113 | if (!drv->device_ap_sme && drv->use_monitor && |
| 4114 | nl80211_create_monitor_interface(drv) && |
| 4115 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4116 | return -1; |
| 4117 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4118 | if (drv->device_ap_sme && |
| 4119 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4120 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4121 | "Probe Request frame reporting in AP mode"); |
| 4122 | /* Try to survive without this */ |
| 4123 | } |
| 4124 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4125 | return 0; |
| 4126 | } |
| 4127 | |
| 4128 | |
| 4129 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4130 | { |
| 4131 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4132 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4133 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4134 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4135 | if (drv->device_ap_sme) { |
| 4136 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4137 | if (!drv->use_monitor) |
| 4138 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4139 | } else if (drv->use_monitor) |
| 4140 | nl80211_remove_monitor_interface(drv); |
| 4141 | else |
| 4142 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4143 | |
| 4144 | bss->beacon_set = 0; |
| 4145 | } |
| 4146 | |
| 4147 | |
| 4148 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4149 | const u8 *addr, const u8 *data, |
| 4150 | size_t data_len) |
| 4151 | { |
| 4152 | struct sockaddr_ll ll; |
| 4153 | int ret; |
| 4154 | |
| 4155 | if (bss->drv->eapol_tx_sock < 0) { |
| 4156 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4157 | return -1; |
| 4158 | } |
| 4159 | |
| 4160 | os_memset(&ll, 0, sizeof(ll)); |
| 4161 | ll.sll_family = AF_PACKET; |
| 4162 | ll.sll_ifindex = bss->ifindex; |
| 4163 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4164 | ll.sll_halen = ETH_ALEN; |
| 4165 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4166 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4167 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4168 | if (ret < 0) |
| 4169 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4170 | strerror(errno)); |
| 4171 | |
| 4172 | return ret; |
| 4173 | } |
| 4174 | |
| 4175 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4176 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4177 | |
| 4178 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4179 | void *priv, const u8 *addr, const u8 *data, |
| 4180 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4181 | { |
| 4182 | struct i802_bss *bss = priv; |
| 4183 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4184 | struct ieee80211_hdr *hdr; |
| 4185 | size_t len; |
| 4186 | u8 *pos; |
| 4187 | int res; |
| 4188 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4189 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4190 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4191 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4192 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4193 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4194 | data_len; |
| 4195 | hdr = os_zalloc(len); |
| 4196 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4197 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4198 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4199 | return -1; |
| 4200 | } |
| 4201 | |
| 4202 | hdr->frame_control = |
| 4203 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4204 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4205 | if (encrypt) |
| 4206 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4207 | if (qos) { |
| 4208 | hdr->frame_control |= |
| 4209 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4210 | } |
| 4211 | |
| 4212 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4213 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4214 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4215 | pos = (u8 *) (hdr + 1); |
| 4216 | |
| 4217 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4218 | /* Set highest priority in QoS header */ |
| 4219 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4220 | pos[1] = 0; |
| 4221 | pos += 2; |
| 4222 | } |
| 4223 | |
| 4224 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4225 | pos += sizeof(rfc1042_header); |
| 4226 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4227 | pos += 2; |
| 4228 | memcpy(pos, data, data_len); |
| 4229 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4230 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
| 4231 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4232 | if (res < 0) { |
| 4233 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4234 | "failed: %d (%s)", |
| 4235 | (unsigned long) len, errno, strerror(errno)); |
| 4236 | } |
| 4237 | os_free(hdr); |
| 4238 | |
| 4239 | return res; |
| 4240 | } |
| 4241 | |
| 4242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4243 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
| 4244 | int total_flags, |
| 4245 | int flags_or, int flags_and) |
| 4246 | { |
| 4247 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4248 | struct nl_msg *msg; |
| 4249 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4250 | struct nl80211_sta_flag_update upd; |
| 4251 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4252 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4253 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4254 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4255 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4256 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4257 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4258 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4259 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4260 | |
| 4261 | /* |
| 4262 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4263 | * can be removed eventually. |
| 4264 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4265 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4266 | if (!flags || |
| 4267 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4268 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4269 | ((total_flags & WPA_STA_WMM) && |
| 4270 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4271 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4272 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4273 | ((total_flags & WPA_STA_MFP) && |
| 4274 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4275 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4276 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4277 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4278 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4279 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4280 | |
| 4281 | os_memset(&upd, 0, sizeof(upd)); |
| 4282 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4283 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4284 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4285 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4286 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4287 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4288 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4289 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4290 | return -ENOBUFS; |
| 4291 | } |
| 4292 | |
| 4293 | |
| 4294 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4295 | struct wpa_driver_associate_params *params) |
| 4296 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4297 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4298 | |
| 4299 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4300 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4301 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4302 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4303 | } else |
| 4304 | nlmode = NL80211_IFTYPE_AP; |
| 4305 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4306 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4307 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4308 | nl80211_remove_monitor_interface(drv); |
| 4309 | return -1; |
| 4310 | } |
| 4311 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4312 | if (params->freq.freq && |
| 4313 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4314 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4315 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4316 | nl80211_remove_monitor_interface(drv); |
| 4317 | return -1; |
| 4318 | } |
| 4319 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4320 | return 0; |
| 4321 | } |
| 4322 | |
| 4323 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4324 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 4325 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4326 | { |
| 4327 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4328 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4329 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4330 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4331 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4332 | if (ret) { |
| 4333 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 4334 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4335 | } else { |
| 4336 | wpa_printf(MSG_DEBUG, |
| 4337 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4338 | } |
| 4339 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4340 | if (reset_mode && |
| 4341 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4342 | NL80211_IFTYPE_STATION)) { |
| 4343 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4344 | "station mode"); |
| 4345 | } |
| 4346 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4347 | return ret; |
| 4348 | } |
| 4349 | |
| 4350 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4351 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 4352 | struct wpa_driver_associate_params *params) |
| 4353 | { |
| 4354 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 4355 | return -1; |
| 4356 | |
| 4357 | if (params->htcaps && params->htcaps_mask) { |
| 4358 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 4359 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 4360 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 4361 | params->htcaps_mask, sz); |
| 4362 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 4363 | params->htcaps) || |
| 4364 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 4365 | params->htcaps_mask)) |
| 4366 | return -1; |
| 4367 | } |
| 4368 | |
| 4369 | #ifdef CONFIG_VHT_OVERRIDES |
| 4370 | if (params->disable_vht) { |
| 4371 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 4372 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 4373 | return -1; |
| 4374 | } |
| 4375 | |
| 4376 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 4377 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 4378 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 4379 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 4380 | params->vhtcaps_mask, sz); |
| 4381 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 4382 | params->vhtcaps) || |
| 4383 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 4384 | params->vhtcaps_mask)) |
| 4385 | return -1; |
| 4386 | } |
| 4387 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 4388 | |
| 4389 | return 0; |
| 4390 | } |
| 4391 | |
| 4392 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4393 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 4394 | struct wpa_driver_associate_params *params) |
| 4395 | { |
| 4396 | struct nl_msg *msg; |
| 4397 | int ret = -1; |
| 4398 | int count = 0; |
| 4399 | |
| 4400 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 4401 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4402 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4403 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4404 | "IBSS mode"); |
| 4405 | return -1; |
| 4406 | } |
| 4407 | |
| 4408 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4409 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 4410 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 4411 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4412 | |
| 4413 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4414 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4415 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4416 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4417 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4418 | drv->ssid_len = params->ssid_len; |
| 4419 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4420 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 4421 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4422 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4423 | |
| 4424 | ret = nl80211_set_conn_keys(params, msg); |
| 4425 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4426 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4427 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4428 | if (params->bssid && params->fixed_bssid) { |
| 4429 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 4430 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4431 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4432 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4433 | } |
| 4434 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4435 | if (params->fixed_freq) { |
| 4436 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 4437 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 4438 | goto fail; |
| 4439 | } |
| 4440 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4441 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4442 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4443 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 4444 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4445 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4446 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4447 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4448 | } |
| 4449 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4450 | if (params->wpa_ie) { |
| 4451 | wpa_hexdump(MSG_DEBUG, |
| 4452 | " * Extra IEs for Beacon/Probe Response frames", |
| 4453 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4454 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 4455 | params->wpa_ie)) |
| 4456 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4457 | } |
| 4458 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4459 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
| 4460 | return -1; |
| 4461 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4462 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4463 | msg = NULL; |
| 4464 | if (ret) { |
| 4465 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 4466 | ret, strerror(-ret)); |
| 4467 | count++; |
| 4468 | if (ret == -EALREADY && count == 1) { |
| 4469 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 4470 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4471 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4472 | nlmsg_free(msg); |
| 4473 | goto retry; |
| 4474 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4475 | } else { |
| 4476 | wpa_printf(MSG_DEBUG, |
| 4477 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4478 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4479 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4480 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4481 | nlmsg_free(msg); |
| 4482 | return ret; |
| 4483 | } |
| 4484 | |
| 4485 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4486 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 4487 | struct wpa_driver_associate_params *params, |
| 4488 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4489 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4490 | if (params->bssid) { |
| 4491 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4492 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4493 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4494 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4495 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4496 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4497 | if (params->bssid_hint) { |
| 4498 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 4499 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4500 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 4501 | params->bssid_hint)) |
| 4502 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4503 | } |
| 4504 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4505 | if (params->freq.freq) { |
| 4506 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4507 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 4508 | params->freq.freq)) |
| 4509 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4510 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4511 | } else |
| 4512 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4513 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4514 | if (params->freq_hint) { |
| 4515 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 4517 | params->freq_hint)) |
| 4518 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4519 | } |
| 4520 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4521 | if (params->bg_scan_period >= 0) { |
| 4522 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 4523 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4524 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 4525 | params->bg_scan_period)) |
| 4526 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4527 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4528 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4529 | if (params->ssid) { |
| 4530 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4531 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4532 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4533 | params->ssid)) |
| 4534 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4535 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4536 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4537 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4538 | drv->ssid_len = params->ssid_len; |
| 4539 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4540 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4541 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4542 | if (params->wpa_ie && |
| 4543 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 4544 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4545 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4546 | if (params->wpa_proto) { |
| 4547 | enum nl80211_wpa_versions ver = 0; |
| 4548 | |
| 4549 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 4550 | ver |= NL80211_WPA_VERSION_1; |
| 4551 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 4552 | ver |= NL80211_WPA_VERSION_2; |
| 4553 | |
| 4554 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4555 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4556 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 4560 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 4561 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4562 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4563 | cipher)) |
| 4564 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4565 | } |
| 4566 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4567 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 4568 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 4569 | /* |
| 4570 | * This is likely to work even though many drivers do not |
| 4571 | * advertise support for operations without GTK. |
| 4572 | */ |
| 4573 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 4574 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4575 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 4576 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4577 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 4578 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4582 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4583 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 4584 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4585 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4586 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 4587 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4588 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4589 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
| 4590 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4591 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 4592 | |
| 4593 | switch (params->key_mgmt_suite) { |
| 4594 | case WPA_KEY_MGMT_CCKM: |
| 4595 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 4596 | break; |
| 4597 | case WPA_KEY_MGMT_IEEE8021X: |
| 4598 | mgmt = WLAN_AKM_SUITE_8021X; |
| 4599 | break; |
| 4600 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 4601 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 4602 | break; |
| 4603 | case WPA_KEY_MGMT_FT_PSK: |
| 4604 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 4605 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4606 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 4607 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; |
| 4608 | break; |
| 4609 | case WPA_KEY_MGMT_PSK_SHA256: |
| 4610 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; |
| 4611 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4612 | case WPA_KEY_MGMT_OSEN: |
| 4613 | mgmt = WLAN_AKM_SUITE_OSEN; |
| 4614 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4615 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 4616 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; |
| 4617 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4618 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
| 4619 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; |
| 4620 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4621 | case WPA_KEY_MGMT_PSK: |
| 4622 | default: |
| 4623 | mgmt = WLAN_AKM_SUITE_PSK; |
| 4624 | break; |
| 4625 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4626 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4627 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 4628 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4629 | } |
| 4630 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4631 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4632 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4633 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4634 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 4635 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 4636 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4637 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4638 | if (params->rrm_used) { |
| 4639 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
| 4640 | if (!(drv_rrm_flags & |
| 4641 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) || |
| 4642 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) || |
| 4643 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 4644 | return -1; |
| 4645 | } |
| 4646 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4647 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4648 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4649 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4650 | if (params->p2p) |
| 4651 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 4652 | |
| 4653 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | |
| 4657 | static int wpa_driver_nl80211_try_connect( |
| 4658 | struct wpa_driver_nl80211_data *drv, |
| 4659 | struct wpa_driver_associate_params *params) |
| 4660 | { |
| 4661 | struct nl_msg *msg; |
| 4662 | enum nl80211_auth_type type; |
| 4663 | int ret; |
| 4664 | int algs; |
| 4665 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4666 | if (params->req_key_mgmt_offload && params->psk && |
| 4667 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4668 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 4669 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 4670 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 4671 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 4672 | if (ret) |
| 4673 | return ret; |
| 4674 | } |
| 4675 | |
| 4676 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 4677 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4678 | if (!msg) |
| 4679 | return -1; |
| 4680 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4681 | ret = nl80211_connect_common(drv, params, msg); |
| 4682 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4683 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4684 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4685 | algs = 0; |
| 4686 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4687 | algs++; |
| 4688 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4689 | algs++; |
| 4690 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4691 | algs++; |
| 4692 | if (algs > 1) { |
| 4693 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 4694 | "selection"); |
| 4695 | goto skip_auth_type; |
| 4696 | } |
| 4697 | |
| 4698 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4699 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 4700 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4701 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 4702 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4703 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 4704 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 4705 | type = NL80211_AUTHTYPE_FT; |
| 4706 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4707 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4708 | |
| 4709 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4710 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 4711 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4712 | |
| 4713 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4714 | ret = nl80211_set_conn_keys(params, msg); |
| 4715 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4716 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4717 | |
| 4718 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4719 | msg = NULL; |
| 4720 | if (ret) { |
| 4721 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 4722 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4723 | } else { |
| 4724 | wpa_printf(MSG_DEBUG, |
| 4725 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4726 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4727 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4728 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4729 | nlmsg_free(msg); |
| 4730 | return ret; |
| 4731 | |
| 4732 | } |
| 4733 | |
| 4734 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4735 | static int wpa_driver_nl80211_connect( |
| 4736 | struct wpa_driver_nl80211_data *drv, |
| 4737 | struct wpa_driver_associate_params *params) |
| 4738 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 4739 | int ret; |
| 4740 | |
| 4741 | /* Store the connection attempted bssid for future use */ |
| 4742 | if (params->bssid) |
| 4743 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 4744 | else |
| 4745 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 4746 | |
| 4747 | ret = wpa_driver_nl80211_try_connect(drv, params); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4748 | if (ret == -EALREADY) { |
| 4749 | /* |
| 4750 | * cfg80211 does not currently accept new connections if |
| 4751 | * we are already connected. As a workaround, force |
| 4752 | * disconnection and try again. |
| 4753 | */ |
| 4754 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 4755 | "disconnecting before reassociation " |
| 4756 | "attempt"); |
| 4757 | if (wpa_driver_nl80211_disconnect( |
| 4758 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 4759 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4760 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 4761 | } |
| 4762 | return ret; |
| 4763 | } |
| 4764 | |
| 4765 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4766 | static int wpa_driver_nl80211_associate( |
| 4767 | void *priv, struct wpa_driver_associate_params *params) |
| 4768 | { |
| 4769 | struct i802_bss *bss = priv; |
| 4770 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4771 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4772 | struct nl_msg *msg; |
| 4773 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4774 | nl80211_unmask_11b_rates(bss); |
| 4775 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4776 | if (params->mode == IEEE80211_MODE_AP) |
| 4777 | return wpa_driver_nl80211_ap(drv, params); |
| 4778 | |
| 4779 | if (params->mode == IEEE80211_MODE_IBSS) |
| 4780 | return wpa_driver_nl80211_ibss(drv, params); |
| 4781 | |
| 4782 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4783 | enum nl80211_iftype nlmode = params->p2p ? |
| 4784 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 4785 | |
| 4786 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4787 | return -1; |
| 4788 | return wpa_driver_nl80211_connect(drv, params); |
| 4789 | } |
| 4790 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4791 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4792 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4793 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 4794 | drv->ifindex); |
| 4795 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4796 | if (!msg) |
| 4797 | return -1; |
| 4798 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4799 | ret = nl80211_connect_common(drv, params, msg); |
| 4800 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4801 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4802 | |
| 4803 | if (params->prev_bssid) { |
| 4804 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 4805 | MAC2STR(params->prev_bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4806 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 4807 | params->prev_bssid)) |
| 4808 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4809 | } |
| 4810 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4811 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4812 | msg = NULL; |
| 4813 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4814 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 4815 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 4816 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4817 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4818 | } else { |
| 4819 | wpa_printf(MSG_DEBUG, |
| 4820 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4821 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4822 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4823 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4824 | nlmsg_free(msg); |
| 4825 | return ret; |
| 4826 | } |
| 4827 | |
| 4828 | |
| 4829 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4830 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4831 | { |
| 4832 | struct nl_msg *msg; |
| 4833 | int ret = -ENOBUFS; |
| 4834 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4835 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 4836 | ifindex, mode, nl80211_iftype_str(mode)); |
| 4837 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4838 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 4839 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 4840 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4841 | |
| 4842 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4843 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4844 | if (!ret) |
| 4845 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4846 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4847 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4848 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 4849 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 4850 | return ret; |
| 4851 | } |
| 4852 | |
| 4853 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4854 | static int wpa_driver_nl80211_set_mode_impl( |
| 4855 | struct i802_bss *bss, |
| 4856 | enum nl80211_iftype nlmode, |
| 4857 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4858 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4859 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4860 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4861 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4862 | int was_ap = is_ap_interface(drv->nlmode); |
| 4863 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4864 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4865 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4866 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 4867 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 4868 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4869 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4870 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4871 | drv->nlmode = nlmode; |
| 4872 | ret = 0; |
| 4873 | goto done; |
| 4874 | } |
| 4875 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4876 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4877 | return -1; |
| 4878 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4879 | if (nlmode == drv->nlmode) { |
| 4880 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 4881 | "requested mode - ignore error"); |
| 4882 | ret = 0; |
| 4883 | goto done; /* Already in the requested mode */ |
| 4884 | } |
| 4885 | |
| 4886 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 4887 | * take the device down, try to set the mode again, and bring the |
| 4888 | * device back up. |
| 4889 | */ |
| 4890 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 4891 | "interface down"); |
| 4892 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4893 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4894 | if (res == -EACCES || res == -ENODEV) |
| 4895 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4896 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4897 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 4898 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4899 | os_sleep(0, 100000); |
| 4900 | continue; |
| 4901 | } |
| 4902 | |
| 4903 | /* |
| 4904 | * Setting the mode will fail for some drivers if the phy is |
| 4905 | * on a frequency that the mode is disallowed in. |
| 4906 | */ |
| 4907 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4908 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4909 | if (res) { |
| 4910 | wpa_printf(MSG_DEBUG, |
| 4911 | "nl80211: Failed to set frequency on interface"); |
| 4912 | } |
| 4913 | } |
| 4914 | |
| 4915 | /* Try to set the mode again while the interface is down */ |
| 4916 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 4917 | if (mode_switch_res == -EBUSY) { |
| 4918 | wpa_printf(MSG_DEBUG, |
| 4919 | "nl80211: Delaying mode set while interface going down"); |
| 4920 | os_sleep(0, 100000); |
| 4921 | continue; |
| 4922 | } |
| 4923 | ret = mode_switch_res; |
| 4924 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | if (!ret) { |
| 4928 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 4929 | "interface is down"); |
| 4930 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4931 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4934 | /* Bring the interface back up */ |
| 4935 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 4936 | if (res != 0) { |
| 4937 | wpa_printf(MSG_DEBUG, |
| 4938 | "nl80211: Failed to set interface up after switching mode"); |
| 4939 | ret = -1; |
| 4940 | } |
| 4941 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4942 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4943 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4944 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 4945 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4946 | return ret; |
| 4947 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4948 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4949 | if (is_p2p_net_interface(nlmode)) { |
| 4950 | wpa_printf(MSG_DEBUG, |
| 4951 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 4952 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4953 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4954 | } else if (drv->disabled_11b_rates) { |
| 4955 | wpa_printf(MSG_DEBUG, |
| 4956 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 4957 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4958 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4959 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4960 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4961 | if (is_ap_interface(nlmode)) { |
| 4962 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 4963 | /* Setup additional AP mode functionality if needed */ |
| 4964 | if (nl80211_setup_ap(bss)) |
| 4965 | return -1; |
| 4966 | } else if (was_ap) { |
| 4967 | /* Remove additional AP mode functionality */ |
| 4968 | nl80211_teardown_ap(bss); |
| 4969 | } else { |
| 4970 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 4971 | } |
| 4972 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4973 | if (is_mesh_interface(nlmode) && |
| 4974 | nl80211_mgmt_subscribe_mesh(bss)) |
| 4975 | return -1; |
| 4976 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4977 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4978 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4979 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 4980 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 4981 | "frame processing - ignore for now"); |
| 4982 | |
| 4983 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4987 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 4988 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4989 | { |
| 4990 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 4991 | } |
| 4992 | |
| 4993 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4994 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 4995 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4996 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4997 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4998 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5002 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5003 | struct wpa_driver_capa *capa) |
| 5004 | { |
| 5005 | struct i802_bss *bss = priv; |
| 5006 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5007 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5008 | if (!drv->has_capability) |
| 5009 | return -1; |
| 5010 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5011 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5012 | capa->extended_capa = drv->extended_capa; |
| 5013 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5014 | capa->extended_capa_len = drv->extended_capa_len; |
| 5015 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5016 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5017 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | |
| 5021 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5022 | { |
| 5023 | struct i802_bss *bss = priv; |
| 5024 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5025 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5026 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5027 | bss->ifname, drv->operstate, state, |
| 5028 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5029 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5030 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5031 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5032 | } |
| 5033 | |
| 5034 | |
| 5035 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5036 | { |
| 5037 | struct i802_bss *bss = priv; |
| 5038 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5039 | struct nl_msg *msg; |
| 5040 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5041 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5042 | |
| 5043 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5044 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5045 | return 0; |
| 5046 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5047 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5048 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5049 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5050 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5051 | os_memset(&upd, 0, sizeof(upd)); |
| 5052 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5053 | if (authorized) |
| 5054 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5055 | |
| 5056 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5057 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5058 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5059 | nlmsg_free(msg); |
| 5060 | return -ENOBUFS; |
| 5061 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5062 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5063 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5064 | if (!ret) |
| 5065 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5066 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5067 | ret, strerror(-ret)); |
| 5068 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5072 | /* Set kernel driver on given frequency (MHz) */ |
| 5073 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5074 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5075 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5076 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5080 | static inline int min_int(int a, int b) |
| 5081 | { |
| 5082 | if (a < b) |
| 5083 | return a; |
| 5084 | return b; |
| 5085 | } |
| 5086 | |
| 5087 | |
| 5088 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5089 | { |
| 5090 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5091 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5092 | |
| 5093 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5094 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5095 | |
| 5096 | /* |
| 5097 | * TODO: validate the key index and mac address! |
| 5098 | * Otherwise, there's a race condition as soon as |
| 5099 | * the kernel starts sending key notifications. |
| 5100 | */ |
| 5101 | |
| 5102 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5103 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5104 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5105 | return NL_SKIP; |
| 5106 | } |
| 5107 | |
| 5108 | |
| 5109 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5110 | int idx, u8 *seq) |
| 5111 | { |
| 5112 | struct i802_bss *bss = priv; |
| 5113 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5114 | struct nl_msg *msg; |
| 5115 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5116 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5117 | NL80211_CMD_GET_KEY); |
| 5118 | if (!msg || |
| 5119 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5120 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5121 | nlmsg_free(msg); |
| 5122 | return -ENOBUFS; |
| 5123 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5124 | |
| 5125 | memset(seq, 0, 6); |
| 5126 | |
| 5127 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5128 | } |
| 5129 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5130 | |
| 5131 | static int i802_set_rts(void *priv, int rts) |
| 5132 | { |
| 5133 | struct i802_bss *bss = priv; |
| 5134 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5135 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5136 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5137 | u32 val; |
| 5138 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5139 | if (rts >= 2347) |
| 5140 | val = (u32) -1; |
| 5141 | else |
| 5142 | val = rts; |
| 5143 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5144 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5145 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5146 | nlmsg_free(msg); |
| 5147 | return -ENOBUFS; |
| 5148 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5149 | |
| 5150 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5151 | if (!ret) |
| 5152 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5153 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5154 | "%d (%s)", rts, ret, strerror(-ret)); |
| 5155 | return ret; |
| 5156 | } |
| 5157 | |
| 5158 | |
| 5159 | static int i802_set_frag(void *priv, int frag) |
| 5160 | { |
| 5161 | struct i802_bss *bss = priv; |
| 5162 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5163 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5164 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5165 | u32 val; |
| 5166 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5167 | if (frag >= 2346) |
| 5168 | val = (u32) -1; |
| 5169 | else |
| 5170 | val = frag; |
| 5171 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5172 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5173 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 5174 | nlmsg_free(msg); |
| 5175 | return -ENOBUFS; |
| 5176 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5177 | |
| 5178 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5179 | if (!ret) |
| 5180 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5181 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 5182 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 5183 | return ret; |
| 5184 | } |
| 5185 | |
| 5186 | |
| 5187 | static int i802_flush(void *priv) |
| 5188 | { |
| 5189 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5190 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5191 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5192 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5193 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 5194 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5195 | |
| 5196 | /* |
| 5197 | * XXX: FIX! this needs to flush all VLANs too |
| 5198 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5199 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 5200 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5201 | if (res) { |
| 5202 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 5203 | "(%s)", res, strerror(-res)); |
| 5204 | } |
| 5205 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5206 | } |
| 5207 | |
| 5208 | |
| 5209 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 5210 | { |
| 5211 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5212 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5213 | struct hostap_sta_driver_data *data = arg; |
| 5214 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 5215 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 5216 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 5217 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 5218 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 5219 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 5220 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5221 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5222 | }; |
| 5223 | |
| 5224 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5225 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5226 | |
| 5227 | /* |
| 5228 | * TODO: validate the interface and mac address! |
| 5229 | * Otherwise, there's a race condition as soon as |
| 5230 | * the kernel starts sending station notifications. |
| 5231 | */ |
| 5232 | |
| 5233 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 5234 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 5235 | return NL_SKIP; |
| 5236 | } |
| 5237 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 5238 | tb[NL80211_ATTR_STA_INFO], |
| 5239 | stats_policy)) { |
| 5240 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 5241 | return NL_SKIP; |
| 5242 | } |
| 5243 | |
| 5244 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 5245 | data->inactive_msec = |
| 5246 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
| 5247 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 5248 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 5249 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 5250 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
| 5251 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 5252 | data->rx_packets = |
| 5253 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 5254 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 5255 | data->tx_packets = |
| 5256 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5257 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 5258 | data->tx_retry_failed = |
| 5259 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5260 | |
| 5261 | return NL_SKIP; |
| 5262 | } |
| 5263 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5264 | static int i802_read_sta_data(struct i802_bss *bss, |
| 5265 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5266 | const u8 *addr) |
| 5267 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5268 | struct nl_msg *msg; |
| 5269 | |
| 5270 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5271 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5272 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 5273 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 5274 | nlmsg_free(msg); |
| 5275 | return -ENOBUFS; |
| 5276 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5277 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5278 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | |
| 5282 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 5283 | int cw_min, int cw_max, int burst_time) |
| 5284 | { |
| 5285 | struct i802_bss *bss = priv; |
| 5286 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5287 | struct nl_msg *msg; |
| 5288 | struct nlattr *txq, *params; |
| 5289 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5290 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5291 | if (!msg) |
| 5292 | return -1; |
| 5293 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5294 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 5295 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5296 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5297 | |
| 5298 | /* We are only sending parameters for a single TXQ at a time */ |
| 5299 | params = nla_nest_start(msg, 1); |
| 5300 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5301 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5302 | |
| 5303 | switch (queue) { |
| 5304 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5305 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 5306 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5307 | break; |
| 5308 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5309 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 5310 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5311 | break; |
| 5312 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5313 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 5314 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5315 | break; |
| 5316 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5317 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 5318 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5319 | break; |
| 5320 | } |
| 5321 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 5322 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5323 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 5324 | (burst_time * 100 + 16) / 32) || |
| 5325 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 5326 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 5327 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 5328 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5329 | |
| 5330 | nla_nest_end(msg, params); |
| 5331 | |
| 5332 | nla_nest_end(msg, txq); |
| 5333 | |
| 5334 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 5335 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5336 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5337 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5338 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5339 | return -1; |
| 5340 | } |
| 5341 | |
| 5342 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5343 | 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] | 5344 | const char *ifname, int vlan_id) |
| 5345 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5346 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5347 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5348 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5349 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5350 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 5351 | ", ifname=%s[%d], vlan_id=%d)", |
| 5352 | bss->ifname, if_nametoindex(bss->ifname), |
| 5353 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5354 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5355 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5356 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 5357 | nlmsg_free(msg); |
| 5358 | return -ENOBUFS; |
| 5359 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5360 | |
| 5361 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5362 | if (ret < 0) { |
| 5363 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 5364 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 5365 | MAC2STR(addr), ifname, vlan_id, ret, |
| 5366 | strerror(-ret)); |
| 5367 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5368 | return ret; |
| 5369 | } |
| 5370 | |
| 5371 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5372 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 5373 | { |
| 5374 | struct hostap_sta_driver_data data; |
| 5375 | int ret; |
| 5376 | |
| 5377 | data.inactive_msec = (unsigned long) -1; |
| 5378 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5379 | if (ret == -ENOENT) |
| 5380 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5381 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 5382 | return -1; |
| 5383 | return data.inactive_msec / 1000; |
| 5384 | } |
| 5385 | |
| 5386 | |
| 5387 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 5388 | { |
| 5389 | #if 0 |
| 5390 | /* TODO */ |
| 5391 | #endif |
| 5392 | return 0; |
| 5393 | } |
| 5394 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5395 | |
| 5396 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 5397 | int reason) |
| 5398 | { |
| 5399 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5400 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5401 | struct ieee80211_mgmt mgmt; |
| 5402 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5403 | if (is_mesh_interface(drv->nlmode)) |
| 5404 | return -1; |
| 5405 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5406 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5407 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5408 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5409 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5410 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5411 | WLAN_FC_STYPE_DEAUTH); |
| 5412 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5413 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5414 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5415 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 5416 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5417 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5418 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
| 5419 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | |
| 5423 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 5424 | int reason) |
| 5425 | { |
| 5426 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5427 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5428 | struct ieee80211_mgmt mgmt; |
| 5429 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5430 | if (is_mesh_interface(drv->nlmode)) |
| 5431 | return -1; |
| 5432 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5433 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5434 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5435 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5436 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5437 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5438 | WLAN_FC_STYPE_DISASSOC); |
| 5439 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5440 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5441 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5442 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 5443 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5444 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5445 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
| 5446 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5447 | } |
| 5448 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5449 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5450 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 5451 | { |
| 5452 | char buf[200], *pos, *end; |
| 5453 | int i, res; |
| 5454 | |
| 5455 | pos = buf; |
| 5456 | end = pos + sizeof(buf); |
| 5457 | |
| 5458 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5459 | if (!drv->if_indices[i]) |
| 5460 | continue; |
| 5461 | res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5462 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5463 | break; |
| 5464 | pos += res; |
| 5465 | } |
| 5466 | *pos = '\0'; |
| 5467 | |
| 5468 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 5469 | drv->num_if_indices, buf); |
| 5470 | } |
| 5471 | |
| 5472 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5473 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5474 | { |
| 5475 | int i; |
| 5476 | int *old; |
| 5477 | |
| 5478 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", |
| 5479 | ifidx); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5480 | if (have_ifidx(drv, ifidx)) { |
| 5481 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 5482 | ifidx); |
| 5483 | return; |
| 5484 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5485 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5486 | if (drv->if_indices[i] == 0) { |
| 5487 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5488 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5489 | return; |
| 5490 | } |
| 5491 | } |
| 5492 | |
| 5493 | if (drv->if_indices != drv->default_if_indices) |
| 5494 | old = drv->if_indices; |
| 5495 | else |
| 5496 | old = NULL; |
| 5497 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5498 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 5499 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5500 | if (!drv->if_indices) { |
| 5501 | if (!old) |
| 5502 | drv->if_indices = drv->default_if_indices; |
| 5503 | else |
| 5504 | drv->if_indices = old; |
| 5505 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 5506 | "interfaces"); |
| 5507 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 5508 | return; |
| 5509 | } else if (!old) |
| 5510 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 5511 | sizeof(drv->default_if_indices)); |
| 5512 | drv->if_indices[drv->num_if_indices] = ifidx; |
| 5513 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5514 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | |
| 5518 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5519 | { |
| 5520 | int i; |
| 5521 | |
| 5522 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5523 | if (drv->if_indices[i] == ifidx) { |
| 5524 | drv->if_indices[i] = 0; |
| 5525 | break; |
| 5526 | } |
| 5527 | } |
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 | } |
| 5530 | |
| 5531 | |
| 5532 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5533 | { |
| 5534 | int i; |
| 5535 | |
| 5536 | for (i = 0; i < drv->num_if_indices; i++) |
| 5537 | if (drv->if_indices[i] == ifidx) |
| 5538 | return 1; |
| 5539 | |
| 5540 | return 0; |
| 5541 | } |
| 5542 | |
| 5543 | |
| 5544 | 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] | 5545 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5546 | { |
| 5547 | struct i802_bss *bss = priv; |
| 5548 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5549 | char name[IFNAMSIZ + 1]; |
| 5550 | |
| 5551 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5552 | if (ifname_wds) |
| 5553 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 5554 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5555 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 5556 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 5557 | if (val) { |
| 5558 | if (!if_nametoindex(name)) { |
| 5559 | if (nl80211_create_iface(drv, name, |
| 5560 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5561 | bss->addr, 1, NULL, NULL, 0) < |
| 5562 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5563 | return -1; |
| 5564 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5565 | linux_br_add_if(drv->global->ioctl_sock, |
| 5566 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5567 | return -1; |
| 5568 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5569 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 5570 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 5571 | "interface %s up", name); |
| 5572 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5573 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 5574 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5575 | if (bridge_ifname) |
| 5576 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 5577 | name); |
| 5578 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5579 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 5580 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 5581 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | |
| 5586 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 5587 | { |
| 5588 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 5589 | struct sockaddr_ll lladdr; |
| 5590 | unsigned char buf[3000]; |
| 5591 | int len; |
| 5592 | socklen_t fromlen = sizeof(lladdr); |
| 5593 | |
| 5594 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 5595 | (struct sockaddr *)&lladdr, &fromlen); |
| 5596 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5597 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 5598 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5599 | return; |
| 5600 | } |
| 5601 | |
| 5602 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
| 5603 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 5604 | } |
| 5605 | |
| 5606 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5607 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 5608 | struct i802_bss *bss, |
| 5609 | const char *brname, const char *ifname) |
| 5610 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5611 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5612 | char in_br[IFNAMSIZ]; |
| 5613 | |
| 5614 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5615 | br_ifindex = if_nametoindex(brname); |
| 5616 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5617 | /* |
| 5618 | * Bridge was configured, but the bridge device does |
| 5619 | * not exist. Try to add it now. |
| 5620 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5621 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5622 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 5623 | "bridge interface %s: %s", |
| 5624 | brname, strerror(errno)); |
| 5625 | return -1; |
| 5626 | } |
| 5627 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5628 | br_ifindex = if_nametoindex(brname); |
| 5629 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5630 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5631 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5632 | |
| 5633 | if (linux_br_get(in_br, ifname) == 0) { |
| 5634 | if (os_strcmp(in_br, brname) == 0) |
| 5635 | return 0; /* already in the bridge */ |
| 5636 | |
| 5637 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 5638 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5639 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 5640 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5641 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 5642 | "remove interface %s from bridge " |
| 5643 | "%s: %s", |
| 5644 | ifname, brname, strerror(errno)); |
| 5645 | return -1; |
| 5646 | } |
| 5647 | } |
| 5648 | |
| 5649 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 5650 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5651 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5652 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 5653 | "into bridge %s: %s", |
| 5654 | ifname, brname, strerror(errno)); |
| 5655 | return -1; |
| 5656 | } |
| 5657 | bss->added_if_into_bridge = 1; |
| 5658 | |
| 5659 | return 0; |
| 5660 | } |
| 5661 | |
| 5662 | |
| 5663 | static void *i802_init(struct hostapd_data *hapd, |
| 5664 | struct wpa_init_params *params) |
| 5665 | { |
| 5666 | struct wpa_driver_nl80211_data *drv; |
| 5667 | struct i802_bss *bss; |
| 5668 | size_t i; |
| 5669 | char brname[IFNAMSIZ]; |
| 5670 | int ifindex, br_ifindex; |
| 5671 | int br_added = 0; |
| 5672 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5673 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 5674 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5675 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5676 | if (bss == NULL) |
| 5677 | return NULL; |
| 5678 | |
| 5679 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5680 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5681 | if (linux_br_get(brname, params->ifname) == 0) { |
| 5682 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
| 5683 | params->ifname, brname); |
| 5684 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5685 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5686 | } else { |
| 5687 | brname[0] = '\0'; |
| 5688 | br_ifindex = 0; |
| 5689 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5690 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5691 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5692 | for (i = 0; i < params->num_bridge; i++) { |
| 5693 | if (params->bridge[i]) { |
| 5694 | ifindex = if_nametoindex(params->bridge[i]); |
| 5695 | if (ifindex) |
| 5696 | add_ifidx(drv, ifindex); |
| 5697 | if (ifindex == br_ifindex) |
| 5698 | br_added = 1; |
| 5699 | } |
| 5700 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5701 | |
| 5702 | /* start listening for EAPOL on the default AP interface */ |
| 5703 | add_ifidx(drv, drv->ifindex); |
| 5704 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5705 | if (params->num_bridge && params->bridge[0]) { |
| 5706 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 5707 | params->ifname) < 0) |
| 5708 | goto failed; |
| 5709 | if (os_strcmp(params->bridge[0], brname) != 0) |
| 5710 | br_added = 1; |
| 5711 | } |
| 5712 | |
| 5713 | if (!br_added && br_ifindex && |
| 5714 | (params->num_bridge == 0 || !params->bridge[0])) |
| 5715 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5716 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5717 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5718 | if (bss->added_if_into_bridge) { |
| 5719 | drv->rtnl_sk = nl_socket_alloc(); |
| 5720 | if (drv->rtnl_sk == NULL) { |
| 5721 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 5722 | goto failed; |
| 5723 | } |
| 5724 | |
| 5725 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 5726 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 5727 | strerror(errno)); |
| 5728 | goto failed; |
| 5729 | } |
| 5730 | } |
| 5731 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5732 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5733 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 5734 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5735 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 5736 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5737 | goto failed; |
| 5738 | } |
| 5739 | |
| 5740 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 5741 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5742 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5743 | goto failed; |
| 5744 | } |
| 5745 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5746 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 5747 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5748 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5749 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5750 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5751 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 5752 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5753 | return bss; |
| 5754 | |
| 5755 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5756 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5757 | return NULL; |
| 5758 | } |
| 5759 | |
| 5760 | |
| 5761 | static void i802_deinit(void *priv) |
| 5762 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5763 | struct i802_bss *bss = priv; |
| 5764 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5765 | } |
| 5766 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5767 | |
| 5768 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 5769 | enum wpa_driver_if_type type) |
| 5770 | { |
| 5771 | switch (type) { |
| 5772 | case WPA_IF_STATION: |
| 5773 | return NL80211_IFTYPE_STATION; |
| 5774 | case WPA_IF_P2P_CLIENT: |
| 5775 | case WPA_IF_P2P_GROUP: |
| 5776 | return NL80211_IFTYPE_P2P_CLIENT; |
| 5777 | case WPA_IF_AP_VLAN: |
| 5778 | return NL80211_IFTYPE_AP_VLAN; |
| 5779 | case WPA_IF_AP_BSS: |
| 5780 | return NL80211_IFTYPE_AP; |
| 5781 | case WPA_IF_P2P_GO: |
| 5782 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5783 | case WPA_IF_P2P_DEVICE: |
| 5784 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5785 | case WPA_IF_MESH: |
| 5786 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5787 | } |
| 5788 | return -1; |
| 5789 | } |
| 5790 | |
| 5791 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5792 | #if defined(CONFIG_P2P) || defined(CONFIG_MESH) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5793 | |
| 5794 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 5795 | { |
| 5796 | struct wpa_driver_nl80211_data *drv; |
| 5797 | dl_list_for_each(drv, &global->interfaces, |
| 5798 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5799 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5800 | return 1; |
| 5801 | } |
| 5802 | return 0; |
| 5803 | } |
| 5804 | |
| 5805 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5806 | 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] | 5807 | { |
| 5808 | unsigned int idx; |
| 5809 | |
| 5810 | if (!drv->global) |
| 5811 | return -1; |
| 5812 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5813 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5814 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5815 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5816 | new_addr[0] ^= idx << 2; |
| 5817 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 5818 | break; |
| 5819 | } |
| 5820 | if (idx == 64) |
| 5821 | return -1; |
| 5822 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5823 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5824 | MACSTR, MAC2STR(new_addr)); |
| 5825 | |
| 5826 | return 0; |
| 5827 | } |
| 5828 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5829 | #endif /* CONFIG_P2P || CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5830 | |
| 5831 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5832 | struct wdev_info { |
| 5833 | u64 wdev_id; |
| 5834 | int wdev_id_set; |
| 5835 | u8 macaddr[ETH_ALEN]; |
| 5836 | }; |
| 5837 | |
| 5838 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 5839 | { |
| 5840 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5841 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5842 | struct wdev_info *wi = arg; |
| 5843 | |
| 5844 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5845 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5846 | if (tb[NL80211_ATTR_WDEV]) { |
| 5847 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 5848 | wi->wdev_id_set = 1; |
| 5849 | } |
| 5850 | |
| 5851 | if (tb[NL80211_ATTR_MAC]) |
| 5852 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 5853 | ETH_ALEN); |
| 5854 | |
| 5855 | return NL_SKIP; |
| 5856 | } |
| 5857 | |
| 5858 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5859 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 5860 | const char *ifname, const u8 *addr, |
| 5861 | void *bss_ctx, void **drv_priv, |
| 5862 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5863 | const char *bridge, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5864 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5865 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5866 | struct i802_bss *bss = priv; |
| 5867 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5868 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5869 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5870 | |
| 5871 | if (addr) |
| 5872 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5873 | nlmode = wpa_driver_nl80211_if_type(type); |
| 5874 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 5875 | struct wdev_info p2pdev_info; |
| 5876 | |
| 5877 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 5878 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 5879 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5880 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5881 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 5882 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 5883 | ifname); |
| 5884 | return -1; |
| 5885 | } |
| 5886 | |
| 5887 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 5888 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 5889 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 5890 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 5891 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 5892 | ifname, |
| 5893 | (long long unsigned int) p2pdev_info.wdev_id); |
| 5894 | } else { |
| 5895 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5896 | 0, NULL, NULL, use_existing); |
| 5897 | if (use_existing && ifidx == -ENFILE) { |
| 5898 | added = 0; |
| 5899 | ifidx = if_nametoindex(ifname); |
| 5900 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5901 | return -1; |
| 5902 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5903 | } |
| 5904 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5905 | if (!addr) { |
| 5906 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 5907 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 5908 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 5909 | bss->ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5910 | if (added) |
| 5911 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5912 | return -1; |
| 5913 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5914 | } |
| 5915 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5916 | #if defined(CONFIG_P2P) || defined(CONFIG_MESH) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5917 | if (!addr && |
| 5918 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5919 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5920 | /* Enforce unique P2P Interface Address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5921 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5922 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5923 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5924 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5925 | if (added) |
| 5926 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5927 | return -1; |
| 5928 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5929 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5930 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5931 | "for %s interface", type == WPA_IF_MESH ? |
| 5932 | "mesh" : "P2P group"); |
| 5933 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5934 | if (added) |
| 5935 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5936 | return -1; |
| 5937 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5938 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5939 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5940 | if (added) |
| 5941 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5942 | return -1; |
| 5943 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5944 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 5945 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5946 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5947 | #endif /* CONFIG_P2P || CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5948 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5949 | if (type == WPA_IF_AP_BSS) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5950 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 5951 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5952 | if (added) |
| 5953 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5954 | return -1; |
| 5955 | } |
| 5956 | |
| 5957 | if (bridge && |
| 5958 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 5959 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 5960 | "interface %s to a bridge %s", |
| 5961 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5962 | if (added) |
| 5963 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5964 | os_free(new_bss); |
| 5965 | return -1; |
| 5966 | } |
| 5967 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5968 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 5969 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5970 | if (added) |
| 5971 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5972 | os_free(new_bss); |
| 5973 | return -1; |
| 5974 | } |
| 5975 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5976 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5977 | new_bss->ifindex = ifidx; |
| 5978 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5979 | new_bss->next = drv->first_bss->next; |
| 5980 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5981 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5982 | new_bss->added_if = added; |
| 5983 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5984 | if (drv_priv) |
| 5985 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5986 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5987 | |
| 5988 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 5989 | if (nl80211_setup_ap(new_bss)) |
| 5990 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5991 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5992 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5993 | if (drv->global) |
| 5994 | drv->global->if_add_ifindex = ifidx; |
| 5995 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5996 | /* |
| 5997 | * Some virtual interfaces need to process EAPOL packets and events on |
| 5998 | * the parent interface. This is used mainly with hostapd. |
| 5999 | */ |
| 6000 | if (ifidx > 0 && |
| 6001 | (drv->hostapd || |
| 6002 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 6003 | nlmode == NL80211_IFTYPE_WDS || |
| 6004 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6005 | add_ifidx(drv, ifidx); |
| 6006 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6007 | return 0; |
| 6008 | } |
| 6009 | |
| 6010 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6011 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6012 | enum wpa_driver_if_type type, |
| 6013 | const char *ifname) |
| 6014 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6016 | int ifindex = if_nametoindex(ifname); |
| 6017 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6018 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 6019 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6020 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6021 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6022 | else if (ifindex > 0 && !bss->added_if) { |
| 6023 | struct wpa_driver_nl80211_data *drv2; |
| 6024 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 6025 | struct wpa_driver_nl80211_data, list) |
| 6026 | del_ifidx(drv2, ifindex); |
| 6027 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6028 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6029 | if (type != WPA_IF_AP_BSS) |
| 6030 | return 0; |
| 6031 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6032 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6033 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 6034 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6035 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6036 | "interface %s from bridge %s: %s", |
| 6037 | bss->ifname, bss->brname, strerror(errno)); |
| 6038 | } |
| 6039 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6040 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6041 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6042 | "bridge %s: %s", |
| 6043 | bss->brname, strerror(errno)); |
| 6044 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6045 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6046 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6047 | struct i802_bss *tbss; |
| 6048 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6049 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 6050 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6051 | if (tbss->next == bss) { |
| 6052 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6053 | /* Unsubscribe management frames */ |
| 6054 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6055 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6056 | if (!bss->added_if) |
| 6057 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6058 | os_free(bss); |
| 6059 | bss = NULL; |
| 6060 | break; |
| 6061 | } |
| 6062 | } |
| 6063 | if (bss) |
| 6064 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 6065 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6066 | } else { |
| 6067 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 6068 | nl80211_teardown_ap(bss); |
| 6069 | if (!bss->added_if && !drv->first_bss->next) |
| 6070 | wpa_driver_nl80211_del_beacon(drv); |
| 6071 | nl80211_destroy_bss(bss); |
| 6072 | if (!bss->added_if) |
| 6073 | i802_set_iface_flags(bss, 0); |
| 6074 | if (drv->first_bss->next) { |
| 6075 | drv->first_bss = drv->first_bss->next; |
| 6076 | drv->ctx = drv->first_bss->ctx; |
| 6077 | os_free(bss); |
| 6078 | } else { |
| 6079 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 6080 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6081 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6082 | |
| 6083 | return 0; |
| 6084 | } |
| 6085 | |
| 6086 | |
| 6087 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 6088 | { |
| 6089 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6090 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6091 | u64 *cookie = arg; |
| 6092 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6093 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6094 | if (tb[NL80211_ATTR_COOKIE]) |
| 6095 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 6096 | return NL_SKIP; |
| 6097 | } |
| 6098 | |
| 6099 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6100 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6101 | unsigned int freq, unsigned int wait, |
| 6102 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6103 | u64 *cookie_out, int no_cck, int no_ack, |
| 6104 | int offchanok) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6105 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6106 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6107 | struct nl_msg *msg; |
| 6108 | u64 cookie; |
| 6109 | int ret = -1; |
| 6110 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6111 | 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] | 6112 | "no_ack=%d offchanok=%d", |
| 6113 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6114 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6115 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6116 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 6117 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 6118 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 6119 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6120 | drv->test_use_roc_tx) && |
| 6121 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 6122 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 6123 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
| 6124 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 6125 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6126 | |
| 6127 | cookie = 0; |
| 6128 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6129 | msg = NULL; |
| 6130 | if (ret) { |
| 6131 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6132 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 6133 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6134 | } else { |
| 6135 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 6136 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 6137 | (long long unsigned int) cookie); |
| 6138 | |
| 6139 | if (cookie_out) |
| 6140 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6141 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6142 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6143 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6144 | nlmsg_free(msg); |
| 6145 | return ret; |
| 6146 | } |
| 6147 | |
| 6148 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6149 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 6150 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6151 | unsigned int wait_time, |
| 6152 | const u8 *dst, const u8 *src, |
| 6153 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6154 | const u8 *data, size_t data_len, |
| 6155 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6156 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6157 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6158 | int ret = -1; |
| 6159 | u8 *buf; |
| 6160 | struct ieee80211_hdr *hdr; |
| 6161 | |
| 6162 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6163 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 6164 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6165 | |
| 6166 | buf = os_zalloc(24 + data_len); |
| 6167 | if (buf == NULL) |
| 6168 | return ret; |
| 6169 | os_memcpy(buf + 24, data, data_len); |
| 6170 | hdr = (struct ieee80211_hdr *) buf; |
| 6171 | hdr->frame_control = |
| 6172 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 6173 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 6174 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 6175 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 6176 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6177 | if (is_ap_interface(drv->nlmode) && |
| 6178 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6179 | (int) freq == bss->freq || drv->device_ap_sme || |
| 6180 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6181 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 6182 | 0, freq, no_cck, 1, |
| 6183 | wait_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6184 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6185 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6186 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6187 | &drv->send_action_cookie, |
| 6188 | no_cck, 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6189 | |
| 6190 | os_free(buf); |
| 6191 | return ret; |
| 6192 | } |
| 6193 | |
| 6194 | |
| 6195 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 6196 | { |
| 6197 | struct i802_bss *bss = priv; |
| 6198 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6199 | struct nl_msg *msg; |
| 6200 | int ret; |
| 6201 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 6202 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
| 6203 | (long long unsigned int) drv->send_action_cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6204 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
| 6205 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) { |
| 6206 | nlmsg_free(msg); |
| 6207 | return; |
| 6208 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6209 | |
| 6210 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6211 | if (ret) |
| 6212 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 6213 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6214 | } |
| 6215 | |
| 6216 | |
| 6217 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 6218 | unsigned int duration) |
| 6219 | { |
| 6220 | struct i802_bss *bss = priv; |
| 6221 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6222 | struct nl_msg *msg; |
| 6223 | int ret; |
| 6224 | u64 cookie; |
| 6225 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6226 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 6227 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 6228 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 6229 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6230 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6231 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6232 | |
| 6233 | cookie = 0; |
| 6234 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6235 | if (ret == 0) { |
| 6236 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 6237 | "0x%llx for freq=%u MHz duration=%u", |
| 6238 | (long long unsigned int) cookie, freq, duration); |
| 6239 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6240 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6241 | return 0; |
| 6242 | } |
| 6243 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 6244 | "(freq=%d duration=%u): %d (%s)", |
| 6245 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6246 | return -1; |
| 6247 | } |
| 6248 | |
| 6249 | |
| 6250 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 6251 | { |
| 6252 | struct i802_bss *bss = priv; |
| 6253 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6254 | struct nl_msg *msg; |
| 6255 | int ret; |
| 6256 | |
| 6257 | if (!drv->pending_remain_on_chan) { |
| 6258 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 6259 | "to cancel"); |
| 6260 | return -1; |
| 6261 | } |
| 6262 | |
| 6263 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 6264 | "0x%llx", |
| 6265 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 6266 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6267 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 6268 | if (!msg || |
| 6269 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 6270 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6271 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6272 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6273 | |
| 6274 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6275 | if (ret == 0) |
| 6276 | return 0; |
| 6277 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 6278 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6279 | return -1; |
| 6280 | } |
| 6281 | |
| 6282 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6283 | 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] | 6284 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6285 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6286 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6287 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6288 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 6289 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 6290 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6291 | /* |
| 6292 | * Do not disable Probe Request reporting that was |
| 6293 | * enabled in nl80211_setup_ap(). |
| 6294 | */ |
| 6295 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 6296 | "Probe Request reporting nl_preq=%p while " |
| 6297 | "in AP mode", bss->nl_preq); |
| 6298 | } else if (bss->nl_preq) { |
| 6299 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 6300 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6301 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6302 | } |
| 6303 | return 0; |
| 6304 | } |
| 6305 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6306 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6307 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6308 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6309 | return 0; |
| 6310 | } |
| 6311 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6312 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 6313 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6314 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6315 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 6316 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6317 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6318 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6319 | (WLAN_FC_TYPE_MGMT << 2) | |
| 6320 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6321 | NULL, 0) < 0) |
| 6322 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 6323 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6324 | nl80211_register_eloop_read(&bss->nl_preq, |
| 6325 | wpa_driver_nl80211_event_receive, |
| 6326 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6327 | |
| 6328 | return 0; |
| 6329 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6330 | out_err: |
| 6331 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6332 | return -1; |
| 6333 | } |
| 6334 | |
| 6335 | |
| 6336 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 6337 | int ifindex, int disabled) |
| 6338 | { |
| 6339 | struct nl_msg *msg; |
| 6340 | struct nlattr *bands, *band; |
| 6341 | int ret; |
| 6342 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6343 | wpa_printf(MSG_DEBUG, |
| 6344 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 6345 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 6346 | "no NL80211_TXRATE_LEGACY constraint"); |
| 6347 | |
| 6348 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 6349 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6350 | if (!msg) |
| 6351 | return -1; |
| 6352 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6353 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 6354 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6355 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6356 | |
| 6357 | /* |
| 6358 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 6359 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 6360 | * rates. All 5 GHz rates are left enabled. |
| 6361 | */ |
| 6362 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6363 | if (!band || |
| 6364 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 6365 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 6366 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6367 | nla_nest_end(msg, band); |
| 6368 | |
| 6369 | nla_nest_end(msg, bands); |
| 6370 | |
| 6371 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6372 | if (ret) { |
| 6373 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 6374 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6375 | } else |
| 6376 | drv->disabled_11b_rates = disabled; |
| 6377 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6378 | return ret; |
| 6379 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6380 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6381 | nlmsg_free(msg); |
| 6382 | return -1; |
| 6383 | } |
| 6384 | |
| 6385 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6386 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 6387 | { |
| 6388 | struct i802_bss *bss = priv; |
| 6389 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6390 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6391 | return -1; |
| 6392 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6393 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6394 | |
| 6395 | /* |
| 6396 | * If the P2P GO interface was dynamically added, then it is |
| 6397 | * possible that the interface change to station is not possible. |
| 6398 | */ |
| 6399 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 6400 | return 0; |
| 6401 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6402 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6403 | } |
| 6404 | |
| 6405 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6406 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 6407 | { |
| 6408 | struct i802_bss *bss = priv; |
| 6409 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6410 | if (!is_ap_interface(drv->nlmode)) |
| 6411 | return -1; |
| 6412 | wpa_driver_nl80211_del_beacon(drv); |
| 6413 | bss->beacon_set = 0; |
| 6414 | return 0; |
| 6415 | } |
| 6416 | |
| 6417 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6418 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 6419 | { |
| 6420 | struct i802_bss *bss = priv; |
| 6421 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6422 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 6423 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6424 | |
| 6425 | /* |
| 6426 | * If the P2P Client interface was dynamically added, then it is |
| 6427 | * possible that the interface change to station is not possible. |
| 6428 | */ |
| 6429 | if (bss->if_dynamic) |
| 6430 | return 0; |
| 6431 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6432 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 6433 | } |
| 6434 | |
| 6435 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6436 | static void wpa_driver_nl80211_resume(void *priv) |
| 6437 | { |
| 6438 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6439 | |
| 6440 | if (i802_set_iface_flags(bss, 1)) |
| 6441 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6442 | } |
| 6443 | |
| 6444 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6445 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 6446 | { |
| 6447 | struct i802_bss *bss = priv; |
| 6448 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6449 | struct nl_msg *msg; |
| 6450 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6451 | |
| 6452 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 6453 | "hysteresis=%d", threshold, hysteresis); |
| 6454 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6455 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 6456 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 6457 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 6458 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 6459 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6460 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6461 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6462 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6463 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6464 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6465 | } |
| 6466 | |
| 6467 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6468 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 6469 | { |
| 6470 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6471 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6472 | struct wpa_signal_info *sig_change = arg; |
| 6473 | |
| 6474 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6475 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6476 | |
| 6477 | sig_change->center_frq1 = -1; |
| 6478 | sig_change->center_frq2 = -1; |
| 6479 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 6480 | |
| 6481 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 6482 | sig_change->chanwidth = convert2width( |
| 6483 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 6484 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 6485 | sig_change->center_frq1 = |
| 6486 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 6487 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 6488 | sig_change->center_frq2 = |
| 6489 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 6490 | } |
| 6491 | |
| 6492 | return NL_SKIP; |
| 6493 | } |
| 6494 | |
| 6495 | |
| 6496 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 6497 | struct wpa_signal_info *sig) |
| 6498 | { |
| 6499 | struct nl_msg *msg; |
| 6500 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6501 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6502 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6506 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 6507 | { |
| 6508 | struct i802_bss *bss = priv; |
| 6509 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6510 | int res; |
| 6511 | |
| 6512 | os_memset(si, 0, sizeof(*si)); |
| 6513 | res = nl80211_get_link_signal(drv, si); |
| 6514 | if (res != 0) |
| 6515 | return res; |
| 6516 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6517 | res = nl80211_get_channel_width(drv, si); |
| 6518 | if (res != 0) |
| 6519 | return res; |
| 6520 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6521 | return nl80211_get_link_noise(drv, si); |
| 6522 | } |
| 6523 | |
| 6524 | |
| 6525 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 6526 | int encrypt) |
| 6527 | { |
| 6528 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6529 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
| 6530 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6531 | } |
| 6532 | |
| 6533 | |
| 6534 | static int nl80211_set_param(void *priv, const char *param) |
| 6535 | { |
| 6536 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
| 6537 | if (param == NULL) |
| 6538 | return 0; |
| 6539 | |
| 6540 | #ifdef CONFIG_P2P |
| 6541 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 6542 | struct i802_bss *bss = priv; |
| 6543 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6544 | |
| 6545 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 6546 | "interface"); |
| 6547 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 6548 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 6549 | } |
| 6550 | #endif /* CONFIG_P2P */ |
| 6551 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6552 | if (os_strstr(param, "use_monitor=1")) { |
| 6553 | struct i802_bss *bss = priv; |
| 6554 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6555 | drv->use_monitor = 1; |
| 6556 | } |
| 6557 | |
| 6558 | if (os_strstr(param, "force_connect_cmd=1")) { |
| 6559 | struct i802_bss *bss = priv; |
| 6560 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6561 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6562 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6563 | } |
| 6564 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 6565 | if (os_strstr(param, "no_offchannel_tx=1")) { |
| 6566 | struct i802_bss *bss = priv; |
| 6567 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6568 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 6569 | drv->test_use_roc_tx = 1; |
| 6570 | } |
| 6571 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6572 | return 0; |
| 6573 | } |
| 6574 | |
| 6575 | |
| 6576 | static void * nl80211_global_init(void) |
| 6577 | { |
| 6578 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6579 | struct netlink_config *cfg; |
| 6580 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6581 | global = os_zalloc(sizeof(*global)); |
| 6582 | if (global == NULL) |
| 6583 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6584 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6585 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6586 | global->if_add_ifindex = -1; |
| 6587 | |
| 6588 | cfg = os_zalloc(sizeof(*cfg)); |
| 6589 | if (cfg == NULL) |
| 6590 | goto err; |
| 6591 | |
| 6592 | cfg->ctx = global; |
| 6593 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 6594 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 6595 | global->netlink = netlink_init(cfg); |
| 6596 | if (global->netlink == NULL) { |
| 6597 | os_free(cfg); |
| 6598 | goto err; |
| 6599 | } |
| 6600 | |
| 6601 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 6602 | goto err; |
| 6603 | |
| 6604 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 6605 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6606 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 6607 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6608 | goto err; |
| 6609 | } |
| 6610 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6611 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6612 | |
| 6613 | err: |
| 6614 | nl80211_global_deinit(global); |
| 6615 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6616 | } |
| 6617 | |
| 6618 | |
| 6619 | static void nl80211_global_deinit(void *priv) |
| 6620 | { |
| 6621 | struct nl80211_global *global = priv; |
| 6622 | if (global == NULL) |
| 6623 | return; |
| 6624 | if (!dl_list_empty(&global->interfaces)) { |
| 6625 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 6626 | "nl80211_global_deinit", |
| 6627 | dl_list_len(&global->interfaces)); |
| 6628 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6629 | |
| 6630 | if (global->netlink) |
| 6631 | netlink_deinit(global->netlink); |
| 6632 | |
| 6633 | nl_destroy_handles(&global->nl); |
| 6634 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6635 | if (global->nl_event) |
| 6636 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6637 | |
| 6638 | nl_cb_put(global->nl_cb); |
| 6639 | |
| 6640 | if (global->ioctl_sock >= 0) |
| 6641 | close(global->ioctl_sock); |
| 6642 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6643 | os_free(global); |
| 6644 | } |
| 6645 | |
| 6646 | |
| 6647 | static const char * nl80211_get_radio_name(void *priv) |
| 6648 | { |
| 6649 | struct i802_bss *bss = priv; |
| 6650 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6651 | return drv->phyname; |
| 6652 | } |
| 6653 | |
| 6654 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6655 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 6656 | const u8 *pmkid) |
| 6657 | { |
| 6658 | struct nl_msg *msg; |
| 6659 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6660 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 6661 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
| 6662 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { |
| 6663 | nlmsg_free(msg); |
| 6664 | return -ENOBUFS; |
| 6665 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6666 | |
| 6667 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | |
| 6671 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6672 | { |
| 6673 | struct i802_bss *bss = priv; |
| 6674 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 6675 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 6676 | } |
| 6677 | |
| 6678 | |
| 6679 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6680 | { |
| 6681 | struct i802_bss *bss = priv; |
| 6682 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 6683 | MAC2STR(bssid)); |
| 6684 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 6685 | } |
| 6686 | |
| 6687 | |
| 6688 | static int nl80211_flush_pmkid(void *priv) |
| 6689 | { |
| 6690 | struct i802_bss *bss = priv; |
| 6691 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 6692 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 6693 | } |
| 6694 | |
| 6695 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6696 | static void clean_survey_results(struct survey_results *survey_results) |
| 6697 | { |
| 6698 | struct freq_survey *survey, *tmp; |
| 6699 | |
| 6700 | if (dl_list_empty(&survey_results->survey_list)) |
| 6701 | return; |
| 6702 | |
| 6703 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 6704 | struct freq_survey, list) { |
| 6705 | dl_list_del(&survey->list); |
| 6706 | os_free(survey); |
| 6707 | } |
| 6708 | } |
| 6709 | |
| 6710 | |
| 6711 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 6712 | struct dl_list *survey_list) |
| 6713 | { |
| 6714 | struct freq_survey *survey; |
| 6715 | |
| 6716 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 6717 | if (!survey) |
| 6718 | return; |
| 6719 | |
| 6720 | survey->ifidx = ifidx; |
| 6721 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6722 | survey->filled = 0; |
| 6723 | |
| 6724 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 6725 | survey->nf = (int8_t) |
| 6726 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 6727 | survey->filled |= SURVEY_HAS_NF; |
| 6728 | } |
| 6729 | |
| 6730 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 6731 | survey->channel_time = |
| 6732 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 6733 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 6734 | } |
| 6735 | |
| 6736 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 6737 | survey->channel_time_busy = |
| 6738 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 6739 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 6740 | } |
| 6741 | |
| 6742 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 6743 | survey->channel_time_rx = |
| 6744 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 6745 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 6746 | } |
| 6747 | |
| 6748 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 6749 | survey->channel_time_tx = |
| 6750 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 6751 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 6752 | } |
| 6753 | |
| 6754 | 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)", |
| 6755 | survey->freq, |
| 6756 | survey->nf, |
| 6757 | (unsigned long int) survey->channel_time, |
| 6758 | (unsigned long int) survey->channel_time_busy, |
| 6759 | (unsigned long int) survey->channel_time_tx, |
| 6760 | (unsigned long int) survey->channel_time_rx, |
| 6761 | survey->filled); |
| 6762 | |
| 6763 | dl_list_add_tail(survey_list, &survey->list); |
| 6764 | } |
| 6765 | |
| 6766 | |
| 6767 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 6768 | unsigned int freq_filter) |
| 6769 | { |
| 6770 | if (!freq_filter) |
| 6771 | return 1; |
| 6772 | |
| 6773 | return freq_filter == surveyed_freq; |
| 6774 | } |
| 6775 | |
| 6776 | |
| 6777 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 6778 | { |
| 6779 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6780 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6781 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 6782 | struct survey_results *survey_results; |
| 6783 | u32 surveyed_freq = 0; |
| 6784 | u32 ifidx; |
| 6785 | |
| 6786 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 6787 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 6788 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 6789 | }; |
| 6790 | |
| 6791 | survey_results = (struct survey_results *) arg; |
| 6792 | |
| 6793 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6794 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6795 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 6796 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 6797 | return NL_SKIP; |
| 6798 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6799 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 6800 | |
| 6801 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 6802 | return NL_SKIP; |
| 6803 | |
| 6804 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 6805 | tb[NL80211_ATTR_SURVEY_INFO], |
| 6806 | survey_policy)) |
| 6807 | return NL_SKIP; |
| 6808 | |
| 6809 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 6810 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 6811 | return NL_SKIP; |
| 6812 | } |
| 6813 | |
| 6814 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6815 | |
| 6816 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 6817 | survey_results->freq_filter)) |
| 6818 | return NL_SKIP; |
| 6819 | |
| 6820 | if (survey_results->freq_filter && |
| 6821 | survey_results->freq_filter != surveyed_freq) { |
| 6822 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 6823 | surveyed_freq); |
| 6824 | return NL_SKIP; |
| 6825 | } |
| 6826 | |
| 6827 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 6828 | |
| 6829 | return NL_SKIP; |
| 6830 | } |
| 6831 | |
| 6832 | |
| 6833 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 6834 | { |
| 6835 | struct i802_bss *bss = priv; |
| 6836 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6837 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6838 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6839 | union wpa_event_data data; |
| 6840 | struct survey_results *survey_results; |
| 6841 | |
| 6842 | os_memset(&data, 0, sizeof(data)); |
| 6843 | survey_results = &data.survey_results; |
| 6844 | |
| 6845 | dl_list_init(&survey_results->survey_list); |
| 6846 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6847 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6848 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6849 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6850 | |
| 6851 | if (freq) |
| 6852 | data.survey_results.freq_filter = freq; |
| 6853 | |
| 6854 | do { |
| 6855 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 6856 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 6857 | survey_results); |
| 6858 | } while (err > 0); |
| 6859 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6860 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6861 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6862 | else |
| 6863 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6864 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6865 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6866 | return err; |
| 6867 | } |
| 6868 | |
| 6869 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6870 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 6871 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6872 | const u8 *replay_ctr) |
| 6873 | { |
| 6874 | struct i802_bss *bss = priv; |
| 6875 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6876 | struct nlattr *replay_nested; |
| 6877 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6878 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6879 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6880 | if (!drv->set_rekey_offload) |
| 6881 | return; |
| 6882 | |
| 6883 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6884 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 6885 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6886 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
| 6887 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6888 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 6889 | replay_ctr)) { |
| 6890 | nl80211_nlmsg_clear(msg); |
| 6891 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6892 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6893 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6894 | |
| 6895 | nla_nest_end(msg, replay_nested); |
| 6896 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6897 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 6898 | if (ret == -EOPNOTSUPP) { |
| 6899 | wpa_printf(MSG_DEBUG, |
| 6900 | "nl80211: Driver does not support rekey offload"); |
| 6901 | drv->set_rekey_offload = 0; |
| 6902 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6903 | } |
| 6904 | |
| 6905 | |
| 6906 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 6907 | const u8 *addr, int qos) |
| 6908 | { |
| 6909 | /* send data frame to poll STA and check whether |
| 6910 | * this frame is ACKed */ |
| 6911 | struct { |
| 6912 | struct ieee80211_hdr hdr; |
| 6913 | u16 qos_ctl; |
| 6914 | } STRUCT_PACKED nulldata; |
| 6915 | size_t size; |
| 6916 | |
| 6917 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 6918 | |
| 6919 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 6920 | |
| 6921 | if (qos) { |
| 6922 | nulldata.hdr.frame_control = |
| 6923 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 6924 | WLAN_FC_STYPE_QOS_NULL); |
| 6925 | size = sizeof(nulldata); |
| 6926 | } else { |
| 6927 | nulldata.hdr.frame_control = |
| 6928 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 6929 | WLAN_FC_STYPE_NULLFUNC); |
| 6930 | size = sizeof(struct ieee80211_hdr); |
| 6931 | } |
| 6932 | |
| 6933 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 6934 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 6935 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 6936 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 6937 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6938 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
| 6939 | 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6940 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 6941 | "send poll frame"); |
| 6942 | } |
| 6943 | |
| 6944 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 6945 | int qos) |
| 6946 | { |
| 6947 | struct i802_bss *bss = priv; |
| 6948 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6949 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6950 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6951 | |
| 6952 | if (!drv->poll_command_supported) { |
| 6953 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 6954 | return; |
| 6955 | } |
| 6956 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6957 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 6958 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 6959 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6960 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6961 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6962 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6963 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6964 | if (ret < 0) { |
| 6965 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 6966 | MACSTR " failed: ret=%d (%s)", |
| 6967 | MAC2STR(addr), ret, strerror(-ret)); |
| 6968 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6969 | } |
| 6970 | |
| 6971 | |
| 6972 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 6973 | { |
| 6974 | struct nl_msg *msg; |
| 6975 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6976 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 6977 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 6978 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 6979 | nlmsg_free(msg); |
| 6980 | return -ENOBUFS; |
| 6981 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6982 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6983 | } |
| 6984 | |
| 6985 | |
| 6986 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 6987 | int ctwindow) |
| 6988 | { |
| 6989 | struct i802_bss *bss = priv; |
| 6990 | |
| 6991 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 6992 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 6993 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 6994 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6995 | #ifdef ANDROID_P2P |
| 6996 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 6997 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6998 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 6999 | #endif /* ANDROID_P2P */ |
| 7000 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7001 | |
| 7002 | if (legacy_ps == -1) |
| 7003 | return 0; |
| 7004 | if (legacy_ps != 0 && legacy_ps != 1) |
| 7005 | return -1; /* Not yet supported */ |
| 7006 | |
| 7007 | return nl80211_set_power_save(bss, legacy_ps); |
| 7008 | } |
| 7009 | |
| 7010 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7011 | static int nl80211_start_radar_detection(void *priv, |
| 7012 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7013 | { |
| 7014 | struct i802_bss *bss = priv; |
| 7015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7016 | struct nl_msg *msg; |
| 7017 | int ret; |
| 7018 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7019 | 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)", |
| 7020 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7021 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7022 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7023 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 7024 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 7025 | "detection"); |
| 7026 | return -1; |
| 7027 | } |
| 7028 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7029 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 7030 | nl80211_put_freq_params(msg, freq) < 0) { |
| 7031 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7032 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7033 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7034 | |
| 7035 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7036 | if (ret == 0) |
| 7037 | return 0; |
| 7038 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 7039 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7040 | return -1; |
| 7041 | } |
| 7042 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7043 | #ifdef CONFIG_TDLS |
| 7044 | |
| 7045 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 7046 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7047 | u32 peer_capab, int initiator, const u8 *buf, |
| 7048 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7049 | { |
| 7050 | struct i802_bss *bss = priv; |
| 7051 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7052 | struct nl_msg *msg; |
| 7053 | |
| 7054 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7055 | return -EOPNOTSUPP; |
| 7056 | |
| 7057 | if (!dst) |
| 7058 | return -EINVAL; |
| 7059 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7060 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 7061 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 7062 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 7063 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 7064 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 7065 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7066 | if (peer_capab) { |
| 7067 | /* |
| 7068 | * The internal enum tdls_peer_capability definition is |
| 7069 | * currently identical with the nl80211 enum |
| 7070 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 7071 | * here. |
| 7072 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7073 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 7074 | peer_capab)) |
| 7075 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7076 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7077 | if ((initiator && |
| 7078 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 7079 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 7080 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7081 | |
| 7082 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7083 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7084 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7085 | nlmsg_free(msg); |
| 7086 | return -ENOBUFS; |
| 7087 | } |
| 7088 | |
| 7089 | |
| 7090 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 7091 | { |
| 7092 | struct i802_bss *bss = priv; |
| 7093 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7094 | struct nl_msg *msg; |
| 7095 | enum nl80211_tdls_operation nl80211_oper; |
| 7096 | |
| 7097 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7098 | return -EOPNOTSUPP; |
| 7099 | |
| 7100 | switch (oper) { |
| 7101 | case TDLS_DISCOVERY_REQ: |
| 7102 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 7103 | break; |
| 7104 | case TDLS_SETUP: |
| 7105 | nl80211_oper = NL80211_TDLS_SETUP; |
| 7106 | break; |
| 7107 | case TDLS_TEARDOWN: |
| 7108 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 7109 | break; |
| 7110 | case TDLS_ENABLE_LINK: |
| 7111 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 7112 | break; |
| 7113 | case TDLS_DISABLE_LINK: |
| 7114 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 7115 | break; |
| 7116 | case TDLS_ENABLE: |
| 7117 | return 0; |
| 7118 | case TDLS_DISABLE: |
| 7119 | return 0; |
| 7120 | default: |
| 7121 | return -EINVAL; |
| 7122 | } |
| 7123 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7124 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 7125 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 7126 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 7127 | nlmsg_free(msg); |
| 7128 | return -ENOBUFS; |
| 7129 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7130 | |
| 7131 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7132 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7133 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7134 | |
| 7135 | static int |
| 7136 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 7137 | const struct hostapd_freq_params *params) |
| 7138 | { |
| 7139 | struct i802_bss *bss = priv; |
| 7140 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7141 | struct nl_msg *msg; |
| 7142 | int ret = -ENOBUFS; |
| 7143 | |
| 7144 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7145 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7146 | return -EOPNOTSUPP; |
| 7147 | |
| 7148 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 7149 | " oper_class=%u freq=%u", |
| 7150 | MAC2STR(addr), oper_class, params->freq); |
| 7151 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 7152 | if (!msg || |
| 7153 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7154 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 7155 | (ret = nl80211_put_freq_params(msg, params))) { |
| 7156 | nlmsg_free(msg); |
| 7157 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 7158 | return ret; |
| 7159 | } |
| 7160 | |
| 7161 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7162 | } |
| 7163 | |
| 7164 | |
| 7165 | static int |
| 7166 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 7167 | { |
| 7168 | struct i802_bss *bss = priv; |
| 7169 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7170 | struct nl_msg *msg; |
| 7171 | |
| 7172 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7173 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7174 | return -EOPNOTSUPP; |
| 7175 | |
| 7176 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 7177 | MAC2STR(addr)); |
| 7178 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 7179 | if (!msg || |
| 7180 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7181 | nlmsg_free(msg); |
| 7182 | wpa_printf(MSG_DEBUG, |
| 7183 | "nl80211: Could not build TDLS cancel chan switch"); |
| 7184 | return -ENOBUFS; |
| 7185 | } |
| 7186 | |
| 7187 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7188 | } |
| 7189 | |
| 7190 | #endif /* CONFIG TDLS */ |
| 7191 | |
| 7192 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7193 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 7194 | enum wpa_alg alg, const u8 *addr, |
| 7195 | int key_idx, int set_tx, |
| 7196 | const u8 *seq, size_t seq_len, |
| 7197 | const u8 *key, size_t key_len) |
| 7198 | { |
| 7199 | struct i802_bss *bss = priv; |
| 7200 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 7201 | set_tx, seq, seq_len, key, key_len); |
| 7202 | } |
| 7203 | |
| 7204 | |
| 7205 | static int driver_nl80211_scan2(void *priv, |
| 7206 | struct wpa_driver_scan_params *params) |
| 7207 | { |
| 7208 | struct i802_bss *bss = priv; |
| 7209 | return wpa_driver_nl80211_scan(bss, params); |
| 7210 | } |
| 7211 | |
| 7212 | |
| 7213 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 7214 | int reason_code) |
| 7215 | { |
| 7216 | struct i802_bss *bss = priv; |
| 7217 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 7218 | } |
| 7219 | |
| 7220 | |
| 7221 | static int driver_nl80211_authenticate(void *priv, |
| 7222 | struct wpa_driver_auth_params *params) |
| 7223 | { |
| 7224 | struct i802_bss *bss = priv; |
| 7225 | return wpa_driver_nl80211_authenticate(bss, params); |
| 7226 | } |
| 7227 | |
| 7228 | |
| 7229 | static void driver_nl80211_deinit(void *priv) |
| 7230 | { |
| 7231 | struct i802_bss *bss = priv; |
| 7232 | wpa_driver_nl80211_deinit(bss); |
| 7233 | } |
| 7234 | |
| 7235 | |
| 7236 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 7237 | const char *ifname) |
| 7238 | { |
| 7239 | struct i802_bss *bss = priv; |
| 7240 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 7241 | } |
| 7242 | |
| 7243 | |
| 7244 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
| 7245 | size_t data_len, int noack) |
| 7246 | { |
| 7247 | struct i802_bss *bss = priv; |
| 7248 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
| 7249 | 0, 0, 0, 0); |
| 7250 | } |
| 7251 | |
| 7252 | |
| 7253 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 7254 | { |
| 7255 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7256 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7257 | } |
| 7258 | |
| 7259 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7260 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 7261 | const char *ifname, int vlan_id) |
| 7262 | { |
| 7263 | struct i802_bss *bss = priv; |
| 7264 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 7265 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7266 | |
| 7267 | |
| 7268 | static int driver_nl80211_read_sta_data(void *priv, |
| 7269 | struct hostap_sta_driver_data *data, |
| 7270 | const u8 *addr) |
| 7271 | { |
| 7272 | struct i802_bss *bss = priv; |
| 7273 | return i802_read_sta_data(bss, data, addr); |
| 7274 | } |
| 7275 | |
| 7276 | |
| 7277 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 7278 | unsigned int wait_time, |
| 7279 | const u8 *dst, const u8 *src, |
| 7280 | const u8 *bssid, |
| 7281 | const u8 *data, size_t data_len, |
| 7282 | int no_cck) |
| 7283 | { |
| 7284 | struct i802_bss *bss = priv; |
| 7285 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 7286 | bssid, data, data_len, no_cck); |
| 7287 | } |
| 7288 | |
| 7289 | |
| 7290 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 7291 | { |
| 7292 | struct i802_bss *bss = priv; |
| 7293 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 7294 | } |
| 7295 | |
| 7296 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7297 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 7298 | const u8 *ies, size_t ies_len) |
| 7299 | { |
| 7300 | int ret; |
| 7301 | struct nl_msg *msg; |
| 7302 | struct i802_bss *bss = priv; |
| 7303 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7304 | u16 mdid = WPA_GET_LE16(md); |
| 7305 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7306 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7307 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 7308 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 7309 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 7310 | nlmsg_free(msg); |
| 7311 | return -ENOBUFS; |
| 7312 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7313 | |
| 7314 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7315 | if (ret) { |
| 7316 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 7317 | "err=%d (%s)", ret, strerror(-ret)); |
| 7318 | } |
| 7319 | |
| 7320 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7321 | } |
| 7322 | |
| 7323 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7324 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
| 7325 | { |
| 7326 | struct i802_bss *bss = priv; |
| 7327 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7328 | |
| 7329 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 7330 | return NULL; |
| 7331 | |
| 7332 | return bss->addr; |
| 7333 | } |
| 7334 | |
| 7335 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7336 | static const char * scan_state_str(enum scan_states scan_state) |
| 7337 | { |
| 7338 | switch (scan_state) { |
| 7339 | case NO_SCAN: |
| 7340 | return "NO_SCAN"; |
| 7341 | case SCAN_REQUESTED: |
| 7342 | return "SCAN_REQUESTED"; |
| 7343 | case SCAN_STARTED: |
| 7344 | return "SCAN_STARTED"; |
| 7345 | case SCAN_COMPLETED: |
| 7346 | return "SCAN_COMPLETED"; |
| 7347 | case SCAN_ABORTED: |
| 7348 | return "SCAN_ABORTED"; |
| 7349 | case SCHED_SCAN_STARTED: |
| 7350 | return "SCHED_SCAN_STARTED"; |
| 7351 | case SCHED_SCAN_STOPPED: |
| 7352 | return "SCHED_SCAN_STOPPED"; |
| 7353 | case SCHED_SCAN_RESULTS: |
| 7354 | return "SCHED_SCAN_RESULTS"; |
| 7355 | } |
| 7356 | |
| 7357 | return "??"; |
| 7358 | } |
| 7359 | |
| 7360 | |
| 7361 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 7362 | { |
| 7363 | struct i802_bss *bss = priv; |
| 7364 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7365 | int res; |
| 7366 | char *pos, *end; |
| 7367 | |
| 7368 | pos = buf; |
| 7369 | end = buf + buflen; |
| 7370 | |
| 7371 | res = os_snprintf(pos, end - pos, |
| 7372 | "ifindex=%d\n" |
| 7373 | "ifname=%s\n" |
| 7374 | "brname=%s\n" |
| 7375 | "addr=" MACSTR "\n" |
| 7376 | "freq=%d\n" |
| 7377 | "%s%s%s%s%s", |
| 7378 | bss->ifindex, |
| 7379 | bss->ifname, |
| 7380 | bss->brname, |
| 7381 | MAC2STR(bss->addr), |
| 7382 | bss->freq, |
| 7383 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 7384 | bss->added_if_into_bridge ? |
| 7385 | "added_if_into_bridge=1\n" : "", |
| 7386 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 7387 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 7388 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7389 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7390 | return pos - buf; |
| 7391 | pos += res; |
| 7392 | |
| 7393 | if (bss->wdev_id_set) { |
| 7394 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 7395 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7396 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7397 | return pos - buf; |
| 7398 | pos += res; |
| 7399 | } |
| 7400 | |
| 7401 | res = os_snprintf(pos, end - pos, |
| 7402 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7403 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7404 | "drv_ifindex=%d\n" |
| 7405 | "operstate=%d\n" |
| 7406 | "scan_state=%s\n" |
| 7407 | "auth_bssid=" MACSTR "\n" |
| 7408 | "auth_attempt_bssid=" MACSTR "\n" |
| 7409 | "bssid=" MACSTR "\n" |
| 7410 | "prev_bssid=" MACSTR "\n" |
| 7411 | "associated=%d\n" |
| 7412 | "assoc_freq=%u\n" |
| 7413 | "monitor_sock=%d\n" |
| 7414 | "monitor_ifidx=%d\n" |
| 7415 | "monitor_refcount=%d\n" |
| 7416 | "last_mgmt_freq=%u\n" |
| 7417 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7418 | "%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] | 7419 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7420 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7421 | drv->ifindex, |
| 7422 | drv->operstate, |
| 7423 | scan_state_str(drv->scan_state), |
| 7424 | MAC2STR(drv->auth_bssid), |
| 7425 | MAC2STR(drv->auth_attempt_bssid), |
| 7426 | MAC2STR(drv->bssid), |
| 7427 | MAC2STR(drv->prev_bssid), |
| 7428 | drv->associated, |
| 7429 | drv->assoc_freq, |
| 7430 | drv->monitor_sock, |
| 7431 | drv->monitor_ifidx, |
| 7432 | drv->monitor_refcount, |
| 7433 | drv->last_mgmt_freq, |
| 7434 | drv->eapol_tx_sock, |
| 7435 | drv->ignore_if_down_event ? |
| 7436 | "ignore_if_down_event=1\n" : "", |
| 7437 | drv->scan_complete_events ? |
| 7438 | "scan_complete_events=1\n" : "", |
| 7439 | drv->disabled_11b_rates ? |
| 7440 | "disabled_11b_rates=1\n" : "", |
| 7441 | drv->pending_remain_on_chan ? |
| 7442 | "pending_remain_on_chan=1\n" : "", |
| 7443 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 7444 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 7445 | drv->poll_command_supported ? |
| 7446 | "poll_command_supported=1\n" : "", |
| 7447 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 7448 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 7449 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 7450 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 7451 | drv->ignore_next_local_disconnect ? |
| 7452 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 7453 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7454 | "ignore_next_local_deauth=1\n" : ""); |
| 7455 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7456 | return pos - buf; |
| 7457 | pos += res; |
| 7458 | |
| 7459 | if (drv->has_capability) { |
| 7460 | res = os_snprintf(pos, end - pos, |
| 7461 | "capa.key_mgmt=0x%x\n" |
| 7462 | "capa.enc=0x%x\n" |
| 7463 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7464 | "capa.flags=0x%llx\n" |
| 7465 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7466 | "capa.max_scan_ssids=%d\n" |
| 7467 | "capa.max_sched_scan_ssids=%d\n" |
| 7468 | "capa.sched_scan_supported=%d\n" |
| 7469 | "capa.max_match_sets=%d\n" |
| 7470 | "capa.max_remain_on_chan=%u\n" |
| 7471 | "capa.max_stations=%u\n" |
| 7472 | "capa.probe_resp_offloads=0x%x\n" |
| 7473 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7474 | "capa.num_multichan_concurrent=%u\n" |
| 7475 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
| 7476 | "capa.mac_addr_rand_scan_supported=%d\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7477 | drv->capa.key_mgmt, |
| 7478 | drv->capa.enc, |
| 7479 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7480 | (unsigned long long) drv->capa.flags, |
| 7481 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7482 | drv->capa.max_scan_ssids, |
| 7483 | drv->capa.max_sched_scan_ssids, |
| 7484 | drv->capa.sched_scan_supported, |
| 7485 | drv->capa.max_match_sets, |
| 7486 | drv->capa.max_remain_on_chan, |
| 7487 | drv->capa.max_stations, |
| 7488 | drv->capa.probe_resp_offloads, |
| 7489 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7490 | drv->capa.num_multichan_concurrent, |
| 7491 | drv->capa.mac_addr_rand_sched_scan_supported, |
| 7492 | drv->capa.mac_addr_rand_scan_supported); |
| 7493 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7494 | return pos - buf; |
| 7495 | pos += res; |
| 7496 | } |
| 7497 | |
| 7498 | return pos - buf; |
| 7499 | } |
| 7500 | |
| 7501 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7502 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 7503 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7504 | if ((settings->head && |
| 7505 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 7506 | settings->head_len, settings->head)) || |
| 7507 | (settings->tail && |
| 7508 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 7509 | settings->tail_len, settings->tail)) || |
| 7510 | (settings->beacon_ies && |
| 7511 | nla_put(msg, NL80211_ATTR_IE, |
| 7512 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 7513 | (settings->proberesp_ies && |
| 7514 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 7515 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 7516 | (settings->assocresp_ies && |
| 7517 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 7518 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 7519 | (settings->probe_resp && |
| 7520 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 7521 | settings->probe_resp_len, settings->probe_resp))) |
| 7522 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7523 | |
| 7524 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | |
| 7528 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 7529 | { |
| 7530 | struct nl_msg *msg; |
| 7531 | struct i802_bss *bss = priv; |
| 7532 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7533 | struct nlattr *beacon_csa; |
| 7534 | int ret = -ENOBUFS; |
| 7535 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7536 | 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] | 7537 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7538 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 7539 | settings->freq_params.center_freq1, |
| 7540 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7541 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7542 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7543 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 7544 | return -EOPNOTSUPP; |
| 7545 | } |
| 7546 | |
| 7547 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 7548 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 7549 | return -EOPNOTSUPP; |
| 7550 | |
| 7551 | /* check settings validity */ |
| 7552 | if (!settings->beacon_csa.tail || |
| 7553 | ((settings->beacon_csa.tail_len <= |
| 7554 | settings->counter_offset_beacon) || |
| 7555 | (settings->beacon_csa.tail[settings->counter_offset_beacon] != |
| 7556 | settings->cs_count))) |
| 7557 | return -EINVAL; |
| 7558 | |
| 7559 | if (settings->beacon_csa.probe_resp && |
| 7560 | ((settings->beacon_csa.probe_resp_len <= |
| 7561 | settings->counter_offset_presp) || |
| 7562 | (settings->beacon_csa.probe_resp[settings->counter_offset_presp] != |
| 7563 | settings->cs_count))) |
| 7564 | return -EINVAL; |
| 7565 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7566 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 7567 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 7568 | settings->cs_count) || |
| 7569 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 7570 | (settings->block_tx && |
| 7571 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7572 | goto error; |
| 7573 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7574 | /* beacon_after params */ |
| 7575 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 7576 | if (ret) |
| 7577 | goto error; |
| 7578 | |
| 7579 | /* beacon_csa params */ |
| 7580 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 7581 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7582 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7583 | |
| 7584 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 7585 | if (ret) |
| 7586 | goto error; |
| 7587 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7588 | if (nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 7589 | settings->counter_offset_beacon) || |
| 7590 | (settings->beacon_csa.probe_resp && |
| 7591 | nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 7592 | settings->counter_offset_presp))) |
| 7593 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7594 | |
| 7595 | nla_nest_end(msg, beacon_csa); |
| 7596 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7597 | if (ret) { |
| 7598 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 7599 | ret, strerror(-ret)); |
| 7600 | } |
| 7601 | return ret; |
| 7602 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7603 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7604 | ret = -ENOBUFS; |
| 7605 | error: |
| 7606 | nlmsg_free(msg); |
| 7607 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 7608 | return ret; |
| 7609 | } |
| 7610 | |
| 7611 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7612 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 7613 | u8 user_priority, u16 admitted_time) |
| 7614 | { |
| 7615 | struct i802_bss *bss = priv; |
| 7616 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7617 | struct nl_msg *msg; |
| 7618 | int ret; |
| 7619 | |
| 7620 | wpa_printf(MSG_DEBUG, |
| 7621 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 7622 | tsid, admitted_time, user_priority); |
| 7623 | |
| 7624 | if (!is_sta_interface(drv->nlmode)) |
| 7625 | return -ENOTSUP; |
| 7626 | |
| 7627 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 7628 | if (!msg || |
| 7629 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7630 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7631 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 7632 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 7633 | nlmsg_free(msg); |
| 7634 | return -ENOBUFS; |
| 7635 | } |
| 7636 | |
| 7637 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7638 | if (ret) |
| 7639 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 7640 | ret, strerror(-ret)); |
| 7641 | return ret; |
| 7642 | } |
| 7643 | |
| 7644 | |
| 7645 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 7646 | { |
| 7647 | struct i802_bss *bss = priv; |
| 7648 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7649 | struct nl_msg *msg; |
| 7650 | int ret; |
| 7651 | |
| 7652 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 7653 | |
| 7654 | if (!is_sta_interface(drv->nlmode)) |
| 7655 | return -ENOTSUP; |
| 7656 | |
| 7657 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 7658 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7659 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7660 | nlmsg_free(msg); |
| 7661 | return -ENOBUFS; |
| 7662 | } |
| 7663 | |
| 7664 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7665 | if (ret) |
| 7666 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 7667 | ret, strerror(-ret)); |
| 7668 | return ret; |
| 7669 | } |
| 7670 | |
| 7671 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7672 | #ifdef CONFIG_TESTING_OPTIONS |
| 7673 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 7674 | { |
| 7675 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7676 | struct wpabuf *buf = arg; |
| 7677 | |
| 7678 | if (!buf) |
| 7679 | return NL_SKIP; |
| 7680 | |
| 7681 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 7682 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 7683 | return NL_SKIP; |
| 7684 | } |
| 7685 | |
| 7686 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 7687 | genlmsg_attrlen(gnlh, 0)); |
| 7688 | |
| 7689 | return NL_SKIP; |
| 7690 | } |
| 7691 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7692 | |
| 7693 | |
| 7694 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 7695 | { |
| 7696 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7697 | struct nlattr *nl_vendor_reply, *nl; |
| 7698 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7699 | struct wpabuf *buf = arg; |
| 7700 | int rem; |
| 7701 | |
| 7702 | if (!buf) |
| 7703 | return NL_SKIP; |
| 7704 | |
| 7705 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7706 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7707 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 7708 | |
| 7709 | if (!nl_vendor_reply) |
| 7710 | return NL_SKIP; |
| 7711 | |
| 7712 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 7713 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 7714 | return NL_SKIP; |
| 7715 | } |
| 7716 | |
| 7717 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 7718 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 7719 | } |
| 7720 | |
| 7721 | return NL_SKIP; |
| 7722 | } |
| 7723 | |
| 7724 | |
| 7725 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 7726 | unsigned int subcmd, const u8 *data, |
| 7727 | size_t data_len, struct wpabuf *buf) |
| 7728 | { |
| 7729 | struct i802_bss *bss = priv; |
| 7730 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7731 | struct nl_msg *msg; |
| 7732 | int ret; |
| 7733 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7734 | #ifdef CONFIG_TESTING_OPTIONS |
| 7735 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7736 | msg = nlmsg_alloc(); |
| 7737 | if (!msg) |
| 7738 | return -ENOMEM; |
| 7739 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7740 | nl80211_cmd(drv, msg, 0, subcmd); |
| 7741 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 7742 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7743 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7744 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 7745 | if (ret) |
| 7746 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 7747 | ret); |
| 7748 | return ret; |
| 7749 | } |
| 7750 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7751 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7752 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 7753 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 7754 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 7755 | (data && |
| 7756 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 7757 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7758 | |
| 7759 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 7760 | if (ret) |
| 7761 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 7762 | ret); |
| 7763 | return ret; |
| 7764 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7765 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7766 | nlmsg_free(msg); |
| 7767 | return -ENOBUFS; |
| 7768 | } |
| 7769 | |
| 7770 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7771 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 7772 | u8 qos_map_set_len) |
| 7773 | { |
| 7774 | struct i802_bss *bss = priv; |
| 7775 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7776 | struct nl_msg *msg; |
| 7777 | int ret; |
| 7778 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7779 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 7780 | qos_map_set, qos_map_set_len); |
| 7781 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7782 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 7783 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 7784 | nlmsg_free(msg); |
| 7785 | return -ENOBUFS; |
| 7786 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7787 | |
| 7788 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7789 | if (ret) |
| 7790 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 7791 | |
| 7792 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7793 | } |
| 7794 | |
| 7795 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7796 | static int nl80211_set_wowlan(void *priv, |
| 7797 | const struct wowlan_triggers *triggers) |
| 7798 | { |
| 7799 | struct i802_bss *bss = priv; |
| 7800 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7801 | struct nl_msg *msg; |
| 7802 | struct nlattr *wowlan_triggers; |
| 7803 | int ret; |
| 7804 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7805 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 7806 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7807 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WOWLAN)) || |
| 7808 | !(wowlan_triggers = nla_nest_start(msg, |
| 7809 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 7810 | (triggers->any && |
| 7811 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7812 | (triggers->disconnect && |
| 7813 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7814 | (triggers->magic_pkt && |
| 7815 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7816 | (triggers->gtk_rekey_failure && |
| 7817 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7818 | (triggers->eap_identity_req && |
| 7819 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7820 | (triggers->four_way_handshake && |
| 7821 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7822 | (triggers->rfkill_release && |
| 7823 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 7824 | nlmsg_free(msg); |
| 7825 | return -ENOBUFS; |
| 7826 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7827 | |
| 7828 | nla_nest_end(msg, wowlan_triggers); |
| 7829 | |
| 7830 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7831 | if (ret) |
| 7832 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 7833 | |
| 7834 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7835 | } |
| 7836 | |
| 7837 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7838 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 7839 | { |
| 7840 | struct i802_bss *bss = priv; |
| 7841 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7842 | struct nl_msg *msg; |
| 7843 | struct nlattr *params; |
| 7844 | |
| 7845 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 7846 | |
| 7847 | if (!drv->roaming_vendor_cmd_avail) { |
| 7848 | wpa_printf(MSG_DEBUG, |
| 7849 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 7850 | return -1; |
| 7851 | } |
| 7852 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7853 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 7854 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7855 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7856 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 7857 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7858 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 7859 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 7860 | QCA_ROAMING_NOT_ALLOWED) || |
| 7861 | (bssid && |
| 7862 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 7863 | nlmsg_free(msg); |
| 7864 | return -1; |
| 7865 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7866 | nla_nest_end(msg, params); |
| 7867 | |
| 7868 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7869 | } |
| 7870 | |
| 7871 | |
| 7872 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 7873 | { |
| 7874 | struct i802_bss *bss = priv; |
| 7875 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7876 | int new_addr = addr != NULL; |
| 7877 | |
| 7878 | if (!addr) |
| 7879 | addr = drv->perm_addr; |
| 7880 | |
| 7881 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 7882 | return -1; |
| 7883 | |
| 7884 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 7885 | { |
| 7886 | wpa_printf(MSG_DEBUG, |
| 7887 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 7888 | bss->ifname, MAC2STR(addr)); |
| 7889 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 7890 | 1) < 0) { |
| 7891 | wpa_printf(MSG_DEBUG, |
| 7892 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 7893 | } |
| 7894 | return -1; |
| 7895 | } |
| 7896 | |
| 7897 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 7898 | bss->ifname, MAC2STR(addr)); |
| 7899 | drv->addr_changed = new_addr; |
| 7900 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 7901 | |
| 7902 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 7903 | { |
| 7904 | wpa_printf(MSG_DEBUG, |
| 7905 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 7906 | } |
| 7907 | |
| 7908 | return 0; |
| 7909 | } |
| 7910 | |
| 7911 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7912 | #ifdef CONFIG_MESH |
| 7913 | |
| 7914 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 7915 | { |
| 7916 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 7917 | wpa_printf(MSG_INFO, |
| 7918 | "nl80211: Failed to set interface into mesh mode"); |
| 7919 | return -1; |
| 7920 | } |
| 7921 | return 0; |
| 7922 | } |
| 7923 | |
| 7924 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7925 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 7926 | size_t mesh_id_len) |
| 7927 | { |
| 7928 | if (mesh_id) { |
| 7929 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 7930 | mesh_id, mesh_id_len); |
| 7931 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 7932 | } |
| 7933 | |
| 7934 | return 0; |
| 7935 | } |
| 7936 | |
| 7937 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7938 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7939 | struct wpa_driver_mesh_join_params *params) |
| 7940 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7941 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7942 | struct nl_msg *msg; |
| 7943 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7944 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7945 | |
| 7946 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 7947 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7948 | if (!msg || |
| 7949 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 7950 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 7951 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
| 7952 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7953 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7954 | |
| 7955 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 7956 | |
| 7957 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 7958 | if (!container) |
| 7959 | goto fail; |
| 7960 | |
| 7961 | if (params->ies) { |
| 7962 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 7963 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 7964 | params->ies)) |
| 7965 | goto fail; |
| 7966 | } |
| 7967 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 7968 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 7969 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 7970 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 7971 | goto fail; |
| 7972 | } |
| 7973 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 7974 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 7975 | goto fail; |
| 7976 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 7977 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 7978 | goto fail; |
| 7979 | nla_nest_end(msg, container); |
| 7980 | |
| 7981 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 7982 | if (!container) |
| 7983 | goto fail; |
| 7984 | |
| 7985 | if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
| 7986 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0)) |
| 7987 | goto fail; |
| 7988 | if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) && |
| 7989 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7990 | params->max_peer_links)) |
| 7991 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7992 | |
| 7993 | /* |
| 7994 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 7995 | * the timer could disconnect stations even in that case. |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7996 | */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7997 | if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 7998 | params->conf.peer_link_timeout)) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7999 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 8000 | goto fail; |
| 8001 | } |
| 8002 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8003 | nla_nest_end(msg, container); |
| 8004 | |
| 8005 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8006 | msg = NULL; |
| 8007 | if (ret) { |
| 8008 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 8009 | ret, strerror(-ret)); |
| 8010 | goto fail; |
| 8011 | } |
| 8012 | ret = 0; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8013 | bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8014 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 8015 | |
| 8016 | fail: |
| 8017 | nlmsg_free(msg); |
| 8018 | return ret; |
| 8019 | } |
| 8020 | |
| 8021 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8022 | static int |
| 8023 | wpa_driver_nl80211_join_mesh(void *priv, |
| 8024 | struct wpa_driver_mesh_join_params *params) |
| 8025 | { |
| 8026 | struct i802_bss *bss = priv; |
| 8027 | int ret, timeout; |
| 8028 | |
| 8029 | timeout = params->conf.peer_link_timeout; |
| 8030 | |
| 8031 | /* Disable kernel inactivity timer */ |
| 8032 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 8033 | params->conf.peer_link_timeout = 0; |
| 8034 | |
| 8035 | ret = nl80211_join_mesh(bss, params); |
| 8036 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 8037 | wpa_printf(MSG_DEBUG, |
| 8038 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 8039 | /* |
| 8040 | * Old kernel does not support setting |
| 8041 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 8042 | * into future from peer_link_timeout. |
| 8043 | */ |
| 8044 | params->conf.peer_link_timeout = timeout + 60; |
| 8045 | ret = nl80211_join_mesh(priv, params); |
| 8046 | } |
| 8047 | |
| 8048 | params->conf.peer_link_timeout = timeout; |
| 8049 | return ret; |
| 8050 | } |
| 8051 | |
| 8052 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8053 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 8054 | { |
| 8055 | struct i802_bss *bss = priv; |
| 8056 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8057 | struct nl_msg *msg; |
| 8058 | int ret; |
| 8059 | |
| 8060 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 8061 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 8062 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8063 | if (ret) { |
| 8064 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 8065 | ret, strerror(-ret)); |
| 8066 | } else { |
| 8067 | wpa_printf(MSG_DEBUG, |
| 8068 | "nl80211: mesh leave request send successfully"); |
| 8069 | } |
| 8070 | |
| 8071 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 8072 | NL80211_IFTYPE_STATION)) { |
| 8073 | wpa_printf(MSG_INFO, |
| 8074 | "nl80211: Failed to set interface into station mode"); |
| 8075 | } |
| 8076 | return ret; |
| 8077 | } |
| 8078 | |
| 8079 | #endif /* CONFIG_MESH */ |
| 8080 | |
| 8081 | |
| 8082 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 8083 | const u8 *ipaddr, int prefixlen, |
| 8084 | const u8 *addr) |
| 8085 | { |
| 8086 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8087 | struct i802_bss *bss = priv; |
| 8088 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8089 | struct rtnl_neigh *rn; |
| 8090 | struct nl_addr *nl_ipaddr = NULL; |
| 8091 | struct nl_addr *nl_lladdr = NULL; |
| 8092 | int family, addrsize; |
| 8093 | int res; |
| 8094 | |
| 8095 | if (!ipaddr || prefixlen == 0 || !addr) |
| 8096 | return -EINVAL; |
| 8097 | |
| 8098 | if (bss->br_ifindex == 0) { |
| 8099 | wpa_printf(MSG_DEBUG, |
| 8100 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 8101 | return -1; |
| 8102 | } |
| 8103 | |
| 8104 | if (!drv->rtnl_sk) { |
| 8105 | wpa_printf(MSG_DEBUG, |
| 8106 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8107 | return -1; |
| 8108 | } |
| 8109 | |
| 8110 | if (version == 4) { |
| 8111 | family = AF_INET; |
| 8112 | addrsize = 4; |
| 8113 | } else if (version == 6) { |
| 8114 | family = AF_INET6; |
| 8115 | addrsize = 16; |
| 8116 | } else { |
| 8117 | return -EINVAL; |
| 8118 | } |
| 8119 | |
| 8120 | rn = rtnl_neigh_alloc(); |
| 8121 | if (rn == NULL) |
| 8122 | return -ENOMEM; |
| 8123 | |
| 8124 | /* set the destination ip address for neigh */ |
| 8125 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8126 | if (nl_ipaddr == NULL) { |
| 8127 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8128 | res = -ENOMEM; |
| 8129 | goto errout; |
| 8130 | } |
| 8131 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 8132 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8133 | if (res) { |
| 8134 | wpa_printf(MSG_DEBUG, |
| 8135 | "nl80211: neigh set destination addr failed"); |
| 8136 | goto errout; |
| 8137 | } |
| 8138 | |
| 8139 | /* set the corresponding lladdr for neigh */ |
| 8140 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 8141 | if (nl_lladdr == NULL) { |
| 8142 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 8143 | res = -ENOMEM; |
| 8144 | goto errout; |
| 8145 | } |
| 8146 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 8147 | |
| 8148 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8149 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 8150 | |
| 8151 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 8152 | if (res) { |
| 8153 | wpa_printf(MSG_DEBUG, |
| 8154 | "nl80211: Adding bridge ip neigh failed: %s", |
| 8155 | strerror(errno)); |
| 8156 | } |
| 8157 | errout: |
| 8158 | if (nl_lladdr) |
| 8159 | nl_addr_put(nl_lladdr); |
| 8160 | if (nl_ipaddr) |
| 8161 | nl_addr_put(nl_ipaddr); |
| 8162 | if (rn) |
| 8163 | rtnl_neigh_put(rn); |
| 8164 | return res; |
| 8165 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8166 | return -1; |
| 8167 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8168 | } |
| 8169 | |
| 8170 | |
| 8171 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 8172 | const u8 *ipaddr) |
| 8173 | { |
| 8174 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8175 | struct i802_bss *bss = priv; |
| 8176 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8177 | struct rtnl_neigh *rn; |
| 8178 | struct nl_addr *nl_ipaddr; |
| 8179 | int family, addrsize; |
| 8180 | int res; |
| 8181 | |
| 8182 | if (!ipaddr) |
| 8183 | return -EINVAL; |
| 8184 | |
| 8185 | if (version == 4) { |
| 8186 | family = AF_INET; |
| 8187 | addrsize = 4; |
| 8188 | } else if (version == 6) { |
| 8189 | family = AF_INET6; |
| 8190 | addrsize = 16; |
| 8191 | } else { |
| 8192 | return -EINVAL; |
| 8193 | } |
| 8194 | |
| 8195 | if (bss->br_ifindex == 0) { |
| 8196 | wpa_printf(MSG_DEBUG, |
| 8197 | "nl80211: bridge must be set to delete an ip neigh"); |
| 8198 | return -1; |
| 8199 | } |
| 8200 | |
| 8201 | if (!drv->rtnl_sk) { |
| 8202 | wpa_printf(MSG_DEBUG, |
| 8203 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8204 | return -1; |
| 8205 | } |
| 8206 | |
| 8207 | rn = rtnl_neigh_alloc(); |
| 8208 | if (rn == NULL) |
| 8209 | return -ENOMEM; |
| 8210 | |
| 8211 | /* set the destination ip address for neigh */ |
| 8212 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8213 | if (nl_ipaddr == NULL) { |
| 8214 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8215 | res = -ENOMEM; |
| 8216 | goto errout; |
| 8217 | } |
| 8218 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8219 | if (res) { |
| 8220 | wpa_printf(MSG_DEBUG, |
| 8221 | "nl80211: neigh set destination addr failed"); |
| 8222 | goto errout; |
| 8223 | } |
| 8224 | |
| 8225 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8226 | |
| 8227 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 8228 | if (res) { |
| 8229 | wpa_printf(MSG_DEBUG, |
| 8230 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 8231 | strerror(errno)); |
| 8232 | } |
| 8233 | errout: |
| 8234 | if (nl_ipaddr) |
| 8235 | nl_addr_put(nl_ipaddr); |
| 8236 | if (rn) |
| 8237 | rtnl_neigh_put(rn); |
| 8238 | return res; |
| 8239 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8240 | return -1; |
| 8241 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8242 | } |
| 8243 | |
| 8244 | |
| 8245 | static int linux_write_system_file(const char *path, unsigned int val) |
| 8246 | { |
| 8247 | char buf[50]; |
| 8248 | int fd, len; |
| 8249 | |
| 8250 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 8251 | if (os_snprintf_error(sizeof(buf), len)) |
| 8252 | return -1; |
| 8253 | |
| 8254 | fd = open(path, O_WRONLY); |
| 8255 | if (fd < 0) |
| 8256 | return -1; |
| 8257 | |
| 8258 | if (write(fd, buf, len) < 0) { |
| 8259 | wpa_printf(MSG_DEBUG, |
| 8260 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 8261 | path, val); |
| 8262 | close(fd); |
| 8263 | return -1; |
| 8264 | } |
| 8265 | close(fd); |
| 8266 | |
| 8267 | return 0; |
| 8268 | } |
| 8269 | |
| 8270 | |
| 8271 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 8272 | { |
| 8273 | switch (attr) { |
| 8274 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 8275 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8276 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 8277 | return "hairpin_mode"; |
| 8278 | } |
| 8279 | |
| 8280 | return NULL; |
| 8281 | } |
| 8282 | |
| 8283 | |
| 8284 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 8285 | unsigned int val) |
| 8286 | { |
| 8287 | struct i802_bss *bss = priv; |
| 8288 | char path[128]; |
| 8289 | const char *attr_txt; |
| 8290 | |
| 8291 | attr_txt = drv_br_port_attr_str(attr); |
| 8292 | if (attr_txt == NULL) |
| 8293 | return -EINVAL; |
| 8294 | |
| 8295 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 8296 | bss->ifname, attr_txt); |
| 8297 | |
| 8298 | if (linux_write_system_file(path, val)) |
| 8299 | return -1; |
| 8300 | |
| 8301 | return 0; |
| 8302 | } |
| 8303 | |
| 8304 | |
| 8305 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 8306 | { |
| 8307 | switch (param) { |
| 8308 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8309 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8310 | default: |
| 8311 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8312 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8313 | } |
| 8314 | |
| 8315 | |
| 8316 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 8317 | unsigned int val) |
| 8318 | { |
| 8319 | struct i802_bss *bss = priv; |
| 8320 | char path[128]; |
| 8321 | const char *param_txt; |
| 8322 | int ip_version = 4; |
| 8323 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8324 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 8325 | os_snprintf(path, sizeof(path), |
| 8326 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 8327 | bss->brname); |
| 8328 | goto set_val; |
| 8329 | } |
| 8330 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8331 | param_txt = drv_br_net_param_str(param); |
| 8332 | if (param_txt == NULL) |
| 8333 | return -EINVAL; |
| 8334 | |
| 8335 | switch (param) { |
| 8336 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8337 | ip_version = 4; |
| 8338 | break; |
| 8339 | default: |
| 8340 | return -EINVAL; |
| 8341 | } |
| 8342 | |
| 8343 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 8344 | ip_version, bss->brname, param_txt); |
| 8345 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8346 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8347 | if (linux_write_system_file(path, val)) |
| 8348 | return -1; |
| 8349 | |
| 8350 | return 0; |
| 8351 | } |
| 8352 | |
| 8353 | |
| 8354 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 8355 | { |
| 8356 | switch (hw_mode) { |
| 8357 | case HOSTAPD_MODE_IEEE80211B: |
| 8358 | return QCA_ACS_MODE_IEEE80211B; |
| 8359 | case HOSTAPD_MODE_IEEE80211G: |
| 8360 | return QCA_ACS_MODE_IEEE80211G; |
| 8361 | case HOSTAPD_MODE_IEEE80211A: |
| 8362 | return QCA_ACS_MODE_IEEE80211A; |
| 8363 | case HOSTAPD_MODE_IEEE80211AD: |
| 8364 | return QCA_ACS_MODE_IEEE80211AD; |
| 8365 | default: |
| 8366 | return -1; |
| 8367 | } |
| 8368 | } |
| 8369 | |
| 8370 | |
| 8371 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 8372 | { |
| 8373 | struct i802_bss *bss = priv; |
| 8374 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8375 | struct nl_msg *msg; |
| 8376 | struct nlattr *data; |
| 8377 | int ret; |
| 8378 | int mode; |
| 8379 | |
| 8380 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 8381 | if (mode < 0) |
| 8382 | return -1; |
| 8383 | |
| 8384 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8385 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8386 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8387 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 8388 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8389 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 8390 | (params->ht_enabled && |
| 8391 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 8392 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8393 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 8394 | (params->vht_enabled && |
| 8395 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 8396 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 8397 | params->ch_width) || |
| 8398 | (params->ch_list_len && |
| 8399 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, |
| 8400 | params->ch_list))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8401 | nlmsg_free(msg); |
| 8402 | return -ENOBUFS; |
| 8403 | } |
| 8404 | nla_nest_end(msg, data); |
| 8405 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8406 | wpa_printf(MSG_DEBUG, |
| 8407 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 8408 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 8409 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 8410 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8411 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8412 | if (ret) { |
| 8413 | wpa_printf(MSG_DEBUG, |
| 8414 | "nl80211: Failed to invoke driver ACS function: %s", |
| 8415 | strerror(errno)); |
| 8416 | } |
| 8417 | return ret; |
| 8418 | } |
| 8419 | |
| 8420 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8421 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 8422 | .name = "nl80211", |
| 8423 | .desc = "Linux nl80211/cfg80211", |
| 8424 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 8425 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8426 | .set_key = driver_nl80211_set_key, |
| 8427 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8428 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 8429 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8430 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8431 | .deauthenticate = driver_nl80211_deauthenticate, |
| 8432 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8433 | .associate = wpa_driver_nl80211_associate, |
| 8434 | .global_init = nl80211_global_init, |
| 8435 | .global_deinit = nl80211_global_deinit, |
| 8436 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8437 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8438 | .get_capa = wpa_driver_nl80211_get_capa, |
| 8439 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 8440 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 8441 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8442 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8443 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8444 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8445 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8446 | .if_remove = driver_nl80211_if_remove, |
| 8447 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8448 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8449 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8450 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8451 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 8452 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8453 | .hapd_init = i802_init, |
| 8454 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8455 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8456 | .get_seqnum = i802_get_seqnum, |
| 8457 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8458 | .get_inact_sec = i802_get_inact_sec, |
| 8459 | .sta_clear_stats = i802_sta_clear_stats, |
| 8460 | .set_rts = i802_set_rts, |
| 8461 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8462 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8463 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8464 | .sta_deauth = i802_sta_deauth, |
| 8465 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8466 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8467 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8468 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8469 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 8470 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 8471 | .cancel_remain_on_channel = |
| 8472 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8473 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8474 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8475 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8476 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8477 | .signal_monitor = nl80211_signal_monitor, |
| 8478 | .signal_poll = nl80211_signal_poll, |
| 8479 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8480 | .set_param = nl80211_set_param, |
| 8481 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8482 | .add_pmkid = nl80211_add_pmkid, |
| 8483 | .remove_pmkid = nl80211_remove_pmkid, |
| 8484 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8485 | .set_rekey_info = nl80211_set_rekey_info, |
| 8486 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8487 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8488 | .start_dfs_cac = nl80211_start_radar_detection, |
| 8489 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8490 | #ifdef CONFIG_TDLS |
| 8491 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 8492 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8493 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 8494 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8495 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8496 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8497 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8498 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8499 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8500 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8501 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8502 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8503 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8504 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8505 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 8506 | #ifdef ANDROID |
| 8507 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8508 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8509 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8510 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8511 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8512 | .roaming = nl80211_roaming, |
| 8513 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8514 | #ifdef CONFIG_MESH |
| 8515 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 8516 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 8517 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 8518 | #endif /* CONFIG_MESH */ |
| 8519 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 8520 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 8521 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 8522 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 8523 | .add_tx_ts = nl80211_add_ts, |
| 8524 | .del_tx_ts = nl80211_del_ts, |
| 8525 | .do_acs = wpa_driver_do_acs, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8526 | }; |