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 | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 2504 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 2537 | u32 suite; |
| 2538 | |
| 2539 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2540 | if (!suite) |
| 2541 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2542 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2543 | if (!msg || |
| 2544 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 2545 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2546 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2547 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2550 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2551 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2552 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2553 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2554 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2555 | |
| 2556 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2557 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2558 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2559 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2560 | |
| 2561 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2562 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2563 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2564 | NL80211_KEYTYPE_GROUP)) |
| 2565 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2566 | } |
| 2567 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2568 | struct nlattr *types; |
| 2569 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2570 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2571 | |
| 2572 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2573 | if (!types || |
| 2574 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2575 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2576 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2577 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2578 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2579 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2580 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2581 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2582 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2583 | ret = 0; |
| 2584 | if (ret) |
| 2585 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2586 | ret, strerror(-ret)); |
| 2587 | |
| 2588 | /* |
| 2589 | * If we failed or don't need to set the default TX key (below), |
| 2590 | * we're done here. |
| 2591 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2592 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2593 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2594 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2595 | !is_broadcast_ether_addr(addr)) |
| 2596 | return ret; |
| 2597 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2598 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2599 | if (!msg || |
| 2600 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2601 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2602 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2603 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2604 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2605 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2606 | NL80211_ATTR_KEY_DEFAULT)) |
| 2607 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2608 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2609 | struct nlattr *types; |
| 2610 | |
| 2611 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2612 | if (!types || |
| 2613 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2614 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2615 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2616 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2617 | struct nlattr *types; |
| 2618 | |
| 2619 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2620 | if (!types || |
| 2621 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2622 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2623 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2627 | if (ret == -ENOENT) |
| 2628 | ret = 0; |
| 2629 | if (ret) |
| 2630 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2631 | "err=%d %s)", ret, strerror(-ret)); |
| 2632 | return ret; |
| 2633 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2634 | fail: |
| 2635 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2636 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2637 | return -ENOBUFS; |
| 2638 | } |
| 2639 | |
| 2640 | |
| 2641 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 2642 | int key_idx, int defkey, |
| 2643 | const u8 *seq, size_t seq_len, |
| 2644 | const u8 *key, size_t key_len) |
| 2645 | { |
| 2646 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 2647 | u32 suite; |
| 2648 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2649 | if (!key_attr) |
| 2650 | return -1; |
| 2651 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 2652 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2653 | if (!suite) |
| 2654 | return -1; |
| 2655 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2656 | if (defkey && alg == WPA_ALG_IGTK) { |
| 2657 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 2658 | return -1; |
| 2659 | } else if (defkey) { |
| 2660 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 2661 | return -1; |
| 2662 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2663 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2664 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 2665 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2666 | (seq && seq_len && |
| 2667 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 2668 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 2669 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2670 | |
| 2671 | nla_nest_end(msg, key_attr); |
| 2672 | |
| 2673 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | |
| 2677 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 2678 | struct nl_msg *msg) |
| 2679 | { |
| 2680 | int i, privacy = 0; |
| 2681 | struct nlattr *nl_keys, *nl_key; |
| 2682 | |
| 2683 | for (i = 0; i < 4; i++) { |
| 2684 | if (!params->wep_key[i]) |
| 2685 | continue; |
| 2686 | privacy = 1; |
| 2687 | break; |
| 2688 | } |
| 2689 | if (params->wps == WPS_MODE_PRIVACY) |
| 2690 | privacy = 1; |
| 2691 | if (params->pairwise_suite && |
| 2692 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 2693 | privacy = 1; |
| 2694 | |
| 2695 | if (!privacy) |
| 2696 | return 0; |
| 2697 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2698 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 2699 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2700 | |
| 2701 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 2702 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2703 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2704 | |
| 2705 | for (i = 0; i < 4; i++) { |
| 2706 | if (!params->wep_key[i]) |
| 2707 | continue; |
| 2708 | |
| 2709 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2710 | if (!nl_key || |
| 2711 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 2712 | params->wep_key[i]) || |
| 2713 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2714 | params->wep_key_len[i] == 5 ? |
| 2715 | WLAN_CIPHER_SUITE_WEP40 : |
| 2716 | WLAN_CIPHER_SUITE_WEP104) || |
| 2717 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 2718 | (i == params->wep_tx_keyidx && |
| 2719 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 2720 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2721 | |
| 2722 | nla_nest_end(msg, nl_key); |
| 2723 | } |
| 2724 | nla_nest_end(msg, nl_keys); |
| 2725 | |
| 2726 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2730 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 2731 | const u8 *addr, int cmd, u16 reason_code, |
| 2732 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2733 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2734 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2735 | struct nl_msg *msg; |
| 2736 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2737 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 2738 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 2739 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 2740 | (local_state_change && |
| 2741 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 2742 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2743 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2744 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2745 | |
| 2746 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2747 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2748 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2749 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 2750 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2751 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2752 | return ret; |
| 2753 | } |
| 2754 | |
| 2755 | |
| 2756 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2757 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2758 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2759 | int ret; |
| 2760 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2761 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2762 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2763 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2764 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 2765 | reason_code, 0); |
| 2766 | /* |
| 2767 | * For locally generated disconnect, supplicant already generates a |
| 2768 | * DEAUTH event, so ignore the event from NL80211. |
| 2769 | */ |
| 2770 | drv->ignore_next_local_disconnect = ret == 0; |
| 2771 | |
| 2772 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2776 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 2777 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2778 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2779 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2780 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2781 | |
| 2782 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 2783 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2784 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2785 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2786 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2787 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2788 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 2789 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2790 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2791 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 2792 | reason_code, 0); |
| 2793 | /* |
| 2794 | * For locally generated deauthenticate, supplicant already generates a |
| 2795 | * DEAUTH event, so ignore the event from NL80211. |
| 2796 | */ |
| 2797 | drv->ignore_next_local_deauth = ret == 0; |
| 2798 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2802 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 2803 | struct wpa_driver_auth_params *params) |
| 2804 | { |
| 2805 | int i; |
| 2806 | |
| 2807 | drv->auth_freq = params->freq; |
| 2808 | drv->auth_alg = params->auth_alg; |
| 2809 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 2810 | drv->auth_local_state_change = params->local_state_change; |
| 2811 | drv->auth_p2p = params->p2p; |
| 2812 | |
| 2813 | if (params->bssid) |
| 2814 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 2815 | else |
| 2816 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 2817 | |
| 2818 | if (params->ssid) { |
| 2819 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 2820 | drv->auth_ssid_len = params->ssid_len; |
| 2821 | } else |
| 2822 | drv->auth_ssid_len = 0; |
| 2823 | |
| 2824 | |
| 2825 | os_free(drv->auth_ie); |
| 2826 | drv->auth_ie = NULL; |
| 2827 | drv->auth_ie_len = 0; |
| 2828 | if (params->ie) { |
| 2829 | drv->auth_ie = os_malloc(params->ie_len); |
| 2830 | if (drv->auth_ie) { |
| 2831 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 2832 | drv->auth_ie_len = params->ie_len; |
| 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | for (i = 0; i < 4; i++) { |
| 2837 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 2838 | params->wep_key_len[i] <= 16) { |
| 2839 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 2840 | params->wep_key_len[i]); |
| 2841 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 2842 | } else |
| 2843 | drv->auth_wep_key_len[i] = 0; |
| 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2848 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 2849 | { |
| 2850 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2851 | |
| 2852 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 2853 | return; |
| 2854 | |
| 2855 | /* |
| 2856 | * Looks like we failed to unmask 11b rates previously. This could |
| 2857 | * happen, e.g., if the interface was down at the point in time when a |
| 2858 | * P2P group was terminated. |
| 2859 | */ |
| 2860 | wpa_printf(MSG_DEBUG, |
| 2861 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 2862 | bss->ifname); |
| 2863 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2864 | } |
| 2865 | |
| 2866 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2867 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2868 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2869 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2870 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2871 | int ret = -1, i; |
| 2872 | struct nl_msg *msg; |
| 2873 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2874 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2875 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2876 | int is_retry; |
| 2877 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2878 | nl80211_unmask_11b_rates(bss); |
| 2879 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2880 | is_retry = drv->retry_auth; |
| 2881 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2882 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2883 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2884 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2885 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2886 | if (params->bssid) |
| 2887 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 2888 | else |
| 2889 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2890 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2891 | nlmode = params->p2p ? |
| 2892 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 2893 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2894 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2895 | return -1; |
| 2896 | |
| 2897 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2898 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 2899 | drv->ifindex); |
| 2900 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2901 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 2902 | if (!msg) |
| 2903 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2904 | |
| 2905 | for (i = 0; i < 4; i++) { |
| 2906 | if (!params->wep_key[i]) |
| 2907 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2908 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2909 | NULL, i, |
| 2910 | i == params->wep_tx_keyidx, NULL, 0, |
| 2911 | params->wep_key[i], |
| 2912 | params->wep_key_len[i]); |
| 2913 | if (params->wep_tx_keyidx != i) |
| 2914 | continue; |
| 2915 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2916 | params->wep_key[i], params->wep_key_len[i])) |
| 2917 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2920 | if (params->bssid) { |
| 2921 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 2922 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2923 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 2924 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2925 | } |
| 2926 | if (params->freq) { |
| 2927 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2928 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 2929 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2930 | } |
| 2931 | if (params->ssid) { |
| 2932 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 2933 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2934 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 2935 | params->ssid)) |
| 2936 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2937 | } |
| 2938 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2939 | if (params->ie && |
| 2940 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 2941 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2942 | if (params->sae_data) { |
| 2943 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 2944 | params->sae_data_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2945 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 2946 | params->sae_data)) |
| 2947 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2948 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2949 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 2950 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 2951 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 2952 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 2953 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 2954 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 2955 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 2956 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2957 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 2958 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2959 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2960 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2961 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2962 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 2963 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2964 | if (params->local_state_change) { |
| 2965 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2966 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 2967 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2971 | msg = NULL; |
| 2972 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2973 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2974 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 2975 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2976 | count++; |
| 2977 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 2978 | !params->local_state_change) { |
| 2979 | /* |
| 2980 | * mac80211 does not currently accept new |
| 2981 | * authentication if we are already authenticated. As a |
| 2982 | * workaround, force deauthentication and try again. |
| 2983 | */ |
| 2984 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 2985 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2986 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2987 | wpa_driver_nl80211_deauthenticate( |
| 2988 | bss, params->bssid, |
| 2989 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 2990 | nlmsg_free(msg); |
| 2991 | goto retry; |
| 2992 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2993 | |
| 2994 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 2995 | /* |
| 2996 | * cfg80211 has likely expired the BSS entry even |
| 2997 | * though it was previously available in our internal |
| 2998 | * BSS table. To recover quickly, start a single |
| 2999 | * channel scan on the specified channel. |
| 3000 | */ |
| 3001 | struct wpa_driver_scan_params scan; |
| 3002 | int freqs[2]; |
| 3003 | |
| 3004 | os_memset(&scan, 0, sizeof(scan)); |
| 3005 | scan.num_ssids = 1; |
| 3006 | if (params->ssid) { |
| 3007 | scan.ssids[0].ssid = params->ssid; |
| 3008 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3009 | } |
| 3010 | freqs[0] = params->freq; |
| 3011 | freqs[1] = 0; |
| 3012 | scan.freqs = freqs; |
| 3013 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3014 | "channel scan to refresh cfg80211 BSS " |
| 3015 | "entry"); |
| 3016 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3017 | if (ret == 0) { |
| 3018 | nl80211_copy_auth_params(drv, params); |
| 3019 | drv->scan_for_auth = 1; |
| 3020 | } |
| 3021 | } else if (is_retry) { |
| 3022 | /* |
| 3023 | * Need to indicate this with an event since the return |
| 3024 | * value from the retry is not delivered to core code. |
| 3025 | */ |
| 3026 | union wpa_event_data event; |
| 3027 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3028 | "failed"); |
| 3029 | os_memset(&event, 0, sizeof(event)); |
| 3030 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3031 | ETH_ALEN); |
| 3032 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3033 | &event); |
| 3034 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3035 | } else { |
| 3036 | wpa_printf(MSG_DEBUG, |
| 3037 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3038 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3039 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3040 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3041 | nlmsg_free(msg); |
| 3042 | return ret; |
| 3043 | } |
| 3044 | |
| 3045 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3046 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3047 | { |
| 3048 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3049 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3050 | int i; |
| 3051 | |
| 3052 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3053 | |
| 3054 | os_memset(¶ms, 0, sizeof(params)); |
| 3055 | params.freq = drv->auth_freq; |
| 3056 | params.auth_alg = drv->auth_alg; |
| 3057 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3058 | params.local_state_change = drv->auth_local_state_change; |
| 3059 | params.p2p = drv->auth_p2p; |
| 3060 | |
| 3061 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3062 | params.bssid = drv->auth_bssid_; |
| 3063 | |
| 3064 | if (drv->auth_ssid_len) { |
| 3065 | params.ssid = drv->auth_ssid; |
| 3066 | params.ssid_len = drv->auth_ssid_len; |
| 3067 | } |
| 3068 | |
| 3069 | params.ie = drv->auth_ie; |
| 3070 | params.ie_len = drv->auth_ie_len; |
| 3071 | |
| 3072 | for (i = 0; i < 4; i++) { |
| 3073 | if (drv->auth_wep_key_len[i]) { |
| 3074 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3075 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | drv->retry_auth = 1; |
| 3080 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3081 | } |
| 3082 | |
| 3083 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3084 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3085 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3086 | int encrypt, int noack, |
| 3087 | unsigned int freq, int no_cck, |
| 3088 | int offchanok, unsigned int wait_time) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3089 | { |
| 3090 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3091 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3092 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3093 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3094 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3095 | freq = nl80211_get_assoc_freq(drv); |
| 3096 | wpa_printf(MSG_DEBUG, |
| 3097 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3098 | freq); |
| 3099 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3100 | if (freq == 0) { |
| 3101 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3102 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3103 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3104 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3105 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3106 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3107 | 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] | 3108 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3109 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3110 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3111 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3112 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3113 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
| 3114 | &cookie, no_cck, noack, offchanok); |
| 3115 | if (res == 0 && !noack) { |
| 3116 | const struct ieee80211_mgmt *mgmt; |
| 3117 | u16 fc; |
| 3118 | |
| 3119 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3120 | fc = le_to_host16(mgmt->frame_control); |
| 3121 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3122 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3123 | wpa_printf(MSG_MSGDUMP, |
| 3124 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3125 | (long long unsigned int) |
| 3126 | drv->send_action_cookie, |
| 3127 | (long long unsigned int) cookie); |
| 3128 | drv->send_action_cookie = cookie; |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3133 | } |
| 3134 | |
| 3135 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3136 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3137 | size_t data_len, int noack, |
| 3138 | unsigned int freq, int no_cck, |
| 3139 | int offchanok, |
| 3140 | unsigned int wait_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3141 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3142 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3143 | struct ieee80211_mgmt *mgmt; |
| 3144 | int encrypt = 1; |
| 3145 | u16 fc; |
| 3146 | |
| 3147 | mgmt = (struct ieee80211_mgmt *) data; |
| 3148 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3149 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3150 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3151 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3152 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3153 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3154 | if ((is_sta_interface(drv->nlmode) || |
| 3155 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3156 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3157 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3158 | /* |
| 3159 | * The use of last_mgmt_freq is a bit of a hack, |
| 3160 | * but it works due to the single-threaded nature |
| 3161 | * of wpa_supplicant. |
| 3162 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3163 | if (freq == 0) { |
| 3164 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3165 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3166 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3167 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3168 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3169 | data, data_len, NULL, 1, noack, |
| 3170 | 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3171 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3172 | |
| 3173 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3174 | if (freq == 0) { |
| 3175 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3176 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3177 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3178 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3179 | return nl80211_send_frame_cmd(bss, freq, |
| 3180 | (int) freq == bss->freq ? 0 : |
| 3181 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3182 | data, data_len, |
| 3183 | &drv->send_action_cookie, |
| 3184 | no_cck, noack, offchanok); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3185 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3186 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3187 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3188 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3189 | /* |
| 3190 | * Only one of the authentication frame types is encrypted. |
| 3191 | * In order for static WEP encryption to work properly (i.e., |
| 3192 | * to not encrypt the frame), we need to tell mac80211 about |
| 3193 | * the frames that must not be encrypted. |
| 3194 | */ |
| 3195 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3196 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3197 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3198 | encrypt = 0; |
| 3199 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3200 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3201 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3202 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3203 | noack, freq, no_cck, offchanok, |
| 3204 | wait_time); |
| 3205 | } |
| 3206 | |
| 3207 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3208 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3209 | { |
| 3210 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3211 | u8 rates_len = 0; |
| 3212 | int i; |
| 3213 | |
| 3214 | if (!basic_rates) |
| 3215 | return 0; |
| 3216 | |
| 3217 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3218 | rates[rates_len++] = basic_rates[i] / 5; |
| 3219 | |
| 3220 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3221 | } |
| 3222 | |
| 3223 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3224 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3225 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3226 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3227 | { |
| 3228 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3229 | struct nl_msg *msg; |
| 3230 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3231 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3232 | (cts >= 0 && |
| 3233 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3234 | (preamble >= 0 && |
| 3235 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3236 | (slot >= 0 && |
| 3237 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3238 | (ht_opmode >= 0 && |
| 3239 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3240 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3241 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3242 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3243 | nlmsg_free(msg); |
| 3244 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3245 | } |
| 3246 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3247 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3251 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3252 | struct hostapd_acl_params *params) |
| 3253 | { |
| 3254 | struct i802_bss *bss = priv; |
| 3255 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3256 | struct nl_msg *msg; |
| 3257 | struct nlattr *acl; |
| 3258 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3259 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3260 | |
| 3261 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3262 | return -ENOTSUP; |
| 3263 | |
| 3264 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3265 | return -ENOTSUP; |
| 3266 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3267 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3268 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3269 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3270 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3271 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3272 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3273 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3274 | (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) { |
| 3275 | nlmsg_free(msg); |
| 3276 | return -ENOMEM; |
| 3277 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3278 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3279 | for (i = 0; i < params->num_mac_acl; i++) { |
| 3280 | if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3281 | nlmsg_free(msg); |
| 3282 | return -ENOMEM; |
| 3283 | } |
| 3284 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3285 | |
| 3286 | nla_nest_end(msg, acl); |
| 3287 | |
| 3288 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3289 | if (ret) { |
| 3290 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3291 | ret, strerror(-ret)); |
| 3292 | } |
| 3293 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3294 | return ret; |
| 3295 | } |
| 3296 | |
| 3297 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3298 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3299 | { |
| 3300 | if (beacon_int > 0) { |
| 3301 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3302 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3303 | beacon_int); |
| 3304 | } |
| 3305 | |
| 3306 | return 0; |
| 3307 | } |
| 3308 | |
| 3309 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3310 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3311 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3312 | { |
| 3313 | struct i802_bss *bss = priv; |
| 3314 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3315 | struct nl_msg *msg; |
| 3316 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3317 | int ret; |
| 3318 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3319 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3320 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3321 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3322 | u32 ver; |
| 3323 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3324 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3325 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3326 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3327 | beacon_set); |
| 3328 | if (beacon_set) |
| 3329 | cmd = NL80211_CMD_SET_BEACON; |
| 3330 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3331 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3332 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3333 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3334 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3335 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3336 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3337 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3338 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3339 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3340 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3341 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3342 | params->head) || |
| 3343 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3344 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3345 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3346 | nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) || |
| 3347 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3348 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3349 | if (params->proberesp && params->proberesp_len) { |
| 3350 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3351 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3352 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3353 | params->proberesp)) |
| 3354 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3355 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3356 | switch (params->hide_ssid) { |
| 3357 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3358 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3359 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3360 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3361 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3362 | break; |
| 3363 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3364 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3365 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3366 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3367 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3368 | break; |
| 3369 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3370 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3371 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3372 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3373 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3374 | break; |
| 3375 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3376 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3377 | if (params->privacy && |
| 3378 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3379 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3380 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3381 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3382 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3383 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3384 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3385 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3386 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3387 | goto fail; |
| 3388 | } else { |
| 3389 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3390 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3391 | goto fail; |
| 3392 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3393 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3394 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3395 | ver = 0; |
| 3396 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3397 | ver |= NL80211_WPA_VERSION_1; |
| 3398 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3399 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3400 | if (ver && |
| 3401 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3402 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3403 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3404 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3405 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3406 | num_suites = 0; |
| 3407 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 3408 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 3409 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 3410 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3411 | if (num_suites && |
| 3412 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3413 | suites)) |
| 3414 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3415 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3416 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 3417 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) && |
| 3418 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) |
| 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: pairwise_ciphers=0x%x", |
| 3422 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3423 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 3424 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3425 | if (num_suites && |
| 3426 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 3427 | num_suites * sizeof(u32), suites)) |
| 3428 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3429 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3430 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 3431 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3432 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3433 | if (suite && |
| 3434 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 3435 | goto fail; |
| 3436 | |
| 3437 | switch (params->smps_mode) { |
| 3438 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 3439 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 3440 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 3441 | break; |
| 3442 | case HT_CAP_INFO_SMPS_STATIC: |
| 3443 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 3444 | smps_mode = NL80211_SMPS_STATIC; |
| 3445 | break; |
| 3446 | default: |
| 3447 | /* invalid - fallback to smps off */ |
| 3448 | case HT_CAP_INFO_SMPS_DISABLED: |
| 3449 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 3450 | smps_mode = NL80211_SMPS_OFF; |
| 3451 | break; |
| 3452 | } |
| 3453 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
| 3454 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3455 | |
| 3456 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3457 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 3458 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3459 | if (nla_put(msg, NL80211_ATTR_IE, |
| 3460 | wpabuf_len(params->beacon_ies), |
| 3461 | wpabuf_head(params->beacon_ies))) |
| 3462 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3463 | } |
| 3464 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3465 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 3466 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3467 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 3468 | wpabuf_len(params->proberesp_ies), |
| 3469 | wpabuf_head(params->proberesp_ies))) |
| 3470 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3471 | } |
| 3472 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3473 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 3474 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3475 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 3476 | wpabuf_len(params->assocresp_ies), |
| 3477 | wpabuf_head(params->assocresp_ies))) |
| 3478 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3479 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3480 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3481 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3482 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 3483 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3484 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 3485 | params->ap_max_inactivity)) |
| 3486 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3487 | } |
| 3488 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3489 | #ifdef CONFIG_P2P |
| 3490 | if (params->p2p_go_ctwindow > 0) { |
| 3491 | if (drv->p2p_go_ctwindow_supported) { |
| 3492 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 3493 | params->p2p_go_ctwindow); |
| 3494 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 3495 | params->p2p_go_ctwindow)) |
| 3496 | goto fail; |
| 3497 | } else { |
| 3498 | wpa_printf(MSG_INFO, |
| 3499 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 3500 | } |
| 3501 | } |
| 3502 | #endif /* CONFIG_P2P */ |
| 3503 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3504 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3505 | if (ret) { |
| 3506 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 3507 | ret, strerror(-ret)); |
| 3508 | } else { |
| 3509 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3510 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 3511 | params->short_slot_time, params->ht_opmode, |
| 3512 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3513 | if (beacon_set && params->freq && |
| 3514 | params->freq->bandwidth != bss->bandwidth) { |
| 3515 | wpa_printf(MSG_DEBUG, |
| 3516 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 3517 | bss->ifname, bss->bandwidth, |
| 3518 | params->freq->bandwidth); |
| 3519 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 3520 | if (ret) { |
| 3521 | wpa_printf(MSG_DEBUG, |
| 3522 | "nl80211: Frequency set failed: %d (%s)", |
| 3523 | ret, strerror(-ret)); |
| 3524 | } else { |
| 3525 | wpa_printf(MSG_DEBUG, |
| 3526 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 3527 | bss->bandwidth = params->freq->bandwidth; |
| 3528 | } |
| 3529 | } else if (!beacon_set) { |
| 3530 | /* |
| 3531 | * cfg80211 updates the driver on frequence change in AP |
| 3532 | * mode only at the point when beaconing is started, so |
| 3533 | * set the initial value here. |
| 3534 | */ |
| 3535 | bss->bandwidth = params->freq->bandwidth; |
| 3536 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3537 | } |
| 3538 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3539 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3540 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3541 | return -ENOBUFS; |
| 3542 | } |
| 3543 | |
| 3544 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3545 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3546 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3547 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3548 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3549 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 3550 | return -ENOBUFS; |
| 3551 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3552 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 3553 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 3554 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3555 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3556 | enum nl80211_chan_width cw; |
| 3557 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3558 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3559 | switch (freq->bandwidth) { |
| 3560 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3561 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3562 | break; |
| 3563 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3564 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3565 | break; |
| 3566 | case 80: |
| 3567 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3568 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3569 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3570 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3571 | break; |
| 3572 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3573 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3574 | break; |
| 3575 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3576 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3577 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3578 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3579 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 3580 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 3581 | freq->center_freq1); |
| 3582 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 3583 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3584 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 3585 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 3586 | freq->center_freq1) || |
| 3587 | (freq->center_freq2 && |
| 3588 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 3589 | freq->center_freq2))) |
| 3590 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3591 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3592 | enum nl80211_channel_type ct; |
| 3593 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3594 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 3595 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3596 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3597 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3598 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3599 | break; |
| 3600 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3601 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3602 | break; |
| 3603 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3604 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3605 | break; |
| 3606 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3607 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3608 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3609 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 3610 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3611 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3612 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3616 | static int nl80211_set_channel(struct i802_bss *bss, |
| 3617 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3618 | { |
| 3619 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3620 | struct nl_msg *msg; |
| 3621 | int ret; |
| 3622 | |
| 3623 | wpa_printf(MSG_DEBUG, |
| 3624 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 3625 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 3626 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3627 | |
| 3628 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 3629 | NL80211_CMD_SET_WIPHY); |
| 3630 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 3631 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3632 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3633 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3634 | |
| 3635 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3636 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3637 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3638 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3639 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3640 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3641 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3642 | return -1; |
| 3643 | } |
| 3644 | |
| 3645 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3646 | static u32 sta_flags_nl80211(int flags) |
| 3647 | { |
| 3648 | u32 f = 0; |
| 3649 | |
| 3650 | if (flags & WPA_STA_AUTHORIZED) |
| 3651 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3652 | if (flags & WPA_STA_WMM) |
| 3653 | f |= BIT(NL80211_STA_FLAG_WME); |
| 3654 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 3655 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 3656 | if (flags & WPA_STA_MFP) |
| 3657 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 3658 | if (flags & WPA_STA_TDLS_PEER) |
| 3659 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3660 | if (flags & WPA_STA_AUTHENTICATED) |
| 3661 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3662 | |
| 3663 | return f; |
| 3664 | } |
| 3665 | |
| 3666 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3667 | #ifdef CONFIG_MESH |
| 3668 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 3669 | { |
| 3670 | switch (state) { |
| 3671 | case PLINK_LISTEN: |
| 3672 | return NL80211_PLINK_LISTEN; |
| 3673 | case PLINK_OPEN_SENT: |
| 3674 | return NL80211_PLINK_OPN_SNT; |
| 3675 | case PLINK_OPEN_RCVD: |
| 3676 | return NL80211_PLINK_OPN_RCVD; |
| 3677 | case PLINK_CNF_RCVD: |
| 3678 | return NL80211_PLINK_CNF_RCVD; |
| 3679 | case PLINK_ESTAB: |
| 3680 | return NL80211_PLINK_ESTAB; |
| 3681 | case PLINK_HOLDING: |
| 3682 | return NL80211_PLINK_HOLDING; |
| 3683 | case PLINK_BLOCKED: |
| 3684 | return NL80211_PLINK_BLOCKED; |
| 3685 | default: |
| 3686 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 3687 | state); |
| 3688 | } |
| 3689 | return -1; |
| 3690 | } |
| 3691 | #endif /* CONFIG_MESH */ |
| 3692 | |
| 3693 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3694 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 3695 | struct hostapd_sta_add_params *params) |
| 3696 | { |
| 3697 | struct i802_bss *bss = priv; |
| 3698 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3699 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3700 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3701 | int ret = -ENOBUFS; |
| 3702 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3703 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 3704 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 3705 | return -EOPNOTSUPP; |
| 3706 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3707 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 3708 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3709 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 3710 | NL80211_CMD_NEW_STATION); |
| 3711 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 3712 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3713 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3714 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) { |
| 3715 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 3716 | params->supp_rates, params->supp_rates_len); |
| 3717 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 3718 | params->capability); |
| 3719 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 3720 | params->supp_rates_len, params->supp_rates) || |
| 3721 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 3722 | params->capability)) |
| 3723 | goto fail; |
| 3724 | |
| 3725 | if (params->ht_capabilities) { |
| 3726 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 3727 | (u8 *) params->ht_capabilities, |
| 3728 | sizeof(*params->ht_capabilities)); |
| 3729 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 3730 | sizeof(*params->ht_capabilities), |
| 3731 | params->ht_capabilities)) |
| 3732 | goto fail; |
| 3733 | } |
| 3734 | |
| 3735 | if (params->vht_capabilities) { |
| 3736 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 3737 | (u8 *) params->vht_capabilities, |
| 3738 | sizeof(*params->vht_capabilities)); |
| 3739 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 3740 | sizeof(*params->vht_capabilities), |
| 3741 | params->vht_capabilities)) |
| 3742 | goto fail; |
| 3743 | } |
| 3744 | |
| 3745 | if (params->ext_capab) { |
| 3746 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 3747 | params->ext_capab, params->ext_capab_len); |
| 3748 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 3749 | params->ext_capab_len, params->ext_capab)) |
| 3750 | goto fail; |
| 3751 | } |
| 3752 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3753 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3754 | if (params->aid) { |
| 3755 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3756 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 3757 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3758 | } else { |
| 3759 | /* |
| 3760 | * cfg80211 validates that AID is non-zero, so we have |
| 3761 | * to make this a non-zero value for the TDLS case where |
| 3762 | * a dummy STA entry is used for now. |
| 3763 | */ |
| 3764 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3765 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 3766 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3767 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3768 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 3769 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3770 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 3771 | params->listen_interval)) |
| 3772 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3773 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 3774 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3775 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 3776 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3777 | } |
| 3778 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3779 | if (params->vht_opmode_enabled) { |
| 3780 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3781 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 3782 | params->vht_opmode)) |
| 3783 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3784 | } |
| 3785 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3786 | if (params->supp_channels) { |
| 3787 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 3788 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3789 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 3790 | params->supp_channels_len, params->supp_channels)) |
| 3791 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | if (params->supp_oper_classes) { |
| 3795 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 3796 | params->supp_oper_classes, |
| 3797 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3798 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 3799 | params->supp_oper_classes_len, |
| 3800 | params->supp_oper_classes)) |
| 3801 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3802 | } |
| 3803 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3804 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3805 | upd.set = sta_flags_nl80211(params->flags); |
| 3806 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3807 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 3808 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3809 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 3810 | goto fail; |
| 3811 | |
| 3812 | #ifdef CONFIG_MESH |
| 3813 | if (params->plink_state && |
| 3814 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 3815 | sta_plink_state_nl80211(params->plink_state))) |
| 3816 | goto fail; |
| 3817 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3818 | |
| 3819 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3820 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 3821 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3822 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3823 | if (!wme || |
| 3824 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 3825 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 3826 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 3827 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 3828 | WMM_QOSINFO_STA_SP_MASK)) |
| 3829 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3830 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3831 | } |
| 3832 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3833 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3834 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3835 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3836 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 3837 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 3838 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3839 | if (ret == -EEXIST) |
| 3840 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3841 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3842 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3843 | return ret; |
| 3844 | } |
| 3845 | |
| 3846 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3847 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 3848 | { |
| 3849 | #ifdef CONFIG_LIBNL3_ROUTE |
| 3850 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3851 | struct rtnl_neigh *rn; |
| 3852 | struct nl_addr *nl_addr; |
| 3853 | int err; |
| 3854 | |
| 3855 | rn = rtnl_neigh_alloc(); |
| 3856 | if (!rn) |
| 3857 | return; |
| 3858 | |
| 3859 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 3860 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 3861 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 3862 | if (!nl_addr) { |
| 3863 | rtnl_neigh_put(rn); |
| 3864 | return; |
| 3865 | } |
| 3866 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 3867 | |
| 3868 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 3869 | if (err < 0) { |
| 3870 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 3871 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 3872 | bss->ifindex, nl_geterror(err)); |
| 3873 | } else { |
| 3874 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 3875 | MACSTR, MAC2STR(addr)); |
| 3876 | } |
| 3877 | |
| 3878 | nl_addr_put(nl_addr); |
| 3879 | rtnl_neigh_put(rn); |
| 3880 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 3881 | } |
| 3882 | |
| 3883 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3884 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 3885 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3886 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3887 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3888 | struct nl_msg *msg; |
| 3889 | int ret; |
| 3890 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3891 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 3892 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3893 | (deauth == 0 && |
| 3894 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 3895 | WLAN_FC_STYPE_DISASSOC)) || |
| 3896 | (deauth == 1 && |
| 3897 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 3898 | WLAN_FC_STYPE_DEAUTH)) || |
| 3899 | (reason_code && |
| 3900 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 3901 | nlmsg_free(msg); |
| 3902 | return -ENOBUFS; |
| 3903 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3904 | |
| 3905 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 3906 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 3907 | " --> %d (%s)", |
| 3908 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3909 | |
| 3910 | if (drv->rtnl_sk) |
| 3911 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 3912 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3913 | if (ret == -ENOENT) |
| 3914 | return 0; |
| 3915 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3919 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3920 | { |
| 3921 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3922 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3923 | |
| 3924 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 3925 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3926 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3927 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 3928 | struct wpa_driver_nl80211_data, list) |
| 3929 | del_ifidx(drv2, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3930 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3931 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3932 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 3933 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3934 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 3935 | } |
| 3936 | |
| 3937 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3938 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 3939 | { |
| 3940 | switch (mode) { |
| 3941 | case NL80211_IFTYPE_ADHOC: |
| 3942 | return "ADHOC"; |
| 3943 | case NL80211_IFTYPE_STATION: |
| 3944 | return "STATION"; |
| 3945 | case NL80211_IFTYPE_AP: |
| 3946 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3947 | case NL80211_IFTYPE_AP_VLAN: |
| 3948 | return "AP_VLAN"; |
| 3949 | case NL80211_IFTYPE_WDS: |
| 3950 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3951 | case NL80211_IFTYPE_MONITOR: |
| 3952 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3953 | case NL80211_IFTYPE_MESH_POINT: |
| 3954 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3955 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3956 | return "P2P_CLIENT"; |
| 3957 | case NL80211_IFTYPE_P2P_GO: |
| 3958 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3959 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3960 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3961 | default: |
| 3962 | return "unknown"; |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3967 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 3968 | const char *ifname, |
| 3969 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3970 | const u8 *addr, int wds, |
| 3971 | int (*handler)(struct nl_msg *, void *), |
| 3972 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3973 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3974 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3975 | int ifidx; |
| 3976 | int ret = -ENOBUFS; |
| 3977 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3978 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 3979 | iftype, nl80211_iftype_str(iftype)); |
| 3980 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3981 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 3982 | if (!msg || |
| 3983 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 3984 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 3985 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3986 | |
| 3987 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3988 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3989 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3990 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3991 | if (!flags || |
| 3992 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 3993 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3994 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3995 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3996 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3997 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 3998 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4001 | /* |
| 4002 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4003 | * it, and the interface should be deleted when the socket is closed. |
| 4004 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4005 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4006 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4007 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4008 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4009 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4010 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4011 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4012 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4013 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4014 | ifname, ret, strerror(-ret)); |
| 4015 | return ret; |
| 4016 | } |
| 4017 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4018 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4019 | return 0; |
| 4020 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4021 | ifidx = if_nametoindex(ifname); |
| 4022 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4023 | ifname, ifidx); |
| 4024 | |
| 4025 | if (ifidx <= 0) |
| 4026 | return -1; |
| 4027 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4028 | /* |
| 4029 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4030 | * the parent interface. This is used mainly with hostapd. |
| 4031 | */ |
| 4032 | if (drv->hostapd || |
| 4033 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4034 | iftype == NL80211_IFTYPE_WDS || |
| 4035 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4036 | /* start listening for EAPOL on this interface */ |
| 4037 | add_ifidx(drv, ifidx); |
| 4038 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4039 | |
| 4040 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4041 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4042 | nl80211_remove_iface(drv, ifidx); |
| 4043 | return -1; |
| 4044 | } |
| 4045 | |
| 4046 | return ifidx; |
| 4047 | } |
| 4048 | |
| 4049 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4050 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4051 | const char *ifname, enum nl80211_iftype iftype, |
| 4052 | const u8 *addr, int wds, |
| 4053 | int (*handler)(struct nl_msg *, void *), |
| 4054 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4055 | { |
| 4056 | int ret; |
| 4057 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4058 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4059 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4060 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4061 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4062 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4063 | if (use_existing) { |
| 4064 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4065 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4066 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4067 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4068 | addr) < 0 && |
| 4069 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4070 | ifname, 0) < 0 || |
| 4071 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4072 | addr) < 0 || |
| 4073 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4074 | ifname, 1) < 0)) |
| 4075 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4076 | return -ENFILE; |
| 4077 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4078 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4079 | |
| 4080 | /* Try to remove the interface that was already there. */ |
| 4081 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4082 | |
| 4083 | /* Try to create the interface again */ |
| 4084 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4085 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4088 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4089 | wpa_printf(MSG_DEBUG, |
| 4090 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4091 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4092 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4093 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4094 | |
| 4095 | return ret; |
| 4096 | } |
| 4097 | |
| 4098 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4099 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4100 | { |
| 4101 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4102 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4103 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4104 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4105 | |
| 4106 | /* |
| 4107 | * Disable Probe Request reporting unless we need it in this way for |
| 4108 | * devices that include the AP SME, in the other case (unless using |
| 4109 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4110 | */ |
| 4111 | if (!drv->device_ap_sme) |
| 4112 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4113 | |
| 4114 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4115 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4116 | return -1; |
| 4117 | |
| 4118 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4119 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 4120 | return -1; |
| 4121 | |
| 4122 | if (!drv->device_ap_sme && drv->use_monitor && |
| 4123 | nl80211_create_monitor_interface(drv) && |
| 4124 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4125 | return -1; |
| 4126 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4127 | if (drv->device_ap_sme && |
| 4128 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4129 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4130 | "Probe Request frame reporting in AP mode"); |
| 4131 | /* Try to survive without this */ |
| 4132 | } |
| 4133 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4134 | return 0; |
| 4135 | } |
| 4136 | |
| 4137 | |
| 4138 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4139 | { |
| 4140 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4141 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4142 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4143 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4144 | if (drv->device_ap_sme) { |
| 4145 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4146 | if (!drv->use_monitor) |
| 4147 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4148 | } else if (drv->use_monitor) |
| 4149 | nl80211_remove_monitor_interface(drv); |
| 4150 | else |
| 4151 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4152 | |
| 4153 | bss->beacon_set = 0; |
| 4154 | } |
| 4155 | |
| 4156 | |
| 4157 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4158 | const u8 *addr, const u8 *data, |
| 4159 | size_t data_len) |
| 4160 | { |
| 4161 | struct sockaddr_ll ll; |
| 4162 | int ret; |
| 4163 | |
| 4164 | if (bss->drv->eapol_tx_sock < 0) { |
| 4165 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4166 | return -1; |
| 4167 | } |
| 4168 | |
| 4169 | os_memset(&ll, 0, sizeof(ll)); |
| 4170 | ll.sll_family = AF_PACKET; |
| 4171 | ll.sll_ifindex = bss->ifindex; |
| 4172 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4173 | ll.sll_halen = ETH_ALEN; |
| 4174 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4175 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4176 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4177 | if (ret < 0) |
| 4178 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4179 | strerror(errno)); |
| 4180 | |
| 4181 | return ret; |
| 4182 | } |
| 4183 | |
| 4184 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4185 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4186 | |
| 4187 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4188 | void *priv, const u8 *addr, const u8 *data, |
| 4189 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4190 | { |
| 4191 | struct i802_bss *bss = priv; |
| 4192 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4193 | struct ieee80211_hdr *hdr; |
| 4194 | size_t len; |
| 4195 | u8 *pos; |
| 4196 | int res; |
| 4197 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4198 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4199 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4200 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4201 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4202 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4203 | data_len; |
| 4204 | hdr = os_zalloc(len); |
| 4205 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4206 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4207 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4208 | return -1; |
| 4209 | } |
| 4210 | |
| 4211 | hdr->frame_control = |
| 4212 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4213 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4214 | if (encrypt) |
| 4215 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4216 | if (qos) { |
| 4217 | hdr->frame_control |= |
| 4218 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4219 | } |
| 4220 | |
| 4221 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4222 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4223 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4224 | pos = (u8 *) (hdr + 1); |
| 4225 | |
| 4226 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4227 | /* Set highest priority in QoS header */ |
| 4228 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4229 | pos[1] = 0; |
| 4230 | pos += 2; |
| 4231 | } |
| 4232 | |
| 4233 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4234 | pos += sizeof(rfc1042_header); |
| 4235 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4236 | pos += 2; |
| 4237 | memcpy(pos, data, data_len); |
| 4238 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4239 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
| 4240 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4241 | if (res < 0) { |
| 4242 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4243 | "failed: %d (%s)", |
| 4244 | (unsigned long) len, errno, strerror(errno)); |
| 4245 | } |
| 4246 | os_free(hdr); |
| 4247 | |
| 4248 | return res; |
| 4249 | } |
| 4250 | |
| 4251 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4252 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
| 4253 | int total_flags, |
| 4254 | int flags_or, int flags_and) |
| 4255 | { |
| 4256 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4257 | struct nl_msg *msg; |
| 4258 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4259 | struct nl80211_sta_flag_update upd; |
| 4260 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4261 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4262 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4263 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4264 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4265 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4266 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4267 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4268 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4269 | |
| 4270 | /* |
| 4271 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4272 | * can be removed eventually. |
| 4273 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4274 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4275 | if (!flags || |
| 4276 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4277 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4278 | ((total_flags & WPA_STA_WMM) && |
| 4279 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4280 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4281 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4282 | ((total_flags & WPA_STA_MFP) && |
| 4283 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4284 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4285 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4286 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4287 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4288 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4289 | |
| 4290 | os_memset(&upd, 0, sizeof(upd)); |
| 4291 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4292 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4293 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4294 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4295 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4296 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4297 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4298 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4299 | return -ENOBUFS; |
| 4300 | } |
| 4301 | |
| 4302 | |
| 4303 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4304 | struct wpa_driver_associate_params *params) |
| 4305 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4306 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4307 | |
| 4308 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4309 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4310 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4311 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4312 | } else |
| 4313 | nlmode = NL80211_IFTYPE_AP; |
| 4314 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4315 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4316 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4317 | nl80211_remove_monitor_interface(drv); |
| 4318 | return -1; |
| 4319 | } |
| 4320 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4321 | if (params->freq.freq && |
| 4322 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4323 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4324 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4325 | nl80211_remove_monitor_interface(drv); |
| 4326 | return -1; |
| 4327 | } |
| 4328 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4329 | return 0; |
| 4330 | } |
| 4331 | |
| 4332 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4333 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 4334 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4335 | { |
| 4336 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4337 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4338 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4339 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4340 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4341 | if (ret) { |
| 4342 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 4343 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4344 | } else { |
| 4345 | wpa_printf(MSG_DEBUG, |
| 4346 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4347 | } |
| 4348 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4349 | if (reset_mode && |
| 4350 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4351 | NL80211_IFTYPE_STATION)) { |
| 4352 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4353 | "station mode"); |
| 4354 | } |
| 4355 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4356 | return ret; |
| 4357 | } |
| 4358 | |
| 4359 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4360 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 4361 | struct wpa_driver_associate_params *params) |
| 4362 | { |
| 4363 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 4364 | return -1; |
| 4365 | |
| 4366 | if (params->htcaps && params->htcaps_mask) { |
| 4367 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 4368 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 4369 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 4370 | params->htcaps_mask, sz); |
| 4371 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 4372 | params->htcaps) || |
| 4373 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 4374 | params->htcaps_mask)) |
| 4375 | return -1; |
| 4376 | } |
| 4377 | |
| 4378 | #ifdef CONFIG_VHT_OVERRIDES |
| 4379 | if (params->disable_vht) { |
| 4380 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 4381 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 4382 | return -1; |
| 4383 | } |
| 4384 | |
| 4385 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 4386 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 4387 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 4388 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 4389 | params->vhtcaps_mask, sz); |
| 4390 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 4391 | params->vhtcaps) || |
| 4392 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 4393 | params->vhtcaps_mask)) |
| 4394 | return -1; |
| 4395 | } |
| 4396 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 4397 | |
| 4398 | return 0; |
| 4399 | } |
| 4400 | |
| 4401 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4402 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 4403 | struct wpa_driver_associate_params *params) |
| 4404 | { |
| 4405 | struct nl_msg *msg; |
| 4406 | int ret = -1; |
| 4407 | int count = 0; |
| 4408 | |
| 4409 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 4410 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4411 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4412 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4413 | "IBSS mode"); |
| 4414 | return -1; |
| 4415 | } |
| 4416 | |
| 4417 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4418 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 4419 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 4420 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4421 | |
| 4422 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4423 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4424 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4425 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4426 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4427 | drv->ssid_len = params->ssid_len; |
| 4428 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4429 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 4430 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4431 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4432 | |
| 4433 | ret = nl80211_set_conn_keys(params, msg); |
| 4434 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4435 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4436 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4437 | if (params->bssid && params->fixed_bssid) { |
| 4438 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 4439 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4440 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4441 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4442 | } |
| 4443 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4444 | if (params->fixed_freq) { |
| 4445 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 4446 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 4447 | goto fail; |
| 4448 | } |
| 4449 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4450 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4451 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4452 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 4453 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4454 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4455 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4456 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4457 | } |
| 4458 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4459 | if (params->wpa_ie) { |
| 4460 | wpa_hexdump(MSG_DEBUG, |
| 4461 | " * Extra IEs for Beacon/Probe Response frames", |
| 4462 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4463 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 4464 | params->wpa_ie)) |
| 4465 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4468 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
| 4469 | return -1; |
| 4470 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4471 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4472 | msg = NULL; |
| 4473 | if (ret) { |
| 4474 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 4475 | ret, strerror(-ret)); |
| 4476 | count++; |
| 4477 | if (ret == -EALREADY && count == 1) { |
| 4478 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 4479 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4480 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4481 | nlmsg_free(msg); |
| 4482 | goto retry; |
| 4483 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4484 | } else { |
| 4485 | wpa_printf(MSG_DEBUG, |
| 4486 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4487 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4488 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4489 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4490 | nlmsg_free(msg); |
| 4491 | return ret; |
| 4492 | } |
| 4493 | |
| 4494 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4495 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 4496 | struct wpa_driver_associate_params *params, |
| 4497 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4498 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4499 | if (params->bssid) { |
| 4500 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4501 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4502 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4503 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4504 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4505 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4506 | if (params->bssid_hint) { |
| 4507 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 4508 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4509 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 4510 | params->bssid_hint)) |
| 4511 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4512 | } |
| 4513 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4514 | if (params->freq.freq) { |
| 4515 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 4517 | params->freq.freq)) |
| 4518 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4519 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4520 | } else |
| 4521 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4522 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4523 | if (params->freq_hint) { |
| 4524 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4525 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 4526 | params->freq_hint)) |
| 4527 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4528 | } |
| 4529 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4530 | if (params->bg_scan_period >= 0) { |
| 4531 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 4532 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4533 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 4534 | params->bg_scan_period)) |
| 4535 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4536 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4537 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4538 | if (params->ssid) { |
| 4539 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4540 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4541 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4542 | params->ssid)) |
| 4543 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4544 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4545 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4546 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4547 | drv->ssid_len = params->ssid_len; |
| 4548 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4549 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4550 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4551 | if (params->wpa_ie && |
| 4552 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 4553 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4554 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4555 | if (params->wpa_proto) { |
| 4556 | enum nl80211_wpa_versions ver = 0; |
| 4557 | |
| 4558 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 4559 | ver |= NL80211_WPA_VERSION_1; |
| 4560 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 4561 | ver |= NL80211_WPA_VERSION_2; |
| 4562 | |
| 4563 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4564 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4565 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 4569 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 4570 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4571 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4572 | cipher)) |
| 4573 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4574 | } |
| 4575 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4576 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 4577 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 4578 | /* |
| 4579 | * This is likely to work even though many drivers do not |
| 4580 | * advertise support for operations without GTK. |
| 4581 | */ |
| 4582 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 4583 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4584 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 4585 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4586 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 4587 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4591 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4592 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 4593 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4594 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4595 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 4596 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4597 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4598 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
| 4599 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4600 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 4601 | |
| 4602 | switch (params->key_mgmt_suite) { |
| 4603 | case WPA_KEY_MGMT_CCKM: |
| 4604 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 4605 | break; |
| 4606 | case WPA_KEY_MGMT_IEEE8021X: |
| 4607 | mgmt = WLAN_AKM_SUITE_8021X; |
| 4608 | break; |
| 4609 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 4610 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 4611 | break; |
| 4612 | case WPA_KEY_MGMT_FT_PSK: |
| 4613 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 4614 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4615 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 4616 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; |
| 4617 | break; |
| 4618 | case WPA_KEY_MGMT_PSK_SHA256: |
| 4619 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; |
| 4620 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4621 | case WPA_KEY_MGMT_OSEN: |
| 4622 | mgmt = WLAN_AKM_SUITE_OSEN; |
| 4623 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4624 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 4625 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; |
| 4626 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4627 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
| 4628 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; |
| 4629 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4630 | case WPA_KEY_MGMT_PSK: |
| 4631 | default: |
| 4632 | mgmt = WLAN_AKM_SUITE_PSK; |
| 4633 | break; |
| 4634 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4635 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4636 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 4637 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4638 | } |
| 4639 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4640 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4641 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4642 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4643 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 4644 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 4645 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4646 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4647 | if (params->rrm_used) { |
| 4648 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
| 4649 | if (!(drv_rrm_flags & |
| 4650 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) || |
| 4651 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) || |
| 4652 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 4653 | return -1; |
| 4654 | } |
| 4655 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4656 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4657 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4658 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4659 | if (params->p2p) |
| 4660 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 4661 | |
| 4662 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | |
| 4666 | static int wpa_driver_nl80211_try_connect( |
| 4667 | struct wpa_driver_nl80211_data *drv, |
| 4668 | struct wpa_driver_associate_params *params) |
| 4669 | { |
| 4670 | struct nl_msg *msg; |
| 4671 | enum nl80211_auth_type type; |
| 4672 | int ret; |
| 4673 | int algs; |
| 4674 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4675 | if (params->req_key_mgmt_offload && params->psk && |
| 4676 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4677 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 4678 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 4679 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 4680 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 4681 | if (ret) |
| 4682 | return ret; |
| 4683 | } |
| 4684 | |
| 4685 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 4686 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4687 | if (!msg) |
| 4688 | return -1; |
| 4689 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4690 | ret = nl80211_connect_common(drv, params, msg); |
| 4691 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4692 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4693 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4694 | algs = 0; |
| 4695 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4696 | algs++; |
| 4697 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4698 | algs++; |
| 4699 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4700 | algs++; |
| 4701 | if (algs > 1) { |
| 4702 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 4703 | "selection"); |
| 4704 | goto skip_auth_type; |
| 4705 | } |
| 4706 | |
| 4707 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4708 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 4709 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4710 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 4711 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4712 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 4713 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 4714 | type = NL80211_AUTHTYPE_FT; |
| 4715 | else |
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 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4719 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 4720 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4721 | |
| 4722 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4723 | ret = nl80211_set_conn_keys(params, msg); |
| 4724 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4725 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4726 | |
| 4727 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4728 | msg = NULL; |
| 4729 | if (ret) { |
| 4730 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 4731 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4732 | } else { |
| 4733 | wpa_printf(MSG_DEBUG, |
| 4734 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4735 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4736 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4737 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4738 | nlmsg_free(msg); |
| 4739 | return ret; |
| 4740 | |
| 4741 | } |
| 4742 | |
| 4743 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4744 | static int wpa_driver_nl80211_connect( |
| 4745 | struct wpa_driver_nl80211_data *drv, |
| 4746 | struct wpa_driver_associate_params *params) |
| 4747 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 4748 | int ret; |
| 4749 | |
| 4750 | /* Store the connection attempted bssid for future use */ |
| 4751 | if (params->bssid) |
| 4752 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 4753 | else |
| 4754 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 4755 | |
| 4756 | ret = wpa_driver_nl80211_try_connect(drv, params); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4757 | if (ret == -EALREADY) { |
| 4758 | /* |
| 4759 | * cfg80211 does not currently accept new connections if |
| 4760 | * we are already connected. As a workaround, force |
| 4761 | * disconnection and try again. |
| 4762 | */ |
| 4763 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 4764 | "disconnecting before reassociation " |
| 4765 | "attempt"); |
| 4766 | if (wpa_driver_nl80211_disconnect( |
| 4767 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 4768 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4769 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 4770 | } |
| 4771 | return ret; |
| 4772 | } |
| 4773 | |
| 4774 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4775 | static int wpa_driver_nl80211_associate( |
| 4776 | void *priv, struct wpa_driver_associate_params *params) |
| 4777 | { |
| 4778 | struct i802_bss *bss = priv; |
| 4779 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4780 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4781 | struct nl_msg *msg; |
| 4782 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4783 | nl80211_unmask_11b_rates(bss); |
| 4784 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4785 | if (params->mode == IEEE80211_MODE_AP) |
| 4786 | return wpa_driver_nl80211_ap(drv, params); |
| 4787 | |
| 4788 | if (params->mode == IEEE80211_MODE_IBSS) |
| 4789 | return wpa_driver_nl80211_ibss(drv, params); |
| 4790 | |
| 4791 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4792 | enum nl80211_iftype nlmode = params->p2p ? |
| 4793 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 4794 | |
| 4795 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4796 | return -1; |
| 4797 | return wpa_driver_nl80211_connect(drv, params); |
| 4798 | } |
| 4799 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4800 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4801 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4802 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 4803 | drv->ifindex); |
| 4804 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4805 | if (!msg) |
| 4806 | return -1; |
| 4807 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4808 | ret = nl80211_connect_common(drv, params, msg); |
| 4809 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4810 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4811 | |
| 4812 | if (params->prev_bssid) { |
| 4813 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 4814 | MAC2STR(params->prev_bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4815 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 4816 | params->prev_bssid)) |
| 4817 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4818 | } |
| 4819 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4820 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4821 | msg = NULL; |
| 4822 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4823 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 4824 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 4825 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4826 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4827 | } else { |
| 4828 | wpa_printf(MSG_DEBUG, |
| 4829 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4830 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4831 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4832 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4833 | nlmsg_free(msg); |
| 4834 | return ret; |
| 4835 | } |
| 4836 | |
| 4837 | |
| 4838 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4839 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4840 | { |
| 4841 | struct nl_msg *msg; |
| 4842 | int ret = -ENOBUFS; |
| 4843 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4844 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 4845 | ifindex, mode, nl80211_iftype_str(mode)); |
| 4846 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4847 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 4848 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 4849 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4850 | |
| 4851 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4852 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4853 | if (!ret) |
| 4854 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4855 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4856 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4857 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 4858 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 4859 | return ret; |
| 4860 | } |
| 4861 | |
| 4862 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4863 | static int wpa_driver_nl80211_set_mode_impl( |
| 4864 | struct i802_bss *bss, |
| 4865 | enum nl80211_iftype nlmode, |
| 4866 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4867 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4868 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4869 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4870 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4871 | int was_ap = is_ap_interface(drv->nlmode); |
| 4872 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4873 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4874 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4875 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 4876 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 4877 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4878 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4879 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4880 | drv->nlmode = nlmode; |
| 4881 | ret = 0; |
| 4882 | goto done; |
| 4883 | } |
| 4884 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4885 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4886 | return -1; |
| 4887 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4888 | if (nlmode == drv->nlmode) { |
| 4889 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 4890 | "requested mode - ignore error"); |
| 4891 | ret = 0; |
| 4892 | goto done; /* Already in the requested mode */ |
| 4893 | } |
| 4894 | |
| 4895 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 4896 | * take the device down, try to set the mode again, and bring the |
| 4897 | * device back up. |
| 4898 | */ |
| 4899 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 4900 | "interface down"); |
| 4901 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4902 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4903 | if (res == -EACCES || res == -ENODEV) |
| 4904 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4905 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4906 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 4907 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4908 | os_sleep(0, 100000); |
| 4909 | continue; |
| 4910 | } |
| 4911 | |
| 4912 | /* |
| 4913 | * Setting the mode will fail for some drivers if the phy is |
| 4914 | * on a frequency that the mode is disallowed in. |
| 4915 | */ |
| 4916 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4917 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4918 | if (res) { |
| 4919 | wpa_printf(MSG_DEBUG, |
| 4920 | "nl80211: Failed to set frequency on interface"); |
| 4921 | } |
| 4922 | } |
| 4923 | |
| 4924 | /* Try to set the mode again while the interface is down */ |
| 4925 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 4926 | if (mode_switch_res == -EBUSY) { |
| 4927 | wpa_printf(MSG_DEBUG, |
| 4928 | "nl80211: Delaying mode set while interface going down"); |
| 4929 | os_sleep(0, 100000); |
| 4930 | continue; |
| 4931 | } |
| 4932 | ret = mode_switch_res; |
| 4933 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | if (!ret) { |
| 4937 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 4938 | "interface is down"); |
| 4939 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4940 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4941 | } |
| 4942 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4943 | /* Bring the interface back up */ |
| 4944 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 4945 | if (res != 0) { |
| 4946 | wpa_printf(MSG_DEBUG, |
| 4947 | "nl80211: Failed to set interface up after switching mode"); |
| 4948 | ret = -1; |
| 4949 | } |
| 4950 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4951 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4952 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4953 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 4954 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4955 | return ret; |
| 4956 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4957 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4958 | if (is_p2p_net_interface(nlmode)) { |
| 4959 | wpa_printf(MSG_DEBUG, |
| 4960 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 4961 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4962 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4963 | } else if (drv->disabled_11b_rates) { |
| 4964 | wpa_printf(MSG_DEBUG, |
| 4965 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 4966 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4967 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4968 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4969 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4970 | if (is_ap_interface(nlmode)) { |
| 4971 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 4972 | /* Setup additional AP mode functionality if needed */ |
| 4973 | if (nl80211_setup_ap(bss)) |
| 4974 | return -1; |
| 4975 | } else if (was_ap) { |
| 4976 | /* Remove additional AP mode functionality */ |
| 4977 | nl80211_teardown_ap(bss); |
| 4978 | } else { |
| 4979 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 4980 | } |
| 4981 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4982 | if (is_mesh_interface(nlmode) && |
| 4983 | nl80211_mgmt_subscribe_mesh(bss)) |
| 4984 | return -1; |
| 4985 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4986 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4987 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4988 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 4989 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 4990 | "frame processing - ignore for now"); |
| 4991 | |
| 4992 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4996 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 4997 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4998 | { |
| 4999 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5000 | } |
| 5001 | |
| 5002 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5003 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5004 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5005 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5006 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5007 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5011 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5012 | struct wpa_driver_capa *capa) |
| 5013 | { |
| 5014 | struct i802_bss *bss = priv; |
| 5015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5016 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5017 | if (!drv->has_capability) |
| 5018 | return -1; |
| 5019 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5020 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5021 | capa->extended_capa = drv->extended_capa; |
| 5022 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5023 | capa->extended_capa_len = drv->extended_capa_len; |
| 5024 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5025 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5026 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | |
| 5030 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5031 | { |
| 5032 | struct i802_bss *bss = priv; |
| 5033 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5034 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5035 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5036 | bss->ifname, drv->operstate, state, |
| 5037 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5038 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5039 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5040 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5041 | } |
| 5042 | |
| 5043 | |
| 5044 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5045 | { |
| 5046 | struct i802_bss *bss = priv; |
| 5047 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5048 | struct nl_msg *msg; |
| 5049 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5050 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5051 | |
| 5052 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5053 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5054 | return 0; |
| 5055 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5056 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5057 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5058 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5059 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5060 | os_memset(&upd, 0, sizeof(upd)); |
| 5061 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5062 | if (authorized) |
| 5063 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5064 | |
| 5065 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5066 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5067 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5068 | nlmsg_free(msg); |
| 5069 | return -ENOBUFS; |
| 5070 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5071 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5072 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5073 | if (!ret) |
| 5074 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5075 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5076 | ret, strerror(-ret)); |
| 5077 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5078 | } |
| 5079 | |
| 5080 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5081 | /* Set kernel driver on given frequency (MHz) */ |
| 5082 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5083 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5084 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5085 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5089 | static inline int min_int(int a, int b) |
| 5090 | { |
| 5091 | if (a < b) |
| 5092 | return a; |
| 5093 | return b; |
| 5094 | } |
| 5095 | |
| 5096 | |
| 5097 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5098 | { |
| 5099 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5100 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5101 | |
| 5102 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5103 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5104 | |
| 5105 | /* |
| 5106 | * TODO: validate the key index and mac address! |
| 5107 | * Otherwise, there's a race condition as soon as |
| 5108 | * the kernel starts sending key notifications. |
| 5109 | */ |
| 5110 | |
| 5111 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5112 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5113 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5114 | return NL_SKIP; |
| 5115 | } |
| 5116 | |
| 5117 | |
| 5118 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5119 | int idx, u8 *seq) |
| 5120 | { |
| 5121 | struct i802_bss *bss = priv; |
| 5122 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5123 | struct nl_msg *msg; |
| 5124 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5125 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5126 | NL80211_CMD_GET_KEY); |
| 5127 | if (!msg || |
| 5128 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5129 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5130 | nlmsg_free(msg); |
| 5131 | return -ENOBUFS; |
| 5132 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5133 | |
| 5134 | memset(seq, 0, 6); |
| 5135 | |
| 5136 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5137 | } |
| 5138 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5139 | |
| 5140 | static int i802_set_rts(void *priv, int rts) |
| 5141 | { |
| 5142 | struct i802_bss *bss = priv; |
| 5143 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5144 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5145 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5146 | u32 val; |
| 5147 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5148 | if (rts >= 2347) |
| 5149 | val = (u32) -1; |
| 5150 | else |
| 5151 | val = rts; |
| 5152 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5153 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5154 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5155 | nlmsg_free(msg); |
| 5156 | return -ENOBUFS; |
| 5157 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5158 | |
| 5159 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5160 | if (!ret) |
| 5161 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5162 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5163 | "%d (%s)", rts, ret, strerror(-ret)); |
| 5164 | return ret; |
| 5165 | } |
| 5166 | |
| 5167 | |
| 5168 | static int i802_set_frag(void *priv, int frag) |
| 5169 | { |
| 5170 | struct i802_bss *bss = priv; |
| 5171 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5172 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5173 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5174 | u32 val; |
| 5175 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5176 | if (frag >= 2346) |
| 5177 | val = (u32) -1; |
| 5178 | else |
| 5179 | val = frag; |
| 5180 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5181 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5182 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 5183 | nlmsg_free(msg); |
| 5184 | return -ENOBUFS; |
| 5185 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5186 | |
| 5187 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5188 | if (!ret) |
| 5189 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5190 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 5191 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 5192 | return ret; |
| 5193 | } |
| 5194 | |
| 5195 | |
| 5196 | static int i802_flush(void *priv) |
| 5197 | { |
| 5198 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5199 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5200 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5201 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5202 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 5203 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5204 | |
| 5205 | /* |
| 5206 | * XXX: FIX! this needs to flush all VLANs too |
| 5207 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5208 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 5209 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5210 | if (res) { |
| 5211 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 5212 | "(%s)", res, strerror(-res)); |
| 5213 | } |
| 5214 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | |
| 5218 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 5219 | { |
| 5220 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5221 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5222 | struct hostap_sta_driver_data *data = arg; |
| 5223 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 5224 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 5225 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 5226 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 5227 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 5228 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 5229 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5230 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5231 | }; |
| 5232 | |
| 5233 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5234 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5235 | |
| 5236 | /* |
| 5237 | * TODO: validate the interface and mac address! |
| 5238 | * Otherwise, there's a race condition as soon as |
| 5239 | * the kernel starts sending station notifications. |
| 5240 | */ |
| 5241 | |
| 5242 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 5243 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 5244 | return NL_SKIP; |
| 5245 | } |
| 5246 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 5247 | tb[NL80211_ATTR_STA_INFO], |
| 5248 | stats_policy)) { |
| 5249 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 5250 | return NL_SKIP; |
| 5251 | } |
| 5252 | |
| 5253 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 5254 | data->inactive_msec = |
| 5255 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
| 5256 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 5257 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 5258 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 5259 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
| 5260 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 5261 | data->rx_packets = |
| 5262 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 5263 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 5264 | data->tx_packets = |
| 5265 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5266 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 5267 | data->tx_retry_failed = |
| 5268 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5269 | |
| 5270 | return NL_SKIP; |
| 5271 | } |
| 5272 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5273 | static int i802_read_sta_data(struct i802_bss *bss, |
| 5274 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5275 | const u8 *addr) |
| 5276 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5277 | struct nl_msg *msg; |
| 5278 | |
| 5279 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5280 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5281 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 5282 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 5283 | nlmsg_free(msg); |
| 5284 | return -ENOBUFS; |
| 5285 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5286 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5287 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | |
| 5291 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 5292 | int cw_min, int cw_max, int burst_time) |
| 5293 | { |
| 5294 | struct i802_bss *bss = priv; |
| 5295 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5296 | struct nl_msg *msg; |
| 5297 | struct nlattr *txq, *params; |
| 5298 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5299 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5300 | if (!msg) |
| 5301 | return -1; |
| 5302 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5303 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 5304 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5305 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5306 | |
| 5307 | /* We are only sending parameters for a single TXQ at a time */ |
| 5308 | params = nla_nest_start(msg, 1); |
| 5309 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5310 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5311 | |
| 5312 | switch (queue) { |
| 5313 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5314 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 5315 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5316 | break; |
| 5317 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5318 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 5319 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5320 | break; |
| 5321 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5322 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 5323 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5324 | break; |
| 5325 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5326 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 5327 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5328 | break; |
| 5329 | } |
| 5330 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 5331 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5332 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 5333 | (burst_time * 100 + 16) / 32) || |
| 5334 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 5335 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 5336 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 5337 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5338 | |
| 5339 | nla_nest_end(msg, params); |
| 5340 | |
| 5341 | nla_nest_end(msg, txq); |
| 5342 | |
| 5343 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 5344 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5345 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5346 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5347 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5348 | return -1; |
| 5349 | } |
| 5350 | |
| 5351 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5352 | 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] | 5353 | const char *ifname, int vlan_id) |
| 5354 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5355 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5356 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5357 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5358 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5359 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 5360 | ", ifname=%s[%d], vlan_id=%d)", |
| 5361 | bss->ifname, if_nametoindex(bss->ifname), |
| 5362 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5363 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5364 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5365 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 5366 | nlmsg_free(msg); |
| 5367 | return -ENOBUFS; |
| 5368 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5369 | |
| 5370 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5371 | if (ret < 0) { |
| 5372 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 5373 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 5374 | MAC2STR(addr), ifname, vlan_id, ret, |
| 5375 | strerror(-ret)); |
| 5376 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5377 | return ret; |
| 5378 | } |
| 5379 | |
| 5380 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5381 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 5382 | { |
| 5383 | struct hostap_sta_driver_data data; |
| 5384 | int ret; |
| 5385 | |
| 5386 | data.inactive_msec = (unsigned long) -1; |
| 5387 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5388 | if (ret == -ENOENT) |
| 5389 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5390 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 5391 | return -1; |
| 5392 | return data.inactive_msec / 1000; |
| 5393 | } |
| 5394 | |
| 5395 | |
| 5396 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 5397 | { |
| 5398 | #if 0 |
| 5399 | /* TODO */ |
| 5400 | #endif |
| 5401 | return 0; |
| 5402 | } |
| 5403 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5404 | |
| 5405 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 5406 | int reason) |
| 5407 | { |
| 5408 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5409 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5410 | struct ieee80211_mgmt mgmt; |
| 5411 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5412 | if (is_mesh_interface(drv->nlmode)) |
| 5413 | return -1; |
| 5414 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5415 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5416 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5417 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5418 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5419 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5420 | WLAN_FC_STYPE_DEAUTH); |
| 5421 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5422 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5423 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5424 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 5425 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5426 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5427 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
| 5428 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | |
| 5432 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 5433 | int reason) |
| 5434 | { |
| 5435 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5436 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5437 | struct ieee80211_mgmt mgmt; |
| 5438 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5439 | if (is_mesh_interface(drv->nlmode)) |
| 5440 | return -1; |
| 5441 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5442 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5443 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5444 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5445 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5446 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5447 | WLAN_FC_STYPE_DISASSOC); |
| 5448 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5449 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5450 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5451 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 5452 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5453 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5454 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
| 5455 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5458 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5459 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 5460 | { |
| 5461 | char buf[200], *pos, *end; |
| 5462 | int i, res; |
| 5463 | |
| 5464 | pos = buf; |
| 5465 | end = pos + sizeof(buf); |
| 5466 | |
| 5467 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5468 | if (!drv->if_indices[i]) |
| 5469 | continue; |
| 5470 | res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5471 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5472 | break; |
| 5473 | pos += res; |
| 5474 | } |
| 5475 | *pos = '\0'; |
| 5476 | |
| 5477 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 5478 | drv->num_if_indices, buf); |
| 5479 | } |
| 5480 | |
| 5481 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5482 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5483 | { |
| 5484 | int i; |
| 5485 | int *old; |
| 5486 | |
| 5487 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", |
| 5488 | ifidx); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5489 | if (have_ifidx(drv, ifidx)) { |
| 5490 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 5491 | ifidx); |
| 5492 | return; |
| 5493 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5494 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5495 | if (drv->if_indices[i] == 0) { |
| 5496 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5497 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5498 | return; |
| 5499 | } |
| 5500 | } |
| 5501 | |
| 5502 | if (drv->if_indices != drv->default_if_indices) |
| 5503 | old = drv->if_indices; |
| 5504 | else |
| 5505 | old = NULL; |
| 5506 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5507 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 5508 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5509 | if (!drv->if_indices) { |
| 5510 | if (!old) |
| 5511 | drv->if_indices = drv->default_if_indices; |
| 5512 | else |
| 5513 | drv->if_indices = old; |
| 5514 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 5515 | "interfaces"); |
| 5516 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 5517 | return; |
| 5518 | } else if (!old) |
| 5519 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 5520 | sizeof(drv->default_if_indices)); |
| 5521 | drv->if_indices[drv->num_if_indices] = ifidx; |
| 5522 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5523 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5524 | } |
| 5525 | |
| 5526 | |
| 5527 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5528 | { |
| 5529 | int i; |
| 5530 | |
| 5531 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5532 | if (drv->if_indices[i] == ifidx) { |
| 5533 | drv->if_indices[i] = 0; |
| 5534 | break; |
| 5535 | } |
| 5536 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5537 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | |
| 5541 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5542 | { |
| 5543 | int i; |
| 5544 | |
| 5545 | for (i = 0; i < drv->num_if_indices; i++) |
| 5546 | if (drv->if_indices[i] == ifidx) |
| 5547 | return 1; |
| 5548 | |
| 5549 | return 0; |
| 5550 | } |
| 5551 | |
| 5552 | |
| 5553 | 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] | 5554 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5555 | { |
| 5556 | struct i802_bss *bss = priv; |
| 5557 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5558 | char name[IFNAMSIZ + 1]; |
| 5559 | |
| 5560 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5561 | if (ifname_wds) |
| 5562 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 5563 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5564 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 5565 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 5566 | if (val) { |
| 5567 | if (!if_nametoindex(name)) { |
| 5568 | if (nl80211_create_iface(drv, name, |
| 5569 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5570 | bss->addr, 1, NULL, NULL, 0) < |
| 5571 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5572 | return -1; |
| 5573 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5574 | linux_br_add_if(drv->global->ioctl_sock, |
| 5575 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5576 | return -1; |
| 5577 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5578 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 5579 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 5580 | "interface %s up", name); |
| 5581 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5582 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 5583 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5584 | if (bridge_ifname) |
| 5585 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 5586 | name); |
| 5587 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5588 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 5589 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 5590 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5591 | } |
| 5592 | } |
| 5593 | |
| 5594 | |
| 5595 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 5596 | { |
| 5597 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 5598 | struct sockaddr_ll lladdr; |
| 5599 | unsigned char buf[3000]; |
| 5600 | int len; |
| 5601 | socklen_t fromlen = sizeof(lladdr); |
| 5602 | |
| 5603 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 5604 | (struct sockaddr *)&lladdr, &fromlen); |
| 5605 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5606 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 5607 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5608 | return; |
| 5609 | } |
| 5610 | |
| 5611 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
| 5612 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 5613 | } |
| 5614 | |
| 5615 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5616 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 5617 | struct i802_bss *bss, |
| 5618 | const char *brname, const char *ifname) |
| 5619 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5620 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5621 | char in_br[IFNAMSIZ]; |
| 5622 | |
| 5623 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5624 | br_ifindex = if_nametoindex(brname); |
| 5625 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5626 | /* |
| 5627 | * Bridge was configured, but the bridge device does |
| 5628 | * not exist. Try to add it now. |
| 5629 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5630 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5631 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 5632 | "bridge interface %s: %s", |
| 5633 | brname, strerror(errno)); |
| 5634 | return -1; |
| 5635 | } |
| 5636 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5637 | br_ifindex = if_nametoindex(brname); |
| 5638 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5639 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5640 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5641 | |
| 5642 | if (linux_br_get(in_br, ifname) == 0) { |
| 5643 | if (os_strcmp(in_br, brname) == 0) |
| 5644 | return 0; /* already in the bridge */ |
| 5645 | |
| 5646 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 5647 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5648 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 5649 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5650 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 5651 | "remove interface %s from bridge " |
| 5652 | "%s: %s", |
| 5653 | ifname, brname, strerror(errno)); |
| 5654 | return -1; |
| 5655 | } |
| 5656 | } |
| 5657 | |
| 5658 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 5659 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5660 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5661 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 5662 | "into bridge %s: %s", |
| 5663 | ifname, brname, strerror(errno)); |
| 5664 | return -1; |
| 5665 | } |
| 5666 | bss->added_if_into_bridge = 1; |
| 5667 | |
| 5668 | return 0; |
| 5669 | } |
| 5670 | |
| 5671 | |
| 5672 | static void *i802_init(struct hostapd_data *hapd, |
| 5673 | struct wpa_init_params *params) |
| 5674 | { |
| 5675 | struct wpa_driver_nl80211_data *drv; |
| 5676 | struct i802_bss *bss; |
| 5677 | size_t i; |
| 5678 | char brname[IFNAMSIZ]; |
| 5679 | int ifindex, br_ifindex; |
| 5680 | int br_added = 0; |
| 5681 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5682 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 5683 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5684 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5685 | if (bss == NULL) |
| 5686 | return NULL; |
| 5687 | |
| 5688 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5689 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5690 | if (linux_br_get(brname, params->ifname) == 0) { |
| 5691 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
| 5692 | params->ifname, brname); |
| 5693 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5694 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5695 | } else { |
| 5696 | brname[0] = '\0'; |
| 5697 | br_ifindex = 0; |
| 5698 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5699 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5700 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5701 | for (i = 0; i < params->num_bridge; i++) { |
| 5702 | if (params->bridge[i]) { |
| 5703 | ifindex = if_nametoindex(params->bridge[i]); |
| 5704 | if (ifindex) |
| 5705 | add_ifidx(drv, ifindex); |
| 5706 | if (ifindex == br_ifindex) |
| 5707 | br_added = 1; |
| 5708 | } |
| 5709 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5710 | |
| 5711 | /* start listening for EAPOL on the default AP interface */ |
| 5712 | add_ifidx(drv, drv->ifindex); |
| 5713 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5714 | if (params->num_bridge && params->bridge[0]) { |
| 5715 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 5716 | params->ifname) < 0) |
| 5717 | goto failed; |
| 5718 | if (os_strcmp(params->bridge[0], brname) != 0) |
| 5719 | br_added = 1; |
| 5720 | } |
| 5721 | |
| 5722 | if (!br_added && br_ifindex && |
| 5723 | (params->num_bridge == 0 || !params->bridge[0])) |
| 5724 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5725 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5726 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5727 | if (bss->added_if_into_bridge) { |
| 5728 | drv->rtnl_sk = nl_socket_alloc(); |
| 5729 | if (drv->rtnl_sk == NULL) { |
| 5730 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 5731 | goto failed; |
| 5732 | } |
| 5733 | |
| 5734 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 5735 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 5736 | strerror(errno)); |
| 5737 | goto failed; |
| 5738 | } |
| 5739 | } |
| 5740 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5741 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5742 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 5743 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5744 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 5745 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5746 | goto failed; |
| 5747 | } |
| 5748 | |
| 5749 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 5750 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5751 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5752 | goto failed; |
| 5753 | } |
| 5754 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5755 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 5756 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5757 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5758 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5759 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5760 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 5761 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5762 | return bss; |
| 5763 | |
| 5764 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5765 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5766 | return NULL; |
| 5767 | } |
| 5768 | |
| 5769 | |
| 5770 | static void i802_deinit(void *priv) |
| 5771 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5772 | struct i802_bss *bss = priv; |
| 5773 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5774 | } |
| 5775 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5776 | |
| 5777 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 5778 | enum wpa_driver_if_type type) |
| 5779 | { |
| 5780 | switch (type) { |
| 5781 | case WPA_IF_STATION: |
| 5782 | return NL80211_IFTYPE_STATION; |
| 5783 | case WPA_IF_P2P_CLIENT: |
| 5784 | case WPA_IF_P2P_GROUP: |
| 5785 | return NL80211_IFTYPE_P2P_CLIENT; |
| 5786 | case WPA_IF_AP_VLAN: |
| 5787 | return NL80211_IFTYPE_AP_VLAN; |
| 5788 | case WPA_IF_AP_BSS: |
| 5789 | return NL80211_IFTYPE_AP; |
| 5790 | case WPA_IF_P2P_GO: |
| 5791 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5792 | case WPA_IF_P2P_DEVICE: |
| 5793 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5794 | case WPA_IF_MESH: |
| 5795 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5796 | } |
| 5797 | return -1; |
| 5798 | } |
| 5799 | |
| 5800 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5801 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 5802 | { |
| 5803 | struct wpa_driver_nl80211_data *drv; |
| 5804 | dl_list_for_each(drv, &global->interfaces, |
| 5805 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5806 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5807 | return 1; |
| 5808 | } |
| 5809 | return 0; |
| 5810 | } |
| 5811 | |
| 5812 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5813 | 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] | 5814 | { |
| 5815 | unsigned int idx; |
| 5816 | |
| 5817 | if (!drv->global) |
| 5818 | return -1; |
| 5819 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5820 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5821 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5822 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5823 | new_addr[0] ^= idx << 2; |
| 5824 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 5825 | break; |
| 5826 | } |
| 5827 | if (idx == 64) |
| 5828 | return -1; |
| 5829 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5830 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5831 | MACSTR, MAC2STR(new_addr)); |
| 5832 | |
| 5833 | return 0; |
| 5834 | } |
| 5835 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5836 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5837 | struct wdev_info { |
| 5838 | u64 wdev_id; |
| 5839 | int wdev_id_set; |
| 5840 | u8 macaddr[ETH_ALEN]; |
| 5841 | }; |
| 5842 | |
| 5843 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 5844 | { |
| 5845 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5846 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5847 | struct wdev_info *wi = arg; |
| 5848 | |
| 5849 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5850 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5851 | if (tb[NL80211_ATTR_WDEV]) { |
| 5852 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 5853 | wi->wdev_id_set = 1; |
| 5854 | } |
| 5855 | |
| 5856 | if (tb[NL80211_ATTR_MAC]) |
| 5857 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 5858 | ETH_ALEN); |
| 5859 | |
| 5860 | return NL_SKIP; |
| 5861 | } |
| 5862 | |
| 5863 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5864 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 5865 | const char *ifname, const u8 *addr, |
| 5866 | void *bss_ctx, void **drv_priv, |
| 5867 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5868 | const char *bridge, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5869 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5870 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5871 | struct i802_bss *bss = priv; |
| 5872 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5873 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5874 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5875 | |
| 5876 | if (addr) |
| 5877 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5878 | nlmode = wpa_driver_nl80211_if_type(type); |
| 5879 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 5880 | struct wdev_info p2pdev_info; |
| 5881 | |
| 5882 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 5883 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 5884 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5885 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5886 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 5887 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 5888 | ifname); |
| 5889 | return -1; |
| 5890 | } |
| 5891 | |
| 5892 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 5893 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 5894 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 5895 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 5896 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 5897 | ifname, |
| 5898 | (long long unsigned int) p2pdev_info.wdev_id); |
| 5899 | } else { |
| 5900 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5901 | 0, NULL, NULL, use_existing); |
| 5902 | if (use_existing && ifidx == -ENFILE) { |
| 5903 | added = 0; |
| 5904 | ifidx = if_nametoindex(ifname); |
| 5905 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5906 | return -1; |
| 5907 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5910 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 5911 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5912 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 5913 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 5914 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5915 | if (added) |
| 5916 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5917 | return -1; |
| 5918 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5919 | } |
| 5920 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5921 | if (!addr && |
| 5922 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 5923 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 5924 | type == WPA_IF_STATION)) { |
| 5925 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5926 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5927 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5928 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5929 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5930 | if (added) |
| 5931 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5932 | return -1; |
| 5933 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5934 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5935 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 5936 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5937 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5938 | if (added) |
| 5939 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5940 | return -1; |
| 5941 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5942 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5943 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5944 | if (added) |
| 5945 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5946 | return -1; |
| 5947 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5948 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 5949 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5950 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5951 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5952 | if (type == WPA_IF_AP_BSS) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5953 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 5954 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5955 | if (added) |
| 5956 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5957 | return -1; |
| 5958 | } |
| 5959 | |
| 5960 | if (bridge && |
| 5961 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 5962 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 5963 | "interface %s to a bridge %s", |
| 5964 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5965 | if (added) |
| 5966 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5967 | os_free(new_bss); |
| 5968 | return -1; |
| 5969 | } |
| 5970 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5971 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 5972 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5973 | if (added) |
| 5974 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5975 | os_free(new_bss); |
| 5976 | return -1; |
| 5977 | } |
| 5978 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5979 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5980 | new_bss->ifindex = ifidx; |
| 5981 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5982 | new_bss->next = drv->first_bss->next; |
| 5983 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5984 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5985 | new_bss->added_if = added; |
| 5986 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5987 | if (drv_priv) |
| 5988 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5989 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5990 | |
| 5991 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 5992 | if (nl80211_setup_ap(new_bss)) |
| 5993 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5994 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5995 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5996 | if (drv->global) |
| 5997 | drv->global->if_add_ifindex = ifidx; |
| 5998 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5999 | /* |
| 6000 | * Some virtual interfaces need to process EAPOL packets and events on |
| 6001 | * the parent interface. This is used mainly with hostapd. |
| 6002 | */ |
| 6003 | if (ifidx > 0 && |
| 6004 | (drv->hostapd || |
| 6005 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 6006 | nlmode == NL80211_IFTYPE_WDS || |
| 6007 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6008 | add_ifidx(drv, ifidx); |
| 6009 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6010 | return 0; |
| 6011 | } |
| 6012 | |
| 6013 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6014 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6015 | enum wpa_driver_if_type type, |
| 6016 | const char *ifname) |
| 6017 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6018 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6019 | int ifindex = if_nametoindex(ifname); |
| 6020 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6021 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 6022 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6023 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6024 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6025 | else if (ifindex > 0 && !bss->added_if) { |
| 6026 | struct wpa_driver_nl80211_data *drv2; |
| 6027 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 6028 | struct wpa_driver_nl80211_data, list) |
| 6029 | del_ifidx(drv2, ifindex); |
| 6030 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6031 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6032 | if (type != WPA_IF_AP_BSS) |
| 6033 | return 0; |
| 6034 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6035 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6036 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 6037 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6038 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6039 | "interface %s from bridge %s: %s", |
| 6040 | bss->ifname, bss->brname, strerror(errno)); |
| 6041 | } |
| 6042 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6043 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6044 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6045 | "bridge %s: %s", |
| 6046 | bss->brname, strerror(errno)); |
| 6047 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6048 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6049 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6050 | struct i802_bss *tbss; |
| 6051 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6052 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 6053 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6054 | if (tbss->next == bss) { |
| 6055 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6056 | /* Unsubscribe management frames */ |
| 6057 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6058 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6059 | if (!bss->added_if) |
| 6060 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6061 | os_free(bss); |
| 6062 | bss = NULL; |
| 6063 | break; |
| 6064 | } |
| 6065 | } |
| 6066 | if (bss) |
| 6067 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 6068 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6069 | } else { |
| 6070 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 6071 | nl80211_teardown_ap(bss); |
| 6072 | if (!bss->added_if && !drv->first_bss->next) |
| 6073 | wpa_driver_nl80211_del_beacon(drv); |
| 6074 | nl80211_destroy_bss(bss); |
| 6075 | if (!bss->added_if) |
| 6076 | i802_set_iface_flags(bss, 0); |
| 6077 | if (drv->first_bss->next) { |
| 6078 | drv->first_bss = drv->first_bss->next; |
| 6079 | drv->ctx = drv->first_bss->ctx; |
| 6080 | os_free(bss); |
| 6081 | } else { |
| 6082 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 6083 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6084 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6085 | |
| 6086 | return 0; |
| 6087 | } |
| 6088 | |
| 6089 | |
| 6090 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 6091 | { |
| 6092 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6093 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6094 | u64 *cookie = arg; |
| 6095 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6096 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6097 | if (tb[NL80211_ATTR_COOKIE]) |
| 6098 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 6099 | return NL_SKIP; |
| 6100 | } |
| 6101 | |
| 6102 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6103 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6104 | unsigned int freq, unsigned int wait, |
| 6105 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6106 | u64 *cookie_out, int no_cck, int no_ack, |
| 6107 | int offchanok) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6108 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6109 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6110 | struct nl_msg *msg; |
| 6111 | u64 cookie; |
| 6112 | int ret = -1; |
| 6113 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6114 | 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] | 6115 | "no_ack=%d offchanok=%d", |
| 6116 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6117 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6118 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6119 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 6120 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 6121 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 6122 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6123 | drv->test_use_roc_tx) && |
| 6124 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 6125 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 6126 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
| 6127 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 6128 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6129 | |
| 6130 | cookie = 0; |
| 6131 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6132 | msg = NULL; |
| 6133 | if (ret) { |
| 6134 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6135 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 6136 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6137 | } else { |
| 6138 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 6139 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 6140 | (long long unsigned int) cookie); |
| 6141 | |
| 6142 | if (cookie_out) |
| 6143 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6144 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6145 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6146 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6147 | nlmsg_free(msg); |
| 6148 | return ret; |
| 6149 | } |
| 6150 | |
| 6151 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6152 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 6153 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6154 | unsigned int wait_time, |
| 6155 | const u8 *dst, const u8 *src, |
| 6156 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6157 | const u8 *data, size_t data_len, |
| 6158 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6159 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6160 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6161 | int ret = -1; |
| 6162 | u8 *buf; |
| 6163 | struct ieee80211_hdr *hdr; |
| 6164 | |
| 6165 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6166 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 6167 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6168 | |
| 6169 | buf = os_zalloc(24 + data_len); |
| 6170 | if (buf == NULL) |
| 6171 | return ret; |
| 6172 | os_memcpy(buf + 24, data, data_len); |
| 6173 | hdr = (struct ieee80211_hdr *) buf; |
| 6174 | hdr->frame_control = |
| 6175 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 6176 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 6177 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 6178 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 6179 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6180 | if (is_ap_interface(drv->nlmode) && |
| 6181 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6182 | (int) freq == bss->freq || drv->device_ap_sme || |
| 6183 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6184 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 6185 | 0, freq, no_cck, 1, |
| 6186 | wait_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6187 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6188 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6189 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6190 | &drv->send_action_cookie, |
| 6191 | no_cck, 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6192 | |
| 6193 | os_free(buf); |
| 6194 | return ret; |
| 6195 | } |
| 6196 | |
| 6197 | |
| 6198 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 6199 | { |
| 6200 | struct i802_bss *bss = priv; |
| 6201 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6202 | struct nl_msg *msg; |
| 6203 | int ret; |
| 6204 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 6205 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
| 6206 | (long long unsigned int) drv->send_action_cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6207 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
| 6208 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) { |
| 6209 | nlmsg_free(msg); |
| 6210 | return; |
| 6211 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6212 | |
| 6213 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6214 | if (ret) |
| 6215 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 6216 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | |
| 6220 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 6221 | unsigned int duration) |
| 6222 | { |
| 6223 | struct i802_bss *bss = priv; |
| 6224 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6225 | struct nl_msg *msg; |
| 6226 | int ret; |
| 6227 | u64 cookie; |
| 6228 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6229 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 6230 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 6231 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 6232 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6233 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6234 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6235 | |
| 6236 | cookie = 0; |
| 6237 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6238 | if (ret == 0) { |
| 6239 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 6240 | "0x%llx for freq=%u MHz duration=%u", |
| 6241 | (long long unsigned int) cookie, freq, duration); |
| 6242 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6243 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6244 | return 0; |
| 6245 | } |
| 6246 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 6247 | "(freq=%d duration=%u): %d (%s)", |
| 6248 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6249 | return -1; |
| 6250 | } |
| 6251 | |
| 6252 | |
| 6253 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 6254 | { |
| 6255 | struct i802_bss *bss = priv; |
| 6256 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6257 | struct nl_msg *msg; |
| 6258 | int ret; |
| 6259 | |
| 6260 | if (!drv->pending_remain_on_chan) { |
| 6261 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 6262 | "to cancel"); |
| 6263 | return -1; |
| 6264 | } |
| 6265 | |
| 6266 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 6267 | "0x%llx", |
| 6268 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 6269 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6270 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 6271 | if (!msg || |
| 6272 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 6273 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6274 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6275 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6276 | |
| 6277 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6278 | if (ret == 0) |
| 6279 | return 0; |
| 6280 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 6281 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6282 | return -1; |
| 6283 | } |
| 6284 | |
| 6285 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6286 | 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] | 6287 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6288 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6289 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6290 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6291 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 6292 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 6293 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6294 | /* |
| 6295 | * Do not disable Probe Request reporting that was |
| 6296 | * enabled in nl80211_setup_ap(). |
| 6297 | */ |
| 6298 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 6299 | "Probe Request reporting nl_preq=%p while " |
| 6300 | "in AP mode", bss->nl_preq); |
| 6301 | } else if (bss->nl_preq) { |
| 6302 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 6303 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6304 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6305 | } |
| 6306 | return 0; |
| 6307 | } |
| 6308 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6309 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6310 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6311 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6312 | return 0; |
| 6313 | } |
| 6314 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6315 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 6316 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6317 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6318 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 6319 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6320 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6321 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6322 | (WLAN_FC_TYPE_MGMT << 2) | |
| 6323 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6324 | NULL, 0) < 0) |
| 6325 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 6326 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6327 | nl80211_register_eloop_read(&bss->nl_preq, |
| 6328 | wpa_driver_nl80211_event_receive, |
| 6329 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6330 | |
| 6331 | return 0; |
| 6332 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6333 | out_err: |
| 6334 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6335 | return -1; |
| 6336 | } |
| 6337 | |
| 6338 | |
| 6339 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 6340 | int ifindex, int disabled) |
| 6341 | { |
| 6342 | struct nl_msg *msg; |
| 6343 | struct nlattr *bands, *band; |
| 6344 | int ret; |
| 6345 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6346 | wpa_printf(MSG_DEBUG, |
| 6347 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 6348 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 6349 | "no NL80211_TXRATE_LEGACY constraint"); |
| 6350 | |
| 6351 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 6352 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6353 | if (!msg) |
| 6354 | return -1; |
| 6355 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6356 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 6357 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6358 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6359 | |
| 6360 | /* |
| 6361 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 6362 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 6363 | * rates. All 5 GHz rates are left enabled. |
| 6364 | */ |
| 6365 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6366 | if (!band || |
| 6367 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 6368 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 6369 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6370 | nla_nest_end(msg, band); |
| 6371 | |
| 6372 | nla_nest_end(msg, bands); |
| 6373 | |
| 6374 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6375 | if (ret) { |
| 6376 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 6377 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6378 | } else |
| 6379 | drv->disabled_11b_rates = disabled; |
| 6380 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6381 | return ret; |
| 6382 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6383 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6384 | nlmsg_free(msg); |
| 6385 | return -1; |
| 6386 | } |
| 6387 | |
| 6388 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6389 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 6390 | { |
| 6391 | struct i802_bss *bss = priv; |
| 6392 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6393 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6394 | return -1; |
| 6395 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6396 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6397 | |
| 6398 | /* |
| 6399 | * If the P2P GO interface was dynamically added, then it is |
| 6400 | * possible that the interface change to station is not possible. |
| 6401 | */ |
| 6402 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 6403 | return 0; |
| 6404 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6405 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6406 | } |
| 6407 | |
| 6408 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6409 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 6410 | { |
| 6411 | struct i802_bss *bss = priv; |
| 6412 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6413 | if (!is_ap_interface(drv->nlmode)) |
| 6414 | return -1; |
| 6415 | wpa_driver_nl80211_del_beacon(drv); |
| 6416 | bss->beacon_set = 0; |
| 6417 | return 0; |
| 6418 | } |
| 6419 | |
| 6420 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6421 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 6422 | { |
| 6423 | struct i802_bss *bss = priv; |
| 6424 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6425 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 6426 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6427 | |
| 6428 | /* |
| 6429 | * If the P2P Client interface was dynamically added, then it is |
| 6430 | * possible that the interface change to station is not possible. |
| 6431 | */ |
| 6432 | if (bss->if_dynamic) |
| 6433 | return 0; |
| 6434 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6435 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 6436 | } |
| 6437 | |
| 6438 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6439 | static void wpa_driver_nl80211_resume(void *priv) |
| 6440 | { |
| 6441 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6442 | |
| 6443 | if (i802_set_iface_flags(bss, 1)) |
| 6444 | 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] | 6445 | } |
| 6446 | |
| 6447 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6448 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 6449 | { |
| 6450 | struct i802_bss *bss = priv; |
| 6451 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6452 | struct nl_msg *msg; |
| 6453 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6454 | |
| 6455 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 6456 | "hysteresis=%d", threshold, hysteresis); |
| 6457 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6458 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 6459 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 6460 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 6461 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 6462 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6463 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6464 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6465 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6466 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6467 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6468 | } |
| 6469 | |
| 6470 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6471 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 6472 | { |
| 6473 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6474 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6475 | struct wpa_signal_info *sig_change = arg; |
| 6476 | |
| 6477 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6478 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6479 | |
| 6480 | sig_change->center_frq1 = -1; |
| 6481 | sig_change->center_frq2 = -1; |
| 6482 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 6483 | |
| 6484 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 6485 | sig_change->chanwidth = convert2width( |
| 6486 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 6487 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 6488 | sig_change->center_frq1 = |
| 6489 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 6490 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 6491 | sig_change->center_frq2 = |
| 6492 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 6493 | } |
| 6494 | |
| 6495 | return NL_SKIP; |
| 6496 | } |
| 6497 | |
| 6498 | |
| 6499 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 6500 | struct wpa_signal_info *sig) |
| 6501 | { |
| 6502 | struct nl_msg *msg; |
| 6503 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6504 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6505 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6506 | } |
| 6507 | |
| 6508 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6509 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 6510 | { |
| 6511 | struct i802_bss *bss = priv; |
| 6512 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6513 | int res; |
| 6514 | |
| 6515 | os_memset(si, 0, sizeof(*si)); |
| 6516 | res = nl80211_get_link_signal(drv, si); |
| 6517 | if (res != 0) |
| 6518 | return res; |
| 6519 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6520 | res = nl80211_get_channel_width(drv, si); |
| 6521 | if (res != 0) |
| 6522 | return res; |
| 6523 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6524 | return nl80211_get_link_noise(drv, si); |
| 6525 | } |
| 6526 | |
| 6527 | |
| 6528 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 6529 | int encrypt) |
| 6530 | { |
| 6531 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6532 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
| 6533 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6534 | } |
| 6535 | |
| 6536 | |
| 6537 | static int nl80211_set_param(void *priv, const char *param) |
| 6538 | { |
| 6539 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
| 6540 | if (param == NULL) |
| 6541 | return 0; |
| 6542 | |
| 6543 | #ifdef CONFIG_P2P |
| 6544 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 6545 | struct i802_bss *bss = priv; |
| 6546 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6547 | |
| 6548 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 6549 | "interface"); |
| 6550 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 6551 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 6552 | } |
| 6553 | #endif /* CONFIG_P2P */ |
| 6554 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6555 | if (os_strstr(param, "use_monitor=1")) { |
| 6556 | struct i802_bss *bss = priv; |
| 6557 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6558 | drv->use_monitor = 1; |
| 6559 | } |
| 6560 | |
| 6561 | if (os_strstr(param, "force_connect_cmd=1")) { |
| 6562 | struct i802_bss *bss = priv; |
| 6563 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6564 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6565 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6566 | } |
| 6567 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 6568 | if (os_strstr(param, "no_offchannel_tx=1")) { |
| 6569 | struct i802_bss *bss = priv; |
| 6570 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6571 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 6572 | drv->test_use_roc_tx = 1; |
| 6573 | } |
| 6574 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6575 | return 0; |
| 6576 | } |
| 6577 | |
| 6578 | |
| 6579 | static void * nl80211_global_init(void) |
| 6580 | { |
| 6581 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6582 | struct netlink_config *cfg; |
| 6583 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6584 | global = os_zalloc(sizeof(*global)); |
| 6585 | if (global == NULL) |
| 6586 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6587 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6588 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6589 | global->if_add_ifindex = -1; |
| 6590 | |
| 6591 | cfg = os_zalloc(sizeof(*cfg)); |
| 6592 | if (cfg == NULL) |
| 6593 | goto err; |
| 6594 | |
| 6595 | cfg->ctx = global; |
| 6596 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 6597 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 6598 | global->netlink = netlink_init(cfg); |
| 6599 | if (global->netlink == NULL) { |
| 6600 | os_free(cfg); |
| 6601 | goto err; |
| 6602 | } |
| 6603 | |
| 6604 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 6605 | goto err; |
| 6606 | |
| 6607 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 6608 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6609 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 6610 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6611 | goto err; |
| 6612 | } |
| 6613 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6614 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6615 | |
| 6616 | err: |
| 6617 | nl80211_global_deinit(global); |
| 6618 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6619 | } |
| 6620 | |
| 6621 | |
| 6622 | static void nl80211_global_deinit(void *priv) |
| 6623 | { |
| 6624 | struct nl80211_global *global = priv; |
| 6625 | if (global == NULL) |
| 6626 | return; |
| 6627 | if (!dl_list_empty(&global->interfaces)) { |
| 6628 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 6629 | "nl80211_global_deinit", |
| 6630 | dl_list_len(&global->interfaces)); |
| 6631 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6632 | |
| 6633 | if (global->netlink) |
| 6634 | netlink_deinit(global->netlink); |
| 6635 | |
| 6636 | nl_destroy_handles(&global->nl); |
| 6637 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6638 | if (global->nl_event) |
| 6639 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6640 | |
| 6641 | nl_cb_put(global->nl_cb); |
| 6642 | |
| 6643 | if (global->ioctl_sock >= 0) |
| 6644 | close(global->ioctl_sock); |
| 6645 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6646 | os_free(global); |
| 6647 | } |
| 6648 | |
| 6649 | |
| 6650 | static const char * nl80211_get_radio_name(void *priv) |
| 6651 | { |
| 6652 | struct i802_bss *bss = priv; |
| 6653 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6654 | return drv->phyname; |
| 6655 | } |
| 6656 | |
| 6657 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6658 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 6659 | const u8 *pmkid) |
| 6660 | { |
| 6661 | struct nl_msg *msg; |
| 6662 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6663 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 6664 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
| 6665 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { |
| 6666 | nlmsg_free(msg); |
| 6667 | return -ENOBUFS; |
| 6668 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6669 | |
| 6670 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6671 | } |
| 6672 | |
| 6673 | |
| 6674 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6675 | { |
| 6676 | struct i802_bss *bss = priv; |
| 6677 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 6678 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 6679 | } |
| 6680 | |
| 6681 | |
| 6682 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6683 | { |
| 6684 | struct i802_bss *bss = priv; |
| 6685 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 6686 | MAC2STR(bssid)); |
| 6687 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 6688 | } |
| 6689 | |
| 6690 | |
| 6691 | static int nl80211_flush_pmkid(void *priv) |
| 6692 | { |
| 6693 | struct i802_bss *bss = priv; |
| 6694 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 6695 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 6696 | } |
| 6697 | |
| 6698 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6699 | static void clean_survey_results(struct survey_results *survey_results) |
| 6700 | { |
| 6701 | struct freq_survey *survey, *tmp; |
| 6702 | |
| 6703 | if (dl_list_empty(&survey_results->survey_list)) |
| 6704 | return; |
| 6705 | |
| 6706 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 6707 | struct freq_survey, list) { |
| 6708 | dl_list_del(&survey->list); |
| 6709 | os_free(survey); |
| 6710 | } |
| 6711 | } |
| 6712 | |
| 6713 | |
| 6714 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 6715 | struct dl_list *survey_list) |
| 6716 | { |
| 6717 | struct freq_survey *survey; |
| 6718 | |
| 6719 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 6720 | if (!survey) |
| 6721 | return; |
| 6722 | |
| 6723 | survey->ifidx = ifidx; |
| 6724 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6725 | survey->filled = 0; |
| 6726 | |
| 6727 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 6728 | survey->nf = (int8_t) |
| 6729 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 6730 | survey->filled |= SURVEY_HAS_NF; |
| 6731 | } |
| 6732 | |
| 6733 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 6734 | survey->channel_time = |
| 6735 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 6736 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 6737 | } |
| 6738 | |
| 6739 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 6740 | survey->channel_time_busy = |
| 6741 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 6742 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 6743 | } |
| 6744 | |
| 6745 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 6746 | survey->channel_time_rx = |
| 6747 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 6748 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 6749 | } |
| 6750 | |
| 6751 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 6752 | survey->channel_time_tx = |
| 6753 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 6754 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 6755 | } |
| 6756 | |
| 6757 | 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)", |
| 6758 | survey->freq, |
| 6759 | survey->nf, |
| 6760 | (unsigned long int) survey->channel_time, |
| 6761 | (unsigned long int) survey->channel_time_busy, |
| 6762 | (unsigned long int) survey->channel_time_tx, |
| 6763 | (unsigned long int) survey->channel_time_rx, |
| 6764 | survey->filled); |
| 6765 | |
| 6766 | dl_list_add_tail(survey_list, &survey->list); |
| 6767 | } |
| 6768 | |
| 6769 | |
| 6770 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 6771 | unsigned int freq_filter) |
| 6772 | { |
| 6773 | if (!freq_filter) |
| 6774 | return 1; |
| 6775 | |
| 6776 | return freq_filter == surveyed_freq; |
| 6777 | } |
| 6778 | |
| 6779 | |
| 6780 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 6781 | { |
| 6782 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6783 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6784 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 6785 | struct survey_results *survey_results; |
| 6786 | u32 surveyed_freq = 0; |
| 6787 | u32 ifidx; |
| 6788 | |
| 6789 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 6790 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 6791 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 6792 | }; |
| 6793 | |
| 6794 | survey_results = (struct survey_results *) arg; |
| 6795 | |
| 6796 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6797 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6798 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 6799 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 6800 | return NL_SKIP; |
| 6801 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6802 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 6803 | |
| 6804 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 6805 | return NL_SKIP; |
| 6806 | |
| 6807 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 6808 | tb[NL80211_ATTR_SURVEY_INFO], |
| 6809 | survey_policy)) |
| 6810 | return NL_SKIP; |
| 6811 | |
| 6812 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 6813 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 6814 | return NL_SKIP; |
| 6815 | } |
| 6816 | |
| 6817 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6818 | |
| 6819 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 6820 | survey_results->freq_filter)) |
| 6821 | return NL_SKIP; |
| 6822 | |
| 6823 | if (survey_results->freq_filter && |
| 6824 | survey_results->freq_filter != surveyed_freq) { |
| 6825 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 6826 | surveyed_freq); |
| 6827 | return NL_SKIP; |
| 6828 | } |
| 6829 | |
| 6830 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 6831 | |
| 6832 | return NL_SKIP; |
| 6833 | } |
| 6834 | |
| 6835 | |
| 6836 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 6837 | { |
| 6838 | struct i802_bss *bss = priv; |
| 6839 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6840 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6841 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6842 | union wpa_event_data data; |
| 6843 | struct survey_results *survey_results; |
| 6844 | |
| 6845 | os_memset(&data, 0, sizeof(data)); |
| 6846 | survey_results = &data.survey_results; |
| 6847 | |
| 6848 | dl_list_init(&survey_results->survey_list); |
| 6849 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6850 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6851 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6852 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6853 | |
| 6854 | if (freq) |
| 6855 | data.survey_results.freq_filter = freq; |
| 6856 | |
| 6857 | do { |
| 6858 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 6859 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 6860 | survey_results); |
| 6861 | } while (err > 0); |
| 6862 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6863 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6864 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6865 | else |
| 6866 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6867 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6868 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6869 | return err; |
| 6870 | } |
| 6871 | |
| 6872 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6873 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 6874 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6875 | const u8 *replay_ctr) |
| 6876 | { |
| 6877 | struct i802_bss *bss = priv; |
| 6878 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6879 | struct nlattr *replay_nested; |
| 6880 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6881 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6882 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6883 | if (!drv->set_rekey_offload) |
| 6884 | return; |
| 6885 | |
| 6886 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6887 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 6888 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6889 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
| 6890 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6891 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 6892 | replay_ctr)) { |
| 6893 | nl80211_nlmsg_clear(msg); |
| 6894 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6895 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6896 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6897 | |
| 6898 | nla_nest_end(msg, replay_nested); |
| 6899 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6900 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 6901 | if (ret == -EOPNOTSUPP) { |
| 6902 | wpa_printf(MSG_DEBUG, |
| 6903 | "nl80211: Driver does not support rekey offload"); |
| 6904 | drv->set_rekey_offload = 0; |
| 6905 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6906 | } |
| 6907 | |
| 6908 | |
| 6909 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 6910 | const u8 *addr, int qos) |
| 6911 | { |
| 6912 | /* send data frame to poll STA and check whether |
| 6913 | * this frame is ACKed */ |
| 6914 | struct { |
| 6915 | struct ieee80211_hdr hdr; |
| 6916 | u16 qos_ctl; |
| 6917 | } STRUCT_PACKED nulldata; |
| 6918 | size_t size; |
| 6919 | |
| 6920 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 6921 | |
| 6922 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 6923 | |
| 6924 | if (qos) { |
| 6925 | nulldata.hdr.frame_control = |
| 6926 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 6927 | WLAN_FC_STYPE_QOS_NULL); |
| 6928 | size = sizeof(nulldata); |
| 6929 | } else { |
| 6930 | nulldata.hdr.frame_control = |
| 6931 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 6932 | WLAN_FC_STYPE_NULLFUNC); |
| 6933 | size = sizeof(struct ieee80211_hdr); |
| 6934 | } |
| 6935 | |
| 6936 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 6937 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 6938 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 6939 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 6940 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6941 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
| 6942 | 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6943 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 6944 | "send poll frame"); |
| 6945 | } |
| 6946 | |
| 6947 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 6948 | int qos) |
| 6949 | { |
| 6950 | struct i802_bss *bss = priv; |
| 6951 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6952 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6953 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6954 | |
| 6955 | if (!drv->poll_command_supported) { |
| 6956 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 6957 | return; |
| 6958 | } |
| 6959 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6960 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 6961 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 6962 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6963 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6964 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6965 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6966 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6967 | if (ret < 0) { |
| 6968 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 6969 | MACSTR " failed: ret=%d (%s)", |
| 6970 | MAC2STR(addr), ret, strerror(-ret)); |
| 6971 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | |
| 6975 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 6976 | { |
| 6977 | struct nl_msg *msg; |
| 6978 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6979 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 6980 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 6981 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 6982 | nlmsg_free(msg); |
| 6983 | return -ENOBUFS; |
| 6984 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6985 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6986 | } |
| 6987 | |
| 6988 | |
| 6989 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 6990 | int ctwindow) |
| 6991 | { |
| 6992 | struct i802_bss *bss = priv; |
| 6993 | |
| 6994 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 6995 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 6996 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 6997 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6998 | #ifdef ANDROID_P2P |
| 6999 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7000 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7001 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7002 | #endif /* ANDROID_P2P */ |
| 7003 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7004 | |
| 7005 | if (legacy_ps == -1) |
| 7006 | return 0; |
| 7007 | if (legacy_ps != 0 && legacy_ps != 1) |
| 7008 | return -1; /* Not yet supported */ |
| 7009 | |
| 7010 | return nl80211_set_power_save(bss, legacy_ps); |
| 7011 | } |
| 7012 | |
| 7013 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7014 | static int nl80211_start_radar_detection(void *priv, |
| 7015 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7016 | { |
| 7017 | struct i802_bss *bss = priv; |
| 7018 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7019 | struct nl_msg *msg; |
| 7020 | int ret; |
| 7021 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7022 | 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)", |
| 7023 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7024 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7025 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7026 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 7027 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 7028 | "detection"); |
| 7029 | return -1; |
| 7030 | } |
| 7031 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7032 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 7033 | nl80211_put_freq_params(msg, freq) < 0) { |
| 7034 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7035 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7036 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7037 | |
| 7038 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7039 | if (ret == 0) |
| 7040 | return 0; |
| 7041 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 7042 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7043 | return -1; |
| 7044 | } |
| 7045 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7046 | #ifdef CONFIG_TDLS |
| 7047 | |
| 7048 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 7049 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7050 | u32 peer_capab, int initiator, const u8 *buf, |
| 7051 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7052 | { |
| 7053 | struct i802_bss *bss = priv; |
| 7054 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7055 | struct nl_msg *msg; |
| 7056 | |
| 7057 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7058 | return -EOPNOTSUPP; |
| 7059 | |
| 7060 | if (!dst) |
| 7061 | return -EINVAL; |
| 7062 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7063 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 7064 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 7065 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 7066 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 7067 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 7068 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7069 | if (peer_capab) { |
| 7070 | /* |
| 7071 | * The internal enum tdls_peer_capability definition is |
| 7072 | * currently identical with the nl80211 enum |
| 7073 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 7074 | * here. |
| 7075 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7076 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 7077 | peer_capab)) |
| 7078 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7079 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7080 | if ((initiator && |
| 7081 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 7082 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 7083 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7084 | |
| 7085 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7086 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7087 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7088 | nlmsg_free(msg); |
| 7089 | return -ENOBUFS; |
| 7090 | } |
| 7091 | |
| 7092 | |
| 7093 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 7094 | { |
| 7095 | struct i802_bss *bss = priv; |
| 7096 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7097 | struct nl_msg *msg; |
| 7098 | enum nl80211_tdls_operation nl80211_oper; |
| 7099 | |
| 7100 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7101 | return -EOPNOTSUPP; |
| 7102 | |
| 7103 | switch (oper) { |
| 7104 | case TDLS_DISCOVERY_REQ: |
| 7105 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 7106 | break; |
| 7107 | case TDLS_SETUP: |
| 7108 | nl80211_oper = NL80211_TDLS_SETUP; |
| 7109 | break; |
| 7110 | case TDLS_TEARDOWN: |
| 7111 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 7112 | break; |
| 7113 | case TDLS_ENABLE_LINK: |
| 7114 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 7115 | break; |
| 7116 | case TDLS_DISABLE_LINK: |
| 7117 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 7118 | break; |
| 7119 | case TDLS_ENABLE: |
| 7120 | return 0; |
| 7121 | case TDLS_DISABLE: |
| 7122 | return 0; |
| 7123 | default: |
| 7124 | return -EINVAL; |
| 7125 | } |
| 7126 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7127 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 7128 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 7129 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 7130 | nlmsg_free(msg); |
| 7131 | return -ENOBUFS; |
| 7132 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7133 | |
| 7134 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7135 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7136 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7137 | |
| 7138 | static int |
| 7139 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 7140 | const struct hostapd_freq_params *params) |
| 7141 | { |
| 7142 | struct i802_bss *bss = priv; |
| 7143 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7144 | struct nl_msg *msg; |
| 7145 | int ret = -ENOBUFS; |
| 7146 | |
| 7147 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7148 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7149 | return -EOPNOTSUPP; |
| 7150 | |
| 7151 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 7152 | " oper_class=%u freq=%u", |
| 7153 | MAC2STR(addr), oper_class, params->freq); |
| 7154 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 7155 | if (!msg || |
| 7156 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7157 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 7158 | (ret = nl80211_put_freq_params(msg, params))) { |
| 7159 | nlmsg_free(msg); |
| 7160 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 7161 | return ret; |
| 7162 | } |
| 7163 | |
| 7164 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7165 | } |
| 7166 | |
| 7167 | |
| 7168 | static int |
| 7169 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 7170 | { |
| 7171 | struct i802_bss *bss = priv; |
| 7172 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7173 | struct nl_msg *msg; |
| 7174 | |
| 7175 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7176 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7177 | return -EOPNOTSUPP; |
| 7178 | |
| 7179 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 7180 | MAC2STR(addr)); |
| 7181 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 7182 | if (!msg || |
| 7183 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7184 | nlmsg_free(msg); |
| 7185 | wpa_printf(MSG_DEBUG, |
| 7186 | "nl80211: Could not build TDLS cancel chan switch"); |
| 7187 | return -ENOBUFS; |
| 7188 | } |
| 7189 | |
| 7190 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | #endif /* CONFIG TDLS */ |
| 7194 | |
| 7195 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7196 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 7197 | enum wpa_alg alg, const u8 *addr, |
| 7198 | int key_idx, int set_tx, |
| 7199 | const u8 *seq, size_t seq_len, |
| 7200 | const u8 *key, size_t key_len) |
| 7201 | { |
| 7202 | struct i802_bss *bss = priv; |
| 7203 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 7204 | set_tx, seq, seq_len, key, key_len); |
| 7205 | } |
| 7206 | |
| 7207 | |
| 7208 | static int driver_nl80211_scan2(void *priv, |
| 7209 | struct wpa_driver_scan_params *params) |
| 7210 | { |
| 7211 | struct i802_bss *bss = priv; |
| 7212 | return wpa_driver_nl80211_scan(bss, params); |
| 7213 | } |
| 7214 | |
| 7215 | |
| 7216 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 7217 | int reason_code) |
| 7218 | { |
| 7219 | struct i802_bss *bss = priv; |
| 7220 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 7221 | } |
| 7222 | |
| 7223 | |
| 7224 | static int driver_nl80211_authenticate(void *priv, |
| 7225 | struct wpa_driver_auth_params *params) |
| 7226 | { |
| 7227 | struct i802_bss *bss = priv; |
| 7228 | return wpa_driver_nl80211_authenticate(bss, params); |
| 7229 | } |
| 7230 | |
| 7231 | |
| 7232 | static void driver_nl80211_deinit(void *priv) |
| 7233 | { |
| 7234 | struct i802_bss *bss = priv; |
| 7235 | wpa_driver_nl80211_deinit(bss); |
| 7236 | } |
| 7237 | |
| 7238 | |
| 7239 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 7240 | const char *ifname) |
| 7241 | { |
| 7242 | struct i802_bss *bss = priv; |
| 7243 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 7244 | } |
| 7245 | |
| 7246 | |
| 7247 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
| 7248 | size_t data_len, int noack) |
| 7249 | { |
| 7250 | struct i802_bss *bss = priv; |
| 7251 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
| 7252 | 0, 0, 0, 0); |
| 7253 | } |
| 7254 | |
| 7255 | |
| 7256 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 7257 | { |
| 7258 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7259 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7260 | } |
| 7261 | |
| 7262 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7263 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 7264 | const char *ifname, int vlan_id) |
| 7265 | { |
| 7266 | struct i802_bss *bss = priv; |
| 7267 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 7268 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7269 | |
| 7270 | |
| 7271 | static int driver_nl80211_read_sta_data(void *priv, |
| 7272 | struct hostap_sta_driver_data *data, |
| 7273 | const u8 *addr) |
| 7274 | { |
| 7275 | struct i802_bss *bss = priv; |
| 7276 | return i802_read_sta_data(bss, data, addr); |
| 7277 | } |
| 7278 | |
| 7279 | |
| 7280 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 7281 | unsigned int wait_time, |
| 7282 | const u8 *dst, const u8 *src, |
| 7283 | const u8 *bssid, |
| 7284 | const u8 *data, size_t data_len, |
| 7285 | int no_cck) |
| 7286 | { |
| 7287 | struct i802_bss *bss = priv; |
| 7288 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 7289 | bssid, data, data_len, no_cck); |
| 7290 | } |
| 7291 | |
| 7292 | |
| 7293 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 7294 | { |
| 7295 | struct i802_bss *bss = priv; |
| 7296 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 7297 | } |
| 7298 | |
| 7299 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7300 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 7301 | const u8 *ies, size_t ies_len) |
| 7302 | { |
| 7303 | int ret; |
| 7304 | struct nl_msg *msg; |
| 7305 | struct i802_bss *bss = priv; |
| 7306 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7307 | u16 mdid = WPA_GET_LE16(md); |
| 7308 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7309 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7310 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 7311 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 7312 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 7313 | nlmsg_free(msg); |
| 7314 | return -ENOBUFS; |
| 7315 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7316 | |
| 7317 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7318 | if (ret) { |
| 7319 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 7320 | "err=%d (%s)", ret, strerror(-ret)); |
| 7321 | } |
| 7322 | |
| 7323 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7324 | } |
| 7325 | |
| 7326 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7327 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
| 7328 | { |
| 7329 | struct i802_bss *bss = priv; |
| 7330 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7331 | |
| 7332 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 7333 | return NULL; |
| 7334 | |
| 7335 | return bss->addr; |
| 7336 | } |
| 7337 | |
| 7338 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7339 | static const char * scan_state_str(enum scan_states scan_state) |
| 7340 | { |
| 7341 | switch (scan_state) { |
| 7342 | case NO_SCAN: |
| 7343 | return "NO_SCAN"; |
| 7344 | case SCAN_REQUESTED: |
| 7345 | return "SCAN_REQUESTED"; |
| 7346 | case SCAN_STARTED: |
| 7347 | return "SCAN_STARTED"; |
| 7348 | case SCAN_COMPLETED: |
| 7349 | return "SCAN_COMPLETED"; |
| 7350 | case SCAN_ABORTED: |
| 7351 | return "SCAN_ABORTED"; |
| 7352 | case SCHED_SCAN_STARTED: |
| 7353 | return "SCHED_SCAN_STARTED"; |
| 7354 | case SCHED_SCAN_STOPPED: |
| 7355 | return "SCHED_SCAN_STOPPED"; |
| 7356 | case SCHED_SCAN_RESULTS: |
| 7357 | return "SCHED_SCAN_RESULTS"; |
| 7358 | } |
| 7359 | |
| 7360 | return "??"; |
| 7361 | } |
| 7362 | |
| 7363 | |
| 7364 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 7365 | { |
| 7366 | struct i802_bss *bss = priv; |
| 7367 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7368 | int res; |
| 7369 | char *pos, *end; |
| 7370 | |
| 7371 | pos = buf; |
| 7372 | end = buf + buflen; |
| 7373 | |
| 7374 | res = os_snprintf(pos, end - pos, |
| 7375 | "ifindex=%d\n" |
| 7376 | "ifname=%s\n" |
| 7377 | "brname=%s\n" |
| 7378 | "addr=" MACSTR "\n" |
| 7379 | "freq=%d\n" |
| 7380 | "%s%s%s%s%s", |
| 7381 | bss->ifindex, |
| 7382 | bss->ifname, |
| 7383 | bss->brname, |
| 7384 | MAC2STR(bss->addr), |
| 7385 | bss->freq, |
| 7386 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 7387 | bss->added_if_into_bridge ? |
| 7388 | "added_if_into_bridge=1\n" : "", |
| 7389 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 7390 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 7391 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7392 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7393 | return pos - buf; |
| 7394 | pos += res; |
| 7395 | |
| 7396 | if (bss->wdev_id_set) { |
| 7397 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 7398 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7399 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7400 | return pos - buf; |
| 7401 | pos += res; |
| 7402 | } |
| 7403 | |
| 7404 | res = os_snprintf(pos, end - pos, |
| 7405 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7406 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7407 | "drv_ifindex=%d\n" |
| 7408 | "operstate=%d\n" |
| 7409 | "scan_state=%s\n" |
| 7410 | "auth_bssid=" MACSTR "\n" |
| 7411 | "auth_attempt_bssid=" MACSTR "\n" |
| 7412 | "bssid=" MACSTR "\n" |
| 7413 | "prev_bssid=" MACSTR "\n" |
| 7414 | "associated=%d\n" |
| 7415 | "assoc_freq=%u\n" |
| 7416 | "monitor_sock=%d\n" |
| 7417 | "monitor_ifidx=%d\n" |
| 7418 | "monitor_refcount=%d\n" |
| 7419 | "last_mgmt_freq=%u\n" |
| 7420 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7421 | "%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] | 7422 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7423 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7424 | drv->ifindex, |
| 7425 | drv->operstate, |
| 7426 | scan_state_str(drv->scan_state), |
| 7427 | MAC2STR(drv->auth_bssid), |
| 7428 | MAC2STR(drv->auth_attempt_bssid), |
| 7429 | MAC2STR(drv->bssid), |
| 7430 | MAC2STR(drv->prev_bssid), |
| 7431 | drv->associated, |
| 7432 | drv->assoc_freq, |
| 7433 | drv->monitor_sock, |
| 7434 | drv->monitor_ifidx, |
| 7435 | drv->monitor_refcount, |
| 7436 | drv->last_mgmt_freq, |
| 7437 | drv->eapol_tx_sock, |
| 7438 | drv->ignore_if_down_event ? |
| 7439 | "ignore_if_down_event=1\n" : "", |
| 7440 | drv->scan_complete_events ? |
| 7441 | "scan_complete_events=1\n" : "", |
| 7442 | drv->disabled_11b_rates ? |
| 7443 | "disabled_11b_rates=1\n" : "", |
| 7444 | drv->pending_remain_on_chan ? |
| 7445 | "pending_remain_on_chan=1\n" : "", |
| 7446 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 7447 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 7448 | drv->poll_command_supported ? |
| 7449 | "poll_command_supported=1\n" : "", |
| 7450 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 7451 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 7452 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 7453 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 7454 | drv->ignore_next_local_disconnect ? |
| 7455 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 7456 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7457 | "ignore_next_local_deauth=1\n" : ""); |
| 7458 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7459 | return pos - buf; |
| 7460 | pos += res; |
| 7461 | |
| 7462 | if (drv->has_capability) { |
| 7463 | res = os_snprintf(pos, end - pos, |
| 7464 | "capa.key_mgmt=0x%x\n" |
| 7465 | "capa.enc=0x%x\n" |
| 7466 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7467 | "capa.flags=0x%llx\n" |
| 7468 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7469 | "capa.max_scan_ssids=%d\n" |
| 7470 | "capa.max_sched_scan_ssids=%d\n" |
| 7471 | "capa.sched_scan_supported=%d\n" |
| 7472 | "capa.max_match_sets=%d\n" |
| 7473 | "capa.max_remain_on_chan=%u\n" |
| 7474 | "capa.max_stations=%u\n" |
| 7475 | "capa.probe_resp_offloads=0x%x\n" |
| 7476 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7477 | "capa.num_multichan_concurrent=%u\n" |
| 7478 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
| 7479 | "capa.mac_addr_rand_scan_supported=%d\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7480 | drv->capa.key_mgmt, |
| 7481 | drv->capa.enc, |
| 7482 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7483 | (unsigned long long) drv->capa.flags, |
| 7484 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7485 | drv->capa.max_scan_ssids, |
| 7486 | drv->capa.max_sched_scan_ssids, |
| 7487 | drv->capa.sched_scan_supported, |
| 7488 | drv->capa.max_match_sets, |
| 7489 | drv->capa.max_remain_on_chan, |
| 7490 | drv->capa.max_stations, |
| 7491 | drv->capa.probe_resp_offloads, |
| 7492 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7493 | drv->capa.num_multichan_concurrent, |
| 7494 | drv->capa.mac_addr_rand_sched_scan_supported, |
| 7495 | drv->capa.mac_addr_rand_scan_supported); |
| 7496 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7497 | return pos - buf; |
| 7498 | pos += res; |
| 7499 | } |
| 7500 | |
| 7501 | return pos - buf; |
| 7502 | } |
| 7503 | |
| 7504 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7505 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 7506 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7507 | if ((settings->head && |
| 7508 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 7509 | settings->head_len, settings->head)) || |
| 7510 | (settings->tail && |
| 7511 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 7512 | settings->tail_len, settings->tail)) || |
| 7513 | (settings->beacon_ies && |
| 7514 | nla_put(msg, NL80211_ATTR_IE, |
| 7515 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 7516 | (settings->proberesp_ies && |
| 7517 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 7518 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 7519 | (settings->assocresp_ies && |
| 7520 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 7521 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 7522 | (settings->probe_resp && |
| 7523 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 7524 | settings->probe_resp_len, settings->probe_resp))) |
| 7525 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7526 | |
| 7527 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7528 | } |
| 7529 | |
| 7530 | |
| 7531 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 7532 | { |
| 7533 | struct nl_msg *msg; |
| 7534 | struct i802_bss *bss = priv; |
| 7535 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7536 | struct nlattr *beacon_csa; |
| 7537 | int ret = -ENOBUFS; |
| 7538 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7539 | 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] | 7540 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7541 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 7542 | settings->freq_params.center_freq1, |
| 7543 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7544 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7545 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7546 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 7547 | return -EOPNOTSUPP; |
| 7548 | } |
| 7549 | |
| 7550 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 7551 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 7552 | return -EOPNOTSUPP; |
| 7553 | |
| 7554 | /* check settings validity */ |
| 7555 | if (!settings->beacon_csa.tail || |
| 7556 | ((settings->beacon_csa.tail_len <= |
| 7557 | settings->counter_offset_beacon) || |
| 7558 | (settings->beacon_csa.tail[settings->counter_offset_beacon] != |
| 7559 | settings->cs_count))) |
| 7560 | return -EINVAL; |
| 7561 | |
| 7562 | if (settings->beacon_csa.probe_resp && |
| 7563 | ((settings->beacon_csa.probe_resp_len <= |
| 7564 | settings->counter_offset_presp) || |
| 7565 | (settings->beacon_csa.probe_resp[settings->counter_offset_presp] != |
| 7566 | settings->cs_count))) |
| 7567 | return -EINVAL; |
| 7568 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7569 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 7570 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 7571 | settings->cs_count) || |
| 7572 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 7573 | (settings->block_tx && |
| 7574 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7575 | goto error; |
| 7576 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7577 | /* beacon_after params */ |
| 7578 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 7579 | if (ret) |
| 7580 | goto error; |
| 7581 | |
| 7582 | /* beacon_csa params */ |
| 7583 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 7584 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7585 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7586 | |
| 7587 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 7588 | if (ret) |
| 7589 | goto error; |
| 7590 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7591 | if (nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 7592 | settings->counter_offset_beacon) || |
| 7593 | (settings->beacon_csa.probe_resp && |
| 7594 | nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 7595 | settings->counter_offset_presp))) |
| 7596 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7597 | |
| 7598 | nla_nest_end(msg, beacon_csa); |
| 7599 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7600 | if (ret) { |
| 7601 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 7602 | ret, strerror(-ret)); |
| 7603 | } |
| 7604 | return ret; |
| 7605 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7606 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7607 | ret = -ENOBUFS; |
| 7608 | error: |
| 7609 | nlmsg_free(msg); |
| 7610 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 7611 | return ret; |
| 7612 | } |
| 7613 | |
| 7614 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7615 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 7616 | u8 user_priority, u16 admitted_time) |
| 7617 | { |
| 7618 | struct i802_bss *bss = priv; |
| 7619 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7620 | struct nl_msg *msg; |
| 7621 | int ret; |
| 7622 | |
| 7623 | wpa_printf(MSG_DEBUG, |
| 7624 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 7625 | tsid, admitted_time, user_priority); |
| 7626 | |
| 7627 | if (!is_sta_interface(drv->nlmode)) |
| 7628 | return -ENOTSUP; |
| 7629 | |
| 7630 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 7631 | if (!msg || |
| 7632 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7633 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7634 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 7635 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 7636 | nlmsg_free(msg); |
| 7637 | return -ENOBUFS; |
| 7638 | } |
| 7639 | |
| 7640 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7641 | if (ret) |
| 7642 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 7643 | ret, strerror(-ret)); |
| 7644 | return ret; |
| 7645 | } |
| 7646 | |
| 7647 | |
| 7648 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 7649 | { |
| 7650 | struct i802_bss *bss = priv; |
| 7651 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7652 | struct nl_msg *msg; |
| 7653 | int ret; |
| 7654 | |
| 7655 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 7656 | |
| 7657 | if (!is_sta_interface(drv->nlmode)) |
| 7658 | return -ENOTSUP; |
| 7659 | |
| 7660 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 7661 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7662 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7663 | nlmsg_free(msg); |
| 7664 | return -ENOBUFS; |
| 7665 | } |
| 7666 | |
| 7667 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7668 | if (ret) |
| 7669 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 7670 | ret, strerror(-ret)); |
| 7671 | return ret; |
| 7672 | } |
| 7673 | |
| 7674 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7675 | #ifdef CONFIG_TESTING_OPTIONS |
| 7676 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 7677 | { |
| 7678 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7679 | struct wpabuf *buf = arg; |
| 7680 | |
| 7681 | if (!buf) |
| 7682 | return NL_SKIP; |
| 7683 | |
| 7684 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 7685 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 7686 | return NL_SKIP; |
| 7687 | } |
| 7688 | |
| 7689 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 7690 | genlmsg_attrlen(gnlh, 0)); |
| 7691 | |
| 7692 | return NL_SKIP; |
| 7693 | } |
| 7694 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7695 | |
| 7696 | |
| 7697 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 7698 | { |
| 7699 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7700 | struct nlattr *nl_vendor_reply, *nl; |
| 7701 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7702 | struct wpabuf *buf = arg; |
| 7703 | int rem; |
| 7704 | |
| 7705 | if (!buf) |
| 7706 | return NL_SKIP; |
| 7707 | |
| 7708 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7709 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7710 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 7711 | |
| 7712 | if (!nl_vendor_reply) |
| 7713 | return NL_SKIP; |
| 7714 | |
| 7715 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 7716 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 7717 | return NL_SKIP; |
| 7718 | } |
| 7719 | |
| 7720 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 7721 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 7722 | } |
| 7723 | |
| 7724 | return NL_SKIP; |
| 7725 | } |
| 7726 | |
| 7727 | |
| 7728 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 7729 | unsigned int subcmd, const u8 *data, |
| 7730 | size_t data_len, struct wpabuf *buf) |
| 7731 | { |
| 7732 | struct i802_bss *bss = priv; |
| 7733 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7734 | struct nl_msg *msg; |
| 7735 | int ret; |
| 7736 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7737 | #ifdef CONFIG_TESTING_OPTIONS |
| 7738 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7739 | msg = nlmsg_alloc(); |
| 7740 | if (!msg) |
| 7741 | return -ENOMEM; |
| 7742 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7743 | nl80211_cmd(drv, msg, 0, subcmd); |
| 7744 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 7745 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7746 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7747 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 7748 | if (ret) |
| 7749 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 7750 | ret); |
| 7751 | return ret; |
| 7752 | } |
| 7753 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7754 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7755 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 7756 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 7757 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 7758 | (data && |
| 7759 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 7760 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7761 | |
| 7762 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 7763 | if (ret) |
| 7764 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 7765 | ret); |
| 7766 | return ret; |
| 7767 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7768 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7769 | nlmsg_free(msg); |
| 7770 | return -ENOBUFS; |
| 7771 | } |
| 7772 | |
| 7773 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7774 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 7775 | u8 qos_map_set_len) |
| 7776 | { |
| 7777 | struct i802_bss *bss = priv; |
| 7778 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7779 | struct nl_msg *msg; |
| 7780 | int ret; |
| 7781 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7782 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 7783 | qos_map_set, qos_map_set_len); |
| 7784 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7785 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 7786 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 7787 | nlmsg_free(msg); |
| 7788 | return -ENOBUFS; |
| 7789 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7790 | |
| 7791 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7792 | if (ret) |
| 7793 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 7794 | |
| 7795 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7796 | } |
| 7797 | |
| 7798 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7799 | static int nl80211_set_wowlan(void *priv, |
| 7800 | const struct wowlan_triggers *triggers) |
| 7801 | { |
| 7802 | struct i802_bss *bss = priv; |
| 7803 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7804 | struct nl_msg *msg; |
| 7805 | struct nlattr *wowlan_triggers; |
| 7806 | int ret; |
| 7807 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7808 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 7809 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7810 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WOWLAN)) || |
| 7811 | !(wowlan_triggers = nla_nest_start(msg, |
| 7812 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 7813 | (triggers->any && |
| 7814 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7815 | (triggers->disconnect && |
| 7816 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7817 | (triggers->magic_pkt && |
| 7818 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7819 | (triggers->gtk_rekey_failure && |
| 7820 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7821 | (triggers->eap_identity_req && |
| 7822 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7823 | (triggers->four_way_handshake && |
| 7824 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7825 | (triggers->rfkill_release && |
| 7826 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 7827 | nlmsg_free(msg); |
| 7828 | return -ENOBUFS; |
| 7829 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7830 | |
| 7831 | nla_nest_end(msg, wowlan_triggers); |
| 7832 | |
| 7833 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7834 | if (ret) |
| 7835 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 7836 | |
| 7837 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7838 | } |
| 7839 | |
| 7840 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7841 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 7842 | { |
| 7843 | struct i802_bss *bss = priv; |
| 7844 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7845 | struct nl_msg *msg; |
| 7846 | struct nlattr *params; |
| 7847 | |
| 7848 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 7849 | |
| 7850 | if (!drv->roaming_vendor_cmd_avail) { |
| 7851 | wpa_printf(MSG_DEBUG, |
| 7852 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 7853 | return -1; |
| 7854 | } |
| 7855 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7856 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 7857 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7858 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7859 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 7860 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7861 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 7862 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 7863 | QCA_ROAMING_NOT_ALLOWED) || |
| 7864 | (bssid && |
| 7865 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 7866 | nlmsg_free(msg); |
| 7867 | return -1; |
| 7868 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7869 | nla_nest_end(msg, params); |
| 7870 | |
| 7871 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7872 | } |
| 7873 | |
| 7874 | |
| 7875 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 7876 | { |
| 7877 | struct i802_bss *bss = priv; |
| 7878 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7879 | int new_addr = addr != NULL; |
| 7880 | |
| 7881 | if (!addr) |
| 7882 | addr = drv->perm_addr; |
| 7883 | |
| 7884 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 7885 | return -1; |
| 7886 | |
| 7887 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 7888 | { |
| 7889 | wpa_printf(MSG_DEBUG, |
| 7890 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 7891 | bss->ifname, MAC2STR(addr)); |
| 7892 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 7893 | 1) < 0) { |
| 7894 | wpa_printf(MSG_DEBUG, |
| 7895 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 7896 | } |
| 7897 | return -1; |
| 7898 | } |
| 7899 | |
| 7900 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 7901 | bss->ifname, MAC2STR(addr)); |
| 7902 | drv->addr_changed = new_addr; |
| 7903 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 7904 | |
| 7905 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 7906 | { |
| 7907 | wpa_printf(MSG_DEBUG, |
| 7908 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 7909 | } |
| 7910 | |
| 7911 | return 0; |
| 7912 | } |
| 7913 | |
| 7914 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7915 | #ifdef CONFIG_MESH |
| 7916 | |
| 7917 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 7918 | { |
| 7919 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 7920 | wpa_printf(MSG_INFO, |
| 7921 | "nl80211: Failed to set interface into mesh mode"); |
| 7922 | return -1; |
| 7923 | } |
| 7924 | return 0; |
| 7925 | } |
| 7926 | |
| 7927 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7928 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 7929 | size_t mesh_id_len) |
| 7930 | { |
| 7931 | if (mesh_id) { |
| 7932 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 7933 | mesh_id, mesh_id_len); |
| 7934 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 7935 | } |
| 7936 | |
| 7937 | return 0; |
| 7938 | } |
| 7939 | |
| 7940 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7941 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7942 | struct wpa_driver_mesh_join_params *params) |
| 7943 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7944 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7945 | struct nl_msg *msg; |
| 7946 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7947 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7948 | |
| 7949 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 7950 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7951 | if (!msg || |
| 7952 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 7953 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 7954 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
| 7955 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7956 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7957 | |
| 7958 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 7959 | |
| 7960 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 7961 | if (!container) |
| 7962 | goto fail; |
| 7963 | |
| 7964 | if (params->ies) { |
| 7965 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 7966 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 7967 | params->ies)) |
| 7968 | goto fail; |
| 7969 | } |
| 7970 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 7971 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 7972 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 7973 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 7974 | goto fail; |
| 7975 | } |
| 7976 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 7977 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 7978 | goto fail; |
| 7979 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 7980 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 7981 | goto fail; |
| 7982 | nla_nest_end(msg, container); |
| 7983 | |
| 7984 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 7985 | if (!container) |
| 7986 | goto fail; |
| 7987 | |
| 7988 | if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
| 7989 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0)) |
| 7990 | goto fail; |
| 7991 | if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) && |
| 7992 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7993 | params->max_peer_links)) |
| 7994 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7995 | |
| 7996 | /* |
| 7997 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 7998 | * the timer could disconnect stations even in that case. |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7999 | */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8000 | if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 8001 | params->conf.peer_link_timeout)) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8002 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 8003 | goto fail; |
| 8004 | } |
| 8005 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8006 | nla_nest_end(msg, container); |
| 8007 | |
| 8008 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8009 | msg = NULL; |
| 8010 | if (ret) { |
| 8011 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 8012 | ret, strerror(-ret)); |
| 8013 | goto fail; |
| 8014 | } |
| 8015 | ret = 0; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8016 | bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8017 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 8018 | |
| 8019 | fail: |
| 8020 | nlmsg_free(msg); |
| 8021 | return ret; |
| 8022 | } |
| 8023 | |
| 8024 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8025 | static int |
| 8026 | wpa_driver_nl80211_join_mesh(void *priv, |
| 8027 | struct wpa_driver_mesh_join_params *params) |
| 8028 | { |
| 8029 | struct i802_bss *bss = priv; |
| 8030 | int ret, timeout; |
| 8031 | |
| 8032 | timeout = params->conf.peer_link_timeout; |
| 8033 | |
| 8034 | /* Disable kernel inactivity timer */ |
| 8035 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 8036 | params->conf.peer_link_timeout = 0; |
| 8037 | |
| 8038 | ret = nl80211_join_mesh(bss, params); |
| 8039 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 8040 | wpa_printf(MSG_DEBUG, |
| 8041 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 8042 | /* |
| 8043 | * Old kernel does not support setting |
| 8044 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 8045 | * into future from peer_link_timeout. |
| 8046 | */ |
| 8047 | params->conf.peer_link_timeout = timeout + 60; |
| 8048 | ret = nl80211_join_mesh(priv, params); |
| 8049 | } |
| 8050 | |
| 8051 | params->conf.peer_link_timeout = timeout; |
| 8052 | return ret; |
| 8053 | } |
| 8054 | |
| 8055 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8056 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 8057 | { |
| 8058 | struct i802_bss *bss = priv; |
| 8059 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8060 | struct nl_msg *msg; |
| 8061 | int ret; |
| 8062 | |
| 8063 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 8064 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 8065 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8066 | if (ret) { |
| 8067 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 8068 | ret, strerror(-ret)); |
| 8069 | } else { |
| 8070 | wpa_printf(MSG_DEBUG, |
| 8071 | "nl80211: mesh leave request send successfully"); |
| 8072 | } |
| 8073 | |
| 8074 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 8075 | NL80211_IFTYPE_STATION)) { |
| 8076 | wpa_printf(MSG_INFO, |
| 8077 | "nl80211: Failed to set interface into station mode"); |
| 8078 | } |
| 8079 | return ret; |
| 8080 | } |
| 8081 | |
| 8082 | #endif /* CONFIG_MESH */ |
| 8083 | |
| 8084 | |
| 8085 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 8086 | const u8 *ipaddr, int prefixlen, |
| 8087 | const u8 *addr) |
| 8088 | { |
| 8089 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8090 | struct i802_bss *bss = priv; |
| 8091 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8092 | struct rtnl_neigh *rn; |
| 8093 | struct nl_addr *nl_ipaddr = NULL; |
| 8094 | struct nl_addr *nl_lladdr = NULL; |
| 8095 | int family, addrsize; |
| 8096 | int res; |
| 8097 | |
| 8098 | if (!ipaddr || prefixlen == 0 || !addr) |
| 8099 | return -EINVAL; |
| 8100 | |
| 8101 | if (bss->br_ifindex == 0) { |
| 8102 | wpa_printf(MSG_DEBUG, |
| 8103 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 8104 | return -1; |
| 8105 | } |
| 8106 | |
| 8107 | if (!drv->rtnl_sk) { |
| 8108 | wpa_printf(MSG_DEBUG, |
| 8109 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8110 | return -1; |
| 8111 | } |
| 8112 | |
| 8113 | if (version == 4) { |
| 8114 | family = AF_INET; |
| 8115 | addrsize = 4; |
| 8116 | } else if (version == 6) { |
| 8117 | family = AF_INET6; |
| 8118 | addrsize = 16; |
| 8119 | } else { |
| 8120 | return -EINVAL; |
| 8121 | } |
| 8122 | |
| 8123 | rn = rtnl_neigh_alloc(); |
| 8124 | if (rn == NULL) |
| 8125 | return -ENOMEM; |
| 8126 | |
| 8127 | /* set the destination ip address for neigh */ |
| 8128 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8129 | if (nl_ipaddr == NULL) { |
| 8130 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8131 | res = -ENOMEM; |
| 8132 | goto errout; |
| 8133 | } |
| 8134 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 8135 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8136 | if (res) { |
| 8137 | wpa_printf(MSG_DEBUG, |
| 8138 | "nl80211: neigh set destination addr failed"); |
| 8139 | goto errout; |
| 8140 | } |
| 8141 | |
| 8142 | /* set the corresponding lladdr for neigh */ |
| 8143 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 8144 | if (nl_lladdr == NULL) { |
| 8145 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 8146 | res = -ENOMEM; |
| 8147 | goto errout; |
| 8148 | } |
| 8149 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 8150 | |
| 8151 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8152 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 8153 | |
| 8154 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 8155 | if (res) { |
| 8156 | wpa_printf(MSG_DEBUG, |
| 8157 | "nl80211: Adding bridge ip neigh failed: %s", |
| 8158 | strerror(errno)); |
| 8159 | } |
| 8160 | errout: |
| 8161 | if (nl_lladdr) |
| 8162 | nl_addr_put(nl_lladdr); |
| 8163 | if (nl_ipaddr) |
| 8164 | nl_addr_put(nl_ipaddr); |
| 8165 | if (rn) |
| 8166 | rtnl_neigh_put(rn); |
| 8167 | return res; |
| 8168 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8169 | return -1; |
| 8170 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8171 | } |
| 8172 | |
| 8173 | |
| 8174 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 8175 | const u8 *ipaddr) |
| 8176 | { |
| 8177 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8178 | struct i802_bss *bss = priv; |
| 8179 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8180 | struct rtnl_neigh *rn; |
| 8181 | struct nl_addr *nl_ipaddr; |
| 8182 | int family, addrsize; |
| 8183 | int res; |
| 8184 | |
| 8185 | if (!ipaddr) |
| 8186 | return -EINVAL; |
| 8187 | |
| 8188 | if (version == 4) { |
| 8189 | family = AF_INET; |
| 8190 | addrsize = 4; |
| 8191 | } else if (version == 6) { |
| 8192 | family = AF_INET6; |
| 8193 | addrsize = 16; |
| 8194 | } else { |
| 8195 | return -EINVAL; |
| 8196 | } |
| 8197 | |
| 8198 | if (bss->br_ifindex == 0) { |
| 8199 | wpa_printf(MSG_DEBUG, |
| 8200 | "nl80211: bridge must be set to delete an ip neigh"); |
| 8201 | return -1; |
| 8202 | } |
| 8203 | |
| 8204 | if (!drv->rtnl_sk) { |
| 8205 | wpa_printf(MSG_DEBUG, |
| 8206 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8207 | return -1; |
| 8208 | } |
| 8209 | |
| 8210 | rn = rtnl_neigh_alloc(); |
| 8211 | if (rn == NULL) |
| 8212 | return -ENOMEM; |
| 8213 | |
| 8214 | /* set the destination ip address for neigh */ |
| 8215 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8216 | if (nl_ipaddr == NULL) { |
| 8217 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8218 | res = -ENOMEM; |
| 8219 | goto errout; |
| 8220 | } |
| 8221 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8222 | if (res) { |
| 8223 | wpa_printf(MSG_DEBUG, |
| 8224 | "nl80211: neigh set destination addr failed"); |
| 8225 | goto errout; |
| 8226 | } |
| 8227 | |
| 8228 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8229 | |
| 8230 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 8231 | if (res) { |
| 8232 | wpa_printf(MSG_DEBUG, |
| 8233 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 8234 | strerror(errno)); |
| 8235 | } |
| 8236 | errout: |
| 8237 | if (nl_ipaddr) |
| 8238 | nl_addr_put(nl_ipaddr); |
| 8239 | if (rn) |
| 8240 | rtnl_neigh_put(rn); |
| 8241 | return res; |
| 8242 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8243 | return -1; |
| 8244 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8245 | } |
| 8246 | |
| 8247 | |
| 8248 | static int linux_write_system_file(const char *path, unsigned int val) |
| 8249 | { |
| 8250 | char buf[50]; |
| 8251 | int fd, len; |
| 8252 | |
| 8253 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 8254 | if (os_snprintf_error(sizeof(buf), len)) |
| 8255 | return -1; |
| 8256 | |
| 8257 | fd = open(path, O_WRONLY); |
| 8258 | if (fd < 0) |
| 8259 | return -1; |
| 8260 | |
| 8261 | if (write(fd, buf, len) < 0) { |
| 8262 | wpa_printf(MSG_DEBUG, |
| 8263 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 8264 | path, val); |
| 8265 | close(fd); |
| 8266 | return -1; |
| 8267 | } |
| 8268 | close(fd); |
| 8269 | |
| 8270 | return 0; |
| 8271 | } |
| 8272 | |
| 8273 | |
| 8274 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 8275 | { |
| 8276 | switch (attr) { |
| 8277 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 8278 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8279 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 8280 | return "hairpin_mode"; |
| 8281 | } |
| 8282 | |
| 8283 | return NULL; |
| 8284 | } |
| 8285 | |
| 8286 | |
| 8287 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 8288 | unsigned int val) |
| 8289 | { |
| 8290 | struct i802_bss *bss = priv; |
| 8291 | char path[128]; |
| 8292 | const char *attr_txt; |
| 8293 | |
| 8294 | attr_txt = drv_br_port_attr_str(attr); |
| 8295 | if (attr_txt == NULL) |
| 8296 | return -EINVAL; |
| 8297 | |
| 8298 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 8299 | bss->ifname, attr_txt); |
| 8300 | |
| 8301 | if (linux_write_system_file(path, val)) |
| 8302 | return -1; |
| 8303 | |
| 8304 | return 0; |
| 8305 | } |
| 8306 | |
| 8307 | |
| 8308 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 8309 | { |
| 8310 | switch (param) { |
| 8311 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8312 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8313 | default: |
| 8314 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8315 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8316 | } |
| 8317 | |
| 8318 | |
| 8319 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 8320 | unsigned int val) |
| 8321 | { |
| 8322 | struct i802_bss *bss = priv; |
| 8323 | char path[128]; |
| 8324 | const char *param_txt; |
| 8325 | int ip_version = 4; |
| 8326 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8327 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 8328 | os_snprintf(path, sizeof(path), |
| 8329 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 8330 | bss->brname); |
| 8331 | goto set_val; |
| 8332 | } |
| 8333 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8334 | param_txt = drv_br_net_param_str(param); |
| 8335 | if (param_txt == NULL) |
| 8336 | return -EINVAL; |
| 8337 | |
| 8338 | switch (param) { |
| 8339 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8340 | ip_version = 4; |
| 8341 | break; |
| 8342 | default: |
| 8343 | return -EINVAL; |
| 8344 | } |
| 8345 | |
| 8346 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 8347 | ip_version, bss->brname, param_txt); |
| 8348 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8349 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8350 | if (linux_write_system_file(path, val)) |
| 8351 | return -1; |
| 8352 | |
| 8353 | return 0; |
| 8354 | } |
| 8355 | |
| 8356 | |
| 8357 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 8358 | { |
| 8359 | switch (hw_mode) { |
| 8360 | case HOSTAPD_MODE_IEEE80211B: |
| 8361 | return QCA_ACS_MODE_IEEE80211B; |
| 8362 | case HOSTAPD_MODE_IEEE80211G: |
| 8363 | return QCA_ACS_MODE_IEEE80211G; |
| 8364 | case HOSTAPD_MODE_IEEE80211A: |
| 8365 | return QCA_ACS_MODE_IEEE80211A; |
| 8366 | case HOSTAPD_MODE_IEEE80211AD: |
| 8367 | return QCA_ACS_MODE_IEEE80211AD; |
| 8368 | default: |
| 8369 | return -1; |
| 8370 | } |
| 8371 | } |
| 8372 | |
| 8373 | |
| 8374 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 8375 | { |
| 8376 | struct i802_bss *bss = priv; |
| 8377 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8378 | struct nl_msg *msg; |
| 8379 | struct nlattr *data; |
| 8380 | int ret; |
| 8381 | int mode; |
| 8382 | |
| 8383 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 8384 | if (mode < 0) |
| 8385 | return -1; |
| 8386 | |
| 8387 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8388 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8389 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8390 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 8391 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8392 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 8393 | (params->ht_enabled && |
| 8394 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 8395 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8396 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 8397 | (params->vht_enabled && |
| 8398 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 8399 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 8400 | params->ch_width) || |
| 8401 | (params->ch_list_len && |
| 8402 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, |
| 8403 | params->ch_list))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8404 | nlmsg_free(msg); |
| 8405 | return -ENOBUFS; |
| 8406 | } |
| 8407 | nla_nest_end(msg, data); |
| 8408 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8409 | wpa_printf(MSG_DEBUG, |
| 8410 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 8411 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 8412 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 8413 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8414 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8415 | if (ret) { |
| 8416 | wpa_printf(MSG_DEBUG, |
| 8417 | "nl80211: Failed to invoke driver ACS function: %s", |
| 8418 | strerror(errno)); |
| 8419 | } |
| 8420 | return ret; |
| 8421 | } |
| 8422 | |
| 8423 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8424 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 8425 | .name = "nl80211", |
| 8426 | .desc = "Linux nl80211/cfg80211", |
| 8427 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 8428 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8429 | .set_key = driver_nl80211_set_key, |
| 8430 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8431 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 8432 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8433 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8434 | .deauthenticate = driver_nl80211_deauthenticate, |
| 8435 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8436 | .associate = wpa_driver_nl80211_associate, |
| 8437 | .global_init = nl80211_global_init, |
| 8438 | .global_deinit = nl80211_global_deinit, |
| 8439 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8440 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8441 | .get_capa = wpa_driver_nl80211_get_capa, |
| 8442 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 8443 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 8444 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8445 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8446 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8447 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8448 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8449 | .if_remove = driver_nl80211_if_remove, |
| 8450 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8451 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8452 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8453 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8454 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 8455 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8456 | .hapd_init = i802_init, |
| 8457 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8458 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8459 | .get_seqnum = i802_get_seqnum, |
| 8460 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8461 | .get_inact_sec = i802_get_inact_sec, |
| 8462 | .sta_clear_stats = i802_sta_clear_stats, |
| 8463 | .set_rts = i802_set_rts, |
| 8464 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8465 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8466 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8467 | .sta_deauth = i802_sta_deauth, |
| 8468 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8469 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8470 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8471 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8472 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 8473 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 8474 | .cancel_remain_on_channel = |
| 8475 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8476 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8477 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8478 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8479 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8480 | .signal_monitor = nl80211_signal_monitor, |
| 8481 | .signal_poll = nl80211_signal_poll, |
| 8482 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8483 | .set_param = nl80211_set_param, |
| 8484 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8485 | .add_pmkid = nl80211_add_pmkid, |
| 8486 | .remove_pmkid = nl80211_remove_pmkid, |
| 8487 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8488 | .set_rekey_info = nl80211_set_rekey_info, |
| 8489 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8490 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8491 | .start_dfs_cac = nl80211_start_radar_detection, |
| 8492 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8493 | #ifdef CONFIG_TDLS |
| 8494 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 8495 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8496 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 8497 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8498 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8499 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8500 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8501 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8502 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8503 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8504 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8505 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8506 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8507 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8508 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 8509 | #ifdef ANDROID |
| 8510 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8511 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8512 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8513 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8514 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8515 | .roaming = nl80211_roaming, |
| 8516 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8517 | #ifdef CONFIG_MESH |
| 8518 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 8519 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 8520 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 8521 | #endif /* CONFIG_MESH */ |
| 8522 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 8523 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 8524 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 8525 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 8526 | .add_tx_ts = nl80211_add_ts, |
| 8527 | .del_tx_ts = nl80211_del_ts, |
| 8528 | .do_acs = wpa_driver_do_acs, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8529 | }; |