Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver interaction with Linux nl80211/cfg80211 |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2014, 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" |
| 14 | #include <sys/ioctl.h> |
| 15 | #include <sys/types.h> |
| 16 | #include <sys/stat.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <net/if.h> |
| 19 | #include <netlink/genl/genl.h> |
| 20 | #include <netlink/genl/family.h> |
| 21 | #include <netlink/genl/ctrl.h> |
| 22 | #include <linux/rtnetlink.h> |
| 23 | #include <netpacket/packet.h> |
| 24 | #include <linux/filter.h> |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 25 | #include <linux/errqueue.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 26 | #include "nl80211_copy.h" |
| 27 | |
| 28 | #include "common.h" |
| 29 | #include "eloop.h" |
| 30 | #include "utils/list.h" |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 31 | #include "common/qca-vendor.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 32 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 33 | #include "common/ieee802_11_common.h" |
| 34 | #include "l2_packet/l2_packet.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "netlink.h" |
| 36 | #include "linux_ioctl.h" |
| 37 | #include "radiotap.h" |
| 38 | #include "radiotap_iter.h" |
| 39 | #include "rfkill.h" |
| 40 | #include "driver.h" |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 41 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 42 | #ifndef SO_WIFI_STATUS |
| 43 | # if defined(__sparc__) |
| 44 | # define SO_WIFI_STATUS 0x0025 |
| 45 | # elif defined(__parisc__) |
| 46 | # define SO_WIFI_STATUS 0x4022 |
| 47 | # else |
| 48 | # define SO_WIFI_STATUS 41 |
| 49 | # endif |
| 50 | |
| 51 | # define SCM_WIFI_STATUS SO_WIFI_STATUS |
| 52 | #endif |
| 53 | |
| 54 | #ifndef SO_EE_ORIGIN_TXSTATUS |
| 55 | #define SO_EE_ORIGIN_TXSTATUS 4 |
| 56 | #endif |
| 57 | |
| 58 | #ifndef PACKET_TX_TIMESTAMP |
| 59 | #define PACKET_TX_TIMESTAMP 16 |
| 60 | #endif |
| 61 | |
| 62 | #ifdef ANDROID |
| 63 | #include "android_drv.h" |
| 64 | #endif /* ANDROID */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 65 | #ifdef CONFIG_LIBNL20 |
| 66 | /* libnl 2.0 compatibility code */ |
| 67 | #define nl_handle nl_sock |
| 68 | #define nl80211_handle_alloc nl_socket_alloc_cb |
| 69 | #define nl80211_handle_destroy nl_socket_free |
| 70 | #else |
| 71 | /* |
| 72 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely |
| 73 | * but when you free a socket again it will mess up its bitmap and |
| 74 | * and use the wrong number the next time it needs a socket ID. |
| 75 | * Therefore, we wrap the handle alloc/destroy and add our own pid |
| 76 | * accounting. |
| 77 | */ |
| 78 | static uint32_t port_bitmap[32] = { 0 }; |
| 79 | |
| 80 | static struct nl_handle *nl80211_handle_alloc(void *cb) |
| 81 | { |
| 82 | struct nl_handle *handle; |
| 83 | uint32_t pid = getpid() & 0x3FFFFF; |
| 84 | int i; |
| 85 | |
| 86 | handle = nl_handle_alloc_cb(cb); |
| 87 | |
| 88 | for (i = 0; i < 1024; i++) { |
| 89 | if (port_bitmap[i / 32] & (1 << (i % 32))) |
| 90 | continue; |
| 91 | port_bitmap[i / 32] |= 1 << (i % 32); |
| 92 | pid += i << 22; |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | nl_socket_set_local_port(handle, pid); |
| 97 | |
| 98 | return handle; |
| 99 | } |
| 100 | |
| 101 | static void nl80211_handle_destroy(struct nl_handle *handle) |
| 102 | { |
| 103 | uint32_t port = nl_socket_get_local_port(handle); |
| 104 | |
| 105 | port >>= 22; |
| 106 | port_bitmap[port / 32] &= ~(1 << (port % 32)); |
| 107 | |
| 108 | nl_handle_destroy(handle); |
| 109 | } |
| 110 | #endif /* CONFIG_LIBNL20 */ |
| 111 | |
| 112 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 113 | #ifdef ANDROID |
| 114 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
| 115 | static int android_nl_socket_set_nonblocking(struct nl_handle *handle) |
| 116 | { |
| 117 | return fcntl(nl_socket_get_fd(handle), F_SETFL, O_NONBLOCK); |
| 118 | } |
| 119 | #undef nl_socket_set_nonblocking |
| 120 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
| 121 | #endif /* ANDROID */ |
| 122 | |
| 123 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 124 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 125 | { |
| 126 | struct nl_handle *handle; |
| 127 | |
| 128 | handle = nl80211_handle_alloc(cb); |
| 129 | if (handle == NULL) { |
| 130 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 131 | "callbacks (%s)", dbg); |
| 132 | return NULL; |
| 133 | } |
| 134 | |
| 135 | if (genl_connect(handle)) { |
| 136 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 137 | "netlink (%s)", dbg); |
| 138 | nl80211_handle_destroy(handle); |
| 139 | return NULL; |
| 140 | } |
| 141 | |
| 142 | return handle; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | static void nl_destroy_handles(struct nl_handle **handle) |
| 147 | { |
| 148 | if (*handle == NULL) |
| 149 | return; |
| 150 | nl80211_handle_destroy(*handle); |
| 151 | *handle = NULL; |
| 152 | } |
| 153 | |
| 154 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 155 | #if __WORDSIZE == 64 |
| 156 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 157 | #else |
| 158 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 159 | #endif |
| 160 | |
| 161 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
| 162 | eloop_sock_handler handler, |
| 163 | void *eloop_data) |
| 164 | { |
| 165 | nl_socket_set_nonblocking(*handle); |
| 166 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 167 | eloop_data, *handle); |
| 168 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle) |
| 173 | { |
| 174 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
| 175 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 176 | nl_destroy_handles(handle); |
| 177 | } |
| 178 | |
| 179 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 180 | #ifndef IFF_LOWER_UP |
| 181 | #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ |
| 182 | #endif |
| 183 | #ifndef IFF_DORMANT |
| 184 | #define IFF_DORMANT 0x20000 /* driver signals dormant */ |
| 185 | #endif |
| 186 | |
| 187 | #ifndef IF_OPER_DORMANT |
| 188 | #define IF_OPER_DORMANT 5 |
| 189 | #endif |
| 190 | #ifndef IF_OPER_UP |
| 191 | #define IF_OPER_UP 6 |
| 192 | #endif |
| 193 | |
| 194 | struct nl80211_global { |
| 195 | struct dl_list interfaces; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 196 | int if_add_ifindex; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 197 | u64 if_add_wdevid; |
| 198 | int if_add_wdevid_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 199 | struct netlink_data *netlink; |
| 200 | struct nl_cb *nl_cb; |
| 201 | struct nl_handle *nl; |
| 202 | int nl80211_id; |
| 203 | int ioctl_sock; /* socket for ioctl() use */ |
| 204 | |
| 205 | struct nl_handle *nl_event; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 208 | struct nl80211_wiphy_data { |
| 209 | struct dl_list list; |
| 210 | struct dl_list bsss; |
| 211 | struct dl_list drvs; |
| 212 | |
| 213 | struct nl_handle *nl_beacons; |
| 214 | struct nl_cb *nl_cb; |
| 215 | |
| 216 | int wiphy_idx; |
| 217 | }; |
| 218 | |
| 219 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 220 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 221 | struct i802_bss { |
| 222 | struct wpa_driver_nl80211_data *drv; |
| 223 | struct i802_bss *next; |
| 224 | int ifindex; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 225 | u64 wdev_id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 226 | char ifname[IFNAMSIZ + 1]; |
| 227 | char brname[IFNAMSIZ]; |
| 228 | unsigned int beacon_set:1; |
| 229 | unsigned int added_if_into_bridge:1; |
| 230 | unsigned int added_bridge:1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 231 | unsigned int in_deinit:1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 232 | unsigned int wdev_id_set:1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 233 | unsigned int added_if:1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 234 | |
| 235 | u8 addr[ETH_ALEN]; |
| 236 | |
| 237 | int freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 238 | int if_dynamic; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 239 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 240 | void *ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 241 | struct nl_handle *nl_preq, *nl_mgmt; |
| 242 | struct nl_cb *nl_cb; |
| 243 | |
| 244 | struct nl80211_wiphy_data *wiphy_data; |
| 245 | struct dl_list wiphy_list; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | struct wpa_driver_nl80211_data { |
| 249 | struct nl80211_global *global; |
| 250 | struct dl_list list; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 251 | struct dl_list wiphy_list; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 252 | char phyname[32]; |
| 253 | void *ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 254 | int ifindex; |
| 255 | int if_removed; |
| 256 | int if_disabled; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 257 | int ignore_if_down_event; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 258 | struct rfkill_data *rfkill; |
| 259 | struct wpa_driver_capa capa; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 260 | u8 *extended_capa, *extended_capa_mask; |
| 261 | unsigned int extended_capa_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 262 | int has_capability; |
| 263 | |
| 264 | int operstate; |
| 265 | |
| 266 | int scan_complete_events; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 267 | enum scan_states { |
| 268 | NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED, |
| 269 | SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED, |
| 270 | SCHED_SCAN_RESULTS |
| 271 | } scan_state; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 272 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 273 | struct nl_cb *nl_cb; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 274 | |
| 275 | u8 auth_bssid[ETH_ALEN]; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 276 | u8 auth_attempt_bssid[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 277 | u8 bssid[ETH_ALEN]; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 278 | u8 prev_bssid[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 279 | int associated; |
| 280 | u8 ssid[32]; |
| 281 | size_t ssid_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 282 | enum nl80211_iftype nlmode; |
| 283 | enum nl80211_iftype ap_scan_as_station; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 284 | unsigned int assoc_freq; |
| 285 | |
| 286 | int monitor_sock; |
| 287 | int monitor_ifidx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 288 | int monitor_refcount; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 289 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 290 | unsigned int disabled_11b_rates:1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 291 | unsigned int pending_remain_on_chan:1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 292 | unsigned int in_interface_list:1; |
| 293 | unsigned int device_ap_sme:1; |
| 294 | unsigned int poll_command_supported:1; |
| 295 | unsigned int data_tx_status:1; |
| 296 | unsigned int scan_for_auth:1; |
| 297 | unsigned int retry_auth:1; |
| 298 | unsigned int use_monitor:1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 299 | unsigned int ignore_next_local_disconnect:1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 300 | unsigned int allow_p2p_device:1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 301 | unsigned int hostapd:1; |
| 302 | unsigned int start_mode_ap:1; |
| 303 | unsigned int start_iface_up:1; |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 304 | unsigned int test_use_roc_tx:1; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 305 | unsigned int ignore_deauth_event:1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 306 | |
| 307 | u64 remain_on_chan_cookie; |
| 308 | u64 send_action_cookie; |
| 309 | |
| 310 | unsigned int last_mgmt_freq; |
| 311 | |
| 312 | struct wpa_driver_scan_filter *filter_ssids; |
| 313 | size_t num_filter_ssids; |
| 314 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 315 | struct i802_bss *first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 316 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 317 | int eapol_tx_sock; |
| 318 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 319 | int eapol_sock; /* socket for EAPOL frames */ |
| 320 | |
| 321 | int default_if_indices[16]; |
| 322 | int *if_indices; |
| 323 | int num_if_indices; |
| 324 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 325 | /* From failed authentication command */ |
| 326 | int auth_freq; |
| 327 | u8 auth_bssid_[ETH_ALEN]; |
| 328 | u8 auth_ssid[32]; |
| 329 | size_t auth_ssid_len; |
| 330 | int auth_alg; |
| 331 | u8 *auth_ie; |
| 332 | size_t auth_ie_len; |
| 333 | u8 auth_wep_key[4][16]; |
| 334 | size_t auth_wep_key_len[4]; |
| 335 | int auth_wep_tx_keyidx; |
| 336 | int auth_local_state_change; |
| 337 | int auth_p2p; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 341 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 342 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, |
| 343 | void *timeout_ctx); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 344 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 345 | enum nl80211_iftype nlmode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 346 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 347 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
| 348 | const u8 *set_addr, int first); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 349 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 350 | const u8 *addr, int cmd, u16 reason_code, |
| 351 | int local_state_change); |
| 352 | static void nl80211_remove_monitor_interface( |
| 353 | struct wpa_driver_nl80211_data *drv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 354 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 355 | unsigned int freq, unsigned int wait, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 356 | const u8 *buf, size_t buf_len, u64 *cookie, |
| 357 | int no_cck, int no_ack, int offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 358 | static int nl80211_register_frame(struct i802_bss *bss, |
| 359 | struct nl_handle *hl_handle, |
| 360 | u16 type, const u8 *match, size_t match_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 361 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 362 | int report); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 363 | #ifdef ANDROID |
| 364 | static int android_pno_start(struct i802_bss *bss, |
| 365 | struct wpa_driver_scan_params *params); |
| 366 | static int android_pno_stop(struct i802_bss *bss); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 367 | extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf, |
| 368 | size_t buf_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 369 | #endif /* ANDROID */ |
| 370 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 371 | int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 372 | int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 373 | int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow); |
| 374 | int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 375 | const struct wpabuf *proberesp, |
| 376 | const struct wpabuf *assocresp); |
| 377 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 378 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 379 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
| 380 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
| 381 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 382 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 383 | enum wpa_driver_if_type type, |
| 384 | const char *ifname); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 385 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 386 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
| 387 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 388 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 389 | int ifindex, int disabled); |
| 390 | |
| 391 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 392 | static int wpa_driver_nl80211_authenticate_retry( |
| 393 | struct wpa_driver_nl80211_data *drv); |
| 394 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 395 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
| 396 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 397 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 398 | static const char * nl80211_command_to_string(enum nl80211_commands cmd) |
| 399 | { |
| 400 | #define C2S(x) case x: return #x; |
| 401 | switch (cmd) { |
| 402 | C2S(NL80211_CMD_UNSPEC) |
| 403 | C2S(NL80211_CMD_GET_WIPHY) |
| 404 | C2S(NL80211_CMD_SET_WIPHY) |
| 405 | C2S(NL80211_CMD_NEW_WIPHY) |
| 406 | C2S(NL80211_CMD_DEL_WIPHY) |
| 407 | C2S(NL80211_CMD_GET_INTERFACE) |
| 408 | C2S(NL80211_CMD_SET_INTERFACE) |
| 409 | C2S(NL80211_CMD_NEW_INTERFACE) |
| 410 | C2S(NL80211_CMD_DEL_INTERFACE) |
| 411 | C2S(NL80211_CMD_GET_KEY) |
| 412 | C2S(NL80211_CMD_SET_KEY) |
| 413 | C2S(NL80211_CMD_NEW_KEY) |
| 414 | C2S(NL80211_CMD_DEL_KEY) |
| 415 | C2S(NL80211_CMD_GET_BEACON) |
| 416 | C2S(NL80211_CMD_SET_BEACON) |
| 417 | C2S(NL80211_CMD_START_AP) |
| 418 | C2S(NL80211_CMD_STOP_AP) |
| 419 | C2S(NL80211_CMD_GET_STATION) |
| 420 | C2S(NL80211_CMD_SET_STATION) |
| 421 | C2S(NL80211_CMD_NEW_STATION) |
| 422 | C2S(NL80211_CMD_DEL_STATION) |
| 423 | C2S(NL80211_CMD_GET_MPATH) |
| 424 | C2S(NL80211_CMD_SET_MPATH) |
| 425 | C2S(NL80211_CMD_NEW_MPATH) |
| 426 | C2S(NL80211_CMD_DEL_MPATH) |
| 427 | C2S(NL80211_CMD_SET_BSS) |
| 428 | C2S(NL80211_CMD_SET_REG) |
| 429 | C2S(NL80211_CMD_REQ_SET_REG) |
| 430 | C2S(NL80211_CMD_GET_MESH_CONFIG) |
| 431 | C2S(NL80211_CMD_SET_MESH_CONFIG) |
| 432 | C2S(NL80211_CMD_SET_MGMT_EXTRA_IE) |
| 433 | C2S(NL80211_CMD_GET_REG) |
| 434 | C2S(NL80211_CMD_GET_SCAN) |
| 435 | C2S(NL80211_CMD_TRIGGER_SCAN) |
| 436 | C2S(NL80211_CMD_NEW_SCAN_RESULTS) |
| 437 | C2S(NL80211_CMD_SCAN_ABORTED) |
| 438 | C2S(NL80211_CMD_REG_CHANGE) |
| 439 | C2S(NL80211_CMD_AUTHENTICATE) |
| 440 | C2S(NL80211_CMD_ASSOCIATE) |
| 441 | C2S(NL80211_CMD_DEAUTHENTICATE) |
| 442 | C2S(NL80211_CMD_DISASSOCIATE) |
| 443 | C2S(NL80211_CMD_MICHAEL_MIC_FAILURE) |
| 444 | C2S(NL80211_CMD_REG_BEACON_HINT) |
| 445 | C2S(NL80211_CMD_JOIN_IBSS) |
| 446 | C2S(NL80211_CMD_LEAVE_IBSS) |
| 447 | C2S(NL80211_CMD_TESTMODE) |
| 448 | C2S(NL80211_CMD_CONNECT) |
| 449 | C2S(NL80211_CMD_ROAM) |
| 450 | C2S(NL80211_CMD_DISCONNECT) |
| 451 | C2S(NL80211_CMD_SET_WIPHY_NETNS) |
| 452 | C2S(NL80211_CMD_GET_SURVEY) |
| 453 | C2S(NL80211_CMD_NEW_SURVEY_RESULTS) |
| 454 | C2S(NL80211_CMD_SET_PMKSA) |
| 455 | C2S(NL80211_CMD_DEL_PMKSA) |
| 456 | C2S(NL80211_CMD_FLUSH_PMKSA) |
| 457 | C2S(NL80211_CMD_REMAIN_ON_CHANNEL) |
| 458 | C2S(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL) |
| 459 | C2S(NL80211_CMD_SET_TX_BITRATE_MASK) |
| 460 | C2S(NL80211_CMD_REGISTER_FRAME) |
| 461 | C2S(NL80211_CMD_FRAME) |
| 462 | C2S(NL80211_CMD_FRAME_TX_STATUS) |
| 463 | C2S(NL80211_CMD_SET_POWER_SAVE) |
| 464 | C2S(NL80211_CMD_GET_POWER_SAVE) |
| 465 | C2S(NL80211_CMD_SET_CQM) |
| 466 | C2S(NL80211_CMD_NOTIFY_CQM) |
| 467 | C2S(NL80211_CMD_SET_CHANNEL) |
| 468 | C2S(NL80211_CMD_SET_WDS_PEER) |
| 469 | C2S(NL80211_CMD_FRAME_WAIT_CANCEL) |
| 470 | C2S(NL80211_CMD_JOIN_MESH) |
| 471 | C2S(NL80211_CMD_LEAVE_MESH) |
| 472 | C2S(NL80211_CMD_UNPROT_DEAUTHENTICATE) |
| 473 | C2S(NL80211_CMD_UNPROT_DISASSOCIATE) |
| 474 | C2S(NL80211_CMD_NEW_PEER_CANDIDATE) |
| 475 | C2S(NL80211_CMD_GET_WOWLAN) |
| 476 | C2S(NL80211_CMD_SET_WOWLAN) |
| 477 | C2S(NL80211_CMD_START_SCHED_SCAN) |
| 478 | C2S(NL80211_CMD_STOP_SCHED_SCAN) |
| 479 | C2S(NL80211_CMD_SCHED_SCAN_RESULTS) |
| 480 | C2S(NL80211_CMD_SCHED_SCAN_STOPPED) |
| 481 | C2S(NL80211_CMD_SET_REKEY_OFFLOAD) |
| 482 | C2S(NL80211_CMD_PMKSA_CANDIDATE) |
| 483 | C2S(NL80211_CMD_TDLS_OPER) |
| 484 | C2S(NL80211_CMD_TDLS_MGMT) |
| 485 | C2S(NL80211_CMD_UNEXPECTED_FRAME) |
| 486 | C2S(NL80211_CMD_PROBE_CLIENT) |
| 487 | C2S(NL80211_CMD_REGISTER_BEACONS) |
| 488 | C2S(NL80211_CMD_UNEXPECTED_4ADDR_FRAME) |
| 489 | C2S(NL80211_CMD_SET_NOACK_MAP) |
| 490 | C2S(NL80211_CMD_CH_SWITCH_NOTIFY) |
| 491 | C2S(NL80211_CMD_START_P2P_DEVICE) |
| 492 | C2S(NL80211_CMD_STOP_P2P_DEVICE) |
| 493 | C2S(NL80211_CMD_CONN_FAILED) |
| 494 | C2S(NL80211_CMD_SET_MCAST_RATE) |
| 495 | C2S(NL80211_CMD_SET_MAC_ACL) |
| 496 | C2S(NL80211_CMD_RADAR_DETECT) |
| 497 | C2S(NL80211_CMD_GET_PROTOCOL_FEATURES) |
| 498 | C2S(NL80211_CMD_UPDATE_FT_IES) |
| 499 | C2S(NL80211_CMD_FT_EVENT) |
| 500 | C2S(NL80211_CMD_CRIT_PROTOCOL_START) |
| 501 | C2S(NL80211_CMD_CRIT_PROTOCOL_STOP) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 502 | C2S(NL80211_CMD_GET_COALESCE) |
| 503 | C2S(NL80211_CMD_SET_COALESCE) |
| 504 | C2S(NL80211_CMD_CHANNEL_SWITCH) |
| 505 | C2S(NL80211_CMD_VENDOR) |
| 506 | C2S(NL80211_CMD_SET_QOS_MAP) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 507 | default: |
| 508 | return "NL80211_CMD_UNKNOWN"; |
| 509 | } |
| 510 | #undef C2S |
| 511 | } |
| 512 | |
| 513 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 514 | /* Converts nl80211_chan_width to a common format */ |
| 515 | static enum chan_width convert2width(int width) |
| 516 | { |
| 517 | switch (width) { |
| 518 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 519 | return CHAN_WIDTH_20_NOHT; |
| 520 | case NL80211_CHAN_WIDTH_20: |
| 521 | return CHAN_WIDTH_20; |
| 522 | case NL80211_CHAN_WIDTH_40: |
| 523 | return CHAN_WIDTH_40; |
| 524 | case NL80211_CHAN_WIDTH_80: |
| 525 | return CHAN_WIDTH_80; |
| 526 | case NL80211_CHAN_WIDTH_80P80: |
| 527 | return CHAN_WIDTH_80P80; |
| 528 | case NL80211_CHAN_WIDTH_160: |
| 529 | return CHAN_WIDTH_160; |
| 530 | } |
| 531 | return CHAN_WIDTH_UNKNOWN; |
| 532 | } |
| 533 | |
| 534 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 535 | static int is_ap_interface(enum nl80211_iftype nlmode) |
| 536 | { |
| 537 | return (nlmode == NL80211_IFTYPE_AP || |
| 538 | nlmode == NL80211_IFTYPE_P2P_GO); |
| 539 | } |
| 540 | |
| 541 | |
| 542 | static int is_sta_interface(enum nl80211_iftype nlmode) |
| 543 | { |
| 544 | return (nlmode == NL80211_IFTYPE_STATION || |
| 545 | nlmode == NL80211_IFTYPE_P2P_CLIENT); |
| 546 | } |
| 547 | |
| 548 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 549 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 550 | { |
| 551 | return (nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 552 | nlmode == NL80211_IFTYPE_P2P_GO); |
| 553 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 554 | |
| 555 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 556 | static void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
| 557 | { |
| 558 | if (drv->associated) |
| 559 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 560 | drv->associated = 0; |
| 561 | os_memset(drv->bssid, 0, ETH_ALEN); |
| 562 | } |
| 563 | |
| 564 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 565 | struct nl80211_bss_info_arg { |
| 566 | struct wpa_driver_nl80211_data *drv; |
| 567 | struct wpa_scan_results *res; |
| 568 | unsigned int assoc_freq; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 569 | u8 assoc_bssid[ETH_ALEN]; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | static int bss_info_handler(struct nl_msg *msg, void *arg); |
| 573 | |
| 574 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 575 | /* nl80211 code */ |
| 576 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 577 | { |
| 578 | int *err = arg; |
| 579 | *err = 0; |
| 580 | return NL_STOP; |
| 581 | } |
| 582 | |
| 583 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 584 | { |
| 585 | int *ret = arg; |
| 586 | *ret = 0; |
| 587 | return NL_SKIP; |
| 588 | } |
| 589 | |
| 590 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 591 | void *arg) |
| 592 | { |
| 593 | int *ret = arg; |
| 594 | *ret = err->error; |
| 595 | return NL_SKIP; |
| 596 | } |
| 597 | |
| 598 | |
| 599 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 600 | { |
| 601 | return NL_OK; |
| 602 | } |
| 603 | |
| 604 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 605 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 606 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 607 | int (*valid_handler)(struct nl_msg *, void *), |
| 608 | void *valid_data) |
| 609 | { |
| 610 | struct nl_cb *cb; |
| 611 | int err = -ENOMEM; |
| 612 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 613 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 614 | if (!cb) |
| 615 | goto out; |
| 616 | |
| 617 | err = nl_send_auto_complete(nl_handle, msg); |
| 618 | if (err < 0) |
| 619 | goto out; |
| 620 | |
| 621 | err = 1; |
| 622 | |
| 623 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 624 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 625 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 626 | |
| 627 | if (valid_handler) |
| 628 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 629 | valid_handler, valid_data); |
| 630 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 631 | while (err > 0) { |
| 632 | int res = nl_recvmsgs(nl_handle, cb); |
| 633 | if (res) { |
| 634 | wpa_printf(MSG_INFO, |
| 635 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 636 | __func__, res); |
| 637 | } |
| 638 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 639 | out: |
| 640 | nl_cb_put(cb); |
| 641 | nlmsg_free(msg); |
| 642 | return err; |
| 643 | } |
| 644 | |
| 645 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 646 | static int send_and_recv_msgs_global(struct nl80211_global *global, |
| 647 | struct nl_msg *msg, |
| 648 | int (*valid_handler)(struct nl_msg *, void *), |
| 649 | void *valid_data) |
| 650 | { |
| 651 | return send_and_recv(global, global->nl, msg, valid_handler, |
| 652 | valid_data); |
| 653 | } |
| 654 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 655 | |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 656 | static int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 657 | struct nl_msg *msg, |
| 658 | int (*valid_handler)(struct nl_msg *, void *), |
| 659 | void *valid_data) |
| 660 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 661 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 662 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | |
| 666 | struct family_data { |
| 667 | const char *group; |
| 668 | int id; |
| 669 | }; |
| 670 | |
| 671 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 672 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 673 | { |
| 674 | if (bss->wdev_id_set) |
| 675 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 676 | else |
| 677 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 678 | return 0; |
| 679 | |
| 680 | nla_put_failure: |
| 681 | return -1; |
| 682 | } |
| 683 | |
| 684 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 685 | static int family_handler(struct nl_msg *msg, void *arg) |
| 686 | { |
| 687 | struct family_data *res = arg; |
| 688 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 689 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 690 | struct nlattr *mcgrp; |
| 691 | int i; |
| 692 | |
| 693 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 694 | genlmsg_attrlen(gnlh, 0), NULL); |
| 695 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 696 | return NL_SKIP; |
| 697 | |
| 698 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 699 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 700 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 701 | nla_len(mcgrp), NULL); |
| 702 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 703 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 704 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 705 | res->group, |
| 706 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 707 | continue; |
| 708 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 709 | break; |
| 710 | }; |
| 711 | |
| 712 | return NL_SKIP; |
| 713 | } |
| 714 | |
| 715 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 716 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 717 | const char *family, const char *group) |
| 718 | { |
| 719 | struct nl_msg *msg; |
| 720 | int ret = -1; |
| 721 | struct family_data res = { group, -ENOENT }; |
| 722 | |
| 723 | msg = nlmsg_alloc(); |
| 724 | if (!msg) |
| 725 | return -ENOMEM; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 726 | genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 727 | 0, 0, CTRL_CMD_GETFAMILY, 0); |
| 728 | NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, family); |
| 729 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 730 | ret = send_and_recv_msgs_global(global, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 731 | msg = NULL; |
| 732 | if (ret == 0) |
| 733 | ret = res.id; |
| 734 | |
| 735 | nla_put_failure: |
| 736 | nlmsg_free(msg); |
| 737 | return ret; |
| 738 | } |
| 739 | |
| 740 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 741 | static void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 742 | struct nl_msg *msg, int flags, uint8_t cmd) |
| 743 | { |
| 744 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 745 | 0, flags, cmd, 0); |
| 746 | } |
| 747 | |
| 748 | |
| 749 | struct wiphy_idx_data { |
| 750 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 751 | enum nl80211_iftype nlmode; |
| 752 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 753 | }; |
| 754 | |
| 755 | |
| 756 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 757 | { |
| 758 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 759 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 760 | struct wiphy_idx_data *info = arg; |
| 761 | |
| 762 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 763 | genlmsg_attrlen(gnlh, 0), NULL); |
| 764 | |
| 765 | if (tb[NL80211_ATTR_WIPHY]) |
| 766 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 767 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 768 | if (tb[NL80211_ATTR_IFTYPE]) |
| 769 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 770 | |
| 771 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 772 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 773 | ETH_ALEN); |
| 774 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 775 | return NL_SKIP; |
| 776 | } |
| 777 | |
| 778 | |
| 779 | static int nl80211_get_wiphy_index(struct i802_bss *bss) |
| 780 | { |
| 781 | struct nl_msg *msg; |
| 782 | struct wiphy_idx_data data = { |
| 783 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 784 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 785 | }; |
| 786 | |
| 787 | msg = nlmsg_alloc(); |
| 788 | if (!msg) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 789 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 790 | |
| 791 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_GET_INTERFACE); |
| 792 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 793 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 794 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 795 | |
| 796 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 797 | return data.wiphy_idx; |
| 798 | msg = NULL; |
| 799 | nla_put_failure: |
| 800 | nlmsg_free(msg); |
| 801 | return -1; |
| 802 | } |
| 803 | |
| 804 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 805 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 806 | { |
| 807 | struct nl_msg *msg; |
| 808 | struct wiphy_idx_data data = { |
| 809 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 810 | .macaddr = NULL, |
| 811 | }; |
| 812 | |
| 813 | msg = nlmsg_alloc(); |
| 814 | if (!msg) |
| 815 | return -1; |
| 816 | |
| 817 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_GET_INTERFACE); |
| 818 | |
| 819 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 820 | goto nla_put_failure; |
| 821 | |
| 822 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 823 | return data.nlmode; |
| 824 | msg = NULL; |
| 825 | nla_put_failure: |
| 826 | nlmsg_free(msg); |
| 827 | return NL80211_IFTYPE_UNSPECIFIED; |
| 828 | } |
| 829 | |
| 830 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 831 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 832 | { |
| 833 | struct nl_msg *msg; |
| 834 | struct wiphy_idx_data data = { |
| 835 | .macaddr = bss->addr, |
| 836 | }; |
| 837 | |
| 838 | msg = nlmsg_alloc(); |
| 839 | if (!msg) |
| 840 | return NL80211_IFTYPE_UNSPECIFIED; |
| 841 | |
| 842 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_GET_INTERFACE); |
| 843 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 844 | goto nla_put_failure; |
| 845 | |
| 846 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
| 847 | |
| 848 | nla_put_failure: |
| 849 | nlmsg_free(msg); |
| 850 | return NL80211_IFTYPE_UNSPECIFIED; |
| 851 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 852 | |
| 853 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 854 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 855 | struct nl80211_wiphy_data *w) |
| 856 | { |
| 857 | struct nl_msg *msg; |
| 858 | int ret = -1; |
| 859 | |
| 860 | msg = nlmsg_alloc(); |
| 861 | if (!msg) |
| 862 | return -1; |
| 863 | |
| 864 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS); |
| 865 | |
| 866 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx); |
| 867 | |
| 868 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
| 869 | msg = NULL; |
| 870 | if (ret) { |
| 871 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 872 | "failed: ret=%d (%s)", |
| 873 | ret, strerror(-ret)); |
| 874 | goto nla_put_failure; |
| 875 | } |
| 876 | ret = 0; |
| 877 | nla_put_failure: |
| 878 | nlmsg_free(msg); |
| 879 | return ret; |
| 880 | } |
| 881 | |
| 882 | |
| 883 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 884 | { |
| 885 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 886 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 887 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 888 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 889 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 890 | res = nl_recvmsgs(handle, w->nl_cb); |
| 891 | if (res) { |
| 892 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 893 | __func__, res); |
| 894 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | |
| 898 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 899 | { |
| 900 | struct nl80211_wiphy_data *w = arg; |
| 901 | struct wpa_driver_nl80211_data *drv; |
| 902 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 903 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 904 | union wpa_event_data event; |
| 905 | |
| 906 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 907 | genlmsg_attrlen(gnlh, 0), NULL); |
| 908 | |
| 909 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 910 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 911 | gnlh->cmd); |
| 912 | return NL_SKIP; |
| 913 | } |
| 914 | |
| 915 | if (!tb[NL80211_ATTR_FRAME]) |
| 916 | return NL_SKIP; |
| 917 | |
| 918 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 919 | wiphy_list) { |
| 920 | os_memset(&event, 0, sizeof(event)); |
| 921 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 922 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 923 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 924 | } |
| 925 | |
| 926 | return NL_SKIP; |
| 927 | } |
| 928 | |
| 929 | |
| 930 | static struct nl80211_wiphy_data * |
| 931 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 932 | { |
| 933 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 934 | struct nl80211_wiphy_data *w; |
| 935 | int wiphy_idx, found = 0; |
| 936 | struct i802_bss *tmp_bss; |
| 937 | |
| 938 | if (bss->wiphy_data != NULL) |
| 939 | return bss->wiphy_data; |
| 940 | |
| 941 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 942 | |
| 943 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 944 | if (w->wiphy_idx == wiphy_idx) |
| 945 | goto add; |
| 946 | } |
| 947 | |
| 948 | /* alloc new one */ |
| 949 | w = os_zalloc(sizeof(*w)); |
| 950 | if (w == NULL) |
| 951 | return NULL; |
| 952 | w->wiphy_idx = wiphy_idx; |
| 953 | dl_list_init(&w->bsss); |
| 954 | dl_list_init(&w->drvs); |
| 955 | |
| 956 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 957 | if (!w->nl_cb) { |
| 958 | os_free(w); |
| 959 | return NULL; |
| 960 | } |
| 961 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); |
| 962 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, |
| 963 | w); |
| 964 | |
| 965 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 966 | "wiphy beacons"); |
| 967 | if (w->nl_beacons == NULL) { |
| 968 | os_free(w); |
| 969 | return NULL; |
| 970 | } |
| 971 | |
| 972 | if (nl80211_register_beacons(bss->drv, w)) { |
| 973 | nl_destroy_handles(&w->nl_beacons); |
| 974 | os_free(w); |
| 975 | return NULL; |
| 976 | } |
| 977 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 978 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 979 | |
| 980 | dl_list_add(&nl80211_wiphys, &w->list); |
| 981 | |
| 982 | add: |
| 983 | /* drv entry for this bss already there? */ |
| 984 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 985 | if (tmp_bss->drv == bss->drv) { |
| 986 | found = 1; |
| 987 | break; |
| 988 | } |
| 989 | } |
| 990 | /* if not add it */ |
| 991 | if (!found) |
| 992 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 993 | |
| 994 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 995 | bss->wiphy_data = w; |
| 996 | return w; |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 1001 | { |
| 1002 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 1003 | struct i802_bss *tmp_bss; |
| 1004 | int found = 0; |
| 1005 | |
| 1006 | if (w == NULL) |
| 1007 | return; |
| 1008 | bss->wiphy_data = NULL; |
| 1009 | dl_list_del(&bss->wiphy_list); |
| 1010 | |
| 1011 | /* still any for this drv present? */ |
| 1012 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 1013 | if (tmp_bss->drv == bss->drv) { |
| 1014 | found = 1; |
| 1015 | break; |
| 1016 | } |
| 1017 | } |
| 1018 | /* if not remove it */ |
| 1019 | if (!found) |
| 1020 | dl_list_del(&bss->drv->wiphy_list); |
| 1021 | |
| 1022 | if (!dl_list_empty(&w->bsss)) |
| 1023 | return; |
| 1024 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1025 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1026 | |
| 1027 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1028 | dl_list_del(&w->list); |
| 1029 | os_free(w); |
| 1030 | } |
| 1031 | |
| 1032 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1033 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 1034 | { |
| 1035 | struct i802_bss *bss = priv; |
| 1036 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1037 | if (!drv->associated) |
| 1038 | return -1; |
| 1039 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 1045 | { |
| 1046 | struct i802_bss *bss = priv; |
| 1047 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1048 | if (!drv->associated) |
| 1049 | return -1; |
| 1050 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 1051 | return drv->ssid_len; |
| 1052 | } |
| 1053 | |
| 1054 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1055 | static void wpa_driver_nl80211_event_newlink( |
| 1056 | struct wpa_driver_nl80211_data *drv, char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1057 | { |
| 1058 | union wpa_event_data event; |
| 1059 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1060 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
| 1061 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 1062 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 1063 | drv->first_bss->ifname); |
| 1064 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1065 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1066 | if (!drv->if_removed) |
| 1067 | return; |
| 1068 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 1069 | drv->first_bss->ifname); |
| 1070 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1073 | os_memset(&event, 0, sizeof(event)); |
| 1074 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1075 | sizeof(event.interface_status.ifname)); |
| 1076 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
| 1077 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1078 | } |
| 1079 | |
| 1080 | |
| 1081 | static void wpa_driver_nl80211_event_dellink( |
| 1082 | struct wpa_driver_nl80211_data *drv, char *ifname) |
| 1083 | { |
| 1084 | union wpa_event_data event; |
| 1085 | |
| 1086 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
| 1087 | if (drv->if_removed) { |
| 1088 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 1089 | ifname); |
| 1090 | return; |
| 1091 | } |
| 1092 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 1093 | ifname); |
| 1094 | drv->if_removed = 1; |
| 1095 | } else { |
| 1096 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 1097 | ifname); |
| 1098 | } |
| 1099 | |
| 1100 | os_memset(&event, 0, sizeof(event)); |
| 1101 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1102 | sizeof(event.interface_status.ifname)); |
| 1103 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1104 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1105 | } |
| 1106 | |
| 1107 | |
| 1108 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 1109 | u8 *buf, size_t len) |
| 1110 | { |
| 1111 | int attrlen, rta_len; |
| 1112 | struct rtattr *attr; |
| 1113 | |
| 1114 | attrlen = len; |
| 1115 | attr = (struct rtattr *) buf; |
| 1116 | |
| 1117 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 1118 | while (RTA_OK(attr, attrlen)) { |
| 1119 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1120 | if (os_strcmp(((char *) attr) + rta_len, |
| 1121 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1122 | return 1; |
| 1123 | else |
| 1124 | break; |
| 1125 | } |
| 1126 | attr = RTA_NEXT(attr, attrlen); |
| 1127 | } |
| 1128 | |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 1134 | int ifindex, u8 *buf, size_t len) |
| 1135 | { |
| 1136 | if (drv->ifindex == ifindex) |
| 1137 | return 1; |
| 1138 | |
| 1139 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1140 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 1141 | "interface"); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1142 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1143 | return 1; |
| 1144 | } |
| 1145 | |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1150 | static struct wpa_driver_nl80211_data * |
| 1151 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) |
| 1152 | { |
| 1153 | struct wpa_driver_nl80211_data *drv; |
| 1154 | dl_list_for_each(drv, &global->interfaces, |
| 1155 | struct wpa_driver_nl80211_data, list) { |
| 1156 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || |
| 1157 | have_ifidx(drv, idx)) |
| 1158 | return drv; |
| 1159 | } |
| 1160 | return NULL; |
| 1161 | } |
| 1162 | |
| 1163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1164 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1165 | struct ifinfomsg *ifi, |
| 1166 | u8 *buf, size_t len) |
| 1167 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1168 | struct nl80211_global *global = ctx; |
| 1169 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1170 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1171 | struct rtattr *attr; |
| 1172 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1173 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1174 | char ifname[IFNAMSIZ + 1]; |
| 1175 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1176 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1177 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 1178 | if (!drv) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1179 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d", |
| 1180 | ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1181 | return; |
| 1182 | } |
| 1183 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1184 | extra[0] = '\0'; |
| 1185 | pos = extra; |
| 1186 | end = pos + sizeof(extra); |
| 1187 | ifname[0] = '\0'; |
| 1188 | |
| 1189 | attrlen = len; |
| 1190 | attr = (struct rtattr *) buf; |
| 1191 | while (RTA_OK(attr, attrlen)) { |
| 1192 | switch (attr->rta_type) { |
| 1193 | case IFLA_IFNAME: |
| 1194 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1195 | break; |
| 1196 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1197 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1198 | break; |
| 1199 | case IFLA_MASTER: |
| 1200 | brid = nla_get_u32((struct nlattr *) attr); |
| 1201 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1202 | break; |
| 1203 | case IFLA_WIRELESS: |
| 1204 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1205 | break; |
| 1206 | case IFLA_OPERSTATE: |
| 1207 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1208 | nla_get_u32((struct nlattr *) attr)); |
| 1209 | break; |
| 1210 | case IFLA_LINKMODE: |
| 1211 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1212 | nla_get_u32((struct nlattr *) attr)); |
| 1213 | break; |
| 1214 | } |
| 1215 | attr = RTA_NEXT(attr, attrlen); |
| 1216 | } |
| 1217 | extra[sizeof(extra) - 1] = '\0'; |
| 1218 | |
| 1219 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_flags=0x%x (%s%s%s%s)", |
| 1220 | ifi->ifi_index, ifname, extra, ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1221 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1222 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1223 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1224 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1225 | |
| 1226 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1227 | if (if_indextoname(ifi->ifi_index, namebuf) && |
| 1228 | linux_iface_up(drv->global->ioctl_sock, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1229 | drv->first_bss->ifname) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1230 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1231 | "event since interface %s is up", namebuf); |
| 1232 | return; |
| 1233 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1234 | wpa_printf(MSG_DEBUG, "nl80211: Interface down"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1235 | if (drv->ignore_if_down_event) { |
| 1236 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1237 | "event generated by mode change"); |
| 1238 | drv->ignore_if_down_event = 0; |
| 1239 | } else { |
| 1240 | drv->if_disabled = 1; |
| 1241 | wpa_supplicant_event(drv->ctx, |
| 1242 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1243 | |
| 1244 | /* |
| 1245 | * Try to get drv again, since it may be removed as |
| 1246 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1247 | * dynamic interfaces |
| 1248 | */ |
| 1249 | drv = nl80211_find_drv(global, ifi->ifi_index, |
| 1250 | buf, len); |
| 1251 | if (!drv) |
| 1252 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1253 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1257 | if (if_indextoname(ifi->ifi_index, namebuf) && |
| 1258 | linux_iface_up(drv->global->ioctl_sock, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1259 | drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1260 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1261 | "event since interface %s is down", |
| 1262 | namebuf); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1263 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1264 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1265 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1266 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1267 | } else if (drv->if_removed) { |
| 1268 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1269 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1270 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1271 | } else { |
| 1272 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
| 1273 | drv->if_disabled = 0; |
| 1274 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1275 | NULL); |
| 1276 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | /* |
| 1280 | * Some drivers send the association event before the operup event--in |
| 1281 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1282 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1283 | * IEEE 802.1X authentication |
| 1284 | */ |
| 1285 | if (drv->operstate == 1 && |
| 1286 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1287 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1288 | 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] | 1289 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1290 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1293 | if (ifname[0]) |
| 1294 | wpa_driver_nl80211_event_newlink(drv, ifname); |
| 1295 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1296 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
| 1297 | /* device has been added to bridge */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1298 | if_indextoname(brid, namebuf); |
| 1299 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1300 | brid, namebuf); |
| 1301 | add_ifidx(drv, brid); |
| 1302 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1307 | struct ifinfomsg *ifi, |
| 1308 | u8 *buf, size_t len) |
| 1309 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1310 | struct nl80211_global *global = ctx; |
| 1311 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1312 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1313 | struct rtattr *attr; |
| 1314 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1315 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1316 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1317 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 1318 | if (!drv) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1319 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d", |
| 1320 | ifi->ifi_index); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1321 | return; |
| 1322 | } |
| 1323 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1324 | ifname[0] = '\0'; |
| 1325 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1326 | attrlen = len; |
| 1327 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1328 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1329 | switch (attr->rta_type) { |
| 1330 | case IFLA_IFNAME: |
| 1331 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1332 | break; |
| 1333 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1334 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1335 | break; |
| 1336 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1337 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1338 | break; |
| 1339 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1340 | attr = RTA_NEXT(attr, attrlen); |
| 1341 | } |
| 1342 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1343 | if (ifname[0]) |
| 1344 | wpa_driver_nl80211_event_dellink(drv, ifname); |
| 1345 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1346 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
| 1347 | /* device has been removed from bridge */ |
| 1348 | char namebuf[IFNAMSIZ]; |
| 1349 | if_indextoname(brid, namebuf); |
| 1350 | wpa_printf(MSG_DEBUG, "nl80211: Remove ifindex %u for bridge " |
| 1351 | "%s", brid, namebuf); |
| 1352 | del_ifidx(drv, brid); |
| 1353 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | static void mlme_event_auth(struct wpa_driver_nl80211_data *drv, |
| 1358 | const u8 *frame, size_t len) |
| 1359 | { |
| 1360 | const struct ieee80211_mgmt *mgmt; |
| 1361 | union wpa_event_data event; |
| 1362 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1363 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate event"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1364 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1365 | if (len < 24 + sizeof(mgmt->u.auth)) { |
| 1366 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " |
| 1367 | "frame"); |
| 1368 | return; |
| 1369 | } |
| 1370 | |
| 1371 | os_memcpy(drv->auth_bssid, mgmt->sa, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1372 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1373 | os_memset(&event, 0, sizeof(event)); |
| 1374 | os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN); |
| 1375 | event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1376 | event.auth.auth_transaction = |
| 1377 | le_to_host16(mgmt->u.auth.auth_transaction); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1378 | event.auth.status_code = le_to_host16(mgmt->u.auth.status_code); |
| 1379 | if (len > 24 + sizeof(mgmt->u.auth)) { |
| 1380 | event.auth.ies = mgmt->u.auth.variable; |
| 1381 | event.auth.ies_len = len - 24 - sizeof(mgmt->u.auth); |
| 1382 | } |
| 1383 | |
| 1384 | wpa_supplicant_event(drv->ctx, EVENT_AUTH, &event); |
| 1385 | } |
| 1386 | |
| 1387 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1388 | static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1389 | { |
| 1390 | struct nl_msg *msg; |
| 1391 | int ret; |
| 1392 | struct nl80211_bss_info_arg arg; |
| 1393 | |
| 1394 | os_memset(&arg, 0, sizeof(arg)); |
| 1395 | msg = nlmsg_alloc(); |
| 1396 | if (!msg) |
| 1397 | goto nla_put_failure; |
| 1398 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1399 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1400 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 1401 | |
| 1402 | arg.drv = drv; |
| 1403 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
| 1404 | msg = NULL; |
| 1405 | if (ret == 0) { |
| 1406 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
| 1407 | "associated BSS from scan results: %u MHz", |
| 1408 | arg.assoc_freq); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1409 | if (arg.assoc_freq) |
| 1410 | drv->assoc_freq = arg.assoc_freq; |
| 1411 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1412 | } |
| 1413 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1414 | "(%s)", ret, strerror(-ret)); |
| 1415 | nla_put_failure: |
| 1416 | nlmsg_free(msg); |
| 1417 | return drv->assoc_freq; |
| 1418 | } |
| 1419 | |
| 1420 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1421 | static void mlme_event_assoc(struct wpa_driver_nl80211_data *drv, |
| 1422 | const u8 *frame, size_t len) |
| 1423 | { |
| 1424 | const struct ieee80211_mgmt *mgmt; |
| 1425 | union wpa_event_data event; |
| 1426 | u16 status; |
| 1427 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1428 | wpa_printf(MSG_DEBUG, "nl80211: Associate event"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1429 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1430 | if (len < 24 + sizeof(mgmt->u.assoc_resp)) { |
| 1431 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " |
| 1432 | "frame"); |
| 1433 | return; |
| 1434 | } |
| 1435 | |
| 1436 | status = le_to_host16(mgmt->u.assoc_resp.status_code); |
| 1437 | if (status != WLAN_STATUS_SUCCESS) { |
| 1438 | os_memset(&event, 0, sizeof(event)); |
| 1439 | event.assoc_reject.bssid = mgmt->bssid; |
| 1440 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { |
| 1441 | event.assoc_reject.resp_ies = |
| 1442 | (u8 *) mgmt->u.assoc_resp.variable; |
| 1443 | event.assoc_reject.resp_ies_len = |
| 1444 | len - 24 - sizeof(mgmt->u.assoc_resp); |
| 1445 | } |
| 1446 | event.assoc_reject.status_code = status; |
| 1447 | |
| 1448 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); |
| 1449 | return; |
| 1450 | } |
| 1451 | |
| 1452 | drv->associated = 1; |
| 1453 | os_memcpy(drv->bssid, mgmt->sa, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1454 | os_memcpy(drv->prev_bssid, mgmt->sa, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1455 | |
| 1456 | os_memset(&event, 0, sizeof(event)); |
| 1457 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { |
| 1458 | event.assoc_info.resp_ies = (u8 *) mgmt->u.assoc_resp.variable; |
| 1459 | event.assoc_info.resp_ies_len = |
| 1460 | len - 24 - sizeof(mgmt->u.assoc_resp); |
| 1461 | } |
| 1462 | |
| 1463 | event.assoc_info.freq = drv->assoc_freq; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1464 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1465 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
| 1466 | } |
| 1467 | |
| 1468 | |
| 1469 | static void mlme_event_connect(struct wpa_driver_nl80211_data *drv, |
| 1470 | enum nl80211_commands cmd, struct nlattr *status, |
| 1471 | struct nlattr *addr, struct nlattr *req_ie, |
| 1472 | struct nlattr *resp_ie) |
| 1473 | { |
| 1474 | union wpa_event_data event; |
| 1475 | |
| 1476 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 1477 | /* |
| 1478 | * Avoid reporting two association events that would confuse |
| 1479 | * the core code. |
| 1480 | */ |
| 1481 | wpa_printf(MSG_DEBUG, "nl80211: Ignore connect event (cmd=%d) " |
| 1482 | "when using userspace SME", cmd); |
| 1483 | return; |
| 1484 | } |
| 1485 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1486 | if (cmd == NL80211_CMD_CONNECT) |
| 1487 | wpa_printf(MSG_DEBUG, "nl80211: Connect event"); |
| 1488 | else if (cmd == NL80211_CMD_ROAM) |
| 1489 | wpa_printf(MSG_DEBUG, "nl80211: Roam event"); |
| 1490 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1491 | os_memset(&event, 0, sizeof(event)); |
| 1492 | if (cmd == NL80211_CMD_CONNECT && |
| 1493 | nla_get_u16(status) != WLAN_STATUS_SUCCESS) { |
| 1494 | if (addr) |
| 1495 | event.assoc_reject.bssid = nla_data(addr); |
| 1496 | if (resp_ie) { |
| 1497 | event.assoc_reject.resp_ies = nla_data(resp_ie); |
| 1498 | event.assoc_reject.resp_ies_len = nla_len(resp_ie); |
| 1499 | } |
| 1500 | event.assoc_reject.status_code = nla_get_u16(status); |
| 1501 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); |
| 1502 | return; |
| 1503 | } |
| 1504 | |
| 1505 | drv->associated = 1; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1506 | if (addr) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1507 | os_memcpy(drv->bssid, nla_data(addr), ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1508 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 1509 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1510 | |
| 1511 | if (req_ie) { |
| 1512 | event.assoc_info.req_ies = nla_data(req_ie); |
| 1513 | event.assoc_info.req_ies_len = nla_len(req_ie); |
| 1514 | } |
| 1515 | if (resp_ie) { |
| 1516 | event.assoc_info.resp_ies = nla_data(resp_ie); |
| 1517 | event.assoc_info.resp_ies_len = nla_len(resp_ie); |
| 1518 | } |
| 1519 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1520 | event.assoc_info.freq = nl80211_get_assoc_freq(drv); |
| 1521 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1522 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
| 1523 | } |
| 1524 | |
| 1525 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1526 | static void mlme_event_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1527 | struct nlattr *reason, struct nlattr *addr, |
| 1528 | struct nlattr *by_ap) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1529 | { |
| 1530 | union wpa_event_data data; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1531 | unsigned int locally_generated = by_ap == NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1532 | |
| 1533 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 1534 | /* |
| 1535 | * Avoid reporting two disassociation events that could |
| 1536 | * confuse the core code. |
| 1537 | */ |
| 1538 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " |
| 1539 | "event when using userspace SME"); |
| 1540 | return; |
| 1541 | } |
| 1542 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1543 | if (drv->ignore_next_local_disconnect) { |
| 1544 | drv->ignore_next_local_disconnect = 0; |
| 1545 | if (locally_generated) { |
| 1546 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " |
| 1547 | "event triggered during reassociation"); |
| 1548 | return; |
| 1549 | } |
| 1550 | wpa_printf(MSG_WARNING, "nl80211: Was expecting local " |
| 1551 | "disconnect but got another disconnect " |
| 1552 | "event first"); |
| 1553 | } |
| 1554 | |
| 1555 | wpa_printf(MSG_DEBUG, "nl80211: Disconnect event"); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1556 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1557 | os_memset(&data, 0, sizeof(data)); |
| 1558 | if (reason) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1559 | data.deauth_info.reason_code = nla_get_u16(reason); |
| 1560 | data.deauth_info.locally_generated = by_ap == NULL; |
| 1561 | wpa_supplicant_event(drv->ctx, EVENT_DEAUTH, &data); |
| 1562 | } |
| 1563 | |
| 1564 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 1565 | static int calculate_chan_offset(int width, int freq, int cf1, int cf2) |
| 1566 | { |
| 1567 | int freq1 = 0; |
| 1568 | |
| 1569 | switch (convert2width(width)) { |
| 1570 | case CHAN_WIDTH_20_NOHT: |
| 1571 | case CHAN_WIDTH_20: |
| 1572 | return 0; |
| 1573 | case CHAN_WIDTH_40: |
| 1574 | freq1 = cf1 - 10; |
| 1575 | break; |
| 1576 | case CHAN_WIDTH_80: |
| 1577 | freq1 = cf1 - 30; |
| 1578 | break; |
| 1579 | case CHAN_WIDTH_160: |
| 1580 | freq1 = cf1 - 70; |
| 1581 | break; |
| 1582 | case CHAN_WIDTH_UNKNOWN: |
| 1583 | case CHAN_WIDTH_80P80: |
| 1584 | /* FIXME: implement this */ |
| 1585 | return 0; |
| 1586 | } |
| 1587 | |
| 1588 | return (abs(freq - freq1) / 20) % 2 == 0 ? 1 : -1; |
| 1589 | } |
| 1590 | |
| 1591 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1592 | static void mlme_event_ch_switch(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1593 | struct nlattr *ifindex, struct nlattr *freq, |
| 1594 | struct nlattr *type, struct nlattr *bw, |
| 1595 | struct nlattr *cf1, struct nlattr *cf2) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1596 | { |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1597 | struct i802_bss *bss; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1598 | union wpa_event_data data; |
| 1599 | int ht_enabled = 1; |
| 1600 | int chan_offset = 0; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1601 | int ifidx; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1602 | |
| 1603 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch event"); |
| 1604 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1605 | if (!freq) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1606 | return; |
| 1607 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1608 | ifidx = nla_get_u32(ifindex); |
| 1609 | for (bss = drv->first_bss; bss; bss = bss->next) |
| 1610 | if (bss->ifindex == ifidx) |
| 1611 | break; |
| 1612 | |
| 1613 | if (bss == NULL) { |
| 1614 | wpa_printf(MSG_WARNING, "nl80211: Unknown ifindex (%d) for channel switch, ignoring", |
| 1615 | ifidx); |
| 1616 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1619 | if (type) { |
| 1620 | switch (nla_get_u32(type)) { |
| 1621 | case NL80211_CHAN_NO_HT: |
| 1622 | ht_enabled = 0; |
| 1623 | break; |
| 1624 | case NL80211_CHAN_HT20: |
| 1625 | break; |
| 1626 | case NL80211_CHAN_HT40PLUS: |
| 1627 | chan_offset = 1; |
| 1628 | break; |
| 1629 | case NL80211_CHAN_HT40MINUS: |
| 1630 | chan_offset = -1; |
| 1631 | break; |
| 1632 | } |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 1633 | } else if (bw && cf1) { |
| 1634 | /* This can happen for example with VHT80 ch switch */ |
| 1635 | chan_offset = calculate_chan_offset(nla_get_u32(bw), |
| 1636 | nla_get_u32(freq), |
| 1637 | nla_get_u32(cf1), |
| 1638 | cf2 ? nla_get_u32(cf2) : 0); |
| 1639 | } else { |
| 1640 | wpa_printf(MSG_WARNING, "nl80211: Unknown secondary channel information - following channel definition calculations may fail"); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1644 | data.ch_switch.freq = nla_get_u32(freq); |
| 1645 | data.ch_switch.ht_enabled = ht_enabled; |
| 1646 | data.ch_switch.ch_offset = chan_offset; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1647 | if (bw) |
| 1648 | data.ch_switch.ch_width = convert2width(nla_get_u32(bw)); |
| 1649 | if (cf1) |
| 1650 | data.ch_switch.cf1 = nla_get_u32(cf1); |
| 1651 | if (cf2) |
| 1652 | data.ch_switch.cf2 = nla_get_u32(cf2); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1653 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1654 | bss->freq = data.ch_switch.freq; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1655 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1656 | wpa_supplicant_event(drv->ctx, EVENT_CH_SWITCH, &data); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1660 | static void mlme_timeout_event(struct wpa_driver_nl80211_data *drv, |
| 1661 | enum nl80211_commands cmd, struct nlattr *addr) |
| 1662 | { |
| 1663 | union wpa_event_data event; |
| 1664 | enum wpa_event_type ev; |
| 1665 | |
| 1666 | if (nla_len(addr) != ETH_ALEN) |
| 1667 | return; |
| 1668 | |
| 1669 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d; timeout with " MACSTR, |
| 1670 | cmd, MAC2STR((u8 *) nla_data(addr))); |
| 1671 | |
| 1672 | if (cmd == NL80211_CMD_AUTHENTICATE) |
| 1673 | ev = EVENT_AUTH_TIMED_OUT; |
| 1674 | else if (cmd == NL80211_CMD_ASSOCIATE) |
| 1675 | ev = EVENT_ASSOC_TIMED_OUT; |
| 1676 | else |
| 1677 | return; |
| 1678 | |
| 1679 | os_memset(&event, 0, sizeof(event)); |
| 1680 | os_memcpy(event.timeout_event.addr, nla_data(addr), ETH_ALEN); |
| 1681 | wpa_supplicant_event(drv->ctx, ev, &event); |
| 1682 | } |
| 1683 | |
| 1684 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1685 | static void mlme_event_mgmt(struct i802_bss *bss, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1686 | struct nlattr *freq, struct nlattr *sig, |
| 1687 | const u8 *frame, size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1688 | { |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1689 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1690 | const struct ieee80211_mgmt *mgmt; |
| 1691 | union wpa_event_data event; |
| 1692 | u16 fc, stype; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1693 | int ssi_signal = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1694 | int rx_freq = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1695 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1696 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame event"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1697 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1698 | if (len < 24) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1699 | wpa_printf(MSG_DEBUG, "nl80211: Too short management frame"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1700 | return; |
| 1701 | } |
| 1702 | |
| 1703 | fc = le_to_host16(mgmt->frame_control); |
| 1704 | stype = WLAN_FC_GET_STYPE(fc); |
| 1705 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1706 | if (sig) |
| 1707 | ssi_signal = (s32) nla_get_u32(sig); |
| 1708 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1709 | os_memset(&event, 0, sizeof(event)); |
| 1710 | if (freq) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1711 | event.rx_mgmt.freq = nla_get_u32(freq); |
| 1712 | rx_freq = drv->last_mgmt_freq = event.rx_mgmt.freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1713 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1714 | wpa_printf(MSG_DEBUG, |
| 1715 | "nl80211: RX frame freq=%d ssi_signal=%d stype=%u len=%u", |
| 1716 | rx_freq, ssi_signal, stype, (unsigned int) len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1717 | event.rx_mgmt.frame = frame; |
| 1718 | event.rx_mgmt.frame_len = len; |
| 1719 | event.rx_mgmt.ssi_signal = ssi_signal; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1720 | event.rx_mgmt.drv_priv = bss; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1721 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1725 | static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data *drv, |
| 1726 | struct nlattr *cookie, const u8 *frame, |
| 1727 | size_t len, struct nlattr *ack) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1728 | { |
| 1729 | union wpa_event_data event; |
| 1730 | const struct ieee80211_hdr *hdr; |
| 1731 | u16 fc; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1732 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1733 | wpa_printf(MSG_DEBUG, "nl80211: Frame TX status event"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1734 | if (!is_ap_interface(drv->nlmode)) { |
| 1735 | u64 cookie_val; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1736 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1737 | if (!cookie) |
| 1738 | return; |
| 1739 | |
| 1740 | cookie_val = nla_get_u64(cookie); |
| 1741 | wpa_printf(MSG_DEBUG, "nl80211: Action TX status:" |
| 1742 | " cookie=0%llx%s (ack=%d)", |
| 1743 | (long long unsigned int) cookie_val, |
| 1744 | cookie_val == drv->send_action_cookie ? |
| 1745 | " (match)" : " (unknown)", ack != NULL); |
| 1746 | if (cookie_val != drv->send_action_cookie) |
| 1747 | return; |
| 1748 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1749 | |
| 1750 | hdr = (const struct ieee80211_hdr *) frame; |
| 1751 | fc = le_to_host16(hdr->frame_control); |
| 1752 | |
| 1753 | os_memset(&event, 0, sizeof(event)); |
| 1754 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); |
| 1755 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); |
| 1756 | event.tx_status.dst = hdr->addr1; |
| 1757 | event.tx_status.data = frame; |
| 1758 | event.tx_status.data_len = len; |
| 1759 | event.tx_status.ack = ack != NULL; |
| 1760 | wpa_supplicant_event(drv->ctx, EVENT_TX_STATUS, &event); |
| 1761 | } |
| 1762 | |
| 1763 | |
| 1764 | static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data *drv, |
| 1765 | enum wpa_event_type type, |
| 1766 | const u8 *frame, size_t len) |
| 1767 | { |
| 1768 | const struct ieee80211_mgmt *mgmt; |
| 1769 | union wpa_event_data event; |
| 1770 | const u8 *bssid = NULL; |
| 1771 | u16 reason_code = 0; |
| 1772 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1773 | if (type == EVENT_DEAUTH) |
| 1774 | wpa_printf(MSG_DEBUG, "nl80211: Deauthenticate event"); |
| 1775 | else |
| 1776 | wpa_printf(MSG_DEBUG, "nl80211: Disassociate event"); |
| 1777 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1778 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1779 | if (len >= 24) { |
| 1780 | bssid = mgmt->bssid; |
| 1781 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1782 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_SME) && |
| 1783 | !drv->associated && |
| 1784 | os_memcmp(bssid, drv->auth_bssid, ETH_ALEN) != 0 && |
| 1785 | os_memcmp(bssid, drv->auth_attempt_bssid, ETH_ALEN) != 0 && |
| 1786 | os_memcmp(bssid, drv->prev_bssid, ETH_ALEN) == 0) { |
| 1787 | /* |
| 1788 | * Avoid issues with some roaming cases where |
| 1789 | * disconnection event for the old AP may show up after |
| 1790 | * we have started connection with the new AP. |
| 1791 | */ |
| 1792 | wpa_printf(MSG_DEBUG, "nl80211: Ignore deauth/disassoc event from old AP " MACSTR " when already authenticating with " MACSTR, |
| 1793 | MAC2STR(bssid), |
| 1794 | MAC2STR(drv->auth_attempt_bssid)); |
| 1795 | return; |
| 1796 | } |
| 1797 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1798 | if (drv->associated != 0 && |
| 1799 | os_memcmp(bssid, drv->bssid, ETH_ALEN) != 0 && |
| 1800 | os_memcmp(bssid, drv->auth_bssid, ETH_ALEN) != 0) { |
| 1801 | /* |
| 1802 | * We have presumably received this deauth as a |
| 1803 | * response to a clear_state_mismatch() outgoing |
| 1804 | * deauth. Don't let it take us offline! |
| 1805 | */ |
| 1806 | wpa_printf(MSG_DEBUG, "nl80211: Deauth received " |
| 1807 | "from Unknown BSSID " MACSTR " -- ignoring", |
| 1808 | MAC2STR(bssid)); |
| 1809 | return; |
| 1810 | } |
| 1811 | } |
| 1812 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1813 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1814 | os_memset(&event, 0, sizeof(event)); |
| 1815 | |
| 1816 | /* Note: Same offset for Reason Code in both frame subtypes */ |
| 1817 | if (len >= 24 + sizeof(mgmt->u.deauth)) |
| 1818 | reason_code = le_to_host16(mgmt->u.deauth.reason_code); |
| 1819 | |
| 1820 | if (type == EVENT_DISASSOC) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1821 | event.disassoc_info.locally_generated = |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1822 | !os_memcmp(mgmt->sa, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1823 | event.disassoc_info.addr = bssid; |
| 1824 | event.disassoc_info.reason_code = reason_code; |
| 1825 | if (frame + len > mgmt->u.disassoc.variable) { |
| 1826 | event.disassoc_info.ie = mgmt->u.disassoc.variable; |
| 1827 | event.disassoc_info.ie_len = frame + len - |
| 1828 | mgmt->u.disassoc.variable; |
| 1829 | } |
| 1830 | } else { |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1831 | if (drv->ignore_deauth_event) { |
| 1832 | wpa_printf(MSG_DEBUG, "nl80211: Ignore deauth event due to previous forced deauth-during-auth"); |
| 1833 | drv->ignore_deauth_event = 0; |
| 1834 | return; |
| 1835 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1836 | event.deauth_info.locally_generated = |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1837 | !os_memcmp(mgmt->sa, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1838 | event.deauth_info.addr = bssid; |
| 1839 | event.deauth_info.reason_code = reason_code; |
| 1840 | if (frame + len > mgmt->u.deauth.variable) { |
| 1841 | event.deauth_info.ie = mgmt->u.deauth.variable; |
| 1842 | event.deauth_info.ie_len = frame + len - |
| 1843 | mgmt->u.deauth.variable; |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | wpa_supplicant_event(drv->ctx, type, &event); |
| 1848 | } |
| 1849 | |
| 1850 | |
| 1851 | static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data *drv, |
| 1852 | enum wpa_event_type type, |
| 1853 | const u8 *frame, size_t len) |
| 1854 | { |
| 1855 | const struct ieee80211_mgmt *mgmt; |
| 1856 | union wpa_event_data event; |
| 1857 | u16 reason_code = 0; |
| 1858 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1859 | if (type == EVENT_UNPROT_DEAUTH) |
| 1860 | wpa_printf(MSG_DEBUG, "nl80211: Unprot Deauthenticate event"); |
| 1861 | else |
| 1862 | wpa_printf(MSG_DEBUG, "nl80211: Unprot Disassociate event"); |
| 1863 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1864 | if (len < 24) |
| 1865 | return; |
| 1866 | |
| 1867 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1868 | |
| 1869 | os_memset(&event, 0, sizeof(event)); |
| 1870 | /* Note: Same offset for Reason Code in both frame subtypes */ |
| 1871 | if (len >= 24 + sizeof(mgmt->u.deauth)) |
| 1872 | reason_code = le_to_host16(mgmt->u.deauth.reason_code); |
| 1873 | |
| 1874 | if (type == EVENT_UNPROT_DISASSOC) { |
| 1875 | event.unprot_disassoc.sa = mgmt->sa; |
| 1876 | event.unprot_disassoc.da = mgmt->da; |
| 1877 | event.unprot_disassoc.reason_code = reason_code; |
| 1878 | } else { |
| 1879 | event.unprot_deauth.sa = mgmt->sa; |
| 1880 | event.unprot_deauth.da = mgmt->da; |
| 1881 | event.unprot_deauth.reason_code = reason_code; |
| 1882 | } |
| 1883 | |
| 1884 | wpa_supplicant_event(drv->ctx, type, &event); |
| 1885 | } |
| 1886 | |
| 1887 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1888 | static void mlme_event(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1889 | enum nl80211_commands cmd, struct nlattr *frame, |
| 1890 | struct nlattr *addr, struct nlattr *timed_out, |
| 1891 | struct nlattr *freq, struct nlattr *ack, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1892 | struct nlattr *cookie, struct nlattr *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1893 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1894 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1895 | const u8 *data; |
| 1896 | size_t len; |
| 1897 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1898 | if (timed_out && addr) { |
| 1899 | mlme_timeout_event(drv, cmd, addr); |
| 1900 | return; |
| 1901 | } |
| 1902 | |
| 1903 | if (frame == NULL) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1904 | wpa_printf(MSG_DEBUG, |
| 1905 | "nl80211: MLME event %d (%s) without frame data", |
| 1906 | cmd, nl80211_command_to_string(cmd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1907 | return; |
| 1908 | } |
| 1909 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1910 | data = nla_data(frame); |
| 1911 | len = nla_len(frame); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 1912 | if (len < 4 + 2 * ETH_ALEN) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1913 | wpa_printf(MSG_MSGDUMP, "nl80211: MLME event %d (%s) on %s(" |
| 1914 | MACSTR ") - too short", |
| 1915 | cmd, nl80211_command_to_string(cmd), bss->ifname, |
| 1916 | MAC2STR(bss->addr)); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1917 | return; |
| 1918 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1919 | wpa_printf(MSG_MSGDUMP, "nl80211: MLME event %d (%s) on %s(" MACSTR |
| 1920 | ") A1=" MACSTR " A2=" MACSTR, cmd, |
| 1921 | nl80211_command_to_string(cmd), bss->ifname, |
| 1922 | MAC2STR(bss->addr), MAC2STR(data + 4), |
| 1923 | MAC2STR(data + 4 + ETH_ALEN)); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1924 | if (cmd != NL80211_CMD_FRAME_TX_STATUS && !(data[4] & 0x01) && |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 1925 | os_memcmp(bss->addr, data + 4, ETH_ALEN) != 0 && |
| 1926 | os_memcmp(bss->addr, data + 4 + ETH_ALEN, ETH_ALEN) != 0) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1927 | wpa_printf(MSG_MSGDUMP, "nl80211: %s: Ignore MLME frame event " |
| 1928 | "for foreign address", bss->ifname); |
| 1929 | return; |
| 1930 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1931 | wpa_hexdump(MSG_MSGDUMP, "nl80211: MLME event frame", |
| 1932 | nla_data(frame), nla_len(frame)); |
| 1933 | |
| 1934 | switch (cmd) { |
| 1935 | case NL80211_CMD_AUTHENTICATE: |
| 1936 | mlme_event_auth(drv, nla_data(frame), nla_len(frame)); |
| 1937 | break; |
| 1938 | case NL80211_CMD_ASSOCIATE: |
| 1939 | mlme_event_assoc(drv, nla_data(frame), nla_len(frame)); |
| 1940 | break; |
| 1941 | case NL80211_CMD_DEAUTHENTICATE: |
| 1942 | mlme_event_deauth_disassoc(drv, EVENT_DEAUTH, |
| 1943 | nla_data(frame), nla_len(frame)); |
| 1944 | break; |
| 1945 | case NL80211_CMD_DISASSOCIATE: |
| 1946 | mlme_event_deauth_disassoc(drv, EVENT_DISASSOC, |
| 1947 | nla_data(frame), nla_len(frame)); |
| 1948 | break; |
| 1949 | case NL80211_CMD_FRAME: |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1950 | mlme_event_mgmt(bss, freq, sig, nla_data(frame), |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1951 | nla_len(frame)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1952 | break; |
| 1953 | case NL80211_CMD_FRAME_TX_STATUS: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1954 | mlme_event_mgmt_tx_status(drv, cookie, nla_data(frame), |
| 1955 | nla_len(frame), ack); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1956 | break; |
| 1957 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
| 1958 | mlme_event_unprot_disconnect(drv, EVENT_UNPROT_DEAUTH, |
| 1959 | nla_data(frame), nla_len(frame)); |
| 1960 | break; |
| 1961 | case NL80211_CMD_UNPROT_DISASSOCIATE: |
| 1962 | mlme_event_unprot_disconnect(drv, EVENT_UNPROT_DISASSOC, |
| 1963 | nla_data(frame), nla_len(frame)); |
| 1964 | break; |
| 1965 | default: |
| 1966 | break; |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1971 | static void mlme_event_michael_mic_failure(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1972 | struct nlattr *tb[]) |
| 1973 | { |
| 1974 | union wpa_event_data data; |
| 1975 | |
| 1976 | wpa_printf(MSG_DEBUG, "nl80211: MLME event Michael MIC failure"); |
| 1977 | os_memset(&data, 0, sizeof(data)); |
| 1978 | if (tb[NL80211_ATTR_MAC]) { |
| 1979 | wpa_hexdump(MSG_DEBUG, "nl80211: Source MAC address", |
| 1980 | nla_data(tb[NL80211_ATTR_MAC]), |
| 1981 | nla_len(tb[NL80211_ATTR_MAC])); |
| 1982 | data.michael_mic_failure.src = nla_data(tb[NL80211_ATTR_MAC]); |
| 1983 | } |
| 1984 | if (tb[NL80211_ATTR_KEY_SEQ]) { |
| 1985 | wpa_hexdump(MSG_DEBUG, "nl80211: TSC", |
| 1986 | nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 1987 | nla_len(tb[NL80211_ATTR_KEY_SEQ])); |
| 1988 | } |
| 1989 | if (tb[NL80211_ATTR_KEY_TYPE]) { |
| 1990 | enum nl80211_key_type key_type = |
| 1991 | nla_get_u32(tb[NL80211_ATTR_KEY_TYPE]); |
| 1992 | wpa_printf(MSG_DEBUG, "nl80211: Key Type %d", key_type); |
| 1993 | if (key_type == NL80211_KEYTYPE_PAIRWISE) |
| 1994 | data.michael_mic_failure.unicast = 1; |
| 1995 | } else |
| 1996 | data.michael_mic_failure.unicast = 1; |
| 1997 | |
| 1998 | if (tb[NL80211_ATTR_KEY_IDX]) { |
| 1999 | u8 key_id = nla_get_u8(tb[NL80211_ATTR_KEY_IDX]); |
| 2000 | wpa_printf(MSG_DEBUG, "nl80211: Key Id %d", key_id); |
| 2001 | } |
| 2002 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2003 | wpa_supplicant_event(bss->ctx, EVENT_MICHAEL_MIC_FAILURE, &data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | |
| 2007 | static void mlme_event_join_ibss(struct wpa_driver_nl80211_data *drv, |
| 2008 | struct nlattr *tb[]) |
| 2009 | { |
| 2010 | if (tb[NL80211_ATTR_MAC] == NULL) { |
| 2011 | wpa_printf(MSG_DEBUG, "nl80211: No address in IBSS joined " |
| 2012 | "event"); |
| 2013 | return; |
| 2014 | } |
| 2015 | os_memcpy(drv->bssid, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2016 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2017 | drv->associated = 1; |
| 2018 | wpa_printf(MSG_DEBUG, "nl80211: IBSS " MACSTR " joined", |
| 2019 | MAC2STR(drv->bssid)); |
| 2020 | |
| 2021 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL); |
| 2022 | } |
| 2023 | |
| 2024 | |
| 2025 | static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data *drv, |
| 2026 | int cancel_event, struct nlattr *tb[]) |
| 2027 | { |
| 2028 | unsigned int freq, chan_type, duration; |
| 2029 | union wpa_event_data data; |
| 2030 | u64 cookie; |
| 2031 | |
| 2032 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 2033 | freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 2034 | else |
| 2035 | freq = 0; |
| 2036 | |
| 2037 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) |
| 2038 | chan_type = nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2039 | else |
| 2040 | chan_type = 0; |
| 2041 | |
| 2042 | if (tb[NL80211_ATTR_DURATION]) |
| 2043 | duration = nla_get_u32(tb[NL80211_ATTR_DURATION]); |
| 2044 | else |
| 2045 | duration = 0; |
| 2046 | |
| 2047 | if (tb[NL80211_ATTR_COOKIE]) |
| 2048 | cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 2049 | else |
| 2050 | cookie = 0; |
| 2051 | |
| 2052 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel event (cancel=%d " |
| 2053 | "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))", |
| 2054 | cancel_event, freq, chan_type, duration, |
| 2055 | (long long unsigned int) cookie, |
| 2056 | cookie == drv->remain_on_chan_cookie ? "match" : "unknown"); |
| 2057 | |
| 2058 | if (cookie != drv->remain_on_chan_cookie) |
| 2059 | return; /* not for us */ |
| 2060 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2061 | if (cancel_event) |
| 2062 | drv->pending_remain_on_chan = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2063 | |
| 2064 | os_memset(&data, 0, sizeof(data)); |
| 2065 | data.remain_on_channel.freq = freq; |
| 2066 | data.remain_on_channel.duration = duration; |
| 2067 | wpa_supplicant_event(drv->ctx, cancel_event ? |
| 2068 | EVENT_CANCEL_REMAIN_ON_CHANNEL : |
| 2069 | EVENT_REMAIN_ON_CHANNEL, &data); |
| 2070 | } |
| 2071 | |
| 2072 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2073 | static void mlme_event_ft_event(struct wpa_driver_nl80211_data *drv, |
| 2074 | struct nlattr *tb[]) |
| 2075 | { |
| 2076 | union wpa_event_data data; |
| 2077 | |
| 2078 | os_memset(&data, 0, sizeof(data)); |
| 2079 | |
| 2080 | if (tb[NL80211_ATTR_IE]) { |
| 2081 | data.ft_ies.ies = nla_data(tb[NL80211_ATTR_IE]); |
| 2082 | data.ft_ies.ies_len = nla_len(tb[NL80211_ATTR_IE]); |
| 2083 | } |
| 2084 | |
| 2085 | if (tb[NL80211_ATTR_IE_RIC]) { |
| 2086 | data.ft_ies.ric_ies = nla_data(tb[NL80211_ATTR_IE_RIC]); |
| 2087 | data.ft_ies.ric_ies_len = nla_len(tb[NL80211_ATTR_IE_RIC]); |
| 2088 | } |
| 2089 | |
| 2090 | if (tb[NL80211_ATTR_MAC]) |
| 2091 | os_memcpy(data.ft_ies.target_ap, |
| 2092 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 2093 | |
| 2094 | wpa_printf(MSG_DEBUG, "nl80211: FT event target_ap " MACSTR, |
| 2095 | MAC2STR(data.ft_ies.target_ap)); |
| 2096 | |
| 2097 | wpa_supplicant_event(drv->ctx, EVENT_FT_RESPONSE, &data); |
| 2098 | } |
| 2099 | |
| 2100 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2101 | static void send_scan_event(struct wpa_driver_nl80211_data *drv, int aborted, |
| 2102 | struct nlattr *tb[]) |
| 2103 | { |
| 2104 | union wpa_event_data event; |
| 2105 | struct nlattr *nl; |
| 2106 | int rem; |
| 2107 | struct scan_info *info; |
| 2108 | #define MAX_REPORT_FREQS 50 |
| 2109 | int freqs[MAX_REPORT_FREQS]; |
| 2110 | int num_freqs = 0; |
| 2111 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2112 | if (drv->scan_for_auth) { |
| 2113 | drv->scan_for_auth = 0; |
| 2114 | wpa_printf(MSG_DEBUG, "nl80211: Scan results for missing " |
| 2115 | "cfg80211 BSS entry"); |
| 2116 | wpa_driver_nl80211_authenticate_retry(drv); |
| 2117 | return; |
| 2118 | } |
| 2119 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2120 | os_memset(&event, 0, sizeof(event)); |
| 2121 | info = &event.scan_info; |
| 2122 | info->aborted = aborted; |
| 2123 | |
| 2124 | if (tb[NL80211_ATTR_SCAN_SSIDS]) { |
| 2125 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_SSIDS], rem) { |
| 2126 | struct wpa_driver_scan_ssid *s = |
| 2127 | &info->ssids[info->num_ssids]; |
| 2128 | s->ssid = nla_data(nl); |
| 2129 | s->ssid_len = nla_len(nl); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2130 | wpa_printf(MSG_DEBUG, "nl80211: Scan probed for SSID '%s'", |
| 2131 | wpa_ssid_txt(s->ssid, s->ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2132 | info->num_ssids++; |
| 2133 | if (info->num_ssids == WPAS_MAX_SCAN_SSIDS) |
| 2134 | break; |
| 2135 | } |
| 2136 | } |
| 2137 | if (tb[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2138 | char msg[200], *pos, *end; |
| 2139 | int res; |
| 2140 | |
| 2141 | pos = msg; |
| 2142 | end = pos + sizeof(msg); |
| 2143 | *pos = '\0'; |
| 2144 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2145 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_FREQUENCIES], rem) |
| 2146 | { |
| 2147 | freqs[num_freqs] = nla_get_u32(nl); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2148 | res = os_snprintf(pos, end - pos, " %d", |
| 2149 | freqs[num_freqs]); |
| 2150 | if (res > 0 && end - pos > res) |
| 2151 | pos += res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2152 | num_freqs++; |
| 2153 | if (num_freqs == MAX_REPORT_FREQS - 1) |
| 2154 | break; |
| 2155 | } |
| 2156 | info->freqs = freqs; |
| 2157 | info->num_freqs = num_freqs; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2158 | wpa_printf(MSG_DEBUG, "nl80211: Scan included frequencies:%s", |
| 2159 | msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2160 | } |
| 2161 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, &event); |
| 2162 | } |
| 2163 | |
| 2164 | |
| 2165 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 2166 | { |
| 2167 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2168 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2169 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 2170 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 2171 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2172 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2173 | }; |
| 2174 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 2175 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 2176 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 2177 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 2178 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 2179 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 2180 | }; |
| 2181 | struct wpa_signal_info *sig_change = arg; |
| 2182 | |
| 2183 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2184 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2185 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 2186 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 2187 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 2188 | return NL_SKIP; |
| 2189 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 2190 | return NL_SKIP; |
| 2191 | |
| 2192 | sig_change->current_signal = |
| 2193 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 2194 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2195 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 2196 | sig_change->avg_signal = |
| 2197 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 2198 | else |
| 2199 | sig_change->avg_signal = 0; |
| 2200 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2201 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 2202 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 2203 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 2204 | rate_policy)) { |
| 2205 | sig_change->current_txrate = 0; |
| 2206 | } else { |
| 2207 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 2208 | sig_change->current_txrate = |
| 2209 | nla_get_u16(rinfo[ |
| 2210 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | return NL_SKIP; |
| 2216 | } |
| 2217 | |
| 2218 | |
| 2219 | static int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 2220 | struct wpa_signal_info *sig) |
| 2221 | { |
| 2222 | struct nl_msg *msg; |
| 2223 | |
| 2224 | sig->current_signal = -9999; |
| 2225 | sig->current_txrate = 0; |
| 2226 | |
| 2227 | msg = nlmsg_alloc(); |
| 2228 | if (!msg) |
| 2229 | return -ENOMEM; |
| 2230 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2231 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2232 | |
| 2233 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 2234 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
| 2235 | |
| 2236 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
| 2237 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2238 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2239 | return -ENOBUFS; |
| 2240 | } |
| 2241 | |
| 2242 | |
| 2243 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 2244 | { |
| 2245 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2246 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2247 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 2248 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 2249 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 2250 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 2251 | }; |
| 2252 | struct wpa_signal_info *sig_change = arg; |
| 2253 | |
| 2254 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2255 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2256 | |
| 2257 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 2258 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 2259 | return NL_SKIP; |
| 2260 | } |
| 2261 | |
| 2262 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 2263 | tb[NL80211_ATTR_SURVEY_INFO], |
| 2264 | survey_policy)) { |
| 2265 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 2266 | "attributes!"); |
| 2267 | return NL_SKIP; |
| 2268 | } |
| 2269 | |
| 2270 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 2271 | return NL_SKIP; |
| 2272 | |
| 2273 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 2274 | sig_change->frequency) |
| 2275 | return NL_SKIP; |
| 2276 | |
| 2277 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 2278 | return NL_SKIP; |
| 2279 | |
| 2280 | sig_change->current_noise = |
| 2281 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 2282 | |
| 2283 | return NL_SKIP; |
| 2284 | } |
| 2285 | |
| 2286 | |
| 2287 | static int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 2288 | struct wpa_signal_info *sig_change) |
| 2289 | { |
| 2290 | struct nl_msg *msg; |
| 2291 | |
| 2292 | sig_change->current_noise = 9999; |
| 2293 | sig_change->frequency = drv->assoc_freq; |
| 2294 | |
| 2295 | msg = nlmsg_alloc(); |
| 2296 | if (!msg) |
| 2297 | return -ENOMEM; |
| 2298 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2299 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2300 | |
| 2301 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 2302 | |
| 2303 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
| 2304 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2305 | nlmsg_free(msg); |
| 2306 | return -ENOBUFS; |
| 2307 | } |
| 2308 | |
| 2309 | |
| 2310 | static int get_noise_for_scan_results(struct nl_msg *msg, void *arg) |
| 2311 | { |
| 2312 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2313 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2314 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 2315 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 2316 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 2317 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 2318 | }; |
| 2319 | struct wpa_scan_results *scan_results = arg; |
| 2320 | struct wpa_scan_res *scan_res; |
| 2321 | size_t i; |
| 2322 | |
| 2323 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2324 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2325 | |
| 2326 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 2327 | wpa_printf(MSG_DEBUG, "nl80211: Survey data missing"); |
| 2328 | return NL_SKIP; |
| 2329 | } |
| 2330 | |
| 2331 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 2332 | tb[NL80211_ATTR_SURVEY_INFO], |
| 2333 | survey_policy)) { |
| 2334 | wpa_printf(MSG_DEBUG, "nl80211: Failed to parse nested " |
| 2335 | "attributes"); |
| 2336 | return NL_SKIP; |
| 2337 | } |
| 2338 | |
| 2339 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 2340 | return NL_SKIP; |
| 2341 | |
| 2342 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 2343 | return NL_SKIP; |
| 2344 | |
| 2345 | for (i = 0; i < scan_results->num; ++i) { |
| 2346 | scan_res = scan_results->res[i]; |
| 2347 | if (!scan_res) |
| 2348 | continue; |
| 2349 | if ((int) nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 2350 | scan_res->freq) |
| 2351 | continue; |
| 2352 | if (!(scan_res->flags & WPA_SCAN_NOISE_INVALID)) |
| 2353 | continue; |
| 2354 | scan_res->noise = (s8) |
| 2355 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 2356 | scan_res->flags &= ~WPA_SCAN_NOISE_INVALID; |
| 2357 | } |
| 2358 | |
| 2359 | return NL_SKIP; |
| 2360 | } |
| 2361 | |
| 2362 | |
| 2363 | static int nl80211_get_noise_for_scan_results( |
| 2364 | struct wpa_driver_nl80211_data *drv, |
| 2365 | struct wpa_scan_results *scan_res) |
| 2366 | { |
| 2367 | struct nl_msg *msg; |
| 2368 | |
| 2369 | msg = nlmsg_alloc(); |
| 2370 | if (!msg) |
| 2371 | return -ENOMEM; |
| 2372 | |
| 2373 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
| 2374 | |
| 2375 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 2376 | |
| 2377 | return send_and_recv_msgs(drv, msg, get_noise_for_scan_results, |
| 2378 | scan_res); |
| 2379 | nla_put_failure: |
| 2380 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | return -ENOBUFS; |
| 2382 | } |
| 2383 | |
| 2384 | |
| 2385 | static void nl80211_cqm_event(struct wpa_driver_nl80211_data *drv, |
| 2386 | struct nlattr *tb[]) |
| 2387 | { |
| 2388 | static struct nla_policy cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
| 2389 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 2390 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U8 }, |
| 2391 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 2392 | [NL80211_ATTR_CQM_PKT_LOSS_EVENT] = { .type = NLA_U32 }, |
| 2393 | }; |
| 2394 | struct nlattr *cqm[NL80211_ATTR_CQM_MAX + 1]; |
| 2395 | enum nl80211_cqm_rssi_threshold_event event; |
| 2396 | union wpa_event_data ed; |
| 2397 | struct wpa_signal_info sig; |
| 2398 | int res; |
| 2399 | |
| 2400 | if (tb[NL80211_ATTR_CQM] == NULL || |
| 2401 | nla_parse_nested(cqm, NL80211_ATTR_CQM_MAX, tb[NL80211_ATTR_CQM], |
| 2402 | cqm_policy)) { |
| 2403 | wpa_printf(MSG_DEBUG, "nl80211: Ignore invalid CQM event"); |
| 2404 | return; |
| 2405 | } |
| 2406 | |
| 2407 | os_memset(&ed, 0, sizeof(ed)); |
| 2408 | |
| 2409 | if (cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT]) { |
| 2410 | if (!tb[NL80211_ATTR_MAC]) |
| 2411 | return; |
| 2412 | os_memcpy(ed.low_ack.addr, nla_data(tb[NL80211_ATTR_MAC]), |
| 2413 | ETH_ALEN); |
| 2414 | wpa_supplicant_event(drv->ctx, EVENT_STATION_LOW_ACK, &ed); |
| 2415 | return; |
| 2416 | } |
| 2417 | |
| 2418 | if (cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] == NULL) |
| 2419 | return; |
| 2420 | event = nla_get_u32(cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]); |
| 2421 | |
| 2422 | if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH) { |
| 2423 | wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor " |
| 2424 | "event: RSSI high"); |
| 2425 | ed.signal_change.above_threshold = 1; |
| 2426 | } else if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW) { |
| 2427 | wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor " |
| 2428 | "event: RSSI low"); |
| 2429 | ed.signal_change.above_threshold = 0; |
| 2430 | } else |
| 2431 | return; |
| 2432 | |
| 2433 | res = nl80211_get_link_signal(drv, &sig); |
| 2434 | if (res == 0) { |
| 2435 | ed.signal_change.current_signal = sig.current_signal; |
| 2436 | ed.signal_change.current_txrate = sig.current_txrate; |
| 2437 | wpa_printf(MSG_DEBUG, "nl80211: Signal: %d dBm txrate: %d", |
| 2438 | sig.current_signal, sig.current_txrate); |
| 2439 | } |
| 2440 | |
| 2441 | res = nl80211_get_link_noise(drv, &sig); |
| 2442 | if (res == 0) { |
| 2443 | ed.signal_change.current_noise = sig.current_noise; |
| 2444 | wpa_printf(MSG_DEBUG, "nl80211: Noise: %d dBm", |
| 2445 | sig.current_noise); |
| 2446 | } |
| 2447 | |
| 2448 | wpa_supplicant_event(drv->ctx, EVENT_SIGNAL_CHANGE, &ed); |
| 2449 | } |
| 2450 | |
| 2451 | |
| 2452 | static void nl80211_new_station_event(struct wpa_driver_nl80211_data *drv, |
| 2453 | struct nlattr **tb) |
| 2454 | { |
| 2455 | u8 *addr; |
| 2456 | union wpa_event_data data; |
| 2457 | |
| 2458 | if (tb[NL80211_ATTR_MAC] == NULL) |
| 2459 | return; |
| 2460 | addr = nla_data(tb[NL80211_ATTR_MAC]); |
| 2461 | wpa_printf(MSG_DEBUG, "nl80211: New station " MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2462 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2463 | if (is_ap_interface(drv->nlmode) && drv->device_ap_sme) { |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2464 | u8 *ies = NULL; |
| 2465 | size_t ies_len = 0; |
| 2466 | if (tb[NL80211_ATTR_IE]) { |
| 2467 | ies = nla_data(tb[NL80211_ATTR_IE]); |
| 2468 | ies_len = nla_len(tb[NL80211_ATTR_IE]); |
| 2469 | } |
| 2470 | wpa_hexdump(MSG_DEBUG, "nl80211: Assoc Req IEs", ies, ies_len); |
| 2471 | drv_event_assoc(drv->ctx, addr, ies, ies_len, 0); |
| 2472 | return; |
| 2473 | } |
| 2474 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2475 | if (drv->nlmode != NL80211_IFTYPE_ADHOC) |
| 2476 | return; |
| 2477 | |
| 2478 | os_memset(&data, 0, sizeof(data)); |
| 2479 | os_memcpy(data.ibss_rsn_start.peer, addr, ETH_ALEN); |
| 2480 | wpa_supplicant_event(drv->ctx, EVENT_IBSS_RSN_START, &data); |
| 2481 | } |
| 2482 | |
| 2483 | |
| 2484 | static void nl80211_del_station_event(struct wpa_driver_nl80211_data *drv, |
| 2485 | struct nlattr **tb) |
| 2486 | { |
| 2487 | u8 *addr; |
| 2488 | union wpa_event_data data; |
| 2489 | |
| 2490 | if (tb[NL80211_ATTR_MAC] == NULL) |
| 2491 | return; |
| 2492 | addr = nla_data(tb[NL80211_ATTR_MAC]); |
| 2493 | wpa_printf(MSG_DEBUG, "nl80211: Delete station " MACSTR, |
| 2494 | MAC2STR(addr)); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2495 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2496 | if (is_ap_interface(drv->nlmode) && drv->device_ap_sme) { |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2497 | drv_event_disassoc(drv->ctx, addr); |
| 2498 | return; |
| 2499 | } |
| 2500 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2501 | if (drv->nlmode != NL80211_IFTYPE_ADHOC) |
| 2502 | return; |
| 2503 | |
| 2504 | os_memset(&data, 0, sizeof(data)); |
| 2505 | os_memcpy(data.ibss_peer_lost.peer, addr, ETH_ALEN); |
| 2506 | wpa_supplicant_event(drv->ctx, EVENT_IBSS_PEER_LOST, &data); |
| 2507 | } |
| 2508 | |
| 2509 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2510 | static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data *drv, |
| 2511 | struct nlattr **tb) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2512 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2513 | struct nlattr *rekey_info[NUM_NL80211_REKEY_DATA]; |
| 2514 | static struct nla_policy rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 2515 | [NL80211_REKEY_DATA_KEK] = { |
| 2516 | .minlen = NL80211_KEK_LEN, |
| 2517 | .maxlen = NL80211_KEK_LEN, |
| 2518 | }, |
| 2519 | [NL80211_REKEY_DATA_KCK] = { |
| 2520 | .minlen = NL80211_KCK_LEN, |
| 2521 | .maxlen = NL80211_KCK_LEN, |
| 2522 | }, |
| 2523 | [NL80211_REKEY_DATA_REPLAY_CTR] = { |
| 2524 | .minlen = NL80211_REPLAY_CTR_LEN, |
| 2525 | .maxlen = NL80211_REPLAY_CTR_LEN, |
| 2526 | }, |
| 2527 | }; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2528 | union wpa_event_data data; |
| 2529 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2530 | if (!tb[NL80211_ATTR_MAC]) |
| 2531 | return; |
| 2532 | if (!tb[NL80211_ATTR_REKEY_DATA]) |
| 2533 | return; |
| 2534 | if (nla_parse_nested(rekey_info, MAX_NL80211_REKEY_DATA, |
| 2535 | tb[NL80211_ATTR_REKEY_DATA], rekey_policy)) |
| 2536 | return; |
| 2537 | if (!rekey_info[NL80211_REKEY_DATA_REPLAY_CTR]) |
| 2538 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2539 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2540 | os_memset(&data, 0, sizeof(data)); |
| 2541 | data.driver_gtk_rekey.bssid = nla_data(tb[NL80211_ATTR_MAC]); |
| 2542 | wpa_printf(MSG_DEBUG, "nl80211: Rekey offload event for BSSID " MACSTR, |
| 2543 | MAC2STR(data.driver_gtk_rekey.bssid)); |
| 2544 | data.driver_gtk_rekey.replay_ctr = |
| 2545 | nla_data(rekey_info[NL80211_REKEY_DATA_REPLAY_CTR]); |
| 2546 | wpa_hexdump(MSG_DEBUG, "nl80211: Rekey offload - Replay Counter", |
| 2547 | data.driver_gtk_rekey.replay_ctr, NL80211_REPLAY_CTR_LEN); |
| 2548 | wpa_supplicant_event(drv->ctx, EVENT_DRIVER_GTK_REKEY, &data); |
| 2549 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2550 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2551 | |
| 2552 | static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data *drv, |
| 2553 | struct nlattr **tb) |
| 2554 | { |
| 2555 | struct nlattr *cand[NUM_NL80211_PMKSA_CANDIDATE]; |
| 2556 | static struct nla_policy cand_policy[NUM_NL80211_PMKSA_CANDIDATE] = { |
| 2557 | [NL80211_PMKSA_CANDIDATE_INDEX] = { .type = NLA_U32 }, |
| 2558 | [NL80211_PMKSA_CANDIDATE_BSSID] = { |
| 2559 | .minlen = ETH_ALEN, |
| 2560 | .maxlen = ETH_ALEN, |
| 2561 | }, |
| 2562 | [NL80211_PMKSA_CANDIDATE_PREAUTH] = { .type = NLA_FLAG }, |
| 2563 | }; |
| 2564 | union wpa_event_data data; |
| 2565 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2566 | wpa_printf(MSG_DEBUG, "nl80211: PMKSA candidate event"); |
| 2567 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2568 | if (!tb[NL80211_ATTR_PMKSA_CANDIDATE]) |
| 2569 | return; |
| 2570 | if (nla_parse_nested(cand, MAX_NL80211_PMKSA_CANDIDATE, |
| 2571 | tb[NL80211_ATTR_PMKSA_CANDIDATE], cand_policy)) |
| 2572 | return; |
| 2573 | if (!cand[NL80211_PMKSA_CANDIDATE_INDEX] || |
| 2574 | !cand[NL80211_PMKSA_CANDIDATE_BSSID]) |
| 2575 | return; |
| 2576 | |
| 2577 | os_memset(&data, 0, sizeof(data)); |
| 2578 | os_memcpy(data.pmkid_candidate.bssid, |
| 2579 | nla_data(cand[NL80211_PMKSA_CANDIDATE_BSSID]), ETH_ALEN); |
| 2580 | data.pmkid_candidate.index = |
| 2581 | nla_get_u32(cand[NL80211_PMKSA_CANDIDATE_INDEX]); |
| 2582 | data.pmkid_candidate.preauth = |
| 2583 | cand[NL80211_PMKSA_CANDIDATE_PREAUTH] != NULL; |
| 2584 | wpa_supplicant_event(drv->ctx, EVENT_PMKID_CANDIDATE, &data); |
| 2585 | } |
| 2586 | |
| 2587 | |
| 2588 | static void nl80211_client_probe_event(struct wpa_driver_nl80211_data *drv, |
| 2589 | struct nlattr **tb) |
| 2590 | { |
| 2591 | union wpa_event_data data; |
| 2592 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2593 | wpa_printf(MSG_DEBUG, "nl80211: Probe client event"); |
| 2594 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2595 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_ACK]) |
| 2596 | return; |
| 2597 | |
| 2598 | os_memset(&data, 0, sizeof(data)); |
| 2599 | os_memcpy(data.client_poll.addr, |
| 2600 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 2601 | |
| 2602 | wpa_supplicant_event(drv->ctx, EVENT_DRIVER_CLIENT_POLL_OK, &data); |
| 2603 | } |
| 2604 | |
| 2605 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2606 | static void nl80211_tdls_oper_event(struct wpa_driver_nl80211_data *drv, |
| 2607 | struct nlattr **tb) |
| 2608 | { |
| 2609 | union wpa_event_data data; |
| 2610 | |
| 2611 | wpa_printf(MSG_DEBUG, "nl80211: TDLS operation event"); |
| 2612 | |
| 2613 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_TDLS_OPERATION]) |
| 2614 | return; |
| 2615 | |
| 2616 | os_memset(&data, 0, sizeof(data)); |
| 2617 | os_memcpy(data.tdls.peer, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 2618 | switch (nla_get_u8(tb[NL80211_ATTR_TDLS_OPERATION])) { |
| 2619 | case NL80211_TDLS_SETUP: |
| 2620 | wpa_printf(MSG_DEBUG, "nl80211: TDLS setup request for peer " |
| 2621 | MACSTR, MAC2STR(data.tdls.peer)); |
| 2622 | data.tdls.oper = TDLS_REQUEST_SETUP; |
| 2623 | break; |
| 2624 | case NL80211_TDLS_TEARDOWN: |
| 2625 | wpa_printf(MSG_DEBUG, "nl80211: TDLS teardown request for peer " |
| 2626 | MACSTR, MAC2STR(data.tdls.peer)); |
| 2627 | data.tdls.oper = TDLS_REQUEST_TEARDOWN; |
| 2628 | break; |
| 2629 | default: |
| 2630 | wpa_printf(MSG_DEBUG, "nl80211: Unsupported TDLS operatione " |
| 2631 | "event"); |
| 2632 | return; |
| 2633 | } |
| 2634 | if (tb[NL80211_ATTR_REASON_CODE]) { |
| 2635 | data.tdls.reason_code = |
| 2636 | nla_get_u16(tb[NL80211_ATTR_REASON_CODE]); |
| 2637 | } |
| 2638 | |
| 2639 | wpa_supplicant_event(drv->ctx, EVENT_TDLS, &data); |
| 2640 | } |
| 2641 | |
| 2642 | |
Dmitry Shmidt | 5393a0f | 2013-08-08 11:23:34 -0700 | [diff] [blame] | 2643 | static void nl80211_stop_ap(struct wpa_driver_nl80211_data *drv, |
| 2644 | struct nlattr **tb) |
| 2645 | { |
| 2646 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_UNAVAILABLE, NULL); |
| 2647 | } |
| 2648 | |
| 2649 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2650 | static void nl80211_connect_failed_event(struct wpa_driver_nl80211_data *drv, |
| 2651 | struct nlattr **tb) |
| 2652 | { |
| 2653 | union wpa_event_data data; |
| 2654 | u32 reason; |
| 2655 | |
| 2656 | wpa_printf(MSG_DEBUG, "nl80211: Connect failed event"); |
| 2657 | |
| 2658 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_CONN_FAILED_REASON]) |
| 2659 | return; |
| 2660 | |
| 2661 | os_memset(&data, 0, sizeof(data)); |
| 2662 | os_memcpy(data.connect_failed_reason.addr, |
| 2663 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 2664 | |
| 2665 | reason = nla_get_u32(tb[NL80211_ATTR_CONN_FAILED_REASON]); |
| 2666 | switch (reason) { |
| 2667 | case NL80211_CONN_FAIL_MAX_CLIENTS: |
| 2668 | wpa_printf(MSG_DEBUG, "nl80211: Max client reached"); |
| 2669 | data.connect_failed_reason.code = MAX_CLIENT_REACHED; |
| 2670 | break; |
| 2671 | case NL80211_CONN_FAIL_BLOCKED_CLIENT: |
| 2672 | wpa_printf(MSG_DEBUG, "nl80211: Blocked client " MACSTR |
| 2673 | " tried to connect", |
| 2674 | MAC2STR(data.connect_failed_reason.addr)); |
| 2675 | data.connect_failed_reason.code = BLOCKED_CLIENT; |
| 2676 | break; |
| 2677 | default: |
| 2678 | wpa_printf(MSG_DEBUG, "nl8021l: Unknown connect failed reason " |
| 2679 | "%u", reason); |
| 2680 | return; |
| 2681 | } |
| 2682 | |
| 2683 | wpa_supplicant_event(drv->ctx, EVENT_CONNECT_FAILED_REASON, &data); |
| 2684 | } |
| 2685 | |
| 2686 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 2687 | static void nl80211_radar_event(struct wpa_driver_nl80211_data *drv, |
| 2688 | struct nlattr **tb) |
| 2689 | { |
| 2690 | union wpa_event_data data; |
| 2691 | enum nl80211_radar_event event_type; |
| 2692 | |
| 2693 | if (!tb[NL80211_ATTR_WIPHY_FREQ] || !tb[NL80211_ATTR_RADAR_EVENT]) |
| 2694 | return; |
| 2695 | |
| 2696 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2697 | data.dfs_event.freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 2698 | event_type = nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT]); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 2699 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2700 | /* Check HT params */ |
| 2701 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2702 | data.dfs_event.ht_enabled = 1; |
| 2703 | data.dfs_event.chan_offset = 0; |
| 2704 | |
| 2705 | switch (nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE])) { |
| 2706 | case NL80211_CHAN_NO_HT: |
| 2707 | data.dfs_event.ht_enabled = 0; |
| 2708 | break; |
| 2709 | case NL80211_CHAN_HT20: |
| 2710 | break; |
| 2711 | case NL80211_CHAN_HT40PLUS: |
| 2712 | data.dfs_event.chan_offset = 1; |
| 2713 | break; |
| 2714 | case NL80211_CHAN_HT40MINUS: |
| 2715 | data.dfs_event.chan_offset = -1; |
| 2716 | break; |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | /* Get VHT params */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2721 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) |
| 2722 | data.dfs_event.chan_width = |
| 2723 | convert2width(nla_get_u32( |
| 2724 | tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 2725 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 2726 | data.dfs_event.cf1 = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2727 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 2728 | data.dfs_event.cf2 = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 2729 | |
| 2730 | wpa_printf(MSG_DEBUG, "nl80211: DFS event on freq %d MHz, ht: %d, offset: %d, width: %d, cf1: %dMHz, cf2: %dMHz", |
| 2731 | data.dfs_event.freq, data.dfs_event.ht_enabled, |
| 2732 | data.dfs_event.chan_offset, data.dfs_event.chan_width, |
| 2733 | data.dfs_event.cf1, data.dfs_event.cf2); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 2734 | |
| 2735 | switch (event_type) { |
| 2736 | case NL80211_RADAR_DETECTED: |
| 2737 | wpa_supplicant_event(drv->ctx, EVENT_DFS_RADAR_DETECTED, &data); |
| 2738 | break; |
| 2739 | case NL80211_RADAR_CAC_FINISHED: |
| 2740 | wpa_supplicant_event(drv->ctx, EVENT_DFS_CAC_FINISHED, &data); |
| 2741 | break; |
| 2742 | case NL80211_RADAR_CAC_ABORTED: |
| 2743 | wpa_supplicant_event(drv->ctx, EVENT_DFS_CAC_ABORTED, &data); |
| 2744 | break; |
| 2745 | case NL80211_RADAR_NOP_FINISHED: |
| 2746 | wpa_supplicant_event(drv->ctx, EVENT_DFS_NOP_FINISHED, &data); |
| 2747 | break; |
| 2748 | default: |
| 2749 | wpa_printf(MSG_DEBUG, "nl80211: Unknown radar event %d " |
| 2750 | "received", event_type); |
| 2751 | break; |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2756 | static void nl80211_spurious_frame(struct i802_bss *bss, struct nlattr **tb, |
| 2757 | int wds) |
| 2758 | { |
| 2759 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2760 | union wpa_event_data event; |
| 2761 | |
| 2762 | if (!tb[NL80211_ATTR_MAC]) |
| 2763 | return; |
| 2764 | |
| 2765 | os_memset(&event, 0, sizeof(event)); |
| 2766 | event.rx_from_unknown.bssid = bss->addr; |
| 2767 | event.rx_from_unknown.addr = nla_data(tb[NL80211_ATTR_MAC]); |
| 2768 | event.rx_from_unknown.wds = wds; |
| 2769 | |
| 2770 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); |
| 2771 | } |
| 2772 | |
| 2773 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2774 | static void qca_nl80211_avoid_freq(struct wpa_driver_nl80211_data *drv, |
| 2775 | const u8 *data, size_t len) |
| 2776 | { |
| 2777 | u32 i, count; |
| 2778 | union wpa_event_data event; |
| 2779 | struct wpa_freq_range *range = NULL; |
| 2780 | const struct qca_avoid_freq_list *freq_range; |
| 2781 | |
| 2782 | freq_range = (const struct qca_avoid_freq_list *) data; |
| 2783 | if (len < sizeof(freq_range->count)) |
| 2784 | return; |
| 2785 | |
| 2786 | count = freq_range->count; |
| 2787 | if (len < sizeof(freq_range->count) + |
| 2788 | count * sizeof(struct qca_avoid_freq_range)) { |
| 2789 | wpa_printf(MSG_DEBUG, "nl80211: Ignored too short avoid frequency list (len=%u)", |
| 2790 | (unsigned int) len); |
| 2791 | return; |
| 2792 | } |
| 2793 | |
| 2794 | if (count > 0) { |
| 2795 | range = os_calloc(count, sizeof(struct wpa_freq_range)); |
| 2796 | if (range == NULL) |
| 2797 | return; |
| 2798 | } |
| 2799 | |
| 2800 | os_memset(&event, 0, sizeof(event)); |
| 2801 | for (i = 0; i < count; i++) { |
| 2802 | unsigned int idx = event.freq_range.num; |
| 2803 | range[idx].min = freq_range->range[i].start_freq; |
| 2804 | range[idx].max = freq_range->range[i].end_freq; |
| 2805 | wpa_printf(MSG_DEBUG, "nl80211: Avoid frequency range: %u-%u", |
| 2806 | range[idx].min, range[idx].max); |
| 2807 | if (range[idx].min > range[idx].max) { |
| 2808 | wpa_printf(MSG_DEBUG, "nl80211: Ignore invalid frequency range"); |
| 2809 | continue; |
| 2810 | } |
| 2811 | event.freq_range.num++; |
| 2812 | } |
| 2813 | event.freq_range.range = range; |
| 2814 | |
| 2815 | wpa_supplicant_event(drv->ctx, EVENT_AVOID_FREQUENCIES, &event); |
| 2816 | |
| 2817 | os_free(range); |
| 2818 | } |
| 2819 | |
| 2820 | |
| 2821 | static void nl80211_vendor_event_qca(struct wpa_driver_nl80211_data *drv, |
| 2822 | u32 subcmd, u8 *data, size_t len) |
| 2823 | { |
| 2824 | switch (subcmd) { |
| 2825 | case QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY: |
| 2826 | qca_nl80211_avoid_freq(drv, data, len); |
| 2827 | break; |
| 2828 | default: |
| 2829 | wpa_printf(MSG_DEBUG, |
| 2830 | "nl80211: Ignore unsupported QCA vendor event %u", |
| 2831 | subcmd); |
| 2832 | break; |
| 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2837 | static void nl80211_vendor_event(struct wpa_driver_nl80211_data *drv, |
| 2838 | struct nlattr **tb) |
| 2839 | { |
| 2840 | u32 vendor_id, subcmd, wiphy = 0; |
| 2841 | int wiphy_idx; |
| 2842 | u8 *data = NULL; |
| 2843 | size_t len = 0; |
| 2844 | |
| 2845 | if (!tb[NL80211_ATTR_VENDOR_ID] || |
| 2846 | !tb[NL80211_ATTR_VENDOR_SUBCMD]) |
| 2847 | return; |
| 2848 | |
| 2849 | vendor_id = nla_get_u32(tb[NL80211_ATTR_VENDOR_ID]); |
| 2850 | subcmd = nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]); |
| 2851 | |
| 2852 | if (tb[NL80211_ATTR_WIPHY]) |
| 2853 | wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2854 | |
| 2855 | wpa_printf(MSG_DEBUG, "nl80211: Vendor event: wiphy=%u vendor_id=0x%x subcmd=%u", |
| 2856 | wiphy, vendor_id, subcmd); |
| 2857 | |
| 2858 | if (tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2859 | data = nla_data(tb[NL80211_ATTR_VENDOR_DATA]); |
| 2860 | len = nla_len(tb[NL80211_ATTR_VENDOR_DATA]); |
| 2861 | wpa_hexdump(MSG_MSGDUMP, "nl80211: Vendor data", data, len); |
| 2862 | } |
| 2863 | |
| 2864 | wiphy_idx = nl80211_get_wiphy_index(drv->first_bss); |
| 2865 | if (wiphy_idx >= 0 && wiphy_idx != (int) wiphy) { |
| 2866 | wpa_printf(MSG_DEBUG, "nl80211: Ignore vendor event for foreign wiphy %u (own: %d)", |
| 2867 | wiphy, wiphy_idx); |
| 2868 | return; |
| 2869 | } |
| 2870 | |
| 2871 | switch (vendor_id) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2872 | case OUI_QCA: |
| 2873 | nl80211_vendor_event_qca(drv, subcmd, data, len); |
| 2874 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2875 | default: |
| 2876 | wpa_printf(MSG_DEBUG, "nl80211: Ignore unsupported vendor event"); |
| 2877 | break; |
| 2878 | } |
| 2879 | } |
| 2880 | |
| 2881 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2882 | static void do_process_drv_event(struct i802_bss *bss, int cmd, |
| 2883 | struct nlattr **tb) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2884 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2885 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2886 | union wpa_event_data data; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2887 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2888 | wpa_printf(MSG_DEBUG, "nl80211: Drv Event %d (%s) received for %s", |
| 2889 | cmd, nl80211_command_to_string(cmd), bss->ifname); |
| 2890 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2891 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED && |
| 2892 | (cmd == NL80211_CMD_NEW_SCAN_RESULTS || |
| 2893 | cmd == NL80211_CMD_SCAN_ABORTED)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2894 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2895 | drv->ap_scan_as_station); |
| 2896 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2897 | } |
| 2898 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2899 | switch (cmd) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2900 | case NL80211_CMD_TRIGGER_SCAN: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2901 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan trigger"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2902 | drv->scan_state = SCAN_STARTED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2903 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_STARTED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2904 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2905 | case NL80211_CMD_START_SCHED_SCAN: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2906 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan started"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2907 | drv->scan_state = SCHED_SCAN_STARTED; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2908 | break; |
| 2909 | case NL80211_CMD_SCHED_SCAN_STOPPED: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2910 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan stopped"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2911 | drv->scan_state = SCHED_SCAN_STOPPED; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2912 | wpa_supplicant_event(drv->ctx, EVENT_SCHED_SCAN_STOPPED, NULL); |
| 2913 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2914 | case NL80211_CMD_NEW_SCAN_RESULTS: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2915 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2916 | "nl80211: New scan results available"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2917 | drv->scan_state = SCAN_COMPLETED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2918 | drv->scan_complete_events = 1; |
| 2919 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, |
| 2920 | drv->ctx); |
| 2921 | send_scan_event(drv, 0, tb); |
| 2922 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2923 | case NL80211_CMD_SCHED_SCAN_RESULTS: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2924 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2925 | "nl80211: New sched scan results available"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2926 | drv->scan_state = SCHED_SCAN_RESULTS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2927 | send_scan_event(drv, 0, tb); |
| 2928 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2929 | case NL80211_CMD_SCAN_ABORTED: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2930 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan aborted"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2931 | drv->scan_state = SCAN_ABORTED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2932 | /* |
| 2933 | * Need to indicate that scan results are available in order |
| 2934 | * not to make wpa_supplicant stop its scanning. |
| 2935 | */ |
| 2936 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, |
| 2937 | drv->ctx); |
| 2938 | send_scan_event(drv, 1, tb); |
| 2939 | break; |
| 2940 | case NL80211_CMD_AUTHENTICATE: |
| 2941 | case NL80211_CMD_ASSOCIATE: |
| 2942 | case NL80211_CMD_DEAUTHENTICATE: |
| 2943 | case NL80211_CMD_DISASSOCIATE: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2944 | case NL80211_CMD_FRAME_TX_STATUS: |
| 2945 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
| 2946 | case NL80211_CMD_UNPROT_DISASSOCIATE: |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2947 | mlme_event(bss, cmd, tb[NL80211_ATTR_FRAME], |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2948 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
| 2949 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2950 | tb[NL80211_ATTR_COOKIE], |
| 2951 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2952 | break; |
| 2953 | case NL80211_CMD_CONNECT: |
| 2954 | case NL80211_CMD_ROAM: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2955 | mlme_event_connect(drv, cmd, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2956 | tb[NL80211_ATTR_STATUS_CODE], |
| 2957 | tb[NL80211_ATTR_MAC], |
| 2958 | tb[NL80211_ATTR_REQ_IE], |
| 2959 | tb[NL80211_ATTR_RESP_IE]); |
| 2960 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2961 | case NL80211_CMD_CH_SWITCH_NOTIFY: |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2962 | mlme_event_ch_switch(drv, |
| 2963 | tb[NL80211_ATTR_IFINDEX], |
| 2964 | tb[NL80211_ATTR_WIPHY_FREQ], |
| 2965 | tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 2966 | tb[NL80211_ATTR_CHANNEL_WIDTH], |
| 2967 | tb[NL80211_ATTR_CENTER_FREQ1], |
| 2968 | tb[NL80211_ATTR_CENTER_FREQ2]); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2969 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2970 | case NL80211_CMD_DISCONNECT: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2971 | mlme_event_disconnect(drv, tb[NL80211_ATTR_REASON_CODE], |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2972 | tb[NL80211_ATTR_MAC], |
| 2973 | tb[NL80211_ATTR_DISCONNECTED_BY_AP]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2974 | break; |
| 2975 | case NL80211_CMD_MICHAEL_MIC_FAILURE: |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2976 | mlme_event_michael_mic_failure(bss, tb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2977 | break; |
| 2978 | case NL80211_CMD_JOIN_IBSS: |
| 2979 | mlme_event_join_ibss(drv, tb); |
| 2980 | break; |
| 2981 | case NL80211_CMD_REMAIN_ON_CHANNEL: |
| 2982 | mlme_event_remain_on_channel(drv, 0, tb); |
| 2983 | break; |
| 2984 | case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: |
| 2985 | mlme_event_remain_on_channel(drv, 1, tb); |
| 2986 | break; |
| 2987 | case NL80211_CMD_NOTIFY_CQM: |
| 2988 | nl80211_cqm_event(drv, tb); |
| 2989 | break; |
| 2990 | case NL80211_CMD_REG_CHANGE: |
| 2991 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory domain change"); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2992 | if (tb[NL80211_ATTR_REG_INITIATOR] == NULL) |
| 2993 | break; |
| 2994 | os_memset(&data, 0, sizeof(data)); |
| 2995 | switch (nla_get_u8(tb[NL80211_ATTR_REG_INITIATOR])) { |
| 2996 | case NL80211_REGDOM_SET_BY_CORE: |
| 2997 | data.channel_list_changed.initiator = |
| 2998 | REGDOM_SET_BY_CORE; |
| 2999 | break; |
| 3000 | case NL80211_REGDOM_SET_BY_USER: |
| 3001 | data.channel_list_changed.initiator = |
| 3002 | REGDOM_SET_BY_USER; |
| 3003 | break; |
| 3004 | case NL80211_REGDOM_SET_BY_DRIVER: |
| 3005 | data.channel_list_changed.initiator = |
| 3006 | REGDOM_SET_BY_DRIVER; |
| 3007 | break; |
| 3008 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
| 3009 | data.channel_list_changed.initiator = |
| 3010 | REGDOM_SET_BY_COUNTRY_IE; |
| 3011 | break; |
| 3012 | default: |
| 3013 | wpa_printf(MSG_DEBUG, "nl80211: Unknown reg change initiator %d received", |
| 3014 | nla_get_u8(tb[NL80211_ATTR_REG_INITIATOR])); |
| 3015 | break; |
| 3016 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3017 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3018 | &data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3019 | break; |
| 3020 | case NL80211_CMD_REG_BEACON_HINT: |
| 3021 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory beacon hint"); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 3022 | os_memset(&data, 0, sizeof(data)); |
| 3023 | data.channel_list_changed.initiator = REGDOM_BEACON_HINT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3024 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 3025 | &data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3026 | break; |
| 3027 | case NL80211_CMD_NEW_STATION: |
| 3028 | nl80211_new_station_event(drv, tb); |
| 3029 | break; |
| 3030 | case NL80211_CMD_DEL_STATION: |
| 3031 | nl80211_del_station_event(drv, tb); |
| 3032 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3033 | case NL80211_CMD_SET_REKEY_OFFLOAD: |
| 3034 | nl80211_rekey_offload_event(drv, tb); |
| 3035 | break; |
| 3036 | case NL80211_CMD_PMKSA_CANDIDATE: |
| 3037 | nl80211_pmksa_candidate_event(drv, tb); |
| 3038 | break; |
| 3039 | case NL80211_CMD_PROBE_CLIENT: |
| 3040 | nl80211_client_probe_event(drv, tb); |
| 3041 | break; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3042 | case NL80211_CMD_TDLS_OPER: |
| 3043 | nl80211_tdls_oper_event(drv, tb); |
| 3044 | break; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3045 | case NL80211_CMD_CONN_FAILED: |
| 3046 | nl80211_connect_failed_event(drv, tb); |
| 3047 | break; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3048 | case NL80211_CMD_FT_EVENT: |
| 3049 | mlme_event_ft_event(drv, tb); |
| 3050 | break; |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 3051 | case NL80211_CMD_RADAR_DETECT: |
| 3052 | nl80211_radar_event(drv, tb); |
| 3053 | break; |
Dmitry Shmidt | 5393a0f | 2013-08-08 11:23:34 -0700 | [diff] [blame] | 3054 | case NL80211_CMD_STOP_AP: |
| 3055 | nl80211_stop_ap(drv, tb); |
| 3056 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3057 | case NL80211_CMD_VENDOR: |
| 3058 | nl80211_vendor_event(drv, tb); |
| 3059 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3060 | default: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3061 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Ignored unknown event " |
| 3062 | "(cmd=%d)", cmd); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3063 | break; |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | |
| 3068 | static int process_drv_event(struct nl_msg *msg, void *arg) |
| 3069 | { |
| 3070 | struct wpa_driver_nl80211_data *drv = arg; |
| 3071 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3072 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3073 | struct i802_bss *bss; |
| 3074 | int ifidx = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3075 | |
| 3076 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3077 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3078 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3079 | if (tb[NL80211_ATTR_IFINDEX]) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3080 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 3081 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3082 | for (bss = drv->first_bss; bss; bss = bss->next) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3083 | if (ifidx == -1 || ifidx == bss->ifindex) { |
| 3084 | do_process_drv_event(bss, gnlh->cmd, tb); |
| 3085 | return NL_SKIP; |
| 3086 | } |
| 3087 | wpa_printf(MSG_DEBUG, |
| 3088 | "nl80211: Ignored event (cmd=%d) for foreign interface (ifindex %d)", |
| 3089 | gnlh->cmd, ifidx); |
| 3090 | } else if (tb[NL80211_ATTR_WDEV]) { |
| 3091 | u64 wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 3092 | wpa_printf(MSG_DEBUG, "nl80211: Process event on P2P device"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3093 | for (bss = drv->first_bss; bss; bss = bss->next) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3094 | if (bss->wdev_id_set && wdev_id == bss->wdev_id) { |
| 3095 | do_process_drv_event(bss, gnlh->cmd, tb); |
| 3096 | return NL_SKIP; |
| 3097 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3098 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3099 | wpa_printf(MSG_DEBUG, |
| 3100 | "nl80211: Ignored event (cmd=%d) for foreign interface (wdev 0x%llx)", |
| 3101 | gnlh->cmd, (long long unsigned int) wdev_id); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3102 | } |
| 3103 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3104 | return NL_SKIP; |
| 3105 | } |
| 3106 | |
| 3107 | |
| 3108 | static int process_global_event(struct nl_msg *msg, void *arg) |
| 3109 | { |
| 3110 | struct nl80211_global *global = arg; |
| 3111 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3112 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3113 | struct wpa_driver_nl80211_data *drv, *tmp; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3114 | int ifidx = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3115 | struct i802_bss *bss; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3116 | u64 wdev_id = 0; |
| 3117 | int wdev_id_set = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3118 | |
| 3119 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3120 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3121 | |
| 3122 | if (tb[NL80211_ATTR_IFINDEX]) |
| 3123 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3124 | else if (tb[NL80211_ATTR_WDEV]) { |
| 3125 | wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 3126 | wdev_id_set = 1; |
| 3127 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3128 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3129 | dl_list_for_each_safe(drv, tmp, &global->interfaces, |
| 3130 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3131 | for (bss = drv->first_bss; bss; bss = bss->next) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3132 | if ((ifidx == -1 && !wdev_id_set) || |
| 3133 | ifidx == bss->ifindex || |
| 3134 | (wdev_id_set && bss->wdev_id_set && |
| 3135 | wdev_id == bss->wdev_id)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3136 | do_process_drv_event(bss, gnlh->cmd, tb); |
| 3137 | return NL_SKIP; |
| 3138 | } |
| 3139 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | return NL_SKIP; |
| 3143 | } |
| 3144 | |
| 3145 | |
| 3146 | static int process_bss_event(struct nl_msg *msg, void *arg) |
| 3147 | { |
| 3148 | struct i802_bss *bss = arg; |
| 3149 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3150 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 3151 | |
| 3152 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3153 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3154 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3155 | wpa_printf(MSG_DEBUG, "nl80211: BSS Event %d (%s) received for %s", |
| 3156 | gnlh->cmd, nl80211_command_to_string(gnlh->cmd), |
| 3157 | bss->ifname); |
| 3158 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3159 | switch (gnlh->cmd) { |
| 3160 | case NL80211_CMD_FRAME: |
| 3161 | case NL80211_CMD_FRAME_TX_STATUS: |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3162 | mlme_event(bss, gnlh->cmd, tb[NL80211_ATTR_FRAME], |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3163 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
| 3164 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3165 | tb[NL80211_ATTR_COOKIE], |
| 3166 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3167 | break; |
| 3168 | case NL80211_CMD_UNEXPECTED_FRAME: |
| 3169 | nl80211_spurious_frame(bss, tb, 0); |
| 3170 | break; |
| 3171 | case NL80211_CMD_UNEXPECTED_4ADDR_FRAME: |
| 3172 | nl80211_spurious_frame(bss, tb, 1); |
| 3173 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3174 | default: |
| 3175 | wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event " |
| 3176 | "(cmd=%d)", gnlh->cmd); |
| 3177 | break; |
| 3178 | } |
| 3179 | |
| 3180 | return NL_SKIP; |
| 3181 | } |
| 3182 | |
| 3183 | |
| 3184 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 3185 | void *handle) |
| 3186 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3187 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3188 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3189 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3190 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3191 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3192 | res = nl_recvmsgs(handle, cb); |
| 3193 | if (res) { |
| 3194 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 3195 | __func__, res); |
| 3196 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | |
| 3200 | /** |
| 3201 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 3202 | * @priv: driver_nl80211 private data |
| 3203 | * @alpha2_arg: country to which to switch to |
| 3204 | * Returns: 0 on success, -1 on failure |
| 3205 | * |
| 3206 | * This asks nl80211 to set the regulatory domain for given |
| 3207 | * country ISO / IEC alpha2. |
| 3208 | */ |
| 3209 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 3210 | { |
| 3211 | struct i802_bss *bss = priv; |
| 3212 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3213 | char alpha2[3]; |
| 3214 | struct nl_msg *msg; |
| 3215 | |
| 3216 | msg = nlmsg_alloc(); |
| 3217 | if (!msg) |
| 3218 | return -ENOMEM; |
| 3219 | |
| 3220 | alpha2[0] = alpha2_arg[0]; |
| 3221 | alpha2[1] = alpha2_arg[1]; |
| 3222 | alpha2[2] = '\0'; |
| 3223 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3224 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3225 | |
| 3226 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); |
| 3227 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 3228 | return -EINVAL; |
| 3229 | return 0; |
| 3230 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3231 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3232 | return -EINVAL; |
| 3233 | } |
| 3234 | |
| 3235 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3236 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 3237 | { |
| 3238 | char *alpha2 = arg; |
| 3239 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 3240 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3241 | |
| 3242 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3243 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3244 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 3245 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 3246 | return NL_SKIP; |
| 3247 | } |
| 3248 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 3249 | return NL_SKIP; |
| 3250 | } |
| 3251 | |
| 3252 | |
| 3253 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 3254 | { |
| 3255 | struct i802_bss *bss = priv; |
| 3256 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3257 | struct nl_msg *msg; |
| 3258 | int ret; |
| 3259 | |
| 3260 | msg = nlmsg_alloc(); |
| 3261 | if (!msg) |
| 3262 | return -ENOMEM; |
| 3263 | |
| 3264 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 3265 | alpha2[0] = '\0'; |
| 3266 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 3267 | if (!alpha2[0]) |
| 3268 | ret = -1; |
| 3269 | |
| 3270 | return ret; |
| 3271 | } |
| 3272 | |
| 3273 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3274 | static int protocol_feature_handler(struct nl_msg *msg, void *arg) |
| 3275 | { |
| 3276 | u32 *feat = arg; |
| 3277 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 3278 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3279 | |
| 3280 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3281 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3282 | |
| 3283 | if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]) |
| 3284 | *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]); |
| 3285 | |
| 3286 | return NL_SKIP; |
| 3287 | } |
| 3288 | |
| 3289 | |
| 3290 | static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv) |
| 3291 | { |
| 3292 | u32 feat = 0; |
| 3293 | struct nl_msg *msg; |
| 3294 | |
| 3295 | msg = nlmsg_alloc(); |
| 3296 | if (!msg) |
| 3297 | goto nla_put_failure; |
| 3298 | |
| 3299 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 3300 | if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0) |
| 3301 | return feat; |
| 3302 | |
| 3303 | msg = NULL; |
| 3304 | nla_put_failure: |
| 3305 | nlmsg_free(msg); |
| 3306 | return 0; |
| 3307 | } |
| 3308 | |
| 3309 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3310 | struct wiphy_info_data { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3311 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3312 | struct wpa_driver_capa *capa; |
| 3313 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3314 | unsigned int num_multichan_concurrent; |
| 3315 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3316 | unsigned int error:1; |
| 3317 | unsigned int device_ap_sme:1; |
| 3318 | unsigned int poll_command_supported:1; |
| 3319 | unsigned int data_tx_status:1; |
| 3320 | unsigned int monitor_supported:1; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3321 | unsigned int auth_supported:1; |
| 3322 | unsigned int connect_supported:1; |
| 3323 | unsigned int p2p_go_supported:1; |
| 3324 | unsigned int p2p_client_supported:1; |
| 3325 | unsigned int p2p_concurrent:1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3326 | unsigned int channel_switch_supported:1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3327 | unsigned int set_qos_map_supported:1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3328 | }; |
| 3329 | |
| 3330 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3331 | static unsigned int probe_resp_offload_support(int supp_protocols) |
| 3332 | { |
| 3333 | unsigned int prot = 0; |
| 3334 | |
| 3335 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS) |
| 3336 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS; |
| 3337 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2) |
| 3338 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2; |
| 3339 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P) |
| 3340 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P; |
| 3341 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U) |
| 3342 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING; |
| 3343 | |
| 3344 | return prot; |
| 3345 | } |
| 3346 | |
| 3347 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3348 | static void wiphy_info_supported_iftypes(struct wiphy_info_data *info, |
| 3349 | struct nlattr *tb) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3350 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3351 | struct nlattr *nl_mode; |
| 3352 | int i; |
| 3353 | |
| 3354 | if (tb == NULL) |
| 3355 | return; |
| 3356 | |
| 3357 | nla_for_each_nested(nl_mode, tb, i) { |
| 3358 | switch (nla_type(nl_mode)) { |
| 3359 | case NL80211_IFTYPE_AP: |
| 3360 | info->capa->flags |= WPA_DRIVER_FLAGS_AP; |
| 3361 | break; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3362 | case NL80211_IFTYPE_ADHOC: |
| 3363 | info->capa->flags |= WPA_DRIVER_FLAGS_IBSS; |
| 3364 | break; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3365 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3366 | info->capa->flags |= |
| 3367 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE; |
| 3368 | break; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3369 | case NL80211_IFTYPE_P2P_GO: |
| 3370 | info->p2p_go_supported = 1; |
| 3371 | break; |
| 3372 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3373 | info->p2p_client_supported = 1; |
| 3374 | break; |
| 3375 | case NL80211_IFTYPE_MONITOR: |
| 3376 | info->monitor_supported = 1; |
| 3377 | break; |
| 3378 | } |
| 3379 | } |
| 3380 | } |
| 3381 | |
| 3382 | |
| 3383 | static int wiphy_info_iface_comb_process(struct wiphy_info_data *info, |
| 3384 | struct nlattr *nl_combi) |
| 3385 | { |
| 3386 | struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB]; |
| 3387 | struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT]; |
| 3388 | struct nlattr *nl_limit, *nl_mode; |
| 3389 | int err, rem_limit, rem_mode; |
| 3390 | int combination_has_p2p = 0, combination_has_mgd = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3391 | static struct nla_policy |
| 3392 | iface_combination_policy[NUM_NL80211_IFACE_COMB] = { |
| 3393 | [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED }, |
| 3394 | [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 }, |
| 3395 | [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG }, |
| 3396 | [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 }, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 3397 | [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 }, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3398 | }, |
| 3399 | iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = { |
| 3400 | [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED }, |
| 3401 | [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 }, |
| 3402 | }; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3403 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3404 | err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB, |
| 3405 | nl_combi, iface_combination_policy); |
| 3406 | if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] || |
| 3407 | !tb_comb[NL80211_IFACE_COMB_MAXNUM] || |
| 3408 | !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) |
| 3409 | return 0; /* broken combination */ |
| 3410 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 3411 | if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]) |
| 3412 | info->capa->flags |= WPA_DRIVER_FLAGS_RADAR; |
| 3413 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3414 | nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], |
| 3415 | rem_limit) { |
| 3416 | err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT, |
| 3417 | nl_limit, iface_limit_policy); |
| 3418 | if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) |
| 3419 | return 0; /* broken combination */ |
| 3420 | |
| 3421 | nla_for_each_nested(nl_mode, |
| 3422 | tb_limit[NL80211_IFACE_LIMIT_TYPES], |
| 3423 | rem_mode) { |
| 3424 | int ift = nla_type(nl_mode); |
| 3425 | if (ift == NL80211_IFTYPE_P2P_GO || |
| 3426 | ift == NL80211_IFTYPE_P2P_CLIENT) |
| 3427 | combination_has_p2p = 1; |
| 3428 | if (ift == NL80211_IFTYPE_STATION) |
| 3429 | combination_has_mgd = 1; |
| 3430 | } |
| 3431 | if (combination_has_p2p && combination_has_mgd) |
| 3432 | break; |
| 3433 | } |
| 3434 | |
| 3435 | if (combination_has_p2p && combination_has_mgd) { |
| 3436 | info->p2p_concurrent = 1; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3437 | info->num_multichan_concurrent = |
| 3438 | nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3439 | return 1; |
| 3440 | } |
| 3441 | |
| 3442 | return 0; |
| 3443 | } |
| 3444 | |
| 3445 | |
| 3446 | static void wiphy_info_iface_comb(struct wiphy_info_data *info, |
| 3447 | struct nlattr *tb) |
| 3448 | { |
| 3449 | struct nlattr *nl_combi; |
| 3450 | int rem_combi; |
| 3451 | |
| 3452 | if (tb == NULL) |
| 3453 | return; |
| 3454 | |
| 3455 | nla_for_each_nested(nl_combi, tb, rem_combi) { |
| 3456 | if (wiphy_info_iface_comb_process(info, nl_combi) > 0) |
| 3457 | break; |
| 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | |
| 3462 | static void wiphy_info_supp_cmds(struct wiphy_info_data *info, |
| 3463 | struct nlattr *tb) |
| 3464 | { |
| 3465 | struct nlattr *nl_cmd; |
| 3466 | int i; |
| 3467 | |
| 3468 | if (tb == NULL) |
| 3469 | return; |
| 3470 | |
| 3471 | nla_for_each_nested(nl_cmd, tb, i) { |
| 3472 | switch (nla_get_u32(nl_cmd)) { |
| 3473 | case NL80211_CMD_AUTHENTICATE: |
| 3474 | info->auth_supported = 1; |
| 3475 | break; |
| 3476 | case NL80211_CMD_CONNECT: |
| 3477 | info->connect_supported = 1; |
| 3478 | break; |
| 3479 | case NL80211_CMD_START_SCHED_SCAN: |
| 3480 | info->capa->sched_scan_supported = 1; |
| 3481 | break; |
| 3482 | case NL80211_CMD_PROBE_CLIENT: |
| 3483 | info->poll_command_supported = 1; |
| 3484 | break; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3485 | case NL80211_CMD_CHANNEL_SWITCH: |
| 3486 | info->channel_switch_supported = 1; |
| 3487 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3488 | case NL80211_CMD_SET_QOS_MAP: |
| 3489 | info->set_qos_map_supported = 1; |
| 3490 | break; |
| 3491 | } |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | |
| 3496 | static void wiphy_info_cipher_suites(struct wiphy_info_data *info, |
| 3497 | struct nlattr *tb) |
| 3498 | { |
| 3499 | int i, num; |
| 3500 | u32 *ciphers; |
| 3501 | |
| 3502 | if (tb == NULL) |
| 3503 | return; |
| 3504 | |
| 3505 | num = nla_len(tb) / sizeof(u32); |
| 3506 | ciphers = nla_data(tb); |
| 3507 | for (i = 0; i < num; i++) { |
| 3508 | u32 c = ciphers[i]; |
| 3509 | |
| 3510 | wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d", |
| 3511 | c >> 24, (c >> 16) & 0xff, |
| 3512 | (c >> 8) & 0xff, c & 0xff); |
| 3513 | switch (c) { |
| 3514 | case WLAN_CIPHER_SUITE_CCMP_256: |
| 3515 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256; |
| 3516 | break; |
| 3517 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 3518 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256; |
| 3519 | break; |
| 3520 | case WLAN_CIPHER_SUITE_CCMP: |
| 3521 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP; |
| 3522 | break; |
| 3523 | case WLAN_CIPHER_SUITE_GCMP: |
| 3524 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP; |
| 3525 | break; |
| 3526 | case WLAN_CIPHER_SUITE_TKIP: |
| 3527 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP; |
| 3528 | break; |
| 3529 | case WLAN_CIPHER_SUITE_WEP104: |
| 3530 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104; |
| 3531 | break; |
| 3532 | case WLAN_CIPHER_SUITE_WEP40: |
| 3533 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40; |
| 3534 | break; |
| 3535 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 3536 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP; |
| 3537 | break; |
| 3538 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 3539 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128; |
| 3540 | break; |
| 3541 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 3542 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256; |
| 3543 | break; |
| 3544 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 3545 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256; |
| 3546 | break; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3547 | case WLAN_CIPHER_SUITE_NO_GROUP_ADDR: |
| 3548 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED; |
| 3549 | break; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3550 | } |
| 3551 | } |
| 3552 | } |
| 3553 | |
| 3554 | |
| 3555 | static void wiphy_info_max_roc(struct wpa_driver_capa *capa, |
| 3556 | struct nlattr *tb) |
| 3557 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3558 | if (tb) |
| 3559 | capa->max_remain_on_chan = nla_get_u32(tb); |
| 3560 | } |
| 3561 | |
| 3562 | |
| 3563 | static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls, |
| 3564 | struct nlattr *ext_setup) |
| 3565 | { |
| 3566 | if (tdls == NULL) |
| 3567 | return; |
| 3568 | |
| 3569 | wpa_printf(MSG_DEBUG, "nl80211: TDLS supported"); |
| 3570 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT; |
| 3571 | |
| 3572 | if (ext_setup) { |
| 3573 | wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup"); |
| 3574 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP; |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | |
| 3579 | static void wiphy_info_feature_flags(struct wiphy_info_data *info, |
| 3580 | struct nlattr *tb) |
| 3581 | { |
| 3582 | u32 flags; |
| 3583 | struct wpa_driver_capa *capa = info->capa; |
| 3584 | |
| 3585 | if (tb == NULL) |
| 3586 | return; |
| 3587 | |
| 3588 | flags = nla_get_u32(tb); |
| 3589 | |
| 3590 | if (flags & NL80211_FEATURE_SK_TX_STATUS) |
| 3591 | info->data_tx_status = 1; |
| 3592 | |
| 3593 | if (flags & NL80211_FEATURE_INACTIVITY_TIMER) |
| 3594 | capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER; |
| 3595 | |
| 3596 | if (flags & NL80211_FEATURE_SAE) |
| 3597 | capa->flags |= WPA_DRIVER_FLAGS_SAE; |
| 3598 | |
| 3599 | if (flags & NL80211_FEATURE_NEED_OBSS_SCAN) |
| 3600 | capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN; |
| 3601 | } |
| 3602 | |
| 3603 | |
| 3604 | static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa, |
| 3605 | struct nlattr *tb) |
| 3606 | { |
| 3607 | u32 protocols; |
| 3608 | |
| 3609 | if (tb == NULL) |
| 3610 | return; |
| 3611 | |
| 3612 | protocols = nla_get_u32(tb); |
| 3613 | wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP " |
| 3614 | "mode"); |
| 3615 | capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD; |
| 3616 | capa->probe_resp_offloads = probe_resp_offload_support(protocols); |
| 3617 | } |
| 3618 | |
| 3619 | |
| 3620 | static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
| 3621 | { |
| 3622 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 3623 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3624 | struct wiphy_info_data *info = arg; |
| 3625 | struct wpa_driver_capa *capa = info->capa; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3626 | struct wpa_driver_nl80211_data *drv = info->drv; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3627 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3628 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3629 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3630 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3631 | if (tb[NL80211_ATTR_WIPHY_NAME]) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3632 | os_strlcpy(drv->phyname, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3633 | nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]), |
| 3634 | sizeof(drv->phyname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3635 | if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3636 | capa->max_scan_ssids = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3637 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]); |
| 3638 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3639 | if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]) |
| 3640 | capa->max_sched_scan_ssids = |
| 3641 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]); |
| 3642 | |
| 3643 | if (tb[NL80211_ATTR_MAX_MATCH_SETS]) |
| 3644 | capa->max_match_sets = |
| 3645 | nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]); |
| 3646 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3647 | if (tb[NL80211_ATTR_MAC_ACL_MAX]) |
| 3648 | capa->max_acl_mac_addrs = |
| 3649 | nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]); |
| 3650 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3651 | wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]); |
| 3652 | wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]); |
| 3653 | wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3654 | wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3655 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3656 | if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) { |
| 3657 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based " |
| 3658 | "off-channel TX"); |
| 3659 | capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 3660 | } |
| 3661 | |
| 3662 | if (tb[NL80211_ATTR_ROAM_SUPPORT]) { |
| 3663 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming"); |
| 3664 | capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 3665 | } |
| 3666 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3667 | wiphy_info_max_roc(capa, |
| 3668 | tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3669 | |
| 3670 | if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD]) |
| 3671 | capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3672 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3673 | wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT], |
| 3674 | tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]); |
Dmitry Shmidt | ad266fb | 2012-08-24 17:03:35 -0700 | [diff] [blame] | 3675 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3676 | if (tb[NL80211_ATTR_DEVICE_AP_SME]) |
| 3677 | info->device_ap_sme = 1; |
| 3678 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3679 | wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]); |
| 3680 | wiphy_info_probe_resp_offload(capa, |
| 3681 | tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3682 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3683 | if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] && |
| 3684 | drv->extended_capa == NULL) { |
| 3685 | drv->extended_capa = |
| 3686 | os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 3687 | if (drv->extended_capa) { |
| 3688 | os_memcpy(drv->extended_capa, |
| 3689 | nla_data(tb[NL80211_ATTR_EXT_CAPA]), |
| 3690 | nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 3691 | drv->extended_capa_len = |
| 3692 | nla_len(tb[NL80211_ATTR_EXT_CAPA]); |
| 3693 | } |
| 3694 | drv->extended_capa_mask = |
| 3695 | os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 3696 | if (drv->extended_capa_mask) { |
| 3697 | os_memcpy(drv->extended_capa_mask, |
| 3698 | nla_data(tb[NL80211_ATTR_EXT_CAPA]), |
| 3699 | nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 3700 | } else { |
| 3701 | os_free(drv->extended_capa); |
| 3702 | drv->extended_capa = NULL; |
| 3703 | drv->extended_capa_len = 0; |
| 3704 | } |
| 3705 | } |
| 3706 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3707 | if (tb[NL80211_ATTR_VENDOR_DATA]) { |
| 3708 | struct nlattr *nl; |
| 3709 | int rem; |
| 3710 | |
| 3711 | nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) { |
| 3712 | struct nl80211_vendor_cmd_info *vinfo; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3713 | if (nla_len(nl) != sizeof(*vinfo)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3714 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info"); |
| 3715 | continue; |
| 3716 | } |
| 3717 | vinfo = nla_data(nl); |
| 3718 | wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u", |
| 3719 | vinfo->vendor_id, vinfo->subcmd); |
| 3720 | } |
| 3721 | } |
| 3722 | |
| 3723 | if (tb[NL80211_ATTR_VENDOR_EVENTS]) { |
| 3724 | struct nlattr *nl; |
| 3725 | int rem; |
| 3726 | |
| 3727 | nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) { |
| 3728 | struct nl80211_vendor_cmd_info *vinfo; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3729 | if (nla_len(nl) != sizeof(*vinfo)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3730 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info"); |
| 3731 | continue; |
| 3732 | } |
| 3733 | vinfo = nla_data(nl); |
| 3734 | wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u", |
| 3735 | vinfo->vendor_id, vinfo->subcmd); |
| 3736 | } |
| 3737 | } |
| 3738 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3739 | return NL_SKIP; |
| 3740 | } |
| 3741 | |
| 3742 | |
| 3743 | static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv, |
| 3744 | struct wiphy_info_data *info) |
| 3745 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3746 | u32 feat; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3747 | struct nl_msg *msg; |
| 3748 | |
| 3749 | os_memset(info, 0, sizeof(*info)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3750 | info->capa = &drv->capa; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3751 | info->drv = drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3752 | |
| 3753 | msg = nlmsg_alloc(); |
| 3754 | if (!msg) |
| 3755 | return -1; |
| 3756 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3757 | feat = get_nl80211_protocol_features(drv); |
| 3758 | if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) |
| 3759 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY); |
| 3760 | else |
| 3761 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3762 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3763 | NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3764 | if (nl80211_set_iface_id(msg, drv->first_bss) < 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3765 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3766 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3767 | if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info)) |
| 3768 | return -1; |
| 3769 | |
| 3770 | if (info->auth_supported) |
| 3771 | drv->capa.flags |= WPA_DRIVER_FLAGS_SME; |
| 3772 | else if (!info->connect_supported) { |
| 3773 | wpa_printf(MSG_INFO, "nl80211: Driver does not support " |
| 3774 | "authentication/association or connect commands"); |
| 3775 | info->error = 1; |
| 3776 | } |
| 3777 | |
| 3778 | if (info->p2p_go_supported && info->p2p_client_supported) |
| 3779 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE; |
| 3780 | if (info->p2p_concurrent) { |
| 3781 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 3782 | "interface (driver advertised support)"); |
| 3783 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 3784 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 3785 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3786 | if (info->num_multichan_concurrent > 1) { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3787 | wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel " |
| 3788 | "concurrent (driver advertised support)"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3789 | drv->capa.num_multichan_concurrent = |
| 3790 | info->num_multichan_concurrent; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3791 | } |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3792 | |
| 3793 | /* default to 5000 since early versions of mac80211 don't set it */ |
| 3794 | if (!drv->capa.max_remain_on_chan) |
| 3795 | drv->capa.max_remain_on_chan = 5000; |
| 3796 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3797 | if (info->channel_switch_supported) |
| 3798 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA; |
| 3799 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3800 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3801 | nla_put_failure: |
| 3802 | nlmsg_free(msg); |
| 3803 | return -1; |
| 3804 | } |
| 3805 | |
| 3806 | |
| 3807 | static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv) |
| 3808 | { |
| 3809 | struct wiphy_info_data info; |
| 3810 | if (wpa_driver_nl80211_get_info(drv, &info)) |
| 3811 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3812 | |
| 3813 | if (info.error) |
| 3814 | return -1; |
| 3815 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3816 | drv->has_capability = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3817 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 3818 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | |
| 3819 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
| 3820 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3821 | drv->capa.auth = WPA_DRIVER_AUTH_OPEN | |
| 3822 | WPA_DRIVER_AUTH_SHARED | |
| 3823 | WPA_DRIVER_AUTH_LEAP; |
| 3824 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3825 | drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES; |
| 3826 | drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3827 | drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
Dmitry Shmidt | ad266fb | 2012-08-24 17:03:35 -0700 | [diff] [blame] | 3828 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 3829 | /* |
| 3830 | * As all cfg80211 drivers must support cases where the AP interface is |
| 3831 | * removed without the knowledge of wpa_supplicant/hostapd, e.g., in |
| 3832 | * case that the user space daemon has crashed, they must be able to |
| 3833 | * cleanup all stations and key entries in the AP tear down flow. Thus, |
| 3834 | * this flag can/should always be set for cfg80211 drivers. |
| 3835 | */ |
| 3836 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT; |
| 3837 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3838 | if (!info.device_ap_sme) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3839 | drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3840 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3841 | /* |
| 3842 | * No AP SME is currently assumed to also indicate no AP MLME |
| 3843 | * in the driver/firmware. |
| 3844 | */ |
| 3845 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME; |
| 3846 | } |
| 3847 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3848 | drv->device_ap_sme = info.device_ap_sme; |
| 3849 | drv->poll_command_supported = info.poll_command_supported; |
| 3850 | drv->data_tx_status = info.data_tx_status; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3851 | if (info.set_qos_map_supported) |
| 3852 | drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3853 | |
| 3854 | /* |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 3855 | * If poll command and tx status are supported, mac80211 is new enough |
| 3856 | * to have everything we need to not need monitor interfaces. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3857 | */ |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 3858 | drv->use_monitor = !info.poll_command_supported || !info.data_tx_status; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3859 | |
| 3860 | if (drv->device_ap_sme && drv->use_monitor) { |
| 3861 | /* |
| 3862 | * Non-mac80211 drivers may not support monitor interface. |
| 3863 | * Make sure we do not get stuck with incorrect capability here |
| 3864 | * by explicitly testing this. |
| 3865 | */ |
| 3866 | if (!info.monitor_supported) { |
| 3867 | wpa_printf(MSG_DEBUG, "nl80211: Disable use_monitor " |
| 3868 | "with device_ap_sme since no monitor mode " |
| 3869 | "support detected"); |
| 3870 | drv->use_monitor = 0; |
| 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | /* |
| 3875 | * If we aren't going to use monitor interfaces, but the |
| 3876 | * driver doesn't support data TX status, we won't get TX |
| 3877 | * status for EAPOL frames. |
| 3878 | */ |
| 3879 | if (!drv->use_monitor && !info.data_tx_status) |
| 3880 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3881 | |
| 3882 | return 0; |
| 3883 | } |
| 3884 | |
| 3885 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3886 | #ifdef ANDROID |
| 3887 | static int android_genl_ctrl_resolve(struct nl_handle *handle, |
| 3888 | const char *name) |
| 3889 | { |
| 3890 | /* |
| 3891 | * Android ICS has very minimal genl_ctrl_resolve() implementation, so |
| 3892 | * need to work around that. |
| 3893 | */ |
| 3894 | struct nl_cache *cache = NULL; |
| 3895 | struct genl_family *nl80211 = NULL; |
| 3896 | int id = -1; |
| 3897 | |
| 3898 | if (genl_ctrl_alloc_cache(handle, &cache) < 0) { |
| 3899 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " |
| 3900 | "netlink cache"); |
| 3901 | goto fail; |
| 3902 | } |
| 3903 | |
| 3904 | nl80211 = genl_ctrl_search_by_name(cache, name); |
| 3905 | if (nl80211 == NULL) |
| 3906 | goto fail; |
| 3907 | |
| 3908 | id = genl_family_get_id(nl80211); |
| 3909 | |
| 3910 | fail: |
| 3911 | if (nl80211) |
| 3912 | genl_family_put(nl80211); |
| 3913 | if (cache) |
| 3914 | nl_cache_free(cache); |
| 3915 | |
| 3916 | return id; |
| 3917 | } |
| 3918 | #define genl_ctrl_resolve android_genl_ctrl_resolve |
| 3919 | #endif /* ANDROID */ |
| 3920 | |
| 3921 | |
| 3922 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3923 | { |
| 3924 | int ret; |
| 3925 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3926 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 3927 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3928 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 3929 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3930 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3931 | } |
| 3932 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3933 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 3934 | if (global->nl == NULL) |
| 3935 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3936 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3937 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 3938 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3939 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 3940 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3941 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3944 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 3945 | if (global->nl_event == NULL) |
| 3946 | goto err; |
| 3947 | |
| 3948 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3949 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3950 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3951 | if (ret < 0) { |
| 3952 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 3953 | "membership for scan events: %d (%s)", |
| 3954 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3955 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3956 | } |
| 3957 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3958 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3959 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3960 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3961 | if (ret < 0) { |
| 3962 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 3963 | "membership for mlme events: %d (%s)", |
| 3964 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3965 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3966 | } |
| 3967 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3968 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3969 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3970 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3971 | if (ret < 0) { |
| 3972 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 3973 | "membership for regulatory events: %d (%s)", |
| 3974 | ret, strerror(-ret)); |
| 3975 | /* Continue without regulatory events */ |
| 3976 | } |
| 3977 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3978 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 3979 | if (ret >= 0) |
| 3980 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 3981 | if (ret < 0) { |
| 3982 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 3983 | "membership for vendor events: %d (%s)", |
| 3984 | ret, strerror(-ret)); |
| 3985 | /* Continue without vendor events */ |
| 3986 | } |
| 3987 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3988 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 3989 | no_seq_check, NULL); |
| 3990 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 3991 | process_global_event, global); |
| 3992 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3993 | nl80211_register_eloop_read(&global->nl_event, |
| 3994 | wpa_driver_nl80211_event_receive, |
| 3995 | global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3996 | |
| 3997 | return 0; |
| 3998 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3999 | err: |
| 4000 | nl_destroy_handles(&global->nl_event); |
| 4001 | nl_destroy_handles(&global->nl); |
| 4002 | nl_cb_put(global->nl_cb); |
| 4003 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4004 | return -1; |
| 4005 | } |
| 4006 | |
| 4007 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4008 | static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data *drv) |
| 4009 | { |
| 4010 | drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 4011 | if (!drv->nl_cb) { |
| 4012 | wpa_printf(MSG_ERROR, "nl80211: Failed to alloc cb struct"); |
| 4013 | return -1; |
| 4014 | } |
| 4015 | |
| 4016 | nl_cb_set(drv->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 4017 | no_seq_check, NULL); |
| 4018 | nl_cb_set(drv->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 4019 | process_drv_event, drv); |
| 4020 | |
| 4021 | return 0; |
| 4022 | } |
| 4023 | |
| 4024 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4025 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 4026 | { |
| 4027 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
| 4028 | /* |
| 4029 | * This may be for any interface; use ifdown event to disable |
| 4030 | * interface. |
| 4031 | */ |
| 4032 | } |
| 4033 | |
| 4034 | |
| 4035 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 4036 | { |
| 4037 | struct wpa_driver_nl80211_data *drv = ctx; |
| 4038 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4039 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4040 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 4041 | "after rfkill unblock"); |
| 4042 | return; |
| 4043 | } |
| 4044 | /* rtnetlink ifup handler will report interface as enabled */ |
| 4045 | } |
| 4046 | |
| 4047 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4048 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 4049 | void *eloop_ctx, |
| 4050 | void *handle) |
| 4051 | { |
| 4052 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 4053 | u8 data[2048]; |
| 4054 | struct msghdr msg; |
| 4055 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4056 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4057 | struct cmsghdr *cmsg; |
| 4058 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 4059 | union wpa_event_data event; |
| 4060 | |
| 4061 | memset(&msg, 0, sizeof(msg)); |
| 4062 | msg.msg_iov = &entry; |
| 4063 | msg.msg_iovlen = 1; |
| 4064 | entry.iov_base = data; |
| 4065 | entry.iov_len = sizeof(data); |
| 4066 | msg.msg_control = &control; |
| 4067 | msg.msg_controllen = sizeof(control); |
| 4068 | |
| 4069 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 4070 | /* if error or not fitting 802.3 header, return */ |
| 4071 | if (res < 14) |
| 4072 | return; |
| 4073 | |
| 4074 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 4075 | { |
| 4076 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 4077 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 4078 | int *ack; |
| 4079 | |
| 4080 | found_wifi = 1; |
| 4081 | ack = (void *)CMSG_DATA(cmsg); |
| 4082 | acked = *ack; |
| 4083 | } |
| 4084 | |
| 4085 | if (cmsg->cmsg_level == SOL_PACKET && |
| 4086 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 4087 | struct sock_extended_err *err = |
| 4088 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 4089 | |
| 4090 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 4091 | found_ee = 1; |
| 4092 | } |
| 4093 | } |
| 4094 | |
| 4095 | if (!found_ee || !found_wifi) |
| 4096 | return; |
| 4097 | |
| 4098 | memset(&event, 0, sizeof(event)); |
| 4099 | event.eapol_tx_status.dst = data; |
| 4100 | event.eapol_tx_status.data = data + 14; |
| 4101 | event.eapol_tx_status.data_len = res - 14; |
| 4102 | event.eapol_tx_status.ack = acked; |
| 4103 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 4104 | } |
| 4105 | |
| 4106 | |
| 4107 | static int nl80211_init_bss(struct i802_bss *bss) |
| 4108 | { |
| 4109 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 4110 | if (!bss->nl_cb) |
| 4111 | return -1; |
| 4112 | |
| 4113 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 4114 | no_seq_check, NULL); |
| 4115 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 4116 | process_bss_event, bss); |
| 4117 | |
| 4118 | return 0; |
| 4119 | } |
| 4120 | |
| 4121 | |
| 4122 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 4123 | { |
| 4124 | nl_cb_put(bss->nl_cb); |
| 4125 | bss->nl_cb = NULL; |
| 4126 | } |
| 4127 | |
| 4128 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4129 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 4130 | void *global_priv, int hostapd, |
| 4131 | const u8 *set_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4132 | { |
| 4133 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4134 | struct rfkill_config *rcfg; |
| 4135 | struct i802_bss *bss; |
| 4136 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4137 | if (global_priv == NULL) |
| 4138 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4139 | drv = os_zalloc(sizeof(*drv)); |
| 4140 | if (drv == NULL) |
| 4141 | return NULL; |
| 4142 | drv->global = global_priv; |
| 4143 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4144 | drv->hostapd = !!hostapd; |
| 4145 | drv->eapol_sock = -1; |
| 4146 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 4147 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4148 | |
| 4149 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 4150 | if (!drv->first_bss) { |
| 4151 | os_free(drv); |
| 4152 | return NULL; |
| 4153 | } |
| 4154 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4155 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4156 | bss->ctx = ctx; |
| 4157 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4158 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 4159 | drv->monitor_ifidx = -1; |
| 4160 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4161 | drv->eapol_tx_sock = -1; |
| 4162 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4163 | |
| 4164 | if (wpa_driver_nl80211_init_nl(drv)) { |
| 4165 | os_free(drv); |
| 4166 | return NULL; |
| 4167 | } |
| 4168 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4169 | if (nl80211_init_bss(bss)) |
| 4170 | goto failed; |
| 4171 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4172 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 4173 | if (rcfg == NULL) |
| 4174 | goto failed; |
| 4175 | rcfg->ctx = drv; |
| 4176 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); |
| 4177 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 4178 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 4179 | drv->rfkill = rfkill_init(rcfg); |
| 4180 | if (drv->rfkill == NULL) { |
| 4181 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 4182 | os_free(rcfg); |
| 4183 | } |
| 4184 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4185 | if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0) |
| 4186 | drv->start_iface_up = 1; |
| 4187 | |
| 4188 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4189 | goto failed; |
| 4190 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4191 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 4192 | if (drv->eapol_tx_sock < 0) |
| 4193 | goto failed; |
| 4194 | |
| 4195 | if (drv->data_tx_status) { |
| 4196 | int enabled = 1; |
| 4197 | |
| 4198 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 4199 | &enabled, sizeof(enabled)) < 0) { |
| 4200 | wpa_printf(MSG_DEBUG, |
| 4201 | "nl80211: wifi status sockopt failed\n"); |
| 4202 | drv->data_tx_status = 0; |
| 4203 | if (!drv->use_monitor) |
| 4204 | drv->capa.flags &= |
| 4205 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 4206 | } else { |
| 4207 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 4208 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 4209 | drv, NULL); |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | if (drv->global) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4214 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4215 | drv->in_interface_list = 1; |
| 4216 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4217 | |
| 4218 | return bss; |
| 4219 | |
| 4220 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4221 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4222 | return NULL; |
| 4223 | } |
| 4224 | |
| 4225 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4226 | /** |
| 4227 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 4228 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 4229 | * e.g., wpa_supplicant_event() |
| 4230 | * @ifname: interface name, e.g., wlan0 |
| 4231 | * @global_priv: private driver global data from global_init() |
| 4232 | * Returns: Pointer to private data, %NULL on failure |
| 4233 | */ |
| 4234 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 4235 | void *global_priv) |
| 4236 | { |
| 4237 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL); |
| 4238 | } |
| 4239 | |
| 4240 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4241 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4242 | struct nl_handle *nl_handle, |
| 4243 | u16 type, const u8 *match, size_t match_len) |
| 4244 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4245 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4246 | struct nl_msg *msg; |
| 4247 | int ret = -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4248 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4249 | |
| 4250 | msg = nlmsg_alloc(); |
| 4251 | if (!msg) |
| 4252 | return -1; |
| 4253 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4254 | buf[0] = '\0'; |
| 4255 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
| 4256 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x nl_handle=%p match=%s", |
| 4257 | type, nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4258 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4259 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_ACTION); |
| 4260 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4261 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 4262 | goto nla_put_failure; |
| 4263 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4264 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, type); |
| 4265 | NLA_PUT(msg, NL80211_ATTR_FRAME_MATCH, match_len, match); |
| 4266 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4267 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4268 | msg = NULL; |
| 4269 | if (ret) { |
| 4270 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 4271 | "failed (type=%u): ret=%d (%s)", |
| 4272 | type, ret, strerror(-ret)); |
| 4273 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 4274 | match, match_len); |
| 4275 | goto nla_put_failure; |
| 4276 | } |
| 4277 | ret = 0; |
| 4278 | nla_put_failure: |
| 4279 | nlmsg_free(msg); |
| 4280 | return ret; |
| 4281 | } |
| 4282 | |
| 4283 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4284 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 4285 | { |
| 4286 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4287 | |
| 4288 | if (bss->nl_mgmt) { |
| 4289 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 4290 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 4291 | return -1; |
| 4292 | } |
| 4293 | |
| 4294 | bss->nl_mgmt = nl_create_handle(drv->nl_cb, "mgmt"); |
| 4295 | if (bss->nl_mgmt == NULL) |
| 4296 | return -1; |
| 4297 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4298 | return 0; |
| 4299 | } |
| 4300 | |
| 4301 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4302 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 4303 | { |
| 4304 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 4305 | wpa_driver_nl80211_event_receive, |
| 4306 | bss->nl_cb); |
| 4307 | } |
| 4308 | |
| 4309 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4310 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4311 | const u8 *match, size_t match_len) |
| 4312 | { |
| 4313 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4314 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4315 | type, match, match_len); |
| 4316 | } |
| 4317 | |
| 4318 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4319 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4320 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4321 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4322 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4323 | |
| 4324 | if (nl80211_alloc_mgmt_handle(bss)) |
| 4325 | return -1; |
| 4326 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 4327 | "handle %p", bss->nl_mgmt); |
| 4328 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4329 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 4330 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 4331 | |
| 4332 | /* register for any AUTH message */ |
| 4333 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 4334 | } |
| 4335 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 4336 | #ifdef CONFIG_INTERWORKING |
| 4337 | /* QoS Map Configure */ |
| 4338 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4339 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 4340 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4341 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4342 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4343 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4344 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4345 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4346 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4347 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4348 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4349 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4350 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4351 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4352 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4353 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4354 | /* Protected GAS Initial Request */ |
| 4355 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 4356 | ret = -1; |
| 4357 | /* Protected GAS Initial Response */ |
| 4358 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 4359 | ret = -1; |
| 4360 | /* Protected GAS Comeback Request */ |
| 4361 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 4362 | ret = -1; |
| 4363 | /* Protected GAS Comeback Response */ |
| 4364 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 4365 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4366 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 4367 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4368 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4369 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4370 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 4371 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4372 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4373 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4374 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4375 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 4376 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4377 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4378 | #endif /* CONFIG_P2P */ |
| 4379 | #ifdef CONFIG_IEEE80211W |
| 4380 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4381 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4382 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4383 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4384 | #ifdef CONFIG_TDLS |
| 4385 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 4386 | /* TDLS Discovery Response */ |
| 4387 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 4388 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4389 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4390 | } |
| 4391 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4392 | |
| 4393 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4394 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4395 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4396 | else |
| 4397 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 4398 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 4399 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4400 | /* WNM - BSS Transition Management Request */ |
| 4401 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4402 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4403 | /* WNM-Sleep Mode Response */ |
| 4404 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4405 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4406 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4407 | #ifdef CONFIG_HS20 |
| 4408 | /* WNM-Notification */ |
| 4409 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
| 4410 | return -1; |
| 4411 | #endif /* CONFIG_HS20 */ |
| 4412 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4413 | nl80211_mgmt_handle_register_eloop(bss); |
| 4414 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4415 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4419 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 4420 | { |
| 4421 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4422 | struct nl_msg *msg; |
| 4423 | int ret = -1; |
| 4424 | |
| 4425 | msg = nlmsg_alloc(); |
| 4426 | if (!msg) |
| 4427 | return -1; |
| 4428 | |
| 4429 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 4430 | |
| 4431 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 4432 | |
| 4433 | ret = send_and_recv(drv->global, bss->nl_mgmt, msg, NULL, NULL); |
| 4434 | msg = NULL; |
| 4435 | if (ret) { |
| 4436 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 4437 | "failed: ret=%d (%s)", |
| 4438 | ret, strerror(-ret)); |
| 4439 | goto nla_put_failure; |
| 4440 | } |
| 4441 | ret = 0; |
| 4442 | nla_put_failure: |
| 4443 | nlmsg_free(msg); |
| 4444 | return ret; |
| 4445 | } |
| 4446 | |
| 4447 | |
| 4448 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 4449 | { |
| 4450 | static const int stypes[] = { |
| 4451 | WLAN_FC_STYPE_AUTH, |
| 4452 | WLAN_FC_STYPE_ASSOC_REQ, |
| 4453 | WLAN_FC_STYPE_REASSOC_REQ, |
| 4454 | WLAN_FC_STYPE_DISASSOC, |
| 4455 | WLAN_FC_STYPE_DEAUTH, |
| 4456 | WLAN_FC_STYPE_ACTION, |
| 4457 | WLAN_FC_STYPE_PROBE_REQ, |
| 4458 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 4459 | * it, but it wouldn't really be the right thing anyway as |
| 4460 | * it isn't per interface ... maybe just dump the scan |
| 4461 | * results periodically for OLBC? |
| 4462 | */ |
| 4463 | // WLAN_FC_STYPE_BEACON, |
| 4464 | }; |
| 4465 | unsigned int i; |
| 4466 | |
| 4467 | if (nl80211_alloc_mgmt_handle(bss)) |
| 4468 | return -1; |
| 4469 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 4470 | "handle %p", bss->nl_mgmt); |
| 4471 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4472 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4473 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 4474 | (WLAN_FC_TYPE_MGMT << 2) | |
| 4475 | (stypes[i] << 4), |
| 4476 | NULL, 0) < 0) { |
| 4477 | goto out_err; |
| 4478 | } |
| 4479 | } |
| 4480 | |
| 4481 | if (nl80211_register_spurious_class3(bss)) |
| 4482 | goto out_err; |
| 4483 | |
| 4484 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 4485 | goto out_err; |
| 4486 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4487 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4488 | return 0; |
| 4489 | |
| 4490 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4491 | nl_destroy_handles(&bss->nl_mgmt); |
| 4492 | return -1; |
| 4493 | } |
| 4494 | |
| 4495 | |
| 4496 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 4497 | { |
| 4498 | if (nl80211_alloc_mgmt_handle(bss)) |
| 4499 | return -1; |
| 4500 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 4501 | "handle %p (device SME)", bss->nl_mgmt); |
| 4502 | |
| 4503 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 4504 | (WLAN_FC_TYPE_MGMT << 2) | |
| 4505 | (WLAN_FC_STYPE_ACTION << 4), |
| 4506 | NULL, 0) < 0) |
| 4507 | goto out_err; |
| 4508 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4509 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4510 | return 0; |
| 4511 | |
| 4512 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4513 | nl_destroy_handles(&bss->nl_mgmt); |
| 4514 | return -1; |
| 4515 | } |
| 4516 | |
| 4517 | |
| 4518 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 4519 | { |
| 4520 | if (bss->nl_mgmt == NULL) |
| 4521 | return; |
| 4522 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 4523 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4524 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4525 | |
| 4526 | nl80211_put_wiphy_data_ap(bss); |
| 4527 | } |
| 4528 | |
| 4529 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4530 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 4531 | { |
| 4532 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 4533 | } |
| 4534 | |
| 4535 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4536 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 4537 | { |
| 4538 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4539 | struct nl_msg *msg; |
| 4540 | int ret; |
| 4541 | |
| 4542 | msg = nlmsg_alloc(); |
| 4543 | if (!msg) |
| 4544 | return; |
| 4545 | |
| 4546 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE); |
| 4547 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 4548 | |
| 4549 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4550 | msg = NULL; |
| 4551 | |
| 4552 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 4553 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4554 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4555 | |
| 4556 | nla_put_failure: |
| 4557 | nlmsg_free(msg); |
| 4558 | } |
| 4559 | |
| 4560 | |
| 4561 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 4562 | { |
| 4563 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4564 | struct nl_msg *msg; |
| 4565 | int ret = -1; |
| 4566 | |
| 4567 | msg = nlmsg_alloc(); |
| 4568 | if (!msg) |
| 4569 | return -1; |
| 4570 | |
| 4571 | if (start) |
| 4572 | nl80211_cmd(drv, msg, 0, NL80211_CMD_START_P2P_DEVICE); |
| 4573 | else |
| 4574 | nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_P2P_DEVICE); |
| 4575 | |
| 4576 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 4577 | |
| 4578 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4579 | msg = NULL; |
| 4580 | |
| 4581 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 4582 | start ? "Start" : "Stop", |
| 4583 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4584 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4585 | |
| 4586 | nla_put_failure: |
| 4587 | nlmsg_free(msg); |
| 4588 | return ret; |
| 4589 | } |
| 4590 | |
| 4591 | |
| 4592 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 4593 | { |
| 4594 | enum nl80211_iftype nlmode; |
| 4595 | |
| 4596 | nlmode = nl80211_get_ifmode(bss); |
| 4597 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 4598 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 4599 | bss->ifname, up); |
| 4600 | } |
| 4601 | |
| 4602 | /* P2P Device has start/stop which is equivalent */ |
| 4603 | return nl80211_set_p2pdev(bss, up); |
| 4604 | } |
| 4605 | |
| 4606 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4607 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4608 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
| 4609 | const u8 *set_addr, int first) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4610 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4611 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4612 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4613 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4614 | |
| 4615 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4616 | bss->ifindex = drv->ifindex; |
| 4617 | bss->wdev_id = drv->global->if_add_wdevid; |
| 4618 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 4619 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4620 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 4621 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4622 | drv->global->if_add_wdevid_set = 0; |
| 4623 | |
| 4624 | if (wpa_driver_nl80211_capa(drv)) |
| 4625 | return -1; |
| 4626 | |
| 4627 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 4628 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4629 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4630 | if (set_addr && |
| 4631 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 4632 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 4633 | set_addr))) |
| 4634 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4635 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4636 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 4637 | drv->start_mode_ap = 1; |
| 4638 | |
| 4639 | if (drv->hostapd) |
| 4640 | nlmode = NL80211_IFTYPE_AP; |
| 4641 | else if (bss->if_dynamic) |
| 4642 | nlmode = nl80211_get_ifmode(bss); |
| 4643 | else |
| 4644 | nlmode = NL80211_IFTYPE_STATION; |
| 4645 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4646 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4647 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4648 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4649 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4650 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4651 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4652 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4653 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4654 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 4655 | int ret = i802_set_iface_flags(bss, 1); |
| 4656 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4657 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 4658 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4659 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4660 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4661 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 4662 | return ret; |
| 4663 | } else { |
| 4664 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 4665 | "interface '%s' due to rfkill", bss->ifname); |
| 4666 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 4667 | return 0; |
| 4668 | drv->if_disabled = 1; |
| 4669 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4672 | if (!drv->hostapd) |
| 4673 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 4674 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4675 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4676 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 4677 | bss->addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4678 | return -1; |
| 4679 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4680 | if (send_rfkill_event) { |
| 4681 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 4682 | drv, drv->ctx); |
| 4683 | } |
| 4684 | |
| 4685 | return 0; |
| 4686 | } |
| 4687 | |
| 4688 | |
| 4689 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 4690 | { |
| 4691 | struct nl_msg *msg; |
| 4692 | |
| 4693 | msg = nlmsg_alloc(); |
| 4694 | if (!msg) |
| 4695 | return -ENOMEM; |
| 4696 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4697 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 4698 | drv->ifindex); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4699 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4700 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 4701 | |
| 4702 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4703 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4704 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4705 | return -ENOBUFS; |
| 4706 | } |
| 4707 | |
| 4708 | |
| 4709 | /** |
| 4710 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4711 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4712 | * |
| 4713 | * Shut down driver interface and processing of driver events. Free |
| 4714 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 4715 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4716 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4717 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4718 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4719 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4720 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4721 | if (drv->data_tx_status) |
| 4722 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 4723 | if (drv->eapol_tx_sock >= 0) |
| 4724 | close(drv->eapol_tx_sock); |
| 4725 | |
| 4726 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4727 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4728 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4729 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 4730 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4731 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 4732 | "interface %s from bridge %s: %s", |
| 4733 | bss->ifname, bss->brname, strerror(errno)); |
| 4734 | } |
| 4735 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4736 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4737 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 4738 | "bridge %s: %s", |
| 4739 | bss->brname, strerror(errno)); |
| 4740 | } |
| 4741 | |
| 4742 | nl80211_remove_monitor_interface(drv); |
| 4743 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4744 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4745 | wpa_driver_nl80211_del_beacon(drv); |
| 4746 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4747 | if (drv->eapol_sock >= 0) { |
| 4748 | eloop_unregister_read_sock(drv->eapol_sock); |
| 4749 | close(drv->eapol_sock); |
| 4750 | } |
| 4751 | |
| 4752 | if (drv->if_indices != drv->default_if_indices) |
| 4753 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4754 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4755 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4756 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 4757 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4758 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 4759 | IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4760 | rfkill_deinit(drv->rfkill); |
| 4761 | |
| 4762 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 4763 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4764 | if (!drv->start_iface_up) |
| 4765 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4766 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4767 | if (!drv->hostapd || !drv->start_mode_ap) |
| 4768 | wpa_driver_nl80211_set_mode(bss, |
| 4769 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4770 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4771 | } else { |
| 4772 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 4773 | nl80211_del_p2pdev(bss); |
| 4774 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4775 | nl_cb_put(drv->nl_cb); |
| 4776 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4777 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4778 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4779 | os_free(drv->filter_ssids); |
| 4780 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4781 | os_free(drv->auth_ie); |
| 4782 | |
| 4783 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4784 | dl_list_del(&drv->list); |
| 4785 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 4786 | os_free(drv->extended_capa); |
| 4787 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4788 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4789 | os_free(drv); |
| 4790 | } |
| 4791 | |
| 4792 | |
| 4793 | /** |
| 4794 | * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion |
| 4795 | * @eloop_ctx: Driver private data |
| 4796 | * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init() |
| 4797 | * |
| 4798 | * This function can be used as registered timeout when starting a scan to |
| 4799 | * generate a scan completed event if the driver does not report this. |
| 4800 | */ |
| 4801 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
| 4802 | { |
| 4803 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4804 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4805 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4806 | drv->ap_scan_as_station); |
| 4807 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4808 | } |
| 4809 | wpa_printf(MSG_DEBUG, "Scan timeout - try to get results"); |
| 4810 | wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL); |
| 4811 | } |
| 4812 | |
| 4813 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4814 | static struct nl_msg * |
| 4815 | nl80211_scan_common(struct wpa_driver_nl80211_data *drv, u8 cmd, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4816 | struct wpa_driver_scan_params *params, u64 *wdev_id) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4817 | { |
| 4818 | struct nl_msg *msg; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4819 | size_t i; |
| 4820 | |
| 4821 | msg = nlmsg_alloc(); |
| 4822 | if (!msg) |
| 4823 | return NULL; |
| 4824 | |
| 4825 | nl80211_cmd(drv, msg, 0, cmd); |
| 4826 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4827 | if (!wdev_id) |
| 4828 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 4829 | else |
| 4830 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, *wdev_id); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4831 | |
| 4832 | if (params->num_ssids) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4833 | struct nlattr *ssids; |
| 4834 | |
| 4835 | ssids = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4836 | if (ssids == NULL) |
| 4837 | goto fail; |
| 4838 | for (i = 0; i < params->num_ssids; i++) { |
| 4839 | wpa_hexdump_ascii(MSG_MSGDUMP, "nl80211: Scan SSID", |
| 4840 | params->ssids[i].ssid, |
| 4841 | params->ssids[i].ssid_len); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4842 | if (nla_put(msg, i + 1, params->ssids[i].ssid_len, |
| 4843 | params->ssids[i].ssid) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4844 | goto fail; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4845 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4846 | nla_nest_end(msg, ssids); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | if (params->extra_ies) { |
| 4850 | wpa_hexdump(MSG_MSGDUMP, "nl80211: Scan extra IEs", |
| 4851 | params->extra_ies, params->extra_ies_len); |
| 4852 | if (nla_put(msg, NL80211_ATTR_IE, params->extra_ies_len, |
| 4853 | params->extra_ies) < 0) |
| 4854 | goto fail; |
| 4855 | } |
| 4856 | |
| 4857 | if (params->freqs) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4858 | struct nlattr *freqs; |
| 4859 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4860 | if (freqs == NULL) |
| 4861 | goto fail; |
| 4862 | for (i = 0; params->freqs[i]; i++) { |
| 4863 | wpa_printf(MSG_MSGDUMP, "nl80211: Scan frequency %u " |
| 4864 | "MHz", params->freqs[i]); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4865 | if (nla_put_u32(msg, i + 1, params->freqs[i]) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4866 | goto fail; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4867 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4868 | nla_nest_end(msg, freqs); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | os_free(drv->filter_ssids); |
| 4872 | drv->filter_ssids = params->filter_ssids; |
| 4873 | params->filter_ssids = NULL; |
| 4874 | drv->num_filter_ssids = params->num_filter_ssids; |
| 4875 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4876 | if (params->only_new_results) { |
| 4877 | wpa_printf(MSG_DEBUG, "nl80211: Add NL80211_SCAN_FLAG_FLUSH"); |
| 4878 | NLA_PUT_U32(msg, NL80211_ATTR_SCAN_FLAGS, |
| 4879 | NL80211_SCAN_FLAG_FLUSH); |
| 4880 | } |
| 4881 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4882 | return msg; |
| 4883 | |
| 4884 | fail: |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4885 | nla_put_failure: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4886 | nlmsg_free(msg); |
| 4887 | return NULL; |
| 4888 | } |
| 4889 | |
| 4890 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4891 | /** |
| 4892 | * wpa_driver_nl80211_scan - Request the driver to initiate scan |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4893 | * @bss: Pointer to private driver data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4894 | * @params: Scan parameters |
| 4895 | * Returns: 0 on success, -1 on failure |
| 4896 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4897 | static int wpa_driver_nl80211_scan(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4898 | struct wpa_driver_scan_params *params) |
| 4899 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4900 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4901 | int ret = -1, timeout; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4902 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4903 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4904 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: scan request"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4905 | drv->scan_for_auth = 0; |
| 4906 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4907 | msg = nl80211_scan_common(drv, NL80211_CMD_TRIGGER_SCAN, params, |
| 4908 | bss->wdev_id_set ? &bss->wdev_id : NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4909 | if (!msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4910 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4911 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4912 | if (params->p2p_probe) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4913 | struct nlattr *rates; |
| 4914 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4915 | wpa_printf(MSG_DEBUG, "nl80211: P2P probe - mask SuppRates"); |
| 4916 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4917 | rates = nla_nest_start(msg, NL80211_ATTR_SCAN_SUPP_RATES); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4918 | if (rates == NULL) |
| 4919 | goto nla_put_failure; |
| 4920 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4921 | /* |
| 4922 | * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates |
| 4923 | * by masking out everything else apart from the OFDM rates 6, |
| 4924 | * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz |
| 4925 | * rates are left enabled. |
| 4926 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4927 | NLA_PUT(msg, NL80211_BAND_2GHZ, 8, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4928 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4929 | nla_nest_end(msg, rates); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4930 | |
| 4931 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); |
| 4932 | } |
| 4933 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4934 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4935 | msg = NULL; |
| 4936 | if (ret) { |
| 4937 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger failed: ret=%d " |
| 4938 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4939 | if (drv->hostapd && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 4940 | enum nl80211_iftype old_mode = drv->nlmode; |
| 4941 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4942 | /* |
| 4943 | * mac80211 does not allow scan requests in AP mode, so |
| 4944 | * try to do this in station mode. |
| 4945 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4946 | if (wpa_driver_nl80211_set_mode( |
| 4947 | bss, NL80211_IFTYPE_STATION)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4948 | goto nla_put_failure; |
| 4949 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4950 | if (wpa_driver_nl80211_scan(bss, params)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4951 | wpa_driver_nl80211_set_mode(bss, drv->nlmode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4952 | goto nla_put_failure; |
| 4953 | } |
| 4954 | |
| 4955 | /* Restore AP mode when processing scan results */ |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 4956 | drv->ap_scan_as_station = old_mode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4957 | ret = 0; |
| 4958 | } else |
| 4959 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4960 | } |
| 4961 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4962 | drv->scan_state = SCAN_REQUESTED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4963 | /* Not all drivers generate "scan completed" wireless event, so try to |
| 4964 | * read results after a timeout. */ |
| 4965 | timeout = 10; |
| 4966 | if (drv->scan_complete_events) { |
| 4967 | /* |
| 4968 | * The driver seems to deliver events to notify when scan is |
| 4969 | * complete, so use longer timeout to avoid race conditions |
| 4970 | * with scanning and following association request. |
| 4971 | */ |
| 4972 | timeout = 30; |
| 4973 | } |
| 4974 | wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d " |
| 4975 | "seconds", ret, timeout); |
| 4976 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 4977 | eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout, |
| 4978 | drv, drv->ctx); |
| 4979 | |
| 4980 | nla_put_failure: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4981 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4982 | return ret; |
| 4983 | } |
| 4984 | |
| 4985 | |
| 4986 | /** |
| 4987 | * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan |
| 4988 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 4989 | * @params: Scan parameters |
| 4990 | * @interval: Interval between scan cycles in milliseconds |
| 4991 | * Returns: 0 on success, -1 on failure or if not supported |
| 4992 | */ |
| 4993 | static int wpa_driver_nl80211_sched_scan(void *priv, |
| 4994 | struct wpa_driver_scan_params *params, |
| 4995 | u32 interval) |
| 4996 | { |
| 4997 | struct i802_bss *bss = priv; |
| 4998 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4999 | int ret = -1; |
| 5000 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5001 | size_t i; |
| 5002 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 5003 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: sched_scan request"); |
| 5004 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5005 | #ifdef ANDROID |
| 5006 | if (!drv->capa.sched_scan_supported) |
| 5007 | return android_pno_start(bss, params); |
| 5008 | #endif /* ANDROID */ |
| 5009 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5010 | msg = nl80211_scan_common(drv, NL80211_CMD_START_SCHED_SCAN, params, |
| 5011 | bss->wdev_id_set ? &bss->wdev_id : NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5012 | if (!msg) |
| 5013 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5014 | |
| 5015 | NLA_PUT_U32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, interval); |
| 5016 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5017 | if ((drv->num_filter_ssids && |
| 5018 | (int) drv->num_filter_ssids <= drv->capa.max_match_sets) || |
| 5019 | params->filter_rssi) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5020 | struct nlattr *match_sets; |
| 5021 | match_sets = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5022 | if (match_sets == NULL) |
| 5023 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5024 | |
| 5025 | for (i = 0; i < drv->num_filter_ssids; i++) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5026 | struct nlattr *match_set_ssid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5027 | wpa_hexdump_ascii(MSG_MSGDUMP, |
| 5028 | "nl80211: Sched scan filter SSID", |
| 5029 | drv->filter_ssids[i].ssid, |
| 5030 | drv->filter_ssids[i].ssid_len); |
| 5031 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5032 | match_set_ssid = nla_nest_start(msg, i + 1); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5033 | if (match_set_ssid == NULL) |
| 5034 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5035 | NLA_PUT(msg, NL80211_ATTR_SCHED_SCAN_MATCH_SSID, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5036 | drv->filter_ssids[i].ssid_len, |
| 5037 | drv->filter_ssids[i].ssid); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 5038 | if (params->filter_rssi) |
| 5039 | NLA_PUT_U32(msg, |
| 5040 | NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, |
| 5041 | params->filter_rssi); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5042 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5043 | nla_nest_end(msg, match_set_ssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5044 | } |
| 5045 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 5046 | /* |
| 5047 | * Due to backward compatibility code, newer kernels treat this |
| 5048 | * matchset (with only an RSSI filter) as the default for all |
| 5049 | * other matchsets, unless it's the only one, in which case the |
| 5050 | * matchset will actually allow all SSIDs above the RSSI. |
| 5051 | */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5052 | if (params->filter_rssi) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5053 | struct nlattr *match_set_rssi; |
| 5054 | match_set_rssi = nla_nest_start(msg, 0); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5055 | if (match_set_rssi == NULL) |
| 5056 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5057 | NLA_PUT_U32(msg, NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5058 | params->filter_rssi); |
| 5059 | wpa_printf(MSG_MSGDUMP, |
| 5060 | "nl80211: Sched scan RSSI filter %d dBm", |
| 5061 | params->filter_rssi); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5062 | nla_nest_end(msg, match_set_rssi); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5063 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5064 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5065 | nla_nest_end(msg, match_sets); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5066 | } |
| 5067 | |
| 5068 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5069 | |
| 5070 | /* TODO: if we get an error here, we should fall back to normal scan */ |
| 5071 | |
| 5072 | msg = NULL; |
| 5073 | if (ret) { |
| 5074 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan start failed: " |
| 5075 | "ret=%d (%s)", ret, strerror(-ret)); |
| 5076 | goto nla_put_failure; |
| 5077 | } |
| 5078 | |
| 5079 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan requested (ret=%d) - " |
| 5080 | "scan interval %d msec", ret, interval); |
| 5081 | |
| 5082 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5083 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5084 | return ret; |
| 5085 | } |
| 5086 | |
| 5087 | |
| 5088 | /** |
| 5089 | * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan |
| 5090 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 5091 | * Returns: 0 on success, -1 on failure or if not supported |
| 5092 | */ |
| 5093 | static int wpa_driver_nl80211_stop_sched_scan(void *priv) |
| 5094 | { |
| 5095 | struct i802_bss *bss = priv; |
| 5096 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5097 | int ret = 0; |
| 5098 | struct nl_msg *msg; |
| 5099 | |
| 5100 | #ifdef ANDROID |
| 5101 | if (!drv->capa.sched_scan_supported) |
| 5102 | return android_pno_stop(bss); |
| 5103 | #endif /* ANDROID */ |
| 5104 | |
| 5105 | msg = nlmsg_alloc(); |
| 5106 | if (!msg) |
| 5107 | return -1; |
| 5108 | |
| 5109 | nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_SCHED_SCAN); |
| 5110 | |
| 5111 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 5112 | |
| 5113 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5114 | msg = NULL; |
| 5115 | if (ret) { |
| 5116 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop failed: " |
| 5117 | "ret=%d (%s)", ret, strerror(-ret)); |
| 5118 | goto nla_put_failure; |
| 5119 | } |
| 5120 | |
| 5121 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop sent (ret=%d)", ret); |
| 5122 | |
| 5123 | nla_put_failure: |
| 5124 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5125 | return ret; |
| 5126 | } |
| 5127 | |
| 5128 | |
| 5129 | static const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie) |
| 5130 | { |
| 5131 | const u8 *end, *pos; |
| 5132 | |
| 5133 | if (ies == NULL) |
| 5134 | return NULL; |
| 5135 | |
| 5136 | pos = ies; |
| 5137 | end = ies + ies_len; |
| 5138 | |
| 5139 | while (pos + 1 < end) { |
| 5140 | if (pos + 2 + pos[1] > end) |
| 5141 | break; |
| 5142 | if (pos[0] == ie) |
| 5143 | return pos; |
| 5144 | pos += 2 + pos[1]; |
| 5145 | } |
| 5146 | |
| 5147 | return NULL; |
| 5148 | } |
| 5149 | |
| 5150 | |
| 5151 | static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv, |
| 5152 | const u8 *ie, size_t ie_len) |
| 5153 | { |
| 5154 | const u8 *ssid; |
| 5155 | size_t i; |
| 5156 | |
| 5157 | if (drv->filter_ssids == NULL) |
| 5158 | return 0; |
| 5159 | |
| 5160 | ssid = nl80211_get_ie(ie, ie_len, WLAN_EID_SSID); |
| 5161 | if (ssid == NULL) |
| 5162 | return 1; |
| 5163 | |
| 5164 | for (i = 0; i < drv->num_filter_ssids; i++) { |
| 5165 | if (ssid[1] == drv->filter_ssids[i].ssid_len && |
| 5166 | os_memcmp(ssid + 2, drv->filter_ssids[i].ssid, ssid[1]) == |
| 5167 | 0) |
| 5168 | return 0; |
| 5169 | } |
| 5170 | |
| 5171 | return 1; |
| 5172 | } |
| 5173 | |
| 5174 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5175 | static int bss_info_handler(struct nl_msg *msg, void *arg) |
| 5176 | { |
| 5177 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5178 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5179 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 5180 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 5181 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 5182 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 5183 | [NL80211_BSS_TSF] = { .type = NLA_U64 }, |
| 5184 | [NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 }, |
| 5185 | [NL80211_BSS_CAPABILITY] = { .type = NLA_U16 }, |
| 5186 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 5187 | [NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 }, |
| 5188 | [NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 }, |
| 5189 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 5190 | [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 }, |
| 5191 | [NL80211_BSS_BEACON_IES] = { .type = NLA_UNSPEC }, |
| 5192 | }; |
| 5193 | struct nl80211_bss_info_arg *_arg = arg; |
| 5194 | struct wpa_scan_results *res = _arg->res; |
| 5195 | struct wpa_scan_res **tmp; |
| 5196 | struct wpa_scan_res *r; |
| 5197 | const u8 *ie, *beacon_ie; |
| 5198 | size_t ie_len, beacon_ie_len; |
| 5199 | u8 *pos; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5200 | size_t i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5201 | |
| 5202 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5203 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5204 | if (!tb[NL80211_ATTR_BSS]) |
| 5205 | return NL_SKIP; |
| 5206 | if (nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 5207 | bss_policy)) |
| 5208 | return NL_SKIP; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5209 | if (bss[NL80211_BSS_STATUS]) { |
| 5210 | enum nl80211_bss_status status; |
| 5211 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 5212 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 5213 | bss[NL80211_BSS_FREQUENCY]) { |
| 5214 | _arg->assoc_freq = |
| 5215 | nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 5216 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 5217 | _arg->assoc_freq); |
| 5218 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5219 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 5220 | bss[NL80211_BSS_BSSID]) { |
| 5221 | os_memcpy(_arg->assoc_bssid, |
| 5222 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 5223 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 5224 | MACSTR, MAC2STR(_arg->assoc_bssid)); |
| 5225 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5226 | } |
| 5227 | if (!res) |
| 5228 | return NL_SKIP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5229 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 5230 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 5231 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 5232 | } else { |
| 5233 | ie = NULL; |
| 5234 | ie_len = 0; |
| 5235 | } |
| 5236 | if (bss[NL80211_BSS_BEACON_IES]) { |
| 5237 | beacon_ie = nla_data(bss[NL80211_BSS_BEACON_IES]); |
| 5238 | beacon_ie_len = nla_len(bss[NL80211_BSS_BEACON_IES]); |
| 5239 | } else { |
| 5240 | beacon_ie = NULL; |
| 5241 | beacon_ie_len = 0; |
| 5242 | } |
| 5243 | |
| 5244 | if (nl80211_scan_filtered(_arg->drv, ie ? ie : beacon_ie, |
| 5245 | ie ? ie_len : beacon_ie_len)) |
| 5246 | return NL_SKIP; |
| 5247 | |
| 5248 | r = os_zalloc(sizeof(*r) + ie_len + beacon_ie_len); |
| 5249 | if (r == NULL) |
| 5250 | return NL_SKIP; |
| 5251 | if (bss[NL80211_BSS_BSSID]) |
| 5252 | os_memcpy(r->bssid, nla_data(bss[NL80211_BSS_BSSID]), |
| 5253 | ETH_ALEN); |
| 5254 | if (bss[NL80211_BSS_FREQUENCY]) |
| 5255 | r->freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 5256 | if (bss[NL80211_BSS_BEACON_INTERVAL]) |
| 5257 | r->beacon_int = nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]); |
| 5258 | if (bss[NL80211_BSS_CAPABILITY]) |
| 5259 | r->caps = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); |
| 5260 | r->flags |= WPA_SCAN_NOISE_INVALID; |
| 5261 | if (bss[NL80211_BSS_SIGNAL_MBM]) { |
| 5262 | r->level = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]); |
| 5263 | r->level /= 100; /* mBm to dBm */ |
| 5264 | r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID; |
| 5265 | } else if (bss[NL80211_BSS_SIGNAL_UNSPEC]) { |
| 5266 | r->level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5267 | r->flags |= WPA_SCAN_QUAL_INVALID; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5268 | } else |
| 5269 | r->flags |= WPA_SCAN_LEVEL_INVALID | WPA_SCAN_QUAL_INVALID; |
| 5270 | if (bss[NL80211_BSS_TSF]) |
| 5271 | r->tsf = nla_get_u64(bss[NL80211_BSS_TSF]); |
| 5272 | if (bss[NL80211_BSS_SEEN_MS_AGO]) |
| 5273 | r->age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); |
| 5274 | r->ie_len = ie_len; |
| 5275 | pos = (u8 *) (r + 1); |
| 5276 | if (ie) { |
| 5277 | os_memcpy(pos, ie, ie_len); |
| 5278 | pos += ie_len; |
| 5279 | } |
| 5280 | r->beacon_ie_len = beacon_ie_len; |
| 5281 | if (beacon_ie) |
| 5282 | os_memcpy(pos, beacon_ie, beacon_ie_len); |
| 5283 | |
| 5284 | if (bss[NL80211_BSS_STATUS]) { |
| 5285 | enum nl80211_bss_status status; |
| 5286 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 5287 | switch (status) { |
| 5288 | case NL80211_BSS_STATUS_AUTHENTICATED: |
| 5289 | r->flags |= WPA_SCAN_AUTHENTICATED; |
| 5290 | break; |
| 5291 | case NL80211_BSS_STATUS_ASSOCIATED: |
| 5292 | r->flags |= WPA_SCAN_ASSOCIATED; |
| 5293 | break; |
| 5294 | default: |
| 5295 | break; |
| 5296 | } |
| 5297 | } |
| 5298 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5299 | /* |
| 5300 | * cfg80211 maintains separate BSS table entries for APs if the same |
| 5301 | * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does |
| 5302 | * not use frequency as a separate key in the BSS table, so filter out |
| 5303 | * duplicated entries. Prefer associated BSS entry in such a case in |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5304 | * order to get the correct frequency into the BSS table. Similarly, |
| 5305 | * prefer newer entries over older. |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5306 | */ |
| 5307 | for (i = 0; i < res->num; i++) { |
| 5308 | const u8 *s1, *s2; |
| 5309 | if (os_memcmp(res->res[i]->bssid, r->bssid, ETH_ALEN) != 0) |
| 5310 | continue; |
| 5311 | |
| 5312 | s1 = nl80211_get_ie((u8 *) (res->res[i] + 1), |
| 5313 | res->res[i]->ie_len, WLAN_EID_SSID); |
| 5314 | s2 = nl80211_get_ie((u8 *) (r + 1), r->ie_len, WLAN_EID_SSID); |
| 5315 | if (s1 == NULL || s2 == NULL || s1[1] != s2[1] || |
| 5316 | os_memcmp(s1, s2, 2 + s1[1]) != 0) |
| 5317 | continue; |
| 5318 | |
| 5319 | /* Same BSSID,SSID was already included in scan results */ |
| 5320 | wpa_printf(MSG_DEBUG, "nl80211: Remove duplicated scan result " |
| 5321 | "for " MACSTR, MAC2STR(r->bssid)); |
| 5322 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5323 | if (((r->flags & WPA_SCAN_ASSOCIATED) && |
| 5324 | !(res->res[i]->flags & WPA_SCAN_ASSOCIATED)) || |
| 5325 | r->age < res->res[i]->age) { |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5326 | os_free(res->res[i]); |
| 5327 | res->res[i] = r; |
| 5328 | } else |
| 5329 | os_free(r); |
| 5330 | return NL_SKIP; |
| 5331 | } |
| 5332 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5333 | tmp = os_realloc_array(res->res, res->num + 1, |
| 5334 | sizeof(struct wpa_scan_res *)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5335 | if (tmp == NULL) { |
| 5336 | os_free(r); |
| 5337 | return NL_SKIP; |
| 5338 | } |
| 5339 | tmp[res->num++] = r; |
| 5340 | res->res = tmp; |
| 5341 | |
| 5342 | return NL_SKIP; |
| 5343 | } |
| 5344 | |
| 5345 | |
| 5346 | static void clear_state_mismatch(struct wpa_driver_nl80211_data *drv, |
| 5347 | const u8 *addr) |
| 5348 | { |
| 5349 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 5350 | wpa_printf(MSG_DEBUG, "nl80211: Clear possible state " |
| 5351 | "mismatch (" MACSTR ")", MAC2STR(addr)); |
| 5352 | wpa_driver_nl80211_mlme(drv, addr, |
| 5353 | NL80211_CMD_DEAUTHENTICATE, |
| 5354 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1); |
| 5355 | } |
| 5356 | } |
| 5357 | |
| 5358 | |
| 5359 | static void wpa_driver_nl80211_check_bss_status( |
| 5360 | struct wpa_driver_nl80211_data *drv, struct wpa_scan_results *res) |
| 5361 | { |
| 5362 | size_t i; |
| 5363 | |
| 5364 | for (i = 0; i < res->num; i++) { |
| 5365 | struct wpa_scan_res *r = res->res[i]; |
| 5366 | if (r->flags & WPA_SCAN_AUTHENTICATED) { |
| 5367 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " |
| 5368 | "indicates BSS status with " MACSTR |
| 5369 | " as authenticated", |
| 5370 | MAC2STR(r->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5371 | if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5372 | os_memcmp(r->bssid, drv->bssid, ETH_ALEN) != 0 && |
| 5373 | os_memcmp(r->bssid, drv->auth_bssid, ETH_ALEN) != |
| 5374 | 0) { |
| 5375 | wpa_printf(MSG_DEBUG, "nl80211: Unknown BSSID" |
| 5376 | " in local state (auth=" MACSTR |
| 5377 | " assoc=" MACSTR ")", |
| 5378 | MAC2STR(drv->auth_bssid), |
| 5379 | MAC2STR(drv->bssid)); |
| 5380 | clear_state_mismatch(drv, r->bssid); |
| 5381 | } |
| 5382 | } |
| 5383 | |
| 5384 | if (r->flags & WPA_SCAN_ASSOCIATED) { |
| 5385 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " |
| 5386 | "indicate BSS status with " MACSTR |
| 5387 | " as associated", |
| 5388 | MAC2STR(r->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5389 | if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5390 | !drv->associated) { |
| 5391 | wpa_printf(MSG_DEBUG, "nl80211: Local state " |
| 5392 | "(not associated) does not match " |
| 5393 | "with BSS state"); |
| 5394 | clear_state_mismatch(drv, r->bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5395 | } else if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5396 | os_memcmp(drv->bssid, r->bssid, ETH_ALEN) != |
| 5397 | 0) { |
| 5398 | wpa_printf(MSG_DEBUG, "nl80211: Local state " |
| 5399 | "(associated with " MACSTR ") does " |
| 5400 | "not match with BSS state", |
| 5401 | MAC2STR(drv->bssid)); |
| 5402 | clear_state_mismatch(drv, r->bssid); |
| 5403 | clear_state_mismatch(drv, drv->bssid); |
| 5404 | } |
| 5405 | } |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5410 | static struct wpa_scan_results * |
| 5411 | nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv) |
| 5412 | { |
| 5413 | struct nl_msg *msg; |
| 5414 | struct wpa_scan_results *res; |
| 5415 | int ret; |
| 5416 | struct nl80211_bss_info_arg arg; |
| 5417 | |
| 5418 | res = os_zalloc(sizeof(*res)); |
| 5419 | if (res == NULL) |
| 5420 | return NULL; |
| 5421 | msg = nlmsg_alloc(); |
| 5422 | if (!msg) |
| 5423 | goto nla_put_failure; |
| 5424 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5425 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5426 | if (nl80211_set_iface_id(msg, drv->first_bss) < 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5427 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5428 | |
| 5429 | arg.drv = drv; |
| 5430 | arg.res = res; |
| 5431 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
| 5432 | msg = NULL; |
| 5433 | if (ret == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5434 | wpa_printf(MSG_DEBUG, "nl80211: Received scan results (%lu " |
| 5435 | "BSSes)", (unsigned long) res->num); |
| 5436 | nl80211_get_noise_for_scan_results(drv, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5437 | return res; |
| 5438 | } |
| 5439 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 5440 | "(%s)", ret, strerror(-ret)); |
| 5441 | nla_put_failure: |
| 5442 | nlmsg_free(msg); |
| 5443 | wpa_scan_results_free(res); |
| 5444 | return NULL; |
| 5445 | } |
| 5446 | |
| 5447 | |
| 5448 | /** |
| 5449 | * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results |
| 5450 | * @priv: Pointer to private wext data from wpa_driver_nl80211_init() |
| 5451 | * Returns: Scan results on success, -1 on failure |
| 5452 | */ |
| 5453 | static struct wpa_scan_results * |
| 5454 | wpa_driver_nl80211_get_scan_results(void *priv) |
| 5455 | { |
| 5456 | struct i802_bss *bss = priv; |
| 5457 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5458 | struct wpa_scan_results *res; |
| 5459 | |
| 5460 | res = nl80211_get_scan_results(drv); |
| 5461 | if (res) |
| 5462 | wpa_driver_nl80211_check_bss_status(drv, res); |
| 5463 | return res; |
| 5464 | } |
| 5465 | |
| 5466 | |
| 5467 | static void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv) |
| 5468 | { |
| 5469 | struct wpa_scan_results *res; |
| 5470 | size_t i; |
| 5471 | |
| 5472 | res = nl80211_get_scan_results(drv); |
| 5473 | if (res == NULL) { |
| 5474 | wpa_printf(MSG_DEBUG, "nl80211: Failed to get scan results"); |
| 5475 | return; |
| 5476 | } |
| 5477 | |
| 5478 | wpa_printf(MSG_DEBUG, "nl80211: Scan result dump"); |
| 5479 | for (i = 0; i < res->num; i++) { |
| 5480 | struct wpa_scan_res *r = res->res[i]; |
| 5481 | wpa_printf(MSG_DEBUG, "nl80211: %d/%d " MACSTR "%s%s", |
| 5482 | (int) i, (int) res->num, MAC2STR(r->bssid), |
| 5483 | r->flags & WPA_SCAN_AUTHENTICATED ? " [auth]" : "", |
| 5484 | r->flags & WPA_SCAN_ASSOCIATED ? " [assoc]" : ""); |
| 5485 | } |
| 5486 | |
| 5487 | wpa_scan_results_free(res); |
| 5488 | } |
| 5489 | |
| 5490 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5491 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 5492 | { |
| 5493 | switch (alg) { |
| 5494 | case WPA_ALG_WEP: |
| 5495 | if (key_len == 5) |
| 5496 | return WLAN_CIPHER_SUITE_WEP40; |
| 5497 | return WLAN_CIPHER_SUITE_WEP104; |
| 5498 | case WPA_ALG_TKIP: |
| 5499 | return WLAN_CIPHER_SUITE_TKIP; |
| 5500 | case WPA_ALG_CCMP: |
| 5501 | return WLAN_CIPHER_SUITE_CCMP; |
| 5502 | case WPA_ALG_GCMP: |
| 5503 | return WLAN_CIPHER_SUITE_GCMP; |
| 5504 | case WPA_ALG_CCMP_256: |
| 5505 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 5506 | case WPA_ALG_GCMP_256: |
| 5507 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 5508 | case WPA_ALG_IGTK: |
| 5509 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 5510 | case WPA_ALG_BIP_GMAC_128: |
| 5511 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 5512 | case WPA_ALG_BIP_GMAC_256: |
| 5513 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 5514 | case WPA_ALG_BIP_CMAC_256: |
| 5515 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 5516 | case WPA_ALG_SMS4: |
| 5517 | return WLAN_CIPHER_SUITE_SMS4; |
| 5518 | case WPA_ALG_KRK: |
| 5519 | return WLAN_CIPHER_SUITE_KRK; |
| 5520 | case WPA_ALG_NONE: |
| 5521 | case WPA_ALG_PMK: |
| 5522 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 5523 | alg); |
| 5524 | return 0; |
| 5525 | } |
| 5526 | |
| 5527 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 5528 | alg); |
| 5529 | return 0; |
| 5530 | } |
| 5531 | |
| 5532 | |
| 5533 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 5534 | { |
| 5535 | switch (cipher) { |
| 5536 | case WPA_CIPHER_CCMP_256: |
| 5537 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 5538 | case WPA_CIPHER_GCMP_256: |
| 5539 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 5540 | case WPA_CIPHER_CCMP: |
| 5541 | return WLAN_CIPHER_SUITE_CCMP; |
| 5542 | case WPA_CIPHER_GCMP: |
| 5543 | return WLAN_CIPHER_SUITE_GCMP; |
| 5544 | case WPA_CIPHER_TKIP: |
| 5545 | return WLAN_CIPHER_SUITE_TKIP; |
| 5546 | case WPA_CIPHER_WEP104: |
| 5547 | return WLAN_CIPHER_SUITE_WEP104; |
| 5548 | case WPA_CIPHER_WEP40: |
| 5549 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5550 | case WPA_CIPHER_GTK_NOT_USED: |
| 5551 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | return 0; |
| 5555 | } |
| 5556 | |
| 5557 | |
| 5558 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 5559 | int max_suites) |
| 5560 | { |
| 5561 | int num_suites = 0; |
| 5562 | |
| 5563 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 5564 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 5565 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 5566 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 5567 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 5568 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 5569 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 5570 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 5571 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 5572 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 5573 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 5574 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 5575 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 5576 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 5577 | |
| 5578 | return num_suites; |
| 5579 | } |
| 5580 | |
| 5581 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5582 | 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] | 5583 | enum wpa_alg alg, const u8 *addr, |
| 5584 | int key_idx, int set_tx, |
| 5585 | const u8 *seq, size_t seq_len, |
| 5586 | const u8 *key, size_t key_len) |
| 5587 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5588 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5589 | int ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5590 | struct nl_msg *msg; |
| 5591 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5592 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5593 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5594 | /* Ignore for P2P Device */ |
| 5595 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 5596 | return 0; |
| 5597 | |
| 5598 | ifindex = if_nametoindex(ifname); |
| 5599 | 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] | 5600 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5601 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5602 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5603 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5604 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5605 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5606 | tdls = 1; |
| 5607 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5608 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5609 | |
| 5610 | msg = nlmsg_alloc(); |
| 5611 | if (!msg) |
| 5612 | return -ENOMEM; |
| 5613 | |
| 5614 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5615 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5616 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5617 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5618 | NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 5619 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5620 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 5621 | wpa_alg_to_cipher_suite(alg, key_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5622 | } |
| 5623 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 5624 | if (seq && seq_len) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5625 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 5626 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 5627 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5628 | |
| 5629 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 5630 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
| 5631 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5632 | |
| 5633 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 5634 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
| 5635 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, |
| 5636 | NL80211_KEYTYPE_GROUP); |
| 5637 | } |
| 5638 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5639 | struct nlattr *types; |
| 5640 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5641 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5642 | |
| 5643 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5644 | if (!types) |
| 5645 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5646 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST); |
| 5647 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5648 | } |
| 5649 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 5650 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 5651 | |
| 5652 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5653 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 5654 | ret = 0; |
| 5655 | if (ret) |
| 5656 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 5657 | ret, strerror(-ret)); |
| 5658 | |
| 5659 | /* |
| 5660 | * If we failed or don't need to set the default TX key (below), |
| 5661 | * we're done here. |
| 5662 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5663 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5664 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5665 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5666 | !is_broadcast_ether_addr(addr)) |
| 5667 | return ret; |
| 5668 | |
| 5669 | msg = nlmsg_alloc(); |
| 5670 | if (!msg) |
| 5671 | return -ENOMEM; |
| 5672 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5673 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5674 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 5675 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 5676 | if (alg == WPA_ALG_IGTK) |
| 5677 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT); |
| 5678 | else |
| 5679 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT); |
| 5680 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5681 | struct nlattr *types; |
| 5682 | |
| 5683 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5684 | if (!types) |
| 5685 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5686 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST); |
| 5687 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5688 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5689 | struct nlattr *types; |
| 5690 | |
| 5691 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5692 | if (!types) |
| 5693 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5694 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST); |
| 5695 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5699 | if (ret == -ENOENT) |
| 5700 | ret = 0; |
| 5701 | if (ret) |
| 5702 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 5703 | "err=%d %s)", ret, strerror(-ret)); |
| 5704 | return ret; |
| 5705 | |
| 5706 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5707 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5708 | return -ENOBUFS; |
| 5709 | } |
| 5710 | |
| 5711 | |
| 5712 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 5713 | int key_idx, int defkey, |
| 5714 | const u8 *seq, size_t seq_len, |
| 5715 | const u8 *key, size_t key_len) |
| 5716 | { |
| 5717 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
| 5718 | if (!key_attr) |
| 5719 | return -1; |
| 5720 | |
| 5721 | if (defkey && alg == WPA_ALG_IGTK) |
| 5722 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_MGMT); |
| 5723 | else if (defkey) |
| 5724 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); |
| 5725 | |
| 5726 | NLA_PUT_U8(msg, NL80211_KEY_IDX, key_idx); |
| 5727 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5728 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 5729 | wpa_alg_to_cipher_suite(alg, key_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5730 | |
| 5731 | if (seq && seq_len) |
| 5732 | NLA_PUT(msg, NL80211_KEY_SEQ, seq_len, seq); |
| 5733 | |
| 5734 | NLA_PUT(msg, NL80211_KEY_DATA, key_len, key); |
| 5735 | |
| 5736 | nla_nest_end(msg, key_attr); |
| 5737 | |
| 5738 | return 0; |
| 5739 | nla_put_failure: |
| 5740 | return -1; |
| 5741 | } |
| 5742 | |
| 5743 | |
| 5744 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 5745 | struct nl_msg *msg) |
| 5746 | { |
| 5747 | int i, privacy = 0; |
| 5748 | struct nlattr *nl_keys, *nl_key; |
| 5749 | |
| 5750 | for (i = 0; i < 4; i++) { |
| 5751 | if (!params->wep_key[i]) |
| 5752 | continue; |
| 5753 | privacy = 1; |
| 5754 | break; |
| 5755 | } |
| 5756 | if (params->wps == WPS_MODE_PRIVACY) |
| 5757 | privacy = 1; |
| 5758 | if (params->pairwise_suite && |
| 5759 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 5760 | privacy = 1; |
| 5761 | |
| 5762 | if (!privacy) |
| 5763 | return 0; |
| 5764 | |
| 5765 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); |
| 5766 | |
| 5767 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 5768 | if (!nl_keys) |
| 5769 | goto nla_put_failure; |
| 5770 | |
| 5771 | for (i = 0; i < 4; i++) { |
| 5772 | if (!params->wep_key[i]) |
| 5773 | continue; |
| 5774 | |
| 5775 | nl_key = nla_nest_start(msg, i); |
| 5776 | if (!nl_key) |
| 5777 | goto nla_put_failure; |
| 5778 | |
| 5779 | NLA_PUT(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 5780 | params->wep_key[i]); |
| 5781 | if (params->wep_key_len[i] == 5) |
| 5782 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 5783 | WLAN_CIPHER_SUITE_WEP40); |
| 5784 | else |
| 5785 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 5786 | WLAN_CIPHER_SUITE_WEP104); |
| 5787 | |
| 5788 | NLA_PUT_U8(msg, NL80211_KEY_IDX, i); |
| 5789 | |
| 5790 | if (i == params->wep_tx_keyidx) |
| 5791 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); |
| 5792 | |
| 5793 | nla_nest_end(msg, nl_key); |
| 5794 | } |
| 5795 | nla_nest_end(msg, nl_keys); |
| 5796 | |
| 5797 | return 0; |
| 5798 | |
| 5799 | nla_put_failure: |
| 5800 | return -ENOBUFS; |
| 5801 | } |
| 5802 | |
| 5803 | |
| 5804 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 5805 | const u8 *addr, int cmd, u16 reason_code, |
| 5806 | int local_state_change) |
| 5807 | { |
| 5808 | int ret = -1; |
| 5809 | struct nl_msg *msg; |
| 5810 | |
| 5811 | msg = nlmsg_alloc(); |
| 5812 | if (!msg) |
| 5813 | return -1; |
| 5814 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5815 | nl80211_cmd(drv, msg, 0, cmd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5816 | |
| 5817 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 5818 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5819 | if (addr) |
| 5820 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5821 | if (local_state_change) |
| 5822 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); |
| 5823 | |
| 5824 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5825 | msg = NULL; |
| 5826 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5827 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 5828 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 5829 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5830 | goto nla_put_failure; |
| 5831 | } |
| 5832 | ret = 0; |
| 5833 | |
| 5834 | nla_put_failure: |
| 5835 | nlmsg_free(msg); |
| 5836 | return ret; |
| 5837 | } |
| 5838 | |
| 5839 | |
| 5840 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5841 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5842 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5843 | int ret; |
| 5844 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5845 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5846 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5847 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5848 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 5849 | reason_code, 0); |
| 5850 | /* |
| 5851 | * For locally generated disconnect, supplicant already generates a |
| 5852 | * DEAUTH event, so ignore the event from NL80211. |
| 5853 | */ |
| 5854 | drv->ignore_next_local_disconnect = ret == 0; |
| 5855 | |
| 5856 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
| 5859 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5860 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 5861 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5862 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5863 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5864 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5865 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5866 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 5867 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5868 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5869 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) |
| 5870 | return nl80211_leave_ibss(drv); |
| 5871 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 5872 | reason_code, 0); |
| 5873 | } |
| 5874 | |
| 5875 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5876 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 5877 | struct wpa_driver_auth_params *params) |
| 5878 | { |
| 5879 | int i; |
| 5880 | |
| 5881 | drv->auth_freq = params->freq; |
| 5882 | drv->auth_alg = params->auth_alg; |
| 5883 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 5884 | drv->auth_local_state_change = params->local_state_change; |
| 5885 | drv->auth_p2p = params->p2p; |
| 5886 | |
| 5887 | if (params->bssid) |
| 5888 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 5889 | else |
| 5890 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 5891 | |
| 5892 | if (params->ssid) { |
| 5893 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 5894 | drv->auth_ssid_len = params->ssid_len; |
| 5895 | } else |
| 5896 | drv->auth_ssid_len = 0; |
| 5897 | |
| 5898 | |
| 5899 | os_free(drv->auth_ie); |
| 5900 | drv->auth_ie = NULL; |
| 5901 | drv->auth_ie_len = 0; |
| 5902 | if (params->ie) { |
| 5903 | drv->auth_ie = os_malloc(params->ie_len); |
| 5904 | if (drv->auth_ie) { |
| 5905 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 5906 | drv->auth_ie_len = params->ie_len; |
| 5907 | } |
| 5908 | } |
| 5909 | |
| 5910 | for (i = 0; i < 4; i++) { |
| 5911 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 5912 | params->wep_key_len[i] <= 16) { |
| 5913 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 5914 | params->wep_key_len[i]); |
| 5915 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 5916 | } else |
| 5917 | drv->auth_wep_key_len[i] = 0; |
| 5918 | } |
| 5919 | } |
| 5920 | |
| 5921 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5922 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5923 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5924 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5925 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5926 | int ret = -1, i; |
| 5927 | struct nl_msg *msg; |
| 5928 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5929 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5930 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5931 | int is_retry; |
| 5932 | |
| 5933 | is_retry = drv->retry_auth; |
| 5934 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 5935 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5936 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5937 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5938 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5939 | if (params->bssid) |
| 5940 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 5941 | else |
| 5942 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5943 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5944 | nlmode = params->p2p ? |
| 5945 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 5946 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5947 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5948 | return -1; |
| 5949 | |
| 5950 | retry: |
| 5951 | msg = nlmsg_alloc(); |
| 5952 | if (!msg) |
| 5953 | return -1; |
| 5954 | |
| 5955 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 5956 | drv->ifindex); |
| 5957 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5958 | nl80211_cmd(drv, msg, 0, NL80211_CMD_AUTHENTICATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5959 | |
| 5960 | for (i = 0; i < 4; i++) { |
| 5961 | if (!params->wep_key[i]) |
| 5962 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5963 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5964 | NULL, i, |
| 5965 | i == params->wep_tx_keyidx, NULL, 0, |
| 5966 | params->wep_key[i], |
| 5967 | params->wep_key_len[i]); |
| 5968 | if (params->wep_tx_keyidx != i) |
| 5969 | continue; |
| 5970 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
| 5971 | params->wep_key[i], params->wep_key_len[i])) { |
| 5972 | nlmsg_free(msg); |
| 5973 | return -1; |
| 5974 | } |
| 5975 | } |
| 5976 | |
| 5977 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 5978 | if (params->bssid) { |
| 5979 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5980 | MAC2STR(params->bssid)); |
| 5981 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 5982 | } |
| 5983 | if (params->freq) { |
| 5984 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 5985 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
| 5986 | } |
| 5987 | if (params->ssid) { |
| 5988 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5989 | params->ssid, params->ssid_len); |
| 5990 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 5991 | params->ssid); |
| 5992 | } |
| 5993 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
| 5994 | if (params->ie) |
| 5995 | NLA_PUT(msg, NL80211_ATTR_IE, params->ie_len, params->ie); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5996 | if (params->sae_data) { |
| 5997 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 5998 | params->sae_data_len); |
| 5999 | NLA_PUT(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 6000 | params->sae_data); |
| 6001 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6002 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 6003 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 6004 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 6005 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 6006 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 6007 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 6008 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 6009 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6010 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 6011 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6012 | else |
| 6013 | goto nla_put_failure; |
| 6014 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 6015 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); |
| 6016 | if (params->local_state_change) { |
| 6017 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
| 6018 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); |
| 6019 | } |
| 6020 | |
| 6021 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6022 | msg = NULL; |
| 6023 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6024 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 6025 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 6026 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6027 | count++; |
| 6028 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 6029 | !params->local_state_change) { |
| 6030 | /* |
| 6031 | * mac80211 does not currently accept new |
| 6032 | * authentication if we are already authenticated. As a |
| 6033 | * workaround, force deauthentication and try again. |
| 6034 | */ |
| 6035 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 6036 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 6037 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6038 | wpa_driver_nl80211_deauthenticate( |
| 6039 | bss, params->bssid, |
| 6040 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 6041 | nlmsg_free(msg); |
| 6042 | goto retry; |
| 6043 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6044 | |
| 6045 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 6046 | /* |
| 6047 | * cfg80211 has likely expired the BSS entry even |
| 6048 | * though it was previously available in our internal |
| 6049 | * BSS table. To recover quickly, start a single |
| 6050 | * channel scan on the specified channel. |
| 6051 | */ |
| 6052 | struct wpa_driver_scan_params scan; |
| 6053 | int freqs[2]; |
| 6054 | |
| 6055 | os_memset(&scan, 0, sizeof(scan)); |
| 6056 | scan.num_ssids = 1; |
| 6057 | if (params->ssid) { |
| 6058 | scan.ssids[0].ssid = params->ssid; |
| 6059 | scan.ssids[0].ssid_len = params->ssid_len; |
| 6060 | } |
| 6061 | freqs[0] = params->freq; |
| 6062 | freqs[1] = 0; |
| 6063 | scan.freqs = freqs; |
| 6064 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 6065 | "channel scan to refresh cfg80211 BSS " |
| 6066 | "entry"); |
| 6067 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 6068 | if (ret == 0) { |
| 6069 | nl80211_copy_auth_params(drv, params); |
| 6070 | drv->scan_for_auth = 1; |
| 6071 | } |
| 6072 | } else if (is_retry) { |
| 6073 | /* |
| 6074 | * Need to indicate this with an event since the return |
| 6075 | * value from the retry is not delivered to core code. |
| 6076 | */ |
| 6077 | union wpa_event_data event; |
| 6078 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 6079 | "failed"); |
| 6080 | os_memset(&event, 0, sizeof(event)); |
| 6081 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 6082 | ETH_ALEN); |
| 6083 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 6084 | &event); |
| 6085 | } |
| 6086 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6087 | goto nla_put_failure; |
| 6088 | } |
| 6089 | ret = 0; |
| 6090 | wpa_printf(MSG_DEBUG, "nl80211: Authentication request send " |
| 6091 | "successfully"); |
| 6092 | |
| 6093 | nla_put_failure: |
| 6094 | nlmsg_free(msg); |
| 6095 | return ret; |
| 6096 | } |
| 6097 | |
| 6098 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6099 | static int wpa_driver_nl80211_authenticate_retry( |
| 6100 | struct wpa_driver_nl80211_data *drv) |
| 6101 | { |
| 6102 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6103 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6104 | int i; |
| 6105 | |
| 6106 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 6107 | |
| 6108 | os_memset(¶ms, 0, sizeof(params)); |
| 6109 | params.freq = drv->auth_freq; |
| 6110 | params.auth_alg = drv->auth_alg; |
| 6111 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 6112 | params.local_state_change = drv->auth_local_state_change; |
| 6113 | params.p2p = drv->auth_p2p; |
| 6114 | |
| 6115 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 6116 | params.bssid = drv->auth_bssid_; |
| 6117 | |
| 6118 | if (drv->auth_ssid_len) { |
| 6119 | params.ssid = drv->auth_ssid; |
| 6120 | params.ssid_len = drv->auth_ssid_len; |
| 6121 | } |
| 6122 | |
| 6123 | params.ie = drv->auth_ie; |
| 6124 | params.ie_len = drv->auth_ie_len; |
| 6125 | |
| 6126 | for (i = 0; i < 4; i++) { |
| 6127 | if (drv->auth_wep_key_len[i]) { |
| 6128 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 6129 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 6130 | } |
| 6131 | } |
| 6132 | |
| 6133 | drv->retry_auth = 1; |
| 6134 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 6135 | } |
| 6136 | |
| 6137 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6138 | struct phy_info_arg { |
| 6139 | u16 *num_modes; |
| 6140 | struct hostapd_hw_modes *modes; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6141 | int last_mode, last_chan_idx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6142 | }; |
| 6143 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6144 | static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa, |
| 6145 | struct nlattr *ampdu_factor, |
| 6146 | struct nlattr *ampdu_density, |
| 6147 | struct nlattr *mcs_set) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6148 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6149 | if (capa) |
| 6150 | mode->ht_capab = nla_get_u16(capa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6151 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6152 | if (ampdu_factor) |
| 6153 | mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6154 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6155 | if (ampdu_density) |
| 6156 | mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2; |
| 6157 | |
| 6158 | if (mcs_set && nla_len(mcs_set) >= 16) { |
| 6159 | u8 *mcs; |
| 6160 | mcs = nla_data(mcs_set); |
| 6161 | os_memcpy(mode->mcs_set, mcs, 16); |
| 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | |
| 6166 | static void phy_info_vht_capa(struct hostapd_hw_modes *mode, |
| 6167 | struct nlattr *capa, |
| 6168 | struct nlattr *mcs_set) |
| 6169 | { |
| 6170 | if (capa) |
| 6171 | mode->vht_capab = nla_get_u32(capa); |
| 6172 | |
| 6173 | if (mcs_set && nla_len(mcs_set) >= 8) { |
| 6174 | u8 *mcs; |
| 6175 | mcs = nla_data(mcs_set); |
| 6176 | os_memcpy(mode->vht_mcs_set, mcs, 8); |
| 6177 | } |
| 6178 | } |
| 6179 | |
| 6180 | |
| 6181 | static void phy_info_freq(struct hostapd_hw_modes *mode, |
| 6182 | struct hostapd_channel_data *chan, |
| 6183 | struct nlattr *tb_freq[]) |
| 6184 | { |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 6185 | u8 channel; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6186 | chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); |
| 6187 | chan->flag = 0; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 6188 | if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES) |
| 6189 | chan->chan = channel; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6190 | |
| 6191 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) |
| 6192 | chan->flag |= HOSTAPD_CHAN_DISABLED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6193 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR]) |
| 6194 | chan->flag |= HOSTAPD_CHAN_PASSIVE_SCAN | HOSTAPD_CHAN_NO_IBSS; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6195 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) |
| 6196 | chan->flag |= HOSTAPD_CHAN_RADAR; |
| 6197 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6198 | if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) { |
| 6199 | enum nl80211_dfs_state state = |
| 6200 | nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]); |
| 6201 | |
| 6202 | switch (state) { |
| 6203 | case NL80211_DFS_USABLE: |
| 6204 | chan->flag |= HOSTAPD_CHAN_DFS_USABLE; |
| 6205 | break; |
| 6206 | case NL80211_DFS_AVAILABLE: |
| 6207 | chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE; |
| 6208 | break; |
| 6209 | case NL80211_DFS_UNAVAILABLE: |
| 6210 | chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE; |
| 6211 | break; |
| 6212 | } |
| 6213 | } |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6214 | } |
| 6215 | |
| 6216 | |
| 6217 | static int phy_info_freqs(struct phy_info_arg *phy_info, |
| 6218 | struct hostapd_hw_modes *mode, struct nlattr *tb) |
| 6219 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6220 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 6221 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, |
| 6222 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6223 | [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6224 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, |
| 6225 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6226 | [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6227 | }; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6228 | int new_channels = 0; |
| 6229 | struct hostapd_channel_data *channel; |
| 6230 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6231 | struct nlattr *nl_freq; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6232 | int rem_freq, idx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6233 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6234 | if (tb == NULL) |
| 6235 | return NL_OK; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6236 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6237 | nla_for_each_nested(nl_freq, tb, rem_freq) { |
| 6238 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, |
| 6239 | nla_data(nl_freq), nla_len(nl_freq), freq_policy); |
| 6240 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 6241 | continue; |
| 6242 | new_channels++; |
| 6243 | } |
| 6244 | |
| 6245 | channel = os_realloc_array(mode->channels, |
| 6246 | mode->num_channels + new_channels, |
| 6247 | sizeof(struct hostapd_channel_data)); |
| 6248 | if (!channel) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6249 | return NL_SKIP; |
| 6250 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6251 | mode->channels = channel; |
| 6252 | mode->num_channels += new_channels; |
| 6253 | |
| 6254 | idx = phy_info->last_chan_idx; |
| 6255 | |
| 6256 | nla_for_each_nested(nl_freq, tb, rem_freq) { |
| 6257 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, |
| 6258 | nla_data(nl_freq), nla_len(nl_freq), freq_policy); |
| 6259 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 6260 | continue; |
| 6261 | phy_info_freq(mode, &mode->channels[idx], tb_freq); |
| 6262 | idx++; |
| 6263 | } |
| 6264 | phy_info->last_chan_idx = idx; |
| 6265 | |
| 6266 | return NL_OK; |
| 6267 | } |
| 6268 | |
| 6269 | |
| 6270 | static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb) |
| 6271 | { |
| 6272 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { |
| 6273 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, |
| 6274 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = |
| 6275 | { .type = NLA_FLAG }, |
| 6276 | }; |
| 6277 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; |
| 6278 | struct nlattr *nl_rate; |
| 6279 | int rem_rate, idx; |
| 6280 | |
| 6281 | if (tb == NULL) |
| 6282 | return NL_OK; |
| 6283 | |
| 6284 | nla_for_each_nested(nl_rate, tb, rem_rate) { |
| 6285 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, |
| 6286 | nla_data(nl_rate), nla_len(nl_rate), |
| 6287 | rate_policy); |
| 6288 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 6289 | continue; |
| 6290 | mode->num_rates++; |
| 6291 | } |
| 6292 | |
| 6293 | mode->rates = os_calloc(mode->num_rates, sizeof(int)); |
| 6294 | if (!mode->rates) |
| 6295 | return NL_SKIP; |
| 6296 | |
| 6297 | idx = 0; |
| 6298 | |
| 6299 | nla_for_each_nested(nl_rate, tb, rem_rate) { |
| 6300 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, |
| 6301 | nla_data(nl_rate), nla_len(nl_rate), |
| 6302 | rate_policy); |
| 6303 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 6304 | continue; |
| 6305 | mode->rates[idx] = nla_get_u32( |
| 6306 | tb_rate[NL80211_BITRATE_ATTR_RATE]); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6307 | idx++; |
| 6308 | } |
| 6309 | |
| 6310 | return NL_OK; |
| 6311 | } |
| 6312 | |
| 6313 | |
| 6314 | static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band) |
| 6315 | { |
| 6316 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; |
| 6317 | struct hostapd_hw_modes *mode; |
| 6318 | int ret; |
| 6319 | |
| 6320 | if (phy_info->last_mode != nl_band->nla_type) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6321 | mode = os_realloc_array(phy_info->modes, |
| 6322 | *phy_info->num_modes + 1, |
| 6323 | sizeof(*mode)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6324 | if (!mode) |
| 6325 | return NL_SKIP; |
| 6326 | phy_info->modes = mode; |
| 6327 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6328 | mode = &phy_info->modes[*(phy_info->num_modes)]; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6329 | os_memset(mode, 0, sizeof(*mode)); |
| 6330 | mode->mode = NUM_HOSTAPD_MODES; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6331 | mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN | |
| 6332 | HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN; |
| 6333 | |
| 6334 | /* |
| 6335 | * Unsupported VHT MCS stream is defined as value 3, so the VHT |
| 6336 | * MCS RX/TX map must be initialized with 0xffff to mark all 8 |
| 6337 | * possible streams as unsupported. This will be overridden if |
| 6338 | * driver advertises VHT support. |
| 6339 | */ |
| 6340 | mode->vht_mcs_set[0] = 0xff; |
| 6341 | mode->vht_mcs_set[1] = 0xff; |
| 6342 | mode->vht_mcs_set[4] = 0xff; |
| 6343 | mode->vht_mcs_set[5] = 0xff; |
| 6344 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6345 | *(phy_info->num_modes) += 1; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6346 | phy_info->last_mode = nl_band->nla_type; |
| 6347 | phy_info->last_chan_idx = 0; |
| 6348 | } else |
| 6349 | mode = &phy_info->modes[*(phy_info->num_modes) - 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6350 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6351 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), |
| 6352 | nla_len(nl_band), NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6353 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6354 | phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA], |
| 6355 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR], |
| 6356 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY], |
| 6357 | tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); |
| 6358 | phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA], |
| 6359 | tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]); |
| 6360 | ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]); |
| 6361 | if (ret != NL_OK) |
| 6362 | return ret; |
| 6363 | ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]); |
| 6364 | if (ret != NL_OK) |
| 6365 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6366 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6367 | return NL_OK; |
| 6368 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6369 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6370 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6371 | static int phy_info_handler(struct nl_msg *msg, void *arg) |
| 6372 | { |
| 6373 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 6374 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6375 | struct phy_info_arg *phy_info = arg; |
| 6376 | struct nlattr *nl_band; |
| 6377 | int rem_band; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6378 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6379 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6380 | genlmsg_attrlen(gnlh, 0), NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6381 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6382 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) |
| 6383 | return NL_SKIP; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6384 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6385 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) |
| 6386 | { |
| 6387 | int res = phy_info_band(phy_info, nl_band); |
| 6388 | if (res != NL_OK) |
| 6389 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6390 | } |
| 6391 | |
| 6392 | return NL_SKIP; |
| 6393 | } |
| 6394 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6395 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6396 | static struct hostapd_hw_modes * |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 6397 | wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes, |
| 6398 | u16 *num_modes) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6399 | { |
| 6400 | u16 m; |
| 6401 | struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; |
| 6402 | int i, mode11g_idx = -1; |
| 6403 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 6404 | /* heuristic to set up modes */ |
| 6405 | for (m = 0; m < *num_modes; m++) { |
| 6406 | if (!modes[m].num_channels) |
| 6407 | continue; |
| 6408 | if (modes[m].channels[0].freq < 4000) { |
| 6409 | modes[m].mode = HOSTAPD_MODE_IEEE80211B; |
| 6410 | for (i = 0; i < modes[m].num_rates; i++) { |
| 6411 | if (modes[m].rates[i] > 200) { |
| 6412 | modes[m].mode = HOSTAPD_MODE_IEEE80211G; |
| 6413 | break; |
| 6414 | } |
| 6415 | } |
| 6416 | } else if (modes[m].channels[0].freq > 50000) |
| 6417 | modes[m].mode = HOSTAPD_MODE_IEEE80211AD; |
| 6418 | else |
| 6419 | modes[m].mode = HOSTAPD_MODE_IEEE80211A; |
| 6420 | } |
| 6421 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6422 | /* If only 802.11g mode is included, use it to construct matching |
| 6423 | * 802.11b mode data. */ |
| 6424 | |
| 6425 | for (m = 0; m < *num_modes; m++) { |
| 6426 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) |
| 6427 | return modes; /* 802.11b already included */ |
| 6428 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) |
| 6429 | mode11g_idx = m; |
| 6430 | } |
| 6431 | |
| 6432 | if (mode11g_idx < 0) |
| 6433 | return modes; /* 2.4 GHz band not supported at all */ |
| 6434 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6435 | nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6436 | if (nmodes == NULL) |
| 6437 | return modes; /* Could not add 802.11b mode */ |
| 6438 | |
| 6439 | mode = &nmodes[*num_modes]; |
| 6440 | os_memset(mode, 0, sizeof(*mode)); |
| 6441 | (*num_modes)++; |
| 6442 | modes = nmodes; |
| 6443 | |
| 6444 | mode->mode = HOSTAPD_MODE_IEEE80211B; |
| 6445 | |
| 6446 | mode11g = &modes[mode11g_idx]; |
| 6447 | mode->num_channels = mode11g->num_channels; |
| 6448 | mode->channels = os_malloc(mode11g->num_channels * |
| 6449 | sizeof(struct hostapd_channel_data)); |
| 6450 | if (mode->channels == NULL) { |
| 6451 | (*num_modes)--; |
| 6452 | return modes; /* Could not add 802.11b mode */ |
| 6453 | } |
| 6454 | os_memcpy(mode->channels, mode11g->channels, |
| 6455 | mode11g->num_channels * sizeof(struct hostapd_channel_data)); |
| 6456 | |
| 6457 | mode->num_rates = 0; |
| 6458 | mode->rates = os_malloc(4 * sizeof(int)); |
| 6459 | if (mode->rates == NULL) { |
| 6460 | os_free(mode->channels); |
| 6461 | (*num_modes)--; |
| 6462 | return modes; /* Could not add 802.11b mode */ |
| 6463 | } |
| 6464 | |
| 6465 | for (i = 0; i < mode11g->num_rates; i++) { |
| 6466 | if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && |
| 6467 | mode11g->rates[i] != 55 && mode11g->rates[i] != 110) |
| 6468 | continue; |
| 6469 | mode->rates[mode->num_rates] = mode11g->rates[i]; |
| 6470 | mode->num_rates++; |
| 6471 | if (mode->num_rates == 4) |
| 6472 | break; |
| 6473 | } |
| 6474 | |
| 6475 | if (mode->num_rates == 0) { |
| 6476 | os_free(mode->channels); |
| 6477 | os_free(mode->rates); |
| 6478 | (*num_modes)--; |
| 6479 | return modes; /* No 802.11b rates */ |
| 6480 | } |
| 6481 | |
| 6482 | wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " |
| 6483 | "information"); |
| 6484 | |
| 6485 | return modes; |
| 6486 | } |
| 6487 | |
| 6488 | |
| 6489 | static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start, |
| 6490 | int end) |
| 6491 | { |
| 6492 | int c; |
| 6493 | |
| 6494 | for (c = 0; c < mode->num_channels; c++) { |
| 6495 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 6496 | if (chan->freq - 10 >= start && chan->freq + 10 <= end) |
| 6497 | chan->flag |= HOSTAPD_CHAN_HT40; |
| 6498 | } |
| 6499 | } |
| 6500 | |
| 6501 | |
| 6502 | static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start, |
| 6503 | int end) |
| 6504 | { |
| 6505 | int c; |
| 6506 | |
| 6507 | for (c = 0; c < mode->num_channels; c++) { |
| 6508 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 6509 | if (!(chan->flag & HOSTAPD_CHAN_HT40)) |
| 6510 | continue; |
| 6511 | if (chan->freq - 30 >= start && chan->freq - 10 <= end) |
| 6512 | chan->flag |= HOSTAPD_CHAN_HT40MINUS; |
| 6513 | if (chan->freq + 10 >= start && chan->freq + 30 <= end) |
| 6514 | chan->flag |= HOSTAPD_CHAN_HT40PLUS; |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6519 | static void nl80211_reg_rule_max_eirp(u32 start, u32 end, u32 max_eirp, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6520 | struct phy_info_arg *results) |
| 6521 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6522 | u16 m; |
| 6523 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6524 | for (m = 0; m < *results->num_modes; m++) { |
| 6525 | int c; |
| 6526 | struct hostapd_hw_modes *mode = &results->modes[m]; |
| 6527 | |
| 6528 | for (c = 0; c < mode->num_channels; c++) { |
| 6529 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 6530 | if ((u32) chan->freq - 10 >= start && |
| 6531 | (u32) chan->freq + 10 <= end) |
| 6532 | chan->max_tx_power = max_eirp; |
| 6533 | } |
| 6534 | } |
| 6535 | } |
| 6536 | |
| 6537 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6538 | static void nl80211_reg_rule_ht40(u32 start, u32 end, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6539 | struct phy_info_arg *results) |
| 6540 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6541 | u16 m; |
| 6542 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6543 | for (m = 0; m < *results->num_modes; m++) { |
| 6544 | if (!(results->modes[m].ht_capab & |
| 6545 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 6546 | continue; |
| 6547 | nl80211_set_ht40_mode(&results->modes[m], start, end); |
| 6548 | } |
| 6549 | } |
| 6550 | |
| 6551 | |
| 6552 | static void nl80211_reg_rule_sec(struct nlattr *tb[], |
| 6553 | struct phy_info_arg *results) |
| 6554 | { |
| 6555 | u32 start, end, max_bw; |
| 6556 | u16 m; |
| 6557 | |
| 6558 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || |
| 6559 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || |
| 6560 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) |
| 6561 | return; |
| 6562 | |
| 6563 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; |
| 6564 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; |
| 6565 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; |
| 6566 | |
| 6567 | if (max_bw < 20) |
| 6568 | return; |
| 6569 | |
| 6570 | for (m = 0; m < *results->num_modes; m++) { |
| 6571 | if (!(results->modes[m].ht_capab & |
| 6572 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 6573 | continue; |
| 6574 | nl80211_set_ht40_mode_sec(&results->modes[m], start, end); |
| 6575 | } |
| 6576 | } |
| 6577 | |
| 6578 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6579 | static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start, |
| 6580 | int end) |
| 6581 | { |
| 6582 | int c; |
| 6583 | |
| 6584 | for (c = 0; c < mode->num_channels; c++) { |
| 6585 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 6586 | if (chan->freq - 10 >= start && chan->freq + 70 <= end) |
| 6587 | chan->flag |= HOSTAPD_CHAN_VHT_10_70; |
| 6588 | |
| 6589 | if (chan->freq - 30 >= start && chan->freq + 50 <= end) |
| 6590 | chan->flag |= HOSTAPD_CHAN_VHT_30_50; |
| 6591 | |
| 6592 | if (chan->freq - 50 >= start && chan->freq + 30 <= end) |
| 6593 | chan->flag |= HOSTAPD_CHAN_VHT_50_30; |
| 6594 | |
| 6595 | if (chan->freq - 70 >= start && chan->freq + 10 <= end) |
| 6596 | chan->flag |= HOSTAPD_CHAN_VHT_70_10; |
| 6597 | } |
| 6598 | } |
| 6599 | |
| 6600 | |
| 6601 | static void nl80211_reg_rule_vht(struct nlattr *tb[], |
| 6602 | struct phy_info_arg *results) |
| 6603 | { |
| 6604 | u32 start, end, max_bw; |
| 6605 | u16 m; |
| 6606 | |
| 6607 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || |
| 6608 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || |
| 6609 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) |
| 6610 | return; |
| 6611 | |
| 6612 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; |
| 6613 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; |
| 6614 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; |
| 6615 | |
| 6616 | if (max_bw < 80) |
| 6617 | return; |
| 6618 | |
| 6619 | for (m = 0; m < *results->num_modes; m++) { |
| 6620 | if (!(results->modes[m].ht_capab & |
| 6621 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 6622 | continue; |
| 6623 | /* TODO: use a real VHT support indication */ |
| 6624 | if (!results->modes[m].vht_capab) |
| 6625 | continue; |
| 6626 | |
| 6627 | nl80211_set_vht_mode(&results->modes[m], start, end); |
| 6628 | } |
| 6629 | } |
| 6630 | |
| 6631 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 6632 | static const char * dfs_domain_name(enum nl80211_dfs_regions region) |
| 6633 | { |
| 6634 | switch (region) { |
| 6635 | case NL80211_DFS_UNSET: |
| 6636 | return "DFS-UNSET"; |
| 6637 | case NL80211_DFS_FCC: |
| 6638 | return "DFS-FCC"; |
| 6639 | case NL80211_DFS_ETSI: |
| 6640 | return "DFS-ETSI"; |
| 6641 | case NL80211_DFS_JP: |
| 6642 | return "DFS-JP"; |
| 6643 | default: |
| 6644 | return "DFS-invalid"; |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6649 | static int nl80211_get_reg(struct nl_msg *msg, void *arg) |
| 6650 | { |
| 6651 | struct phy_info_arg *results = arg; |
| 6652 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 6653 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6654 | struct nlattr *nl_rule; |
| 6655 | struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1]; |
| 6656 | int rem_rule; |
| 6657 | static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 6658 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6659 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6660 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6661 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6662 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6663 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6664 | }; |
| 6665 | |
| 6666 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6667 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6668 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2] || |
| 6669 | !tb_msg[NL80211_ATTR_REG_RULES]) { |
| 6670 | wpa_printf(MSG_DEBUG, "nl80211: No regulatory information " |
| 6671 | "available"); |
| 6672 | return NL_SKIP; |
| 6673 | } |
| 6674 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 6675 | if (tb_msg[NL80211_ATTR_DFS_REGION]) { |
| 6676 | enum nl80211_dfs_regions dfs_domain; |
| 6677 | dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]); |
| 6678 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)", |
| 6679 | (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), |
| 6680 | dfs_domain_name(dfs_domain)); |
| 6681 | } else { |
| 6682 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s", |
| 6683 | (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2])); |
| 6684 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6685 | |
| 6686 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) |
| 6687 | { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6688 | u32 start, end, max_eirp = 0, max_bw = 0, flags = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6689 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, |
| 6690 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6691 | if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL || |
| 6692 | tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL) |
| 6693 | continue; |
| 6694 | start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000; |
| 6695 | end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000; |
| 6696 | if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6697 | max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100; |
| 6698 | if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6699 | max_bw = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6700 | if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6701 | flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6702 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6703 | wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s", |
| 6704 | start, end, max_bw, max_eirp, |
| 6705 | flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "", |
| 6706 | flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "", |
| 6707 | flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "", |
| 6708 | flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" : |
| 6709 | "", |
| 6710 | flags & NL80211_RRF_DFS ? " (DFS)" : "", |
| 6711 | flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "", |
| 6712 | flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "", |
| 6713 | flags & NL80211_RRF_NO_IR ? " (no IR)" : ""); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6714 | if (max_bw >= 40) |
| 6715 | nl80211_reg_rule_ht40(start, end, results); |
| 6716 | if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6717 | nl80211_reg_rule_max_eirp(start, end, max_eirp, |
| 6718 | results); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) |
| 6722 | { |
| 6723 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, |
| 6724 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); |
| 6725 | nl80211_reg_rule_sec(tb_rule, results); |
| 6726 | } |
| 6727 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6728 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) |
| 6729 | { |
| 6730 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, |
| 6731 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); |
| 6732 | nl80211_reg_rule_vht(tb_rule, results); |
| 6733 | } |
| 6734 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6735 | return NL_SKIP; |
| 6736 | } |
| 6737 | |
| 6738 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6739 | static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv, |
| 6740 | struct phy_info_arg *results) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6741 | { |
| 6742 | struct nl_msg *msg; |
| 6743 | |
| 6744 | msg = nlmsg_alloc(); |
| 6745 | if (!msg) |
| 6746 | return -ENOMEM; |
| 6747 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6748 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6749 | return send_and_recv_msgs(drv, msg, nl80211_get_reg, results); |
| 6750 | } |
| 6751 | |
| 6752 | |
| 6753 | static struct hostapd_hw_modes * |
| 6754 | wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags) |
| 6755 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6756 | u32 feat; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6757 | struct i802_bss *bss = priv; |
| 6758 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6759 | struct nl_msg *msg; |
| 6760 | struct phy_info_arg result = { |
| 6761 | .num_modes = num_modes, |
| 6762 | .modes = NULL, |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6763 | .last_mode = -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6764 | }; |
| 6765 | |
| 6766 | *num_modes = 0; |
| 6767 | *flags = 0; |
| 6768 | |
| 6769 | msg = nlmsg_alloc(); |
| 6770 | if (!msg) |
| 6771 | return NULL; |
| 6772 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6773 | feat = get_nl80211_protocol_features(drv); |
| 6774 | if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) |
| 6775 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY); |
| 6776 | else |
| 6777 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6778 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6779 | NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 6780 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 6781 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6782 | |
| 6783 | if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6784 | nl80211_set_regulatory_flags(drv, &result); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 6785 | return wpa_driver_nl80211_postprocess_modes(result.modes, |
| 6786 | num_modes); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6787 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6788 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6789 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6790 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6791 | return NULL; |
| 6792 | } |
| 6793 | |
| 6794 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6795 | static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data *drv, |
| 6796 | const void *data, size_t len, |
| 6797 | int encrypt, int noack) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6798 | { |
| 6799 | __u8 rtap_hdr[] = { |
| 6800 | 0x00, 0x00, /* radiotap version */ |
| 6801 | 0x0e, 0x00, /* radiotap length */ |
| 6802 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ |
| 6803 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ |
| 6804 | 0x00, /* padding */ |
| 6805 | 0x00, 0x00, /* RX and TX flags to indicate that */ |
| 6806 | 0x00, 0x00, /* this is the injected frame directly */ |
| 6807 | }; |
| 6808 | struct iovec iov[2] = { |
| 6809 | { |
| 6810 | .iov_base = &rtap_hdr, |
| 6811 | .iov_len = sizeof(rtap_hdr), |
| 6812 | }, |
| 6813 | { |
| 6814 | .iov_base = (void *) data, |
| 6815 | .iov_len = len, |
| 6816 | } |
| 6817 | }; |
| 6818 | struct msghdr msg = { |
| 6819 | .msg_name = NULL, |
| 6820 | .msg_namelen = 0, |
| 6821 | .msg_iov = iov, |
| 6822 | .msg_iovlen = 2, |
| 6823 | .msg_control = NULL, |
| 6824 | .msg_controllen = 0, |
| 6825 | .msg_flags = 0, |
| 6826 | }; |
| 6827 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6828 | u16 txflags = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6829 | |
| 6830 | if (encrypt) |
| 6831 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; |
| 6832 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 6833 | if (drv->monitor_sock < 0) { |
| 6834 | wpa_printf(MSG_DEBUG, "nl80211: No monitor socket available " |
| 6835 | "for %s", __func__); |
| 6836 | return -1; |
| 6837 | } |
| 6838 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6839 | if (noack) |
| 6840 | txflags |= IEEE80211_RADIOTAP_F_TX_NOACK; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6841 | WPA_PUT_LE16(&rtap_hdr[12], txflags); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6842 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6843 | res = sendmsg(drv->monitor_sock, &msg, 0); |
| 6844 | if (res < 0) { |
| 6845 | wpa_printf(MSG_INFO, "nl80211: sendmsg: %s", strerror(errno)); |
| 6846 | return -1; |
| 6847 | } |
| 6848 | return 0; |
| 6849 | } |
| 6850 | |
| 6851 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6852 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 6853 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6854 | int encrypt, int noack, |
| 6855 | unsigned int freq, int no_cck, |
| 6856 | int offchanok, unsigned int wait_time) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6857 | { |
| 6858 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6859 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6860 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6861 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6862 | if (freq == 0) { |
| 6863 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 6864 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6865 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6866 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6867 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6868 | if (drv->use_monitor) { |
| 6869 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_mntr", |
| 6870 | freq, bss->freq); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6871 | return wpa_driver_nl80211_send_mntr(drv, data, len, |
| 6872 | encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6873 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6874 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6875 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6876 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
| 6877 | &cookie, no_cck, noack, offchanok); |
| 6878 | if (res == 0 && !noack) { |
| 6879 | const struct ieee80211_mgmt *mgmt; |
| 6880 | u16 fc; |
| 6881 | |
| 6882 | mgmt = (const struct ieee80211_mgmt *) data; |
| 6883 | fc = le_to_host16(mgmt->frame_control); |
| 6884 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 6885 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 6886 | wpa_printf(MSG_MSGDUMP, |
| 6887 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 6888 | (long long unsigned int) |
| 6889 | drv->send_action_cookie, |
| 6890 | (long long unsigned int) cookie); |
| 6891 | drv->send_action_cookie = cookie; |
| 6892 | } |
| 6893 | } |
| 6894 | |
| 6895 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6899 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 6900 | size_t data_len, int noack, |
| 6901 | unsigned int freq, int no_cck, |
| 6902 | int offchanok, |
| 6903 | unsigned int wait_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6904 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6905 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6906 | struct ieee80211_mgmt *mgmt; |
| 6907 | int encrypt = 1; |
| 6908 | u16 fc; |
| 6909 | |
| 6910 | mgmt = (struct ieee80211_mgmt *) data; |
| 6911 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6912 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x nlmode=%d", |
| 6913 | noack, freq, no_cck, offchanok, wait_time, fc, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6914 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6915 | if ((is_sta_interface(drv->nlmode) || |
| 6916 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6917 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 6918 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 6919 | /* |
| 6920 | * The use of last_mgmt_freq is a bit of a hack, |
| 6921 | * but it works due to the single-threaded nature |
| 6922 | * of wpa_supplicant. |
| 6923 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6924 | if (freq == 0) { |
| 6925 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 6926 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6927 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6928 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6929 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6930 | data, data_len, NULL, 1, noack, |
| 6931 | 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6932 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6933 | |
| 6934 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6935 | if (freq == 0) { |
| 6936 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 6937 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6938 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6939 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6940 | return nl80211_send_frame_cmd(bss, freq, |
| 6941 | (int) freq == bss->freq ? 0 : |
| 6942 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6943 | data, data_len, |
| 6944 | &drv->send_action_cookie, |
| 6945 | no_cck, noack, offchanok); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6946 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 6947 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6948 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 6949 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 6950 | /* |
| 6951 | * Only one of the authentication frame types is encrypted. |
| 6952 | * In order for static WEP encryption to work properly (i.e., |
| 6953 | * to not encrypt the frame), we need to tell mac80211 about |
| 6954 | * the frames that must not be encrypted. |
| 6955 | */ |
| 6956 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 6957 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 6958 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 6959 | encrypt = 0; |
| 6960 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6961 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6962 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6963 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6964 | noack, freq, no_cck, offchanok, |
| 6965 | wait_time); |
| 6966 | } |
| 6967 | |
| 6968 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6969 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 6970 | int slot, int ht_opmode, int ap_isolate, |
| 6971 | int *basic_rates) |
| 6972 | { |
| 6973 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6974 | struct nl_msg *msg; |
| 6975 | |
| 6976 | msg = nlmsg_alloc(); |
| 6977 | if (!msg) |
| 6978 | return -ENOMEM; |
| 6979 | |
| 6980 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_BSS); |
| 6981 | |
| 6982 | if (cts >= 0) |
| 6983 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts); |
| 6984 | if (preamble >= 0) |
| 6985 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble); |
| 6986 | if (slot >= 0) |
| 6987 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot); |
| 6988 | if (ht_opmode >= 0) |
| 6989 | NLA_PUT_U16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode); |
| 6990 | if (ap_isolate >= 0) |
| 6991 | NLA_PUT_U8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate); |
| 6992 | |
| 6993 | if (basic_rates) { |
| 6994 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 6995 | u8 rates_len = 0; |
| 6996 | int i; |
| 6997 | |
| 6998 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; |
| 6999 | i++) |
| 7000 | rates[rates_len++] = basic_rates[i] / 5; |
| 7001 | |
| 7002 | NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 7003 | } |
| 7004 | |
| 7005 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 7006 | |
| 7007 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7008 | nla_put_failure: |
| 7009 | nlmsg_free(msg); |
| 7010 | return -ENOBUFS; |
| 7011 | } |
| 7012 | |
| 7013 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7014 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 7015 | struct hostapd_acl_params *params) |
| 7016 | { |
| 7017 | struct i802_bss *bss = priv; |
| 7018 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7019 | struct nl_msg *msg; |
| 7020 | struct nlattr *acl; |
| 7021 | unsigned int i; |
| 7022 | int ret = 0; |
| 7023 | |
| 7024 | if (!(drv->capa.max_acl_mac_addrs)) |
| 7025 | return -ENOTSUP; |
| 7026 | |
| 7027 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 7028 | return -ENOTSUP; |
| 7029 | |
| 7030 | msg = nlmsg_alloc(); |
| 7031 | if (!msg) |
| 7032 | return -ENOMEM; |
| 7033 | |
| 7034 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 7035 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 7036 | |
| 7037 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_MAC_ACL); |
| 7038 | |
| 7039 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7040 | |
| 7041 | NLA_PUT_U32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 7042 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 7043 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED); |
| 7044 | |
| 7045 | acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); |
| 7046 | if (acl == NULL) |
| 7047 | goto nla_put_failure; |
| 7048 | |
| 7049 | for (i = 0; i < params->num_mac_acl; i++) |
| 7050 | NLA_PUT(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr); |
| 7051 | |
| 7052 | nla_nest_end(msg, acl); |
| 7053 | |
| 7054 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7055 | msg = NULL; |
| 7056 | if (ret) { |
| 7057 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 7058 | ret, strerror(-ret)); |
| 7059 | } |
| 7060 | |
| 7061 | nla_put_failure: |
| 7062 | nlmsg_free(msg); |
| 7063 | |
| 7064 | return ret; |
| 7065 | } |
| 7066 | |
| 7067 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7068 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 7069 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7070 | { |
| 7071 | struct i802_bss *bss = priv; |
| 7072 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7073 | struct nl_msg *msg; |
| 7074 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 7075 | int ret; |
| 7076 | int beacon_set; |
| 7077 | int ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7078 | int num_suites; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7079 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7080 | u32 ver; |
| 7081 | |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7082 | beacon_set = bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7083 | |
| 7084 | msg = nlmsg_alloc(); |
| 7085 | if (!msg) |
| 7086 | return -ENOMEM; |
| 7087 | |
| 7088 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 7089 | beacon_set); |
| 7090 | if (beacon_set) |
| 7091 | cmd = NL80211_CMD_SET_BEACON; |
| 7092 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7093 | nl80211_cmd(drv, msg, 0, cmd); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7094 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 7095 | params->head, params->head_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7096 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, params->head); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7097 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 7098 | params->tail, params->tail_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7099 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, params->tail); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7100 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7101 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7102 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7103 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7104 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7105 | NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7106 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 7107 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7108 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 7109 | params->ssid); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7110 | if (params->proberesp && params->proberesp_len) { |
| 7111 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 7112 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7113 | NLA_PUT(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 7114 | params->proberesp); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7115 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7116 | switch (params->hide_ssid) { |
| 7117 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7118 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7119 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 7120 | NL80211_HIDDEN_SSID_NOT_IN_USE); |
| 7121 | break; |
| 7122 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7123 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7124 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 7125 | NL80211_HIDDEN_SSID_ZERO_LEN); |
| 7126 | break; |
| 7127 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7128 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7129 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 7130 | NL80211_HIDDEN_SSID_ZERO_CONTENTS); |
| 7131 | break; |
| 7132 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7133 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7134 | if (params->privacy) |
| 7135 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7136 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7137 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 7138 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 7139 | /* Leave out the attribute */ |
| 7140 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) |
| 7141 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, |
| 7142 | NL80211_AUTHTYPE_SHARED_KEY); |
| 7143 | else |
| 7144 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, |
| 7145 | NL80211_AUTHTYPE_OPEN_SYSTEM); |
| 7146 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7147 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7148 | ver = 0; |
| 7149 | if (params->wpa_version & WPA_PROTO_WPA) |
| 7150 | ver |= NL80211_WPA_VERSION_1; |
| 7151 | if (params->wpa_version & WPA_PROTO_RSN) |
| 7152 | ver |= NL80211_WPA_VERSION_2; |
| 7153 | if (ver) |
| 7154 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); |
| 7155 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7156 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 7157 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7158 | num_suites = 0; |
| 7159 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 7160 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 7161 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 7162 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
| 7163 | if (num_suites) { |
| 7164 | NLA_PUT(msg, NL80211_ATTR_AKM_SUITES, |
| 7165 | num_suites * sizeof(u32), suites); |
| 7166 | } |
| 7167 | |
| 7168 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X && |
| 7169 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) |
| 7170 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT); |
| 7171 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7172 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 7173 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7174 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 7175 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7176 | if (num_suites) { |
| 7177 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 7178 | num_suites * sizeof(u32), suites); |
| 7179 | } |
| 7180 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7181 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 7182 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7183 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
| 7184 | if (suite) |
| 7185 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7186 | |
| 7187 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7188 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 7189 | params->beacon_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7190 | NLA_PUT(msg, NL80211_ATTR_IE, wpabuf_len(params->beacon_ies), |
| 7191 | wpabuf_head(params->beacon_ies)); |
| 7192 | } |
| 7193 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7194 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 7195 | params->proberesp_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7196 | NLA_PUT(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 7197 | wpabuf_len(params->proberesp_ies), |
| 7198 | wpabuf_head(params->proberesp_ies)); |
| 7199 | } |
| 7200 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7201 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 7202 | params->assocresp_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7203 | NLA_PUT(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 7204 | wpabuf_len(params->assocresp_ies), |
| 7205 | wpabuf_head(params->assocresp_ies)); |
| 7206 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7207 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7208 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7209 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 7210 | params->ap_max_inactivity); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7211 | NLA_PUT_U16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 7212 | params->ap_max_inactivity); |
| 7213 | } |
| 7214 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7215 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7216 | if (ret) { |
| 7217 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 7218 | ret, strerror(-ret)); |
| 7219 | } else { |
| 7220 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7221 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 7222 | params->short_slot_time, params->ht_opmode, |
| 7223 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7224 | } |
| 7225 | return ret; |
| 7226 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7227 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7228 | return -ENOBUFS; |
| 7229 | } |
| 7230 | |
| 7231 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7232 | static int nl80211_put_freq_params(struct nl_msg *msg, |
| 7233 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7234 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7235 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); |
| 7236 | if (freq->vht_enabled) { |
| 7237 | switch (freq->bandwidth) { |
| 7238 | case 20: |
| 7239 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7240 | NL80211_CHAN_WIDTH_20); |
| 7241 | break; |
| 7242 | case 40: |
| 7243 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7244 | NL80211_CHAN_WIDTH_40); |
| 7245 | break; |
| 7246 | case 80: |
| 7247 | if (freq->center_freq2) |
| 7248 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7249 | NL80211_CHAN_WIDTH_80P80); |
| 7250 | else |
| 7251 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7252 | NL80211_CHAN_WIDTH_80); |
| 7253 | break; |
| 7254 | case 160: |
| 7255 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7256 | NL80211_CHAN_WIDTH_160); |
| 7257 | break; |
| 7258 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7259 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7260 | } |
| 7261 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); |
| 7262 | if (freq->center_freq2) |
| 7263 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 7264 | freq->center_freq2); |
| 7265 | } else if (freq->ht_enabled) { |
| 7266 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7267 | case -1: |
| 7268 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 7269 | NL80211_CHAN_HT40MINUS); |
| 7270 | break; |
| 7271 | case 1: |
| 7272 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 7273 | NL80211_CHAN_HT40PLUS); |
| 7274 | break; |
| 7275 | default: |
| 7276 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 7277 | NL80211_CHAN_HT20); |
| 7278 | break; |
| 7279 | } |
| 7280 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7281 | return 0; |
| 7282 | |
| 7283 | nla_put_failure: |
| 7284 | return -ENOBUFS; |
| 7285 | } |
| 7286 | |
| 7287 | |
| 7288 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
| 7289 | struct hostapd_freq_params *freq) |
| 7290 | { |
| 7291 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7292 | struct nl_msg *msg; |
| 7293 | int ret; |
| 7294 | |
| 7295 | wpa_printf(MSG_DEBUG, |
| 7296 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 7297 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7298 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7299 | msg = nlmsg_alloc(); |
| 7300 | if (!msg) |
| 7301 | return -1; |
| 7302 | |
| 7303 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
| 7304 | |
| 7305 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7306 | if (nl80211_put_freq_params(msg, freq) < 0) |
| 7307 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7308 | |
| 7309 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7310 | msg = NULL; |
| 7311 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7312 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7313 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7314 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7315 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7316 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7317 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7318 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7319 | return -1; |
| 7320 | } |
| 7321 | |
| 7322 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7323 | static u32 sta_flags_nl80211(int flags) |
| 7324 | { |
| 7325 | u32 f = 0; |
| 7326 | |
| 7327 | if (flags & WPA_STA_AUTHORIZED) |
| 7328 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 7329 | if (flags & WPA_STA_WMM) |
| 7330 | f |= BIT(NL80211_STA_FLAG_WME); |
| 7331 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 7332 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 7333 | if (flags & WPA_STA_MFP) |
| 7334 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 7335 | if (flags & WPA_STA_TDLS_PEER) |
| 7336 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 7337 | |
| 7338 | return f; |
| 7339 | } |
| 7340 | |
| 7341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7342 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 7343 | struct hostapd_sta_add_params *params) |
| 7344 | { |
| 7345 | struct i802_bss *bss = priv; |
| 7346 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7347 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7348 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7349 | int ret = -ENOBUFS; |
| 7350 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7351 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 7352 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7353 | return -EOPNOTSUPP; |
| 7354 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7355 | msg = nlmsg_alloc(); |
| 7356 | if (!msg) |
| 7357 | return -ENOMEM; |
| 7358 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7359 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 7360 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7361 | nl80211_cmd(drv, msg, 0, params->set ? NL80211_CMD_SET_STATION : |
| 7362 | NL80211_CMD_NEW_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7363 | |
| 7364 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 7365 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7366 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len, |
| 7367 | params->supp_rates); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7368 | wpa_hexdump(MSG_DEBUG, " * supported rates", params->supp_rates, |
| 7369 | params->supp_rates_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7370 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 7371 | if (params->aid) { |
| 7372 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 7373 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid); |
| 7374 | } else { |
| 7375 | /* |
| 7376 | * cfg80211 validates that AID is non-zero, so we have |
| 7377 | * to make this a non-zero value for the TDLS case where |
| 7378 | * a dummy STA entry is used for now. |
| 7379 | */ |
| 7380 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); |
| 7381 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, 1); |
| 7382 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7383 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 7384 | params->listen_interval); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7385 | NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 7386 | params->listen_interval); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7387 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 7388 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
| 7389 | NLA_PUT_U16(msg, NL80211_ATTR_PEER_AID, params->aid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7390 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7391 | if (params->ht_capabilities) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7392 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 7393 | (u8 *) params->ht_capabilities, |
| 7394 | sizeof(*params->ht_capabilities)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7395 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, |
| 7396 | sizeof(*params->ht_capabilities), |
| 7397 | params->ht_capabilities); |
| 7398 | } |
| 7399 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7400 | if (params->vht_capabilities) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7401 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 7402 | (u8 *) params->vht_capabilities, |
| 7403 | sizeof(*params->vht_capabilities)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7404 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 7405 | sizeof(*params->vht_capabilities), |
| 7406 | params->vht_capabilities); |
| 7407 | } |
| 7408 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 7409 | if (params->vht_opmode_enabled) { |
| 7410 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
| 7411 | NLA_PUT_U8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 7412 | params->vht_opmode); |
| 7413 | } |
| 7414 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7415 | wpa_printf(MSG_DEBUG, " * capability=0x%x", params->capability); |
| 7416 | NLA_PUT_U16(msg, NL80211_ATTR_STA_CAPABILITY, params->capability); |
| 7417 | |
| 7418 | if (params->ext_capab) { |
| 7419 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 7420 | params->ext_capab, params->ext_capab_len); |
| 7421 | NLA_PUT(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 7422 | params->ext_capab_len, params->ext_capab); |
| 7423 | } |
| 7424 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 7425 | if (params->supp_channels) { |
| 7426 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 7427 | params->supp_channels, params->supp_channels_len); |
| 7428 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 7429 | params->supp_channels_len, params->supp_channels); |
| 7430 | } |
| 7431 | |
| 7432 | if (params->supp_oper_classes) { |
| 7433 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 7434 | params->supp_oper_classes, |
| 7435 | params->supp_oper_classes_len); |
| 7436 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 7437 | params->supp_oper_classes_len, |
| 7438 | params->supp_oper_classes); |
| 7439 | } |
| 7440 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7441 | os_memset(&upd, 0, sizeof(upd)); |
| 7442 | upd.mask = sta_flags_nl80211(params->flags); |
| 7443 | upd.set = upd.mask; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7444 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 7445 | upd.set, upd.mask); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7446 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 7447 | |
| 7448 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7449 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 7450 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7451 | if (!wme) |
| 7452 | goto nla_put_failure; |
| 7453 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7454 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7455 | NLA_PUT_U8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7456 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7457 | NLA_PUT_U8(msg, NL80211_STA_WME_MAX_SP, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7458 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7459 | WMM_QOSINFO_STA_SP_MASK); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7460 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7461 | } |
| 7462 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7463 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7464 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7465 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7466 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 7467 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 7468 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7469 | if (ret == -EEXIST) |
| 7470 | ret = 0; |
| 7471 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7472 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7473 | return ret; |
| 7474 | } |
| 7475 | |
| 7476 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7477 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7478 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7479 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7480 | struct nl_msg *msg; |
| 7481 | int ret; |
| 7482 | |
| 7483 | msg = nlmsg_alloc(); |
| 7484 | if (!msg) |
| 7485 | return -ENOMEM; |
| 7486 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7487 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7488 | |
| 7489 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 7490 | if_nametoindex(bss->ifname)); |
| 7491 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7492 | |
| 7493 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7494 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 7495 | " --> %d (%s)", |
| 7496 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7497 | if (ret == -ENOENT) |
| 7498 | return 0; |
| 7499 | return ret; |
| 7500 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7501 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7502 | return -ENOBUFS; |
| 7503 | } |
| 7504 | |
| 7505 | |
| 7506 | static void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, |
| 7507 | int ifidx) |
| 7508 | { |
| 7509 | struct nl_msg *msg; |
| 7510 | |
| 7511 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 7512 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7513 | /* stop listening for EAPOL on this interface */ |
| 7514 | del_ifidx(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7515 | |
| 7516 | msg = nlmsg_alloc(); |
| 7517 | if (!msg) |
| 7518 | goto nla_put_failure; |
| 7519 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7520 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7521 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); |
| 7522 | |
| 7523 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 7524 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7525 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7526 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7527 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7528 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 7529 | } |
| 7530 | |
| 7531 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7532 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 7533 | { |
| 7534 | switch (mode) { |
| 7535 | case NL80211_IFTYPE_ADHOC: |
| 7536 | return "ADHOC"; |
| 7537 | case NL80211_IFTYPE_STATION: |
| 7538 | return "STATION"; |
| 7539 | case NL80211_IFTYPE_AP: |
| 7540 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 7541 | case NL80211_IFTYPE_AP_VLAN: |
| 7542 | return "AP_VLAN"; |
| 7543 | case NL80211_IFTYPE_WDS: |
| 7544 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7545 | case NL80211_IFTYPE_MONITOR: |
| 7546 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 7547 | case NL80211_IFTYPE_MESH_POINT: |
| 7548 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7549 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7550 | return "P2P_CLIENT"; |
| 7551 | case NL80211_IFTYPE_P2P_GO: |
| 7552 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7553 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7554 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7555 | default: |
| 7556 | return "unknown"; |
| 7557 | } |
| 7558 | } |
| 7559 | |
| 7560 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7561 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 7562 | const char *ifname, |
| 7563 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7564 | const u8 *addr, int wds, |
| 7565 | int (*handler)(struct nl_msg *, void *), |
| 7566 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7567 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7568 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7569 | int ifidx; |
| 7570 | int ret = -ENOBUFS; |
| 7571 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7572 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 7573 | iftype, nl80211_iftype_str(iftype)); |
| 7574 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7575 | msg = nlmsg_alloc(); |
| 7576 | if (!msg) |
| 7577 | return -1; |
| 7578 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7579 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_INTERFACE); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7580 | if (nl80211_set_iface_id(msg, drv->first_bss) < 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7581 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7582 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname); |
| 7583 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype); |
| 7584 | |
| 7585 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7586 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7587 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7588 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7589 | if (!flags) |
| 7590 | goto nla_put_failure; |
| 7591 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7592 | NLA_PUT_FLAG(msg, NL80211_MNTR_FLAG_COOK_FRAMES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7593 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7594 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7595 | } else if (wds) { |
| 7596 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, wds); |
| 7597 | } |
| 7598 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7599 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7600 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7601 | if (ret) { |
| 7602 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7603 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7604 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 7605 | ifname, ret, strerror(-ret)); |
| 7606 | return ret; |
| 7607 | } |
| 7608 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7609 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 7610 | return 0; |
| 7611 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7612 | ifidx = if_nametoindex(ifname); |
| 7613 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 7614 | ifname, ifidx); |
| 7615 | |
| 7616 | if (ifidx <= 0) |
| 7617 | return -1; |
| 7618 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7619 | /* start listening for EAPOL on this interface */ |
| 7620 | add_ifidx(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7621 | |
| 7622 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7623 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7624 | nl80211_remove_iface(drv, ifidx); |
| 7625 | return -1; |
| 7626 | } |
| 7627 | |
| 7628 | return ifidx; |
| 7629 | } |
| 7630 | |
| 7631 | |
| 7632 | static int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 7633 | const char *ifname, enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7634 | const u8 *addr, int wds, |
| 7635 | int (*handler)(struct nl_msg *, void *), |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7636 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7637 | { |
| 7638 | int ret; |
| 7639 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7640 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 7641 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7642 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7643 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7644 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7645 | if (use_existing) { |
| 7646 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 7647 | ifname); |
| 7648 | return -ENFILE; |
| 7649 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7650 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 7651 | |
| 7652 | /* Try to remove the interface that was already there. */ |
| 7653 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 7654 | |
| 7655 | /* Try to create the interface again */ |
| 7656 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7657 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7658 | } |
| 7659 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7660 | if (ret >= 0 && is_p2p_net_interface(iftype)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7661 | nl80211_disable_11b_rates(drv, ret, 1); |
| 7662 | |
| 7663 | return ret; |
| 7664 | } |
| 7665 | |
| 7666 | |
| 7667 | static void handle_tx_callback(void *ctx, u8 *buf, size_t len, int ok) |
| 7668 | { |
| 7669 | struct ieee80211_hdr *hdr; |
| 7670 | u16 fc; |
| 7671 | union wpa_event_data event; |
| 7672 | |
| 7673 | hdr = (struct ieee80211_hdr *) buf; |
| 7674 | fc = le_to_host16(hdr->frame_control); |
| 7675 | |
| 7676 | os_memset(&event, 0, sizeof(event)); |
| 7677 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); |
| 7678 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); |
| 7679 | event.tx_status.dst = hdr->addr1; |
| 7680 | event.tx_status.data = buf; |
| 7681 | event.tx_status.data_len = len; |
| 7682 | event.tx_status.ack = ok; |
| 7683 | wpa_supplicant_event(ctx, EVENT_TX_STATUS, &event); |
| 7684 | } |
| 7685 | |
| 7686 | |
| 7687 | static void from_unknown_sta(struct wpa_driver_nl80211_data *drv, |
| 7688 | u8 *buf, size_t len) |
| 7689 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7690 | struct ieee80211_hdr *hdr = (void *)buf; |
| 7691 | u16 fc; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7692 | union wpa_event_data event; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7693 | |
| 7694 | if (len < sizeof(*hdr)) |
| 7695 | return; |
| 7696 | |
| 7697 | fc = le_to_host16(hdr->frame_control); |
| 7698 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7699 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7700 | event.rx_from_unknown.bssid = get_hdr_bssid(hdr, len); |
| 7701 | event.rx_from_unknown.addr = hdr->addr2; |
| 7702 | event.rx_from_unknown.wds = (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) == |
| 7703 | (WLAN_FC_FROMDS | WLAN_FC_TODS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7704 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); |
| 7705 | } |
| 7706 | |
| 7707 | |
| 7708 | static void handle_frame(struct wpa_driver_nl80211_data *drv, |
| 7709 | u8 *buf, size_t len, int datarate, int ssi_signal) |
| 7710 | { |
| 7711 | struct ieee80211_hdr *hdr; |
| 7712 | u16 fc; |
| 7713 | union wpa_event_data event; |
| 7714 | |
| 7715 | hdr = (struct ieee80211_hdr *) buf; |
| 7716 | fc = le_to_host16(hdr->frame_control); |
| 7717 | |
| 7718 | switch (WLAN_FC_GET_TYPE(fc)) { |
| 7719 | case WLAN_FC_TYPE_MGMT: |
| 7720 | os_memset(&event, 0, sizeof(event)); |
| 7721 | event.rx_mgmt.frame = buf; |
| 7722 | event.rx_mgmt.frame_len = len; |
| 7723 | event.rx_mgmt.datarate = datarate; |
| 7724 | event.rx_mgmt.ssi_signal = ssi_signal; |
| 7725 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 7726 | break; |
| 7727 | case WLAN_FC_TYPE_CTRL: |
| 7728 | /* can only get here with PS-Poll frames */ |
| 7729 | wpa_printf(MSG_DEBUG, "CTRL"); |
| 7730 | from_unknown_sta(drv, buf, len); |
| 7731 | break; |
| 7732 | case WLAN_FC_TYPE_DATA: |
| 7733 | from_unknown_sta(drv, buf, len); |
| 7734 | break; |
| 7735 | } |
| 7736 | } |
| 7737 | |
| 7738 | |
| 7739 | static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx) |
| 7740 | { |
| 7741 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 7742 | int len; |
| 7743 | unsigned char buf[3000]; |
| 7744 | struct ieee80211_radiotap_iterator iter; |
| 7745 | int ret; |
| 7746 | int datarate = 0, ssi_signal = 0; |
| 7747 | int injected = 0, failed = 0, rxflags = 0; |
| 7748 | |
| 7749 | len = recv(sock, buf, sizeof(buf), 0); |
| 7750 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7751 | wpa_printf(MSG_ERROR, "nl80211: Monitor socket recv failed: %s", |
| 7752 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7753 | return; |
| 7754 | } |
| 7755 | |
| 7756 | if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7757 | wpa_printf(MSG_INFO, "nl80211: received invalid radiotap frame"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7758 | return; |
| 7759 | } |
| 7760 | |
| 7761 | while (1) { |
| 7762 | ret = ieee80211_radiotap_iterator_next(&iter); |
| 7763 | if (ret == -ENOENT) |
| 7764 | break; |
| 7765 | if (ret) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7766 | wpa_printf(MSG_INFO, "nl80211: received invalid radiotap frame (%d)", |
| 7767 | ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7768 | return; |
| 7769 | } |
| 7770 | switch (iter.this_arg_index) { |
| 7771 | case IEEE80211_RADIOTAP_FLAGS: |
| 7772 | if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS) |
| 7773 | len -= 4; |
| 7774 | break; |
| 7775 | case IEEE80211_RADIOTAP_RX_FLAGS: |
| 7776 | rxflags = 1; |
| 7777 | break; |
| 7778 | case IEEE80211_RADIOTAP_TX_FLAGS: |
| 7779 | injected = 1; |
| 7780 | failed = le_to_host16((*(uint16_t *) iter.this_arg)) & |
| 7781 | IEEE80211_RADIOTAP_F_TX_FAIL; |
| 7782 | break; |
| 7783 | case IEEE80211_RADIOTAP_DATA_RETRIES: |
| 7784 | break; |
| 7785 | case IEEE80211_RADIOTAP_CHANNEL: |
| 7786 | /* TODO: convert from freq/flags to channel number */ |
| 7787 | break; |
| 7788 | case IEEE80211_RADIOTAP_RATE: |
| 7789 | datarate = *iter.this_arg * 5; |
| 7790 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7791 | case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: |
| 7792 | ssi_signal = (s8) *iter.this_arg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7793 | break; |
| 7794 | } |
| 7795 | } |
| 7796 | |
| 7797 | if (rxflags && injected) |
| 7798 | return; |
| 7799 | |
| 7800 | if (!injected) |
| 7801 | handle_frame(drv, buf + iter.max_length, |
| 7802 | len - iter.max_length, datarate, ssi_signal); |
| 7803 | else |
| 7804 | handle_tx_callback(drv->ctx, buf + iter.max_length, |
| 7805 | len - iter.max_length, !failed); |
| 7806 | } |
| 7807 | |
| 7808 | |
| 7809 | /* |
| 7810 | * we post-process the filter code later and rewrite |
| 7811 | * this to the offset to the last instruction |
| 7812 | */ |
| 7813 | #define PASS 0xFF |
| 7814 | #define FAIL 0xFE |
| 7815 | |
| 7816 | static struct sock_filter msock_filter_insns[] = { |
| 7817 | /* |
| 7818 | * do a little-endian load of the radiotap length field |
| 7819 | */ |
| 7820 | /* load lower byte into A */ |
| 7821 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), |
| 7822 | /* put it into X (== index register) */ |
| 7823 | BPF_STMT(BPF_MISC| BPF_TAX, 0), |
| 7824 | /* load upper byte into A */ |
| 7825 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 3), |
| 7826 | /* left-shift it by 8 */ |
| 7827 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8), |
| 7828 | /* or with X */ |
| 7829 | BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0), |
| 7830 | /* put result into X */ |
| 7831 | BPF_STMT(BPF_MISC| BPF_TAX, 0), |
| 7832 | |
| 7833 | /* |
| 7834 | * Allow management frames through, this also gives us those |
| 7835 | * management frames that we sent ourselves with status |
| 7836 | */ |
| 7837 | /* load the lower byte of the IEEE 802.11 frame control field */ |
| 7838 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 7839 | /* mask off frame type and version */ |
| 7840 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF), |
| 7841 | /* accept frame if it's both 0, fall through otherwise */ |
| 7842 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0), |
| 7843 | |
| 7844 | /* |
| 7845 | * TODO: add a bit to radiotap RX flags that indicates |
| 7846 | * that the sending station is not associated, then |
| 7847 | * add a filter here that filters on our DA and that flag |
| 7848 | * to allow us to deauth frames to that bad station. |
| 7849 | * |
| 7850 | * For now allow all To DS data frames through. |
| 7851 | */ |
| 7852 | /* load the IEEE 802.11 frame control field */ |
| 7853 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 0), |
| 7854 | /* mask off frame type, version and DS status */ |
| 7855 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0F03), |
| 7856 | /* accept frame if version 0, type 2 and To DS, fall through otherwise |
| 7857 | */ |
| 7858 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0801, PASS, 0), |
| 7859 | |
| 7860 | #if 0 |
| 7861 | /* |
| 7862 | * drop non-data frames |
| 7863 | */ |
| 7864 | /* load the lower byte of the frame control field */ |
| 7865 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 7866 | /* mask off QoS bit */ |
| 7867 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0c), |
| 7868 | /* drop non-data frames */ |
| 7869 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 8, 0, FAIL), |
| 7870 | #endif |
| 7871 | /* load the upper byte of the frame control field */ |
| 7872 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), |
| 7873 | /* mask off toDS/fromDS */ |
| 7874 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x03), |
| 7875 | /* accept WDS frames */ |
| 7876 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 3, PASS, 0), |
| 7877 | |
| 7878 | /* |
| 7879 | * add header length to index |
| 7880 | */ |
| 7881 | /* load the lower byte of the frame control field */ |
| 7882 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 7883 | /* mask off QoS bit */ |
| 7884 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x80), |
| 7885 | /* right shift it by 6 to give 0 or 2 */ |
| 7886 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 6), |
| 7887 | /* add data frame header length */ |
| 7888 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 24), |
| 7889 | /* add index, was start of 802.11 header */ |
| 7890 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 7891 | /* move to index, now start of LL header */ |
| 7892 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 7893 | |
| 7894 | /* |
| 7895 | * Accept empty data frames, we use those for |
| 7896 | * polling activity. |
| 7897 | */ |
| 7898 | BPF_STMT(BPF_LD | BPF_W | BPF_LEN, 0), |
| 7899 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0), |
| 7900 | |
| 7901 | /* |
| 7902 | * Accept EAPOL frames |
| 7903 | */ |
| 7904 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), |
| 7905 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL), |
| 7906 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 4), |
| 7907 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL), |
| 7908 | |
| 7909 | /* keep these last two statements or change the code below */ |
| 7910 | /* return 0 == "DROP" */ |
| 7911 | BPF_STMT(BPF_RET | BPF_K, 0), |
| 7912 | /* return ~0 == "keep all" */ |
| 7913 | BPF_STMT(BPF_RET | BPF_K, ~0), |
| 7914 | }; |
| 7915 | |
| 7916 | static struct sock_fprog msock_filter = { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7917 | .len = ARRAY_SIZE(msock_filter_insns), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7918 | .filter = msock_filter_insns, |
| 7919 | }; |
| 7920 | |
| 7921 | |
| 7922 | static int add_monitor_filter(int s) |
| 7923 | { |
| 7924 | int idx; |
| 7925 | |
| 7926 | /* rewrite all PASS/FAIL jump offsets */ |
| 7927 | for (idx = 0; idx < msock_filter.len; idx++) { |
| 7928 | struct sock_filter *insn = &msock_filter_insns[idx]; |
| 7929 | |
| 7930 | if (BPF_CLASS(insn->code) == BPF_JMP) { |
| 7931 | if (insn->code == (BPF_JMP|BPF_JA)) { |
| 7932 | if (insn->k == PASS) |
| 7933 | insn->k = msock_filter.len - idx - 2; |
| 7934 | else if (insn->k == FAIL) |
| 7935 | insn->k = msock_filter.len - idx - 3; |
| 7936 | } |
| 7937 | |
| 7938 | if (insn->jt == PASS) |
| 7939 | insn->jt = msock_filter.len - idx - 2; |
| 7940 | else if (insn->jt == FAIL) |
| 7941 | insn->jt = msock_filter.len - idx - 3; |
| 7942 | |
| 7943 | if (insn->jf == PASS) |
| 7944 | insn->jf = msock_filter.len - idx - 2; |
| 7945 | else if (insn->jf == FAIL) |
| 7946 | insn->jf = msock_filter.len - idx - 3; |
| 7947 | } |
| 7948 | } |
| 7949 | |
| 7950 | if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, |
| 7951 | &msock_filter, sizeof(msock_filter))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7952 | wpa_printf(MSG_ERROR, "nl80211: setsockopt(SO_ATTACH_FILTER) failed: %s", |
| 7953 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7954 | return -1; |
| 7955 | } |
| 7956 | |
| 7957 | return 0; |
| 7958 | } |
| 7959 | |
| 7960 | |
| 7961 | static void nl80211_remove_monitor_interface( |
| 7962 | struct wpa_driver_nl80211_data *drv) |
| 7963 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7964 | if (drv->monitor_refcount > 0) |
| 7965 | drv->monitor_refcount--; |
| 7966 | wpa_printf(MSG_DEBUG, "nl80211: Remove monitor interface: refcount=%d", |
| 7967 | drv->monitor_refcount); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7968 | if (drv->monitor_refcount > 0) |
| 7969 | return; |
| 7970 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7971 | if (drv->monitor_ifidx >= 0) { |
| 7972 | nl80211_remove_iface(drv, drv->monitor_ifidx); |
| 7973 | drv->monitor_ifidx = -1; |
| 7974 | } |
| 7975 | if (drv->monitor_sock >= 0) { |
| 7976 | eloop_unregister_read_sock(drv->monitor_sock); |
| 7977 | close(drv->monitor_sock); |
| 7978 | drv->monitor_sock = -1; |
| 7979 | } |
| 7980 | } |
| 7981 | |
| 7982 | |
| 7983 | static int |
| 7984 | nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) |
| 7985 | { |
| 7986 | char buf[IFNAMSIZ]; |
| 7987 | struct sockaddr_ll ll; |
| 7988 | int optval; |
| 7989 | socklen_t optlen; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7990 | |
| 7991 | if (drv->monitor_ifidx >= 0) { |
| 7992 | drv->monitor_refcount++; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7993 | wpa_printf(MSG_DEBUG, "nl80211: Re-use existing monitor interface: refcount=%d", |
| 7994 | drv->monitor_refcount); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7995 | return 0; |
| 7996 | } |
| 7997 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7998 | if (os_strncmp(drv->first_bss->ifname, "p2p-", 4) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7999 | /* |
| 8000 | * P2P interface name is of the format p2p-%s-%d. For monitor |
| 8001 | * interface name corresponding to P2P GO, replace "p2p-" with |
| 8002 | * "mon-" to retain the same interface name length and to |
| 8003 | * indicate that it is a monitor interface. |
| 8004 | */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8005 | snprintf(buf, IFNAMSIZ, "mon-%s", drv->first_bss->ifname + 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8006 | } else { |
| 8007 | /* Non-P2P interface with AP functionality. */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8008 | snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8009 | } |
| 8010 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8011 | buf[IFNAMSIZ - 1] = '\0'; |
| 8012 | |
| 8013 | drv->monitor_ifidx = |
| 8014 | nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8015 | 0, NULL, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8016 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 8017 | if (drv->monitor_ifidx == -EOPNOTSUPP) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8018 | /* |
| 8019 | * This is backward compatibility for a few versions of |
| 8020 | * the kernel only that didn't advertise the right |
| 8021 | * attributes for the only driver that then supported |
| 8022 | * AP mode w/o monitor -- ath6kl. |
| 8023 | */ |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 8024 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support " |
| 8025 | "monitor interface type - try to run without it"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8026 | drv->device_ap_sme = 1; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 8027 | } |
| 8028 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8029 | if (drv->monitor_ifidx < 0) |
| 8030 | return -1; |
| 8031 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8032 | if (linux_set_iface_flags(drv->global->ioctl_sock, buf, 1)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8033 | goto error; |
| 8034 | |
| 8035 | memset(&ll, 0, sizeof(ll)); |
| 8036 | ll.sll_family = AF_PACKET; |
| 8037 | ll.sll_ifindex = drv->monitor_ifidx; |
| 8038 | drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 8039 | if (drv->monitor_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8040 | wpa_printf(MSG_ERROR, "nl80211: socket[PF_PACKET,SOCK_RAW] failed: %s", |
| 8041 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8042 | goto error; |
| 8043 | } |
| 8044 | |
| 8045 | if (add_monitor_filter(drv->monitor_sock)) { |
| 8046 | wpa_printf(MSG_INFO, "Failed to set socket filter for monitor " |
| 8047 | "interface; do filtering in user space"); |
| 8048 | /* This works, but will cost in performance. */ |
| 8049 | } |
| 8050 | |
| 8051 | if (bind(drv->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8052 | wpa_printf(MSG_ERROR, "nl80211: monitor socket bind failed: %s", |
| 8053 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8054 | goto error; |
| 8055 | } |
| 8056 | |
| 8057 | optlen = sizeof(optval); |
| 8058 | optval = 20; |
| 8059 | if (setsockopt |
| 8060 | (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8061 | wpa_printf(MSG_ERROR, "nl80211: Failed to set socket priority: %s", |
| 8062 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8063 | goto error; |
| 8064 | } |
| 8065 | |
| 8066 | if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read, |
| 8067 | drv, NULL)) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8068 | wpa_printf(MSG_INFO, "nl80211: Could not register monitor read socket"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8069 | goto error; |
| 8070 | } |
| 8071 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8072 | drv->monitor_refcount++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8073 | return 0; |
| 8074 | error: |
| 8075 | nl80211_remove_monitor_interface(drv); |
| 8076 | return -1; |
| 8077 | } |
| 8078 | |
| 8079 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8080 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 8081 | { |
| 8082 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8083 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8084 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 8085 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8086 | |
| 8087 | /* |
| 8088 | * Disable Probe Request reporting unless we need it in this way for |
| 8089 | * devices that include the AP SME, in the other case (unless using |
| 8090 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 8091 | */ |
| 8092 | if (!drv->device_ap_sme) |
| 8093 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 8094 | |
| 8095 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 8096 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 8097 | return -1; |
| 8098 | |
| 8099 | if (drv->device_ap_sme && !drv->use_monitor) |
| 8100 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 8101 | return -1; |
| 8102 | |
| 8103 | if (!drv->device_ap_sme && drv->use_monitor && |
| 8104 | nl80211_create_monitor_interface(drv) && |
| 8105 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8106 | return -1; |
| 8107 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8108 | if (drv->device_ap_sme && |
| 8109 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 8110 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 8111 | "Probe Request frame reporting in AP mode"); |
| 8112 | /* Try to survive without this */ |
| 8113 | } |
| 8114 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8115 | return 0; |
| 8116 | } |
| 8117 | |
| 8118 | |
| 8119 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 8120 | { |
| 8121 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8122 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8123 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 8124 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8125 | if (drv->device_ap_sme) { |
| 8126 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 8127 | if (!drv->use_monitor) |
| 8128 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 8129 | } else if (drv->use_monitor) |
| 8130 | nl80211_remove_monitor_interface(drv); |
| 8131 | else |
| 8132 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 8133 | |
| 8134 | bss->beacon_set = 0; |
| 8135 | } |
| 8136 | |
| 8137 | |
| 8138 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 8139 | const u8 *addr, const u8 *data, |
| 8140 | size_t data_len) |
| 8141 | { |
| 8142 | struct sockaddr_ll ll; |
| 8143 | int ret; |
| 8144 | |
| 8145 | if (bss->drv->eapol_tx_sock < 0) { |
| 8146 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 8147 | return -1; |
| 8148 | } |
| 8149 | |
| 8150 | os_memset(&ll, 0, sizeof(ll)); |
| 8151 | ll.sll_family = AF_PACKET; |
| 8152 | ll.sll_ifindex = bss->ifindex; |
| 8153 | ll.sll_protocol = htons(ETH_P_PAE); |
| 8154 | ll.sll_halen = ETH_ALEN; |
| 8155 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 8156 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 8157 | (struct sockaddr *) &ll, sizeof(ll)); |
| 8158 | if (ret < 0) |
| 8159 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 8160 | strerror(errno)); |
| 8161 | |
| 8162 | return ret; |
| 8163 | } |
| 8164 | |
| 8165 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8166 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 8167 | |
| 8168 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 8169 | void *priv, const u8 *addr, const u8 *data, |
| 8170 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 8171 | { |
| 8172 | struct i802_bss *bss = priv; |
| 8173 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8174 | struct ieee80211_hdr *hdr; |
| 8175 | size_t len; |
| 8176 | u8 *pos; |
| 8177 | int res; |
| 8178 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 8179 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8180 | if (drv->device_ap_sme || !drv->use_monitor) |
| 8181 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 8182 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8183 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 8184 | data_len; |
| 8185 | hdr = os_zalloc(len); |
| 8186 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8187 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 8188 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8189 | return -1; |
| 8190 | } |
| 8191 | |
| 8192 | hdr->frame_control = |
| 8193 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 8194 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 8195 | if (encrypt) |
| 8196 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 8197 | if (qos) { |
| 8198 | hdr->frame_control |= |
| 8199 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 8200 | } |
| 8201 | |
| 8202 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 8203 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 8204 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 8205 | pos = (u8 *) (hdr + 1); |
| 8206 | |
| 8207 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8208 | /* Set highest priority in QoS header */ |
| 8209 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8210 | pos[1] = 0; |
| 8211 | pos += 2; |
| 8212 | } |
| 8213 | |
| 8214 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 8215 | pos += sizeof(rfc1042_header); |
| 8216 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 8217 | pos += 2; |
| 8218 | memcpy(pos, data, data_len); |
| 8219 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8220 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
| 8221 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8222 | if (res < 0) { |
| 8223 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 8224 | "failed: %d (%s)", |
| 8225 | (unsigned long) len, errno, strerror(errno)); |
| 8226 | } |
| 8227 | os_free(hdr); |
| 8228 | |
| 8229 | return res; |
| 8230 | } |
| 8231 | |
| 8232 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8233 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
| 8234 | int total_flags, |
| 8235 | int flags_or, int flags_and) |
| 8236 | { |
| 8237 | struct i802_bss *bss = priv; |
| 8238 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8239 | struct nl_msg *msg; |
| 8240 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8241 | struct nl80211_sta_flag_update upd; |
| 8242 | |
| 8243 | msg = nlmsg_alloc(); |
| 8244 | if (!msg) |
| 8245 | return -ENOMEM; |
| 8246 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8247 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8248 | |
| 8249 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 8250 | if_nametoindex(bss->ifname)); |
| 8251 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 8252 | |
| 8253 | /* |
| 8254 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 8255 | * can be removed eventually. |
| 8256 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8257 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
| 8258 | if (!flags) |
| 8259 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8260 | if (total_flags & WPA_STA_AUTHORIZED) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8261 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8262 | |
| 8263 | if (total_flags & WPA_STA_WMM) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8264 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_WME); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8265 | |
| 8266 | if (total_flags & WPA_STA_SHORT_PREAMBLE) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8267 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_SHORT_PREAMBLE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8268 | |
| 8269 | if (total_flags & WPA_STA_MFP) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8270 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_MFP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8271 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8272 | if (total_flags & WPA_STA_TDLS_PEER) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8273 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8274 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8275 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8276 | |
| 8277 | os_memset(&upd, 0, sizeof(upd)); |
| 8278 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 8279 | upd.set = sta_flags_nl80211(flags_or); |
| 8280 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 8281 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8282 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8283 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8284 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8285 | return -ENOBUFS; |
| 8286 | } |
| 8287 | |
| 8288 | |
| 8289 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 8290 | struct wpa_driver_associate_params *params) |
| 8291 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8292 | enum nl80211_iftype nlmode, old_mode; |
| 8293 | struct hostapd_freq_params freq = { |
| 8294 | .freq = params->freq, |
| 8295 | }; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8296 | |
| 8297 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8298 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 8299 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8300 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 8301 | } else |
| 8302 | nlmode = NL80211_IFTYPE_AP; |
| 8303 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8304 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8305 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8306 | nl80211_remove_monitor_interface(drv); |
| 8307 | return -1; |
| 8308 | } |
| 8309 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8310 | if (wpa_driver_nl80211_set_freq(drv->first_bss, &freq)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8311 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8312 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8313 | nl80211_remove_monitor_interface(drv); |
| 8314 | return -1; |
| 8315 | } |
| 8316 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8317 | return 0; |
| 8318 | } |
| 8319 | |
| 8320 | |
| 8321 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv) |
| 8322 | { |
| 8323 | struct nl_msg *msg; |
| 8324 | int ret = -1; |
| 8325 | |
| 8326 | msg = nlmsg_alloc(); |
| 8327 | if (!msg) |
| 8328 | return -1; |
| 8329 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8330 | nl80211_cmd(drv, msg, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8331 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 8332 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8333 | msg = NULL; |
| 8334 | if (ret) { |
| 8335 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 8336 | "(%s)", ret, strerror(-ret)); |
| 8337 | goto nla_put_failure; |
| 8338 | } |
| 8339 | |
| 8340 | ret = 0; |
| 8341 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS request sent successfully"); |
| 8342 | |
| 8343 | nla_put_failure: |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8344 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8345 | NL80211_IFTYPE_STATION)) { |
| 8346 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 8347 | "station mode"); |
| 8348 | } |
| 8349 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8350 | nlmsg_free(msg); |
| 8351 | return ret; |
| 8352 | } |
| 8353 | |
| 8354 | |
| 8355 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 8356 | struct wpa_driver_associate_params *params) |
| 8357 | { |
| 8358 | struct nl_msg *msg; |
| 8359 | int ret = -1; |
| 8360 | int count = 0; |
| 8361 | |
| 8362 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 8363 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8364 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8365 | NL80211_IFTYPE_ADHOC)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8366 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 8367 | "IBSS mode"); |
| 8368 | return -1; |
| 8369 | } |
| 8370 | |
| 8371 | retry: |
| 8372 | msg = nlmsg_alloc(); |
| 8373 | if (!msg) |
| 8374 | return -1; |
| 8375 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8376 | nl80211_cmd(drv, msg, 0, NL80211_CMD_JOIN_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8377 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 8378 | |
| 8379 | if (params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 8380 | goto nla_put_failure; |
| 8381 | |
| 8382 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 8383 | params->ssid, params->ssid_len); |
| 8384 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 8385 | params->ssid); |
| 8386 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 8387 | drv->ssid_len = params->ssid_len; |
| 8388 | |
| 8389 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 8390 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
| 8391 | |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 8392 | if (params->beacon_int > 0) { |
| 8393 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", params->beacon_int); |
| 8394 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 8395 | params->beacon_int); |
| 8396 | } |
| 8397 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8398 | ret = nl80211_set_conn_keys(params, msg); |
| 8399 | if (ret) |
| 8400 | goto nla_put_failure; |
| 8401 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8402 | if (params->bssid && params->fixed_bssid) { |
| 8403 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 8404 | MAC2STR(params->bssid)); |
| 8405 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 8406 | } |
| 8407 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8408 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 8409 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 8410 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 8411 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8412 | wpa_printf(MSG_DEBUG, " * control port"); |
| 8413 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
| 8414 | } |
| 8415 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8416 | if (params->wpa_ie) { |
| 8417 | wpa_hexdump(MSG_DEBUG, |
| 8418 | " * Extra IEs for Beacon/Probe Response frames", |
| 8419 | params->wpa_ie, params->wpa_ie_len); |
| 8420 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 8421 | params->wpa_ie); |
| 8422 | } |
| 8423 | |
| 8424 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8425 | msg = NULL; |
| 8426 | if (ret) { |
| 8427 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 8428 | ret, strerror(-ret)); |
| 8429 | count++; |
| 8430 | if (ret == -EALREADY && count == 1) { |
| 8431 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 8432 | "forced leave"); |
| 8433 | nl80211_leave_ibss(drv); |
| 8434 | nlmsg_free(msg); |
| 8435 | goto retry; |
| 8436 | } |
| 8437 | |
| 8438 | goto nla_put_failure; |
| 8439 | } |
| 8440 | ret = 0; |
| 8441 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS request sent successfully"); |
| 8442 | |
| 8443 | nla_put_failure: |
| 8444 | nlmsg_free(msg); |
| 8445 | return ret; |
| 8446 | } |
| 8447 | |
| 8448 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8449 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 8450 | struct wpa_driver_associate_params *params, |
| 8451 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8452 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8453 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8454 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8455 | if (params->bssid) { |
| 8456 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 8457 | MAC2STR(params->bssid)); |
| 8458 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 8459 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8460 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 8461 | if (params->bssid_hint) { |
| 8462 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 8463 | MAC2STR(params->bssid_hint)); |
| 8464 | NLA_PUT(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 8465 | params->bssid_hint); |
| 8466 | } |
| 8467 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8468 | if (params->freq) { |
| 8469 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 8470 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8471 | drv->assoc_freq = params->freq; |
| 8472 | } else |
| 8473 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8474 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 8475 | if (params->freq_hint) { |
| 8476 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
| 8477 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 8478 | params->freq_hint); |
| 8479 | } |
| 8480 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8481 | if (params->bg_scan_period >= 0) { |
| 8482 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 8483 | params->bg_scan_period); |
| 8484 | NLA_PUT_U16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 8485 | params->bg_scan_period); |
| 8486 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8487 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8488 | if (params->ssid) { |
| 8489 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 8490 | params->ssid, params->ssid_len); |
| 8491 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 8492 | params->ssid); |
| 8493 | if (params->ssid_len > sizeof(drv->ssid)) |
| 8494 | goto nla_put_failure; |
| 8495 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 8496 | drv->ssid_len = params->ssid_len; |
| 8497 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8498 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8499 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
| 8500 | if (params->wpa_ie) |
| 8501 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 8502 | params->wpa_ie); |
| 8503 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8504 | if (params->wpa_proto) { |
| 8505 | enum nl80211_wpa_versions ver = 0; |
| 8506 | |
| 8507 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 8508 | ver |= NL80211_WPA_VERSION_1; |
| 8509 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 8510 | ver |= NL80211_WPA_VERSION_2; |
| 8511 | |
| 8512 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
| 8513 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); |
| 8514 | } |
| 8515 | |
| 8516 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 8517 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 8518 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
| 8519 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); |
| 8520 | } |
| 8521 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8522 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 8523 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 8524 | /* |
| 8525 | * This is likely to work even though many drivers do not |
| 8526 | * advertise support for operations without GTK. |
| 8527 | */ |
| 8528 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 8529 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8530 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 8531 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
| 8532 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); |
| 8533 | } |
| 8534 | |
| 8535 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 8536 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 8537 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 8538 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
| 8539 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM) { |
| 8540 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 8541 | |
| 8542 | switch (params->key_mgmt_suite) { |
| 8543 | case WPA_KEY_MGMT_CCKM: |
| 8544 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 8545 | break; |
| 8546 | case WPA_KEY_MGMT_IEEE8021X: |
| 8547 | mgmt = WLAN_AKM_SUITE_8021X; |
| 8548 | break; |
| 8549 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 8550 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 8551 | break; |
| 8552 | case WPA_KEY_MGMT_FT_PSK: |
| 8553 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 8554 | break; |
| 8555 | case WPA_KEY_MGMT_PSK: |
| 8556 | default: |
| 8557 | mgmt = WLAN_AKM_SUITE_PSK; |
| 8558 | break; |
| 8559 | } |
| 8560 | NLA_PUT_U32(msg, NL80211_ATTR_AKM_SUITES, mgmt); |
| 8561 | } |
| 8562 | |
| 8563 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
| 8564 | |
| 8565 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) |
| 8566 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); |
| 8567 | |
| 8568 | if (params->disable_ht) |
| 8569 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT); |
| 8570 | |
| 8571 | if (params->htcaps && params->htcaps_mask) { |
| 8572 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 8573 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps); |
| 8574 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 8575 | params->htcaps_mask); |
| 8576 | } |
| 8577 | |
| 8578 | #ifdef CONFIG_VHT_OVERRIDES |
| 8579 | if (params->disable_vht) { |
| 8580 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 8581 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_VHT); |
| 8582 | } |
| 8583 | |
| 8584 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 8585 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 8586 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, sz, params->vhtcaps); |
| 8587 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 8588 | params->vhtcaps_mask); |
| 8589 | } |
| 8590 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 8591 | |
| 8592 | if (params->p2p) |
| 8593 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 8594 | |
| 8595 | return 0; |
| 8596 | nla_put_failure: |
| 8597 | return -1; |
| 8598 | } |
| 8599 | |
| 8600 | |
| 8601 | static int wpa_driver_nl80211_try_connect( |
| 8602 | struct wpa_driver_nl80211_data *drv, |
| 8603 | struct wpa_driver_associate_params *params) |
| 8604 | { |
| 8605 | struct nl_msg *msg; |
| 8606 | enum nl80211_auth_type type; |
| 8607 | int ret; |
| 8608 | int algs; |
| 8609 | |
| 8610 | msg = nlmsg_alloc(); |
| 8611 | if (!msg) |
| 8612 | return -1; |
| 8613 | |
| 8614 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 8615 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CONNECT); |
| 8616 | |
| 8617 | ret = nl80211_connect_common(drv, params, msg); |
| 8618 | if (ret) |
| 8619 | goto nla_put_failure; |
| 8620 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8621 | algs = 0; |
| 8622 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 8623 | algs++; |
| 8624 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 8625 | algs++; |
| 8626 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 8627 | algs++; |
| 8628 | if (algs > 1) { |
| 8629 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 8630 | "selection"); |
| 8631 | goto skip_auth_type; |
| 8632 | } |
| 8633 | |
| 8634 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 8635 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 8636 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 8637 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 8638 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 8639 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 8640 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 8641 | type = NL80211_AUTHTYPE_FT; |
| 8642 | else |
| 8643 | goto nla_put_failure; |
| 8644 | |
| 8645 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 8646 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); |
| 8647 | |
| 8648 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8649 | ret = nl80211_set_conn_keys(params, msg); |
| 8650 | if (ret) |
| 8651 | goto nla_put_failure; |
| 8652 | |
| 8653 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8654 | msg = NULL; |
| 8655 | if (ret) { |
| 8656 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 8657 | "(%s)", ret, strerror(-ret)); |
| 8658 | goto nla_put_failure; |
| 8659 | } |
| 8660 | ret = 0; |
| 8661 | wpa_printf(MSG_DEBUG, "nl80211: Connect request send successfully"); |
| 8662 | |
| 8663 | nla_put_failure: |
| 8664 | nlmsg_free(msg); |
| 8665 | return ret; |
| 8666 | |
| 8667 | } |
| 8668 | |
| 8669 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8670 | static int wpa_driver_nl80211_connect( |
| 8671 | struct wpa_driver_nl80211_data *drv, |
| 8672 | struct wpa_driver_associate_params *params) |
| 8673 | { |
| 8674 | int ret = wpa_driver_nl80211_try_connect(drv, params); |
| 8675 | if (ret == -EALREADY) { |
| 8676 | /* |
| 8677 | * cfg80211 does not currently accept new connections if |
| 8678 | * we are already connected. As a workaround, force |
| 8679 | * disconnection and try again. |
| 8680 | */ |
| 8681 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 8682 | "disconnecting before reassociation " |
| 8683 | "attempt"); |
| 8684 | if (wpa_driver_nl80211_disconnect( |
| 8685 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 8686 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8687 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 8688 | } |
| 8689 | return ret; |
| 8690 | } |
| 8691 | |
| 8692 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8693 | static int wpa_driver_nl80211_associate( |
| 8694 | void *priv, struct wpa_driver_associate_params *params) |
| 8695 | { |
| 8696 | struct i802_bss *bss = priv; |
| 8697 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8698 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8699 | struct nl_msg *msg; |
| 8700 | |
| 8701 | if (params->mode == IEEE80211_MODE_AP) |
| 8702 | return wpa_driver_nl80211_ap(drv, params); |
| 8703 | |
| 8704 | if (params->mode == IEEE80211_MODE_IBSS) |
| 8705 | return wpa_driver_nl80211_ibss(drv, params); |
| 8706 | |
| 8707 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8708 | enum nl80211_iftype nlmode = params->p2p ? |
| 8709 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 8710 | |
| 8711 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8712 | return -1; |
| 8713 | return wpa_driver_nl80211_connect(drv, params); |
| 8714 | } |
| 8715 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8716 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8717 | |
| 8718 | msg = nlmsg_alloc(); |
| 8719 | if (!msg) |
| 8720 | return -1; |
| 8721 | |
| 8722 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 8723 | drv->ifindex); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8724 | nl80211_cmd(drv, msg, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8725 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8726 | ret = nl80211_connect_common(drv, params, msg); |
| 8727 | if (ret) |
| 8728 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8729 | |
| 8730 | if (params->prev_bssid) { |
| 8731 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 8732 | MAC2STR(params->prev_bssid)); |
| 8733 | NLA_PUT(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 8734 | params->prev_bssid); |
| 8735 | } |
| 8736 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8737 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8738 | msg = NULL; |
| 8739 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8740 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 8741 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 8742 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8743 | nl80211_dump_scan(drv); |
| 8744 | goto nla_put_failure; |
| 8745 | } |
| 8746 | ret = 0; |
| 8747 | wpa_printf(MSG_DEBUG, "nl80211: Association request send " |
| 8748 | "successfully"); |
| 8749 | |
| 8750 | nla_put_failure: |
| 8751 | nlmsg_free(msg); |
| 8752 | return ret; |
| 8753 | } |
| 8754 | |
| 8755 | |
| 8756 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8757 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8758 | { |
| 8759 | struct nl_msg *msg; |
| 8760 | int ret = -ENOBUFS; |
| 8761 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8762 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 8763 | ifindex, mode, nl80211_iftype_str(mode)); |
| 8764 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8765 | msg = nlmsg_alloc(); |
| 8766 | if (!msg) |
| 8767 | return -ENOMEM; |
| 8768 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8769 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_INTERFACE); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8770 | if (nl80211_set_iface_id(msg, drv->first_bss) < 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8771 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8772 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, mode); |
| 8773 | |
| 8774 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8775 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8776 | if (!ret) |
| 8777 | return 0; |
| 8778 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8779 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8780 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 8781 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 8782 | return ret; |
| 8783 | } |
| 8784 | |
| 8785 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8786 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 8787 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8788 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8789 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8790 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8791 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8792 | int was_ap = is_ap_interface(drv->nlmode); |
| 8793 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8794 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8795 | res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8796 | if (res && nlmode == nl80211_get_ifmode(bss)) |
| 8797 | res = 0; |
| 8798 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8799 | if (res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8800 | drv->nlmode = nlmode; |
| 8801 | ret = 0; |
| 8802 | goto done; |
| 8803 | } |
| 8804 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8805 | if (res == -ENODEV) |
| 8806 | return -1; |
| 8807 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8808 | if (nlmode == drv->nlmode) { |
| 8809 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 8810 | "requested mode - ignore error"); |
| 8811 | ret = 0; |
| 8812 | goto done; /* Already in the requested mode */ |
| 8813 | } |
| 8814 | |
| 8815 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 8816 | * take the device down, try to set the mode again, and bring the |
| 8817 | * device back up. |
| 8818 | */ |
| 8819 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 8820 | "interface down"); |
| 8821 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8822 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8823 | if (res == -EACCES || res == -ENODEV) |
| 8824 | break; |
| 8825 | if (res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8826 | /* Try to set the mode again while the interface is |
| 8827 | * down */ |
| 8828 | ret = nl80211_set_mode(drv, drv->ifindex, nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8829 | if (ret == -EACCES) |
| 8830 | break; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8831 | res = i802_set_iface_flags(bss, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8832 | if (res && !ret) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8833 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8834 | else if (ret != -EBUSY) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8835 | break; |
| 8836 | } else |
| 8837 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 8838 | "interface down"); |
| 8839 | os_sleep(0, 100000); |
| 8840 | } |
| 8841 | |
| 8842 | if (!ret) { |
| 8843 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 8844 | "interface is down"); |
| 8845 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8846 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8847 | } |
| 8848 | |
| 8849 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8850 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8851 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 8852 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8853 | return ret; |
| 8854 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8855 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8856 | if (is_p2p_net_interface(nlmode)) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8857 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 8858 | else if (drv->disabled_11b_rates) |
| 8859 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 8860 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8861 | if (is_ap_interface(nlmode)) { |
| 8862 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 8863 | /* Setup additional AP mode functionality if needed */ |
| 8864 | if (nl80211_setup_ap(bss)) |
| 8865 | return -1; |
| 8866 | } else if (was_ap) { |
| 8867 | /* Remove additional AP mode functionality */ |
| 8868 | nl80211_teardown_ap(bss); |
| 8869 | } else { |
| 8870 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 8871 | } |
| 8872 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8873 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8874 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 8875 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 8876 | "frame processing - ignore for now"); |
| 8877 | |
| 8878 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8879 | } |
| 8880 | |
| 8881 | |
| 8882 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 8883 | struct wpa_driver_capa *capa) |
| 8884 | { |
| 8885 | struct i802_bss *bss = priv; |
| 8886 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8887 | if (!drv->has_capability) |
| 8888 | return -1; |
| 8889 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8890 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 8891 | capa->extended_capa = drv->extended_capa; |
| 8892 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 8893 | capa->extended_capa_len = drv->extended_capa_len; |
| 8894 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8895 | |
| 8896 | if ((capa->flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && |
| 8897 | !drv->allow_p2p_device) { |
| 8898 | wpa_printf(MSG_DEBUG, "nl80211: Do not indicate P2P_DEVICE support (p2p_device=1 driver param not specified)"); |
| 8899 | capa->flags &= ~WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE; |
| 8900 | } |
| 8901 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8902 | return 0; |
| 8903 | } |
| 8904 | |
| 8905 | |
| 8906 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 8907 | { |
| 8908 | struct i802_bss *bss = priv; |
| 8909 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8910 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8911 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 8912 | bss->ifname, drv->operstate, state, |
| 8913 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8914 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8915 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8916 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 8917 | } |
| 8918 | |
| 8919 | |
| 8920 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 8921 | { |
| 8922 | struct i802_bss *bss = priv; |
| 8923 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8924 | struct nl_msg *msg; |
| 8925 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8926 | int ret = -ENOBUFS; |
| 8927 | |
| 8928 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 8929 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 8930 | return 0; |
| 8931 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8932 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8933 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 8934 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 8935 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8936 | msg = nlmsg_alloc(); |
| 8937 | if (!msg) |
| 8938 | return -ENOMEM; |
| 8939 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8940 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8941 | |
| 8942 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 8943 | if_nametoindex(bss->ifname)); |
| 8944 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
| 8945 | |
| 8946 | os_memset(&upd, 0, sizeof(upd)); |
| 8947 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 8948 | if (authorized) |
| 8949 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 8950 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 8951 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8952 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8953 | msg = NULL; |
| 8954 | if (!ret) |
| 8955 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8956 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8957 | nlmsg_free(msg); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8958 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 8959 | ret, strerror(-ret)); |
| 8960 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8961 | } |
| 8962 | |
| 8963 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8964 | /* Set kernel driver on given frequency (MHz) */ |
| 8965 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8966 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8967 | struct i802_bss *bss = priv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8968 | return wpa_driver_nl80211_set_freq(bss, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8969 | } |
| 8970 | |
| 8971 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8972 | static inline int min_int(int a, int b) |
| 8973 | { |
| 8974 | if (a < b) |
| 8975 | return a; |
| 8976 | return b; |
| 8977 | } |
| 8978 | |
| 8979 | |
| 8980 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 8981 | { |
| 8982 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8983 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8984 | |
| 8985 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8986 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8987 | |
| 8988 | /* |
| 8989 | * TODO: validate the key index and mac address! |
| 8990 | * Otherwise, there's a race condition as soon as |
| 8991 | * the kernel starts sending key notifications. |
| 8992 | */ |
| 8993 | |
| 8994 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 8995 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 8996 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 8997 | return NL_SKIP; |
| 8998 | } |
| 8999 | |
| 9000 | |
| 9001 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 9002 | int idx, u8 *seq) |
| 9003 | { |
| 9004 | struct i802_bss *bss = priv; |
| 9005 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9006 | struct nl_msg *msg; |
| 9007 | |
| 9008 | msg = nlmsg_alloc(); |
| 9009 | if (!msg) |
| 9010 | return -ENOMEM; |
| 9011 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9012 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9013 | |
| 9014 | if (addr) |
| 9015 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 9016 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx); |
| 9017 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface)); |
| 9018 | |
| 9019 | memset(seq, 0, 6); |
| 9020 | |
| 9021 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
| 9022 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9023 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9024 | return -ENOBUFS; |
| 9025 | } |
| 9026 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9027 | |
| 9028 | static int i802_set_rts(void *priv, int rts) |
| 9029 | { |
| 9030 | struct i802_bss *bss = priv; |
| 9031 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9032 | struct nl_msg *msg; |
| 9033 | int ret = -ENOBUFS; |
| 9034 | u32 val; |
| 9035 | |
| 9036 | msg = nlmsg_alloc(); |
| 9037 | if (!msg) |
| 9038 | return -ENOMEM; |
| 9039 | |
| 9040 | if (rts >= 2347) |
| 9041 | val = (u32) -1; |
| 9042 | else |
| 9043 | val = rts; |
| 9044 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9045 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9046 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 9047 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val); |
| 9048 | |
| 9049 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9050 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9051 | if (!ret) |
| 9052 | return 0; |
| 9053 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9054 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9055 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 9056 | "%d (%s)", rts, ret, strerror(-ret)); |
| 9057 | return ret; |
| 9058 | } |
| 9059 | |
| 9060 | |
| 9061 | static int i802_set_frag(void *priv, int frag) |
| 9062 | { |
| 9063 | struct i802_bss *bss = priv; |
| 9064 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9065 | struct nl_msg *msg; |
| 9066 | int ret = -ENOBUFS; |
| 9067 | u32 val; |
| 9068 | |
| 9069 | msg = nlmsg_alloc(); |
| 9070 | if (!msg) |
| 9071 | return -ENOMEM; |
| 9072 | |
| 9073 | if (frag >= 2346) |
| 9074 | val = (u32) -1; |
| 9075 | else |
| 9076 | val = frag; |
| 9077 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9078 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9079 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 9080 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val); |
| 9081 | |
| 9082 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9083 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9084 | if (!ret) |
| 9085 | return 0; |
| 9086 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9087 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9088 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 9089 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 9090 | return ret; |
| 9091 | } |
| 9092 | |
| 9093 | |
| 9094 | static int i802_flush(void *priv) |
| 9095 | { |
| 9096 | struct i802_bss *bss = priv; |
| 9097 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9098 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9099 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9100 | |
| 9101 | msg = nlmsg_alloc(); |
| 9102 | if (!msg) |
| 9103 | return -1; |
| 9104 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9105 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 9106 | bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9107 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9108 | |
| 9109 | /* |
| 9110 | * XXX: FIX! this needs to flush all VLANs too |
| 9111 | */ |
| 9112 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 9113 | if_nametoindex(bss->ifname)); |
| 9114 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9115 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9116 | if (res) { |
| 9117 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 9118 | "(%s)", res, strerror(-res)); |
| 9119 | } |
| 9120 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9121 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9122 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9123 | return -ENOBUFS; |
| 9124 | } |
| 9125 | |
| 9126 | |
| 9127 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 9128 | { |
| 9129 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9130 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9131 | struct hostap_sta_driver_data *data = arg; |
| 9132 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 9133 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 9134 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 9135 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 9136 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 9137 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 9138 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 9139 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9140 | }; |
| 9141 | |
| 9142 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9143 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9144 | |
| 9145 | /* |
| 9146 | * TODO: validate the interface and mac address! |
| 9147 | * Otherwise, there's a race condition as soon as |
| 9148 | * the kernel starts sending station notifications. |
| 9149 | */ |
| 9150 | |
| 9151 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 9152 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 9153 | return NL_SKIP; |
| 9154 | } |
| 9155 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 9156 | tb[NL80211_ATTR_STA_INFO], |
| 9157 | stats_policy)) { |
| 9158 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 9159 | return NL_SKIP; |
| 9160 | } |
| 9161 | |
| 9162 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 9163 | data->inactive_msec = |
| 9164 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
| 9165 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 9166 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 9167 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 9168 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
| 9169 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 9170 | data->rx_packets = |
| 9171 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 9172 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 9173 | data->tx_packets = |
| 9174 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 9175 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 9176 | data->tx_retry_failed = |
| 9177 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9178 | |
| 9179 | return NL_SKIP; |
| 9180 | } |
| 9181 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9182 | static int i802_read_sta_data(struct i802_bss *bss, |
| 9183 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9184 | const u8 *addr) |
| 9185 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9186 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9187 | struct nl_msg *msg; |
| 9188 | |
| 9189 | os_memset(data, 0, sizeof(*data)); |
| 9190 | msg = nlmsg_alloc(); |
| 9191 | if (!msg) |
| 9192 | return -ENOMEM; |
| 9193 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9194 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9195 | |
| 9196 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 9197 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 9198 | |
| 9199 | return send_and_recv_msgs(drv, msg, get_sta_handler, data); |
| 9200 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9201 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9202 | return -ENOBUFS; |
| 9203 | } |
| 9204 | |
| 9205 | |
| 9206 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 9207 | int cw_min, int cw_max, int burst_time) |
| 9208 | { |
| 9209 | struct i802_bss *bss = priv; |
| 9210 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9211 | struct nl_msg *msg; |
| 9212 | struct nlattr *txq, *params; |
| 9213 | |
| 9214 | msg = nlmsg_alloc(); |
| 9215 | if (!msg) |
| 9216 | return -1; |
| 9217 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9218 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9219 | |
| 9220 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 9221 | |
| 9222 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 9223 | if (!txq) |
| 9224 | goto nla_put_failure; |
| 9225 | |
| 9226 | /* We are only sending parameters for a single TXQ at a time */ |
| 9227 | params = nla_nest_start(msg, 1); |
| 9228 | if (!params) |
| 9229 | goto nla_put_failure; |
| 9230 | |
| 9231 | switch (queue) { |
| 9232 | case 0: |
| 9233 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO); |
| 9234 | break; |
| 9235 | case 1: |
| 9236 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI); |
| 9237 | break; |
| 9238 | case 2: |
| 9239 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE); |
| 9240 | break; |
| 9241 | case 3: |
| 9242 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK); |
| 9243 | break; |
| 9244 | } |
| 9245 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 9246 | * 32 usec, so need to convert the value here. */ |
| 9247 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32); |
| 9248 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min); |
| 9249 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max); |
| 9250 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs); |
| 9251 | |
| 9252 | nla_nest_end(msg, params); |
| 9253 | |
| 9254 | nla_nest_end(msg, txq); |
| 9255 | |
| 9256 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 9257 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9258 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9259 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9260 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9261 | return -1; |
| 9262 | } |
| 9263 | |
| 9264 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9265 | 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] | 9266 | const char *ifname, int vlan_id) |
| 9267 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9268 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9269 | struct nl_msg *msg; |
| 9270 | int ret = -ENOBUFS; |
| 9271 | |
| 9272 | msg = nlmsg_alloc(); |
| 9273 | if (!msg) |
| 9274 | return -ENOMEM; |
| 9275 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9276 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 9277 | ", ifname=%s[%d], vlan_id=%d)", |
| 9278 | bss->ifname, if_nametoindex(bss->ifname), |
| 9279 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9280 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9281 | |
| 9282 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 9283 | if_nametoindex(bss->ifname)); |
| 9284 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 9285 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, |
| 9286 | if_nametoindex(ifname)); |
| 9287 | |
| 9288 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9289 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9290 | if (ret < 0) { |
| 9291 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 9292 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 9293 | MAC2STR(addr), ifname, vlan_id, ret, |
| 9294 | strerror(-ret)); |
| 9295 | } |
| 9296 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9297 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9298 | return ret; |
| 9299 | } |
| 9300 | |
| 9301 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9302 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 9303 | { |
| 9304 | struct hostap_sta_driver_data data; |
| 9305 | int ret; |
| 9306 | |
| 9307 | data.inactive_msec = (unsigned long) -1; |
| 9308 | ret = i802_read_sta_data(priv, &data, addr); |
| 9309 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 9310 | return -1; |
| 9311 | return data.inactive_msec / 1000; |
| 9312 | } |
| 9313 | |
| 9314 | |
| 9315 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 9316 | { |
| 9317 | #if 0 |
| 9318 | /* TODO */ |
| 9319 | #endif |
| 9320 | return 0; |
| 9321 | } |
| 9322 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9323 | |
| 9324 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 9325 | int reason) |
| 9326 | { |
| 9327 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9328 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9329 | struct ieee80211_mgmt mgmt; |
| 9330 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9331 | if (drv->device_ap_sme) |
| 9332 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 9333 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9334 | memset(&mgmt, 0, sizeof(mgmt)); |
| 9335 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 9336 | WLAN_FC_STYPE_DEAUTH); |
| 9337 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 9338 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 9339 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 9340 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 9341 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 9342 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9343 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
| 9344 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9345 | } |
| 9346 | |
| 9347 | |
| 9348 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 9349 | int reason) |
| 9350 | { |
| 9351 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9352 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9353 | struct ieee80211_mgmt mgmt; |
| 9354 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9355 | if (drv->device_ap_sme) |
| 9356 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 9357 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9358 | memset(&mgmt, 0, sizeof(mgmt)); |
| 9359 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 9360 | WLAN_FC_STYPE_DISASSOC); |
| 9361 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 9362 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 9363 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 9364 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 9365 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 9366 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9367 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
| 9368 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9369 | } |
| 9370 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9371 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9372 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 9373 | { |
| 9374 | int i; |
| 9375 | int *old; |
| 9376 | |
| 9377 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", |
| 9378 | ifidx); |
| 9379 | for (i = 0; i < drv->num_if_indices; i++) { |
| 9380 | if (drv->if_indices[i] == 0) { |
| 9381 | drv->if_indices[i] = ifidx; |
| 9382 | return; |
| 9383 | } |
| 9384 | } |
| 9385 | |
| 9386 | if (drv->if_indices != drv->default_if_indices) |
| 9387 | old = drv->if_indices; |
| 9388 | else |
| 9389 | old = NULL; |
| 9390 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9391 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 9392 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9393 | if (!drv->if_indices) { |
| 9394 | if (!old) |
| 9395 | drv->if_indices = drv->default_if_indices; |
| 9396 | else |
| 9397 | drv->if_indices = old; |
| 9398 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 9399 | "interfaces"); |
| 9400 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 9401 | return; |
| 9402 | } else if (!old) |
| 9403 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 9404 | sizeof(drv->default_if_indices)); |
| 9405 | drv->if_indices[drv->num_if_indices] = ifidx; |
| 9406 | drv->num_if_indices++; |
| 9407 | } |
| 9408 | |
| 9409 | |
| 9410 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 9411 | { |
| 9412 | int i; |
| 9413 | |
| 9414 | for (i = 0; i < drv->num_if_indices; i++) { |
| 9415 | if (drv->if_indices[i] == ifidx) { |
| 9416 | drv->if_indices[i] = 0; |
| 9417 | break; |
| 9418 | } |
| 9419 | } |
| 9420 | } |
| 9421 | |
| 9422 | |
| 9423 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 9424 | { |
| 9425 | int i; |
| 9426 | |
| 9427 | for (i = 0; i < drv->num_if_indices; i++) |
| 9428 | if (drv->if_indices[i] == ifidx) |
| 9429 | return 1; |
| 9430 | |
| 9431 | return 0; |
| 9432 | } |
| 9433 | |
| 9434 | |
| 9435 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 9436 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9437 | { |
| 9438 | struct i802_bss *bss = priv; |
| 9439 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9440 | char name[IFNAMSIZ + 1]; |
| 9441 | |
| 9442 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 9443 | if (ifname_wds) |
| 9444 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 9445 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9446 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 9447 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 9448 | if (val) { |
| 9449 | if (!if_nametoindex(name)) { |
| 9450 | if (nl80211_create_iface(drv, name, |
| 9451 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9452 | bss->addr, 1, NULL, NULL, 0) < |
| 9453 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9454 | return -1; |
| 9455 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9456 | linux_br_add_if(drv->global->ioctl_sock, |
| 9457 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9458 | return -1; |
| 9459 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9460 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 9461 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 9462 | "interface %s up", name); |
| 9463 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9464 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 9465 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 9466 | if (bridge_ifname) |
| 9467 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 9468 | name); |
| 9469 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9470 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9471 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 9472 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9473 | } |
| 9474 | } |
| 9475 | |
| 9476 | |
| 9477 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 9478 | { |
| 9479 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 9480 | struct sockaddr_ll lladdr; |
| 9481 | unsigned char buf[3000]; |
| 9482 | int len; |
| 9483 | socklen_t fromlen = sizeof(lladdr); |
| 9484 | |
| 9485 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 9486 | (struct sockaddr *)&lladdr, &fromlen); |
| 9487 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9488 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 9489 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9490 | return; |
| 9491 | } |
| 9492 | |
| 9493 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
| 9494 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 9495 | } |
| 9496 | |
| 9497 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9498 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 9499 | struct i802_bss *bss, |
| 9500 | const char *brname, const char *ifname) |
| 9501 | { |
| 9502 | int ifindex; |
| 9503 | char in_br[IFNAMSIZ]; |
| 9504 | |
| 9505 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
| 9506 | ifindex = if_nametoindex(brname); |
| 9507 | if (ifindex == 0) { |
| 9508 | /* |
| 9509 | * Bridge was configured, but the bridge device does |
| 9510 | * not exist. Try to add it now. |
| 9511 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9512 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9513 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 9514 | "bridge interface %s: %s", |
| 9515 | brname, strerror(errno)); |
| 9516 | return -1; |
| 9517 | } |
| 9518 | bss->added_bridge = 1; |
| 9519 | add_ifidx(drv, if_nametoindex(brname)); |
| 9520 | } |
| 9521 | |
| 9522 | if (linux_br_get(in_br, ifname) == 0) { |
| 9523 | if (os_strcmp(in_br, brname) == 0) |
| 9524 | return 0; /* already in the bridge */ |
| 9525 | |
| 9526 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 9527 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9528 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 9529 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9530 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 9531 | "remove interface %s from bridge " |
| 9532 | "%s: %s", |
| 9533 | ifname, brname, strerror(errno)); |
| 9534 | return -1; |
| 9535 | } |
| 9536 | } |
| 9537 | |
| 9538 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 9539 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9540 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9541 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 9542 | "into bridge %s: %s", |
| 9543 | ifname, brname, strerror(errno)); |
| 9544 | return -1; |
| 9545 | } |
| 9546 | bss->added_if_into_bridge = 1; |
| 9547 | |
| 9548 | return 0; |
| 9549 | } |
| 9550 | |
| 9551 | |
| 9552 | static void *i802_init(struct hostapd_data *hapd, |
| 9553 | struct wpa_init_params *params) |
| 9554 | { |
| 9555 | struct wpa_driver_nl80211_data *drv; |
| 9556 | struct i802_bss *bss; |
| 9557 | size_t i; |
| 9558 | char brname[IFNAMSIZ]; |
| 9559 | int ifindex, br_ifindex; |
| 9560 | int br_added = 0; |
| 9561 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9562 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 9563 | params->global_priv, 1, |
| 9564 | params->bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9565 | if (bss == NULL) |
| 9566 | return NULL; |
| 9567 | |
| 9568 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9569 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9570 | if (linux_br_get(brname, params->ifname) == 0) { |
| 9571 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
| 9572 | params->ifname, brname); |
| 9573 | br_ifindex = if_nametoindex(brname); |
| 9574 | } else { |
| 9575 | brname[0] = '\0'; |
| 9576 | br_ifindex = 0; |
| 9577 | } |
| 9578 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9579 | for (i = 0; i < params->num_bridge; i++) { |
| 9580 | if (params->bridge[i]) { |
| 9581 | ifindex = if_nametoindex(params->bridge[i]); |
| 9582 | if (ifindex) |
| 9583 | add_ifidx(drv, ifindex); |
| 9584 | if (ifindex == br_ifindex) |
| 9585 | br_added = 1; |
| 9586 | } |
| 9587 | } |
| 9588 | if (!br_added && br_ifindex && |
| 9589 | (params->num_bridge == 0 || !params->bridge[0])) |
| 9590 | add_ifidx(drv, br_ifindex); |
| 9591 | |
| 9592 | /* start listening for EAPOL on the default AP interface */ |
| 9593 | add_ifidx(drv, drv->ifindex); |
| 9594 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9595 | if (params->num_bridge && params->bridge[0] && |
| 9596 | i802_check_bridge(drv, bss, params->bridge[0], params->ifname) < 0) |
| 9597 | goto failed; |
| 9598 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9599 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 9600 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9601 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 9602 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9603 | goto failed; |
| 9604 | } |
| 9605 | |
| 9606 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 9607 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9608 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9609 | goto failed; |
| 9610 | } |
| 9611 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9612 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 9613 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9614 | goto failed; |
| 9615 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9616 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 9617 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9618 | return bss; |
| 9619 | |
| 9620 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9621 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9622 | return NULL; |
| 9623 | } |
| 9624 | |
| 9625 | |
| 9626 | static void i802_deinit(void *priv) |
| 9627 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9628 | struct i802_bss *bss = priv; |
| 9629 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9630 | } |
| 9631 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9632 | |
| 9633 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 9634 | enum wpa_driver_if_type type) |
| 9635 | { |
| 9636 | switch (type) { |
| 9637 | case WPA_IF_STATION: |
| 9638 | return NL80211_IFTYPE_STATION; |
| 9639 | case WPA_IF_P2P_CLIENT: |
| 9640 | case WPA_IF_P2P_GROUP: |
| 9641 | return NL80211_IFTYPE_P2P_CLIENT; |
| 9642 | case WPA_IF_AP_VLAN: |
| 9643 | return NL80211_IFTYPE_AP_VLAN; |
| 9644 | case WPA_IF_AP_BSS: |
| 9645 | return NL80211_IFTYPE_AP; |
| 9646 | case WPA_IF_P2P_GO: |
| 9647 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9648 | case WPA_IF_P2P_DEVICE: |
| 9649 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9650 | } |
| 9651 | return -1; |
| 9652 | } |
| 9653 | |
| 9654 | |
| 9655 | #ifdef CONFIG_P2P |
| 9656 | |
| 9657 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 9658 | { |
| 9659 | struct wpa_driver_nl80211_data *drv; |
| 9660 | dl_list_for_each(drv, &global->interfaces, |
| 9661 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9662 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9663 | return 1; |
| 9664 | } |
| 9665 | return 0; |
| 9666 | } |
| 9667 | |
| 9668 | |
| 9669 | static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data *drv, |
| 9670 | u8 *new_addr) |
| 9671 | { |
| 9672 | unsigned int idx; |
| 9673 | |
| 9674 | if (!drv->global) |
| 9675 | return -1; |
| 9676 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9677 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9678 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9679 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9680 | new_addr[0] ^= idx << 2; |
| 9681 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 9682 | break; |
| 9683 | } |
| 9684 | if (idx == 64) |
| 9685 | return -1; |
| 9686 | |
| 9687 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new P2P Interface Address " |
| 9688 | MACSTR, MAC2STR(new_addr)); |
| 9689 | |
| 9690 | return 0; |
| 9691 | } |
| 9692 | |
| 9693 | #endif /* CONFIG_P2P */ |
| 9694 | |
| 9695 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9696 | struct wdev_info { |
| 9697 | u64 wdev_id; |
| 9698 | int wdev_id_set; |
| 9699 | u8 macaddr[ETH_ALEN]; |
| 9700 | }; |
| 9701 | |
| 9702 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 9703 | { |
| 9704 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9705 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9706 | struct wdev_info *wi = arg; |
| 9707 | |
| 9708 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9709 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9710 | if (tb[NL80211_ATTR_WDEV]) { |
| 9711 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 9712 | wi->wdev_id_set = 1; |
| 9713 | } |
| 9714 | |
| 9715 | if (tb[NL80211_ATTR_MAC]) |
| 9716 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 9717 | ETH_ALEN); |
| 9718 | |
| 9719 | return NL_SKIP; |
| 9720 | } |
| 9721 | |
| 9722 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9723 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 9724 | const char *ifname, const u8 *addr, |
| 9725 | void *bss_ctx, void **drv_priv, |
| 9726 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9727 | const char *bridge, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9728 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9729 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9730 | struct i802_bss *bss = priv; |
| 9731 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9732 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9733 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9734 | |
| 9735 | if (addr) |
| 9736 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9737 | nlmode = wpa_driver_nl80211_if_type(type); |
| 9738 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 9739 | struct wdev_info p2pdev_info; |
| 9740 | |
| 9741 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 9742 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 9743 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9744 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9745 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 9746 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 9747 | ifname); |
| 9748 | return -1; |
| 9749 | } |
| 9750 | |
| 9751 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 9752 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 9753 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 9754 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 9755 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 9756 | ifname, |
| 9757 | (long long unsigned int) p2pdev_info.wdev_id); |
| 9758 | } else { |
| 9759 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9760 | 0, NULL, NULL, use_existing); |
| 9761 | if (use_existing && ifidx == -ENFILE) { |
| 9762 | added = 0; |
| 9763 | ifidx = if_nametoindex(ifname); |
| 9764 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9765 | return -1; |
| 9766 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9767 | } |
| 9768 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9769 | if (!addr) { |
| 9770 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 9771 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 9772 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 9773 | bss->ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9774 | if (added) |
| 9775 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9776 | return -1; |
| 9777 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9778 | } |
| 9779 | |
| 9780 | #ifdef CONFIG_P2P |
| 9781 | if (!addr && |
| 9782 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
| 9783 | type == WPA_IF_P2P_GO)) { |
| 9784 | /* Enforce unique P2P Interface Address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9785 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9786 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9787 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9788 | new_addr) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9789 | nl80211_remove_iface(drv, ifidx); |
| 9790 | return -1; |
| 9791 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9792 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9793 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
| 9794 | "for P2P group interface"); |
| 9795 | if (nl80211_p2p_interface_addr(drv, new_addr) < 0) { |
| 9796 | nl80211_remove_iface(drv, ifidx); |
| 9797 | return -1; |
| 9798 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9799 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9800 | new_addr) < 0) { |
| 9801 | nl80211_remove_iface(drv, ifidx); |
| 9802 | return -1; |
| 9803 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9804 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9805 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9806 | } |
| 9807 | #endif /* CONFIG_P2P */ |
| 9808 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9809 | if (type == WPA_IF_AP_BSS) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9810 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 9811 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9812 | if (added) |
| 9813 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9814 | return -1; |
| 9815 | } |
| 9816 | |
| 9817 | if (bridge && |
| 9818 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 9819 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 9820 | "interface %s to a bridge %s", |
| 9821 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9822 | if (added) |
| 9823 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9824 | os_free(new_bss); |
| 9825 | return -1; |
| 9826 | } |
| 9827 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9828 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 9829 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9830 | nl80211_remove_iface(drv, ifidx); |
| 9831 | os_free(new_bss); |
| 9832 | return -1; |
| 9833 | } |
| 9834 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9835 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9836 | new_bss->ifindex = ifidx; |
| 9837 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9838 | new_bss->next = drv->first_bss->next; |
| 9839 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 9840 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9841 | new_bss->added_if = added; |
| 9842 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9843 | if (drv_priv) |
| 9844 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9845 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9846 | |
| 9847 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 9848 | if (nl80211_setup_ap(new_bss)) |
| 9849 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9850 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9851 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9852 | if (drv->global) |
| 9853 | drv->global->if_add_ifindex = ifidx; |
| 9854 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9855 | return 0; |
| 9856 | } |
| 9857 | |
| 9858 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9859 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9860 | enum wpa_driver_if_type type, |
| 9861 | const char *ifname) |
| 9862 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9863 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9864 | int ifindex = if_nametoindex(ifname); |
| 9865 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9866 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 9867 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 9868 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9869 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 9870 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 9871 | if (type != WPA_IF_AP_BSS) |
| 9872 | return 0; |
| 9873 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9874 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9875 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 9876 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9877 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 9878 | "interface %s from bridge %s: %s", |
| 9879 | bss->ifname, bss->brname, strerror(errno)); |
| 9880 | } |
| 9881 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9882 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9883 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 9884 | "bridge %s: %s", |
| 9885 | bss->brname, strerror(errno)); |
| 9886 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9887 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9888 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9889 | struct i802_bss *tbss; |
| 9890 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9891 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 9892 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9893 | if (tbss->next == bss) { |
| 9894 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9895 | /* Unsubscribe management frames */ |
| 9896 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9897 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9898 | os_free(bss); |
| 9899 | bss = NULL; |
| 9900 | break; |
| 9901 | } |
| 9902 | } |
| 9903 | if (bss) |
| 9904 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 9905 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9906 | } else { |
| 9907 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 9908 | nl80211_teardown_ap(bss); |
| 9909 | if (!bss->added_if && !drv->first_bss->next) |
| 9910 | wpa_driver_nl80211_del_beacon(drv); |
| 9911 | nl80211_destroy_bss(bss); |
| 9912 | if (!bss->added_if) |
| 9913 | i802_set_iface_flags(bss, 0); |
| 9914 | if (drv->first_bss->next) { |
| 9915 | drv->first_bss = drv->first_bss->next; |
| 9916 | drv->ctx = drv->first_bss->ctx; |
| 9917 | os_free(bss); |
| 9918 | } else { |
| 9919 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 9920 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9921 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9922 | |
| 9923 | return 0; |
| 9924 | } |
| 9925 | |
| 9926 | |
| 9927 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 9928 | { |
| 9929 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9930 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9931 | u64 *cookie = arg; |
| 9932 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9933 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9934 | if (tb[NL80211_ATTR_COOKIE]) |
| 9935 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 9936 | return NL_SKIP; |
| 9937 | } |
| 9938 | |
| 9939 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9940 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9941 | unsigned int freq, unsigned int wait, |
| 9942 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9943 | u64 *cookie_out, int no_cck, int no_ack, |
| 9944 | int offchanok) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9945 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9946 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9947 | struct nl_msg *msg; |
| 9948 | u64 cookie; |
| 9949 | int ret = -1; |
| 9950 | |
| 9951 | msg = nlmsg_alloc(); |
| 9952 | if (!msg) |
| 9953 | return -1; |
| 9954 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9955 | 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] | 9956 | "no_ack=%d offchanok=%d", |
| 9957 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 9958 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9959 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9960 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9961 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 9962 | goto nla_put_failure; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 9963 | if (freq) |
| 9964 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9965 | if (wait) |
| 9966 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, wait); |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 9967 | if (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 9968 | drv->test_use_roc_tx)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9969 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 9970 | if (no_cck) |
| 9971 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); |
| 9972 | if (no_ack) |
| 9973 | NLA_PUT_FLAG(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK); |
| 9974 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9975 | NLA_PUT(msg, NL80211_ATTR_FRAME, buf_len, buf); |
| 9976 | |
| 9977 | cookie = 0; |
| 9978 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 9979 | msg = NULL; |
| 9980 | if (ret) { |
| 9981 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9982 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 9983 | freq, wait); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9984 | goto nla_put_failure; |
| 9985 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9986 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9987 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 9988 | (long long unsigned int) cookie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9989 | |
| 9990 | if (cookie_out) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9991 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9992 | |
| 9993 | nla_put_failure: |
| 9994 | nlmsg_free(msg); |
| 9995 | return ret; |
| 9996 | } |
| 9997 | |
| 9998 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9999 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 10000 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10001 | unsigned int wait_time, |
| 10002 | const u8 *dst, const u8 *src, |
| 10003 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10004 | const u8 *data, size_t data_len, |
| 10005 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10006 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10007 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10008 | int ret = -1; |
| 10009 | u8 *buf; |
| 10010 | struct ieee80211_hdr *hdr; |
| 10011 | |
| 10012 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 10013 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 10014 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10015 | |
| 10016 | buf = os_zalloc(24 + data_len); |
| 10017 | if (buf == NULL) |
| 10018 | return ret; |
| 10019 | os_memcpy(buf + 24, data, data_len); |
| 10020 | hdr = (struct ieee80211_hdr *) buf; |
| 10021 | hdr->frame_control = |
| 10022 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 10023 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 10024 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 10025 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 10026 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10027 | if (is_ap_interface(drv->nlmode) && |
| 10028 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 10029 | (int) freq == bss->freq || drv->device_ap_sme || |
| 10030 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10031 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 10032 | 0, freq, no_cck, 1, |
| 10033 | wait_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10034 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10035 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10036 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10037 | &drv->send_action_cookie, |
| 10038 | no_cck, 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10039 | |
| 10040 | os_free(buf); |
| 10041 | return ret; |
| 10042 | } |
| 10043 | |
| 10044 | |
| 10045 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 10046 | { |
| 10047 | struct i802_bss *bss = priv; |
| 10048 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10049 | struct nl_msg *msg; |
| 10050 | int ret; |
| 10051 | |
| 10052 | msg = nlmsg_alloc(); |
| 10053 | if (!msg) |
| 10054 | return; |
| 10055 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 10056 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
| 10057 | (long long unsigned int) drv->send_action_cookie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10058 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME_WAIT_CANCEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10059 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10060 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 10061 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10062 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie); |
| 10063 | |
| 10064 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10065 | msg = NULL; |
| 10066 | if (ret) |
| 10067 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 10068 | "(%s)", ret, strerror(-ret)); |
| 10069 | |
| 10070 | nla_put_failure: |
| 10071 | nlmsg_free(msg); |
| 10072 | } |
| 10073 | |
| 10074 | |
| 10075 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 10076 | unsigned int duration) |
| 10077 | { |
| 10078 | struct i802_bss *bss = priv; |
| 10079 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10080 | struct nl_msg *msg; |
| 10081 | int ret; |
| 10082 | u64 cookie; |
| 10083 | |
| 10084 | msg = nlmsg_alloc(); |
| 10085 | if (!msg) |
| 10086 | return -1; |
| 10087 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10088 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REMAIN_ON_CHANNEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10089 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10090 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 10091 | goto nla_put_failure; |
| 10092 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10093 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 10094 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 10095 | |
| 10096 | cookie = 0; |
| 10097 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10098 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10099 | if (ret == 0) { |
| 10100 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 10101 | "0x%llx for freq=%u MHz duration=%u", |
| 10102 | (long long unsigned int) cookie, freq, duration); |
| 10103 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10104 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10105 | return 0; |
| 10106 | } |
| 10107 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 10108 | "(freq=%d duration=%u): %d (%s)", |
| 10109 | freq, duration, ret, strerror(-ret)); |
| 10110 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10111 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10112 | return -1; |
| 10113 | } |
| 10114 | |
| 10115 | |
| 10116 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 10117 | { |
| 10118 | struct i802_bss *bss = priv; |
| 10119 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10120 | struct nl_msg *msg; |
| 10121 | int ret; |
| 10122 | |
| 10123 | if (!drv->pending_remain_on_chan) { |
| 10124 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 10125 | "to cancel"); |
| 10126 | return -1; |
| 10127 | } |
| 10128 | |
| 10129 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 10130 | "0x%llx", |
| 10131 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 10132 | |
| 10133 | msg = nlmsg_alloc(); |
| 10134 | if (!msg) |
| 10135 | return -1; |
| 10136 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10137 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10138 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10139 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 10140 | goto nla_put_failure; |
| 10141 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10142 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie); |
| 10143 | |
| 10144 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10145 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10146 | if (ret == 0) |
| 10147 | return 0; |
| 10148 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 10149 | "%d (%s)", ret, strerror(-ret)); |
| 10150 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10151 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10152 | return -1; |
| 10153 | } |
| 10154 | |
| 10155 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10156 | 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] | 10157 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10158 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 10159 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10160 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10161 | if (bss->nl_preq && drv->device_ap_sme && |
| 10162 | is_ap_interface(drv->nlmode)) { |
| 10163 | /* |
| 10164 | * Do not disable Probe Request reporting that was |
| 10165 | * enabled in nl80211_setup_ap(). |
| 10166 | */ |
| 10167 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 10168 | "Probe Request reporting nl_preq=%p while " |
| 10169 | "in AP mode", bss->nl_preq); |
| 10170 | } else if (bss->nl_preq) { |
| 10171 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 10172 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10173 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10174 | } |
| 10175 | return 0; |
| 10176 | } |
| 10177 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10178 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10179 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10180 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10181 | return 0; |
| 10182 | } |
| 10183 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10184 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 10185 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10186 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10187 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 10188 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10189 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10190 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10191 | (WLAN_FC_TYPE_MGMT << 2) | |
| 10192 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10193 | NULL, 0) < 0) |
| 10194 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 10195 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10196 | nl80211_register_eloop_read(&bss->nl_preq, |
| 10197 | wpa_driver_nl80211_event_receive, |
| 10198 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10199 | |
| 10200 | return 0; |
| 10201 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10202 | out_err: |
| 10203 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10204 | return -1; |
| 10205 | } |
| 10206 | |
| 10207 | |
| 10208 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 10209 | int ifindex, int disabled) |
| 10210 | { |
| 10211 | struct nl_msg *msg; |
| 10212 | struct nlattr *bands, *band; |
| 10213 | int ret; |
| 10214 | |
| 10215 | msg = nlmsg_alloc(); |
| 10216 | if (!msg) |
| 10217 | return -1; |
| 10218 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10219 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10220 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 10221 | |
| 10222 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 10223 | if (!bands) |
| 10224 | goto nla_put_failure; |
| 10225 | |
| 10226 | /* |
| 10227 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 10228 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 10229 | * rates. All 5 GHz rates are left enabled. |
| 10230 | */ |
| 10231 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 10232 | if (!band) |
| 10233 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10234 | if (disabled) { |
| 10235 | NLA_PUT(msg, NL80211_TXRATE_LEGACY, 8, |
| 10236 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); |
| 10237 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10238 | nla_nest_end(msg, band); |
| 10239 | |
| 10240 | nla_nest_end(msg, bands); |
| 10241 | |
| 10242 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10243 | msg = NULL; |
| 10244 | if (ret) { |
| 10245 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 10246 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10247 | } else |
| 10248 | drv->disabled_11b_rates = disabled; |
| 10249 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10250 | return ret; |
| 10251 | |
| 10252 | nla_put_failure: |
| 10253 | nlmsg_free(msg); |
| 10254 | return -1; |
| 10255 | } |
| 10256 | |
| 10257 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10258 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 10259 | { |
| 10260 | struct i802_bss *bss = priv; |
| 10261 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10262 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10263 | return -1; |
| 10264 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10265 | |
| 10266 | /* |
| 10267 | * If the P2P GO interface was dynamically added, then it is |
| 10268 | * possible that the interface change to station is not possible. |
| 10269 | */ |
| 10270 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 10271 | return 0; |
| 10272 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10273 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10274 | } |
| 10275 | |
| 10276 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10277 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 10278 | { |
| 10279 | struct i802_bss *bss = priv; |
| 10280 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10281 | if (!is_ap_interface(drv->nlmode)) |
| 10282 | return -1; |
| 10283 | wpa_driver_nl80211_del_beacon(drv); |
| 10284 | bss->beacon_set = 0; |
| 10285 | return 0; |
| 10286 | } |
| 10287 | |
| 10288 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10289 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 10290 | { |
| 10291 | struct i802_bss *bss = priv; |
| 10292 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10293 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 10294 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10295 | |
| 10296 | /* |
| 10297 | * If the P2P Client interface was dynamically added, then it is |
| 10298 | * possible that the interface change to station is not possible. |
| 10299 | */ |
| 10300 | if (bss->if_dynamic) |
| 10301 | return 0; |
| 10302 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10303 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 10304 | } |
| 10305 | |
| 10306 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10307 | static void wpa_driver_nl80211_resume(void *priv) |
| 10308 | { |
| 10309 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10310 | |
| 10311 | if (i802_set_iface_flags(bss, 1)) |
| 10312 | 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] | 10313 | } |
| 10314 | |
| 10315 | |
| 10316 | static int nl80211_send_ft_action(void *priv, u8 action, const u8 *target_ap, |
| 10317 | const u8 *ies, size_t ies_len) |
| 10318 | { |
| 10319 | struct i802_bss *bss = priv; |
| 10320 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10321 | int ret; |
| 10322 | u8 *data, *pos; |
| 10323 | size_t data_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10324 | const u8 *own_addr = bss->addr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10325 | |
| 10326 | if (action != 1) { |
| 10327 | wpa_printf(MSG_ERROR, "nl80211: Unsupported send_ft_action " |
| 10328 | "action %d", action); |
| 10329 | return -1; |
| 10330 | } |
| 10331 | |
| 10332 | /* |
| 10333 | * Action frame payload: |
| 10334 | * Category[1] = 6 (Fast BSS Transition) |
| 10335 | * Action[1] = 1 (Fast BSS Transition Request) |
| 10336 | * STA Address |
| 10337 | * Target AP Address |
| 10338 | * FT IEs |
| 10339 | */ |
| 10340 | |
| 10341 | data_len = 2 + 2 * ETH_ALEN + ies_len; |
| 10342 | data = os_malloc(data_len); |
| 10343 | if (data == NULL) |
| 10344 | return -1; |
| 10345 | pos = data; |
| 10346 | *pos++ = 0x06; /* FT Action category */ |
| 10347 | *pos++ = action; |
| 10348 | os_memcpy(pos, own_addr, ETH_ALEN); |
| 10349 | pos += ETH_ALEN; |
| 10350 | os_memcpy(pos, target_ap, ETH_ALEN); |
| 10351 | pos += ETH_ALEN; |
| 10352 | os_memcpy(pos, ies, ies_len); |
| 10353 | |
| 10354 | ret = wpa_driver_nl80211_send_action(bss, drv->assoc_freq, 0, |
| 10355 | drv->bssid, own_addr, drv->bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10356 | data, data_len, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10357 | os_free(data); |
| 10358 | |
| 10359 | return ret; |
| 10360 | } |
| 10361 | |
| 10362 | |
| 10363 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 10364 | { |
| 10365 | struct i802_bss *bss = priv; |
| 10366 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 10367 | struct nl_msg *msg; |
| 10368 | struct nlattr *cqm; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10369 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10370 | |
| 10371 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 10372 | "hysteresis=%d", threshold, hysteresis); |
| 10373 | |
| 10374 | msg = nlmsg_alloc(); |
| 10375 | if (!msg) |
| 10376 | return -1; |
| 10377 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10378 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_CQM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10379 | |
| 10380 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 10381 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 10382 | cqm = nla_nest_start(msg, NL80211_ATTR_CQM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10383 | if (cqm == NULL) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10384 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10385 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 10386 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold); |
| 10387 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis); |
| 10388 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10389 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10390 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10391 | msg = NULL; |
| 10392 | |
| 10393 | nla_put_failure: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10394 | nlmsg_free(msg); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10395 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10396 | } |
| 10397 | |
| 10398 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10399 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 10400 | { |
| 10401 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10402 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10403 | struct wpa_signal_info *sig_change = arg; |
| 10404 | |
| 10405 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10406 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10407 | |
| 10408 | sig_change->center_frq1 = -1; |
| 10409 | sig_change->center_frq2 = -1; |
| 10410 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 10411 | |
| 10412 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 10413 | sig_change->chanwidth = convert2width( |
| 10414 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 10415 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 10416 | sig_change->center_frq1 = |
| 10417 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 10418 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 10419 | sig_change->center_frq2 = |
| 10420 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 10421 | } |
| 10422 | |
| 10423 | return NL_SKIP; |
| 10424 | } |
| 10425 | |
| 10426 | |
| 10427 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 10428 | struct wpa_signal_info *sig) |
| 10429 | { |
| 10430 | struct nl_msg *msg; |
| 10431 | |
| 10432 | msg = nlmsg_alloc(); |
| 10433 | if (!msg) |
| 10434 | return -ENOMEM; |
| 10435 | |
| 10436 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_INTERFACE); |
| 10437 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 10438 | |
| 10439 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
| 10440 | |
| 10441 | nla_put_failure: |
| 10442 | nlmsg_free(msg); |
| 10443 | return -ENOBUFS; |
| 10444 | } |
| 10445 | |
| 10446 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10447 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 10448 | { |
| 10449 | struct i802_bss *bss = priv; |
| 10450 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10451 | int res; |
| 10452 | |
| 10453 | os_memset(si, 0, sizeof(*si)); |
| 10454 | res = nl80211_get_link_signal(drv, si); |
| 10455 | if (res != 0) |
| 10456 | return res; |
| 10457 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10458 | res = nl80211_get_channel_width(drv, si); |
| 10459 | if (res != 0) |
| 10460 | return res; |
| 10461 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10462 | return nl80211_get_link_noise(drv, si); |
| 10463 | } |
| 10464 | |
| 10465 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10466 | static int wpa_driver_nl80211_shared_freq(void *priv) |
| 10467 | { |
| 10468 | struct i802_bss *bss = priv; |
| 10469 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10470 | struct wpa_driver_nl80211_data *driver; |
| 10471 | int freq = 0; |
| 10472 | |
| 10473 | /* |
| 10474 | * If the same PHY is in connected state with some other interface, |
| 10475 | * then retrieve the assoc freq. |
| 10476 | */ |
| 10477 | wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s", |
| 10478 | drv->phyname); |
| 10479 | |
| 10480 | dl_list_for_each(driver, &drv->global->interfaces, |
| 10481 | struct wpa_driver_nl80211_data, list) { |
| 10482 | if (drv == driver || |
| 10483 | os_strcmp(drv->phyname, driver->phyname) != 0 || |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10484 | !driver->associated) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10485 | continue; |
| 10486 | |
| 10487 | wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s " |
| 10488 | MACSTR, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 10489 | driver->phyname, driver->first_bss->ifname, |
| 10490 | MAC2STR(driver->first_bss->addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10491 | if (is_ap_interface(driver->nlmode)) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 10492 | freq = driver->first_bss->freq; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10493 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10494 | freq = nl80211_get_assoc_freq(driver); |
| 10495 | wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d", |
| 10496 | drv->phyname, freq); |
| 10497 | } |
| 10498 | |
| 10499 | if (!freq) |
| 10500 | wpa_printf(MSG_DEBUG, "nl80211: No shared interface for " |
| 10501 | "PHY (%s) in associated state", drv->phyname); |
| 10502 | |
| 10503 | return freq; |
| 10504 | } |
| 10505 | |
| 10506 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10507 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 10508 | int encrypt) |
| 10509 | { |
| 10510 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 10511 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
| 10512 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10513 | } |
| 10514 | |
| 10515 | |
| 10516 | static int nl80211_set_param(void *priv, const char *param) |
| 10517 | { |
| 10518 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
| 10519 | if (param == NULL) |
| 10520 | return 0; |
| 10521 | |
| 10522 | #ifdef CONFIG_P2P |
| 10523 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 10524 | struct i802_bss *bss = priv; |
| 10525 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10526 | |
| 10527 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 10528 | "interface"); |
| 10529 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 10530 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 10531 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10532 | |
| 10533 | if (os_strstr(param, "p2p_device=1")) { |
| 10534 | struct i802_bss *bss = priv; |
| 10535 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10536 | drv->allow_p2p_device = 1; |
| 10537 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10538 | #endif /* CONFIG_P2P */ |
| 10539 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10540 | if (os_strstr(param, "use_monitor=1")) { |
| 10541 | struct i802_bss *bss = priv; |
| 10542 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10543 | drv->use_monitor = 1; |
| 10544 | } |
| 10545 | |
| 10546 | if (os_strstr(param, "force_connect_cmd=1")) { |
| 10547 | struct i802_bss *bss = priv; |
| 10548 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10549 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
| 10550 | } |
| 10551 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 10552 | if (os_strstr(param, "no_offchannel_tx=1")) { |
| 10553 | struct i802_bss *bss = priv; |
| 10554 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10555 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 10556 | drv->test_use_roc_tx = 1; |
| 10557 | } |
| 10558 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10559 | return 0; |
| 10560 | } |
| 10561 | |
| 10562 | |
| 10563 | static void * nl80211_global_init(void) |
| 10564 | { |
| 10565 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10566 | struct netlink_config *cfg; |
| 10567 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10568 | global = os_zalloc(sizeof(*global)); |
| 10569 | if (global == NULL) |
| 10570 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10571 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10572 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10573 | global->if_add_ifindex = -1; |
| 10574 | |
| 10575 | cfg = os_zalloc(sizeof(*cfg)); |
| 10576 | if (cfg == NULL) |
| 10577 | goto err; |
| 10578 | |
| 10579 | cfg->ctx = global; |
| 10580 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 10581 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 10582 | global->netlink = netlink_init(cfg); |
| 10583 | if (global->netlink == NULL) { |
| 10584 | os_free(cfg); |
| 10585 | goto err; |
| 10586 | } |
| 10587 | |
| 10588 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 10589 | goto err; |
| 10590 | |
| 10591 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 10592 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10593 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 10594 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10595 | goto err; |
| 10596 | } |
| 10597 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10598 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10599 | |
| 10600 | err: |
| 10601 | nl80211_global_deinit(global); |
| 10602 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10603 | } |
| 10604 | |
| 10605 | |
| 10606 | static void nl80211_global_deinit(void *priv) |
| 10607 | { |
| 10608 | struct nl80211_global *global = priv; |
| 10609 | if (global == NULL) |
| 10610 | return; |
| 10611 | if (!dl_list_empty(&global->interfaces)) { |
| 10612 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 10613 | "nl80211_global_deinit", |
| 10614 | dl_list_len(&global->interfaces)); |
| 10615 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10616 | |
| 10617 | if (global->netlink) |
| 10618 | netlink_deinit(global->netlink); |
| 10619 | |
| 10620 | nl_destroy_handles(&global->nl); |
| 10621 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10622 | if (global->nl_event) |
| 10623 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10624 | |
| 10625 | nl_cb_put(global->nl_cb); |
| 10626 | |
| 10627 | if (global->ioctl_sock >= 0) |
| 10628 | close(global->ioctl_sock); |
| 10629 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10630 | os_free(global); |
| 10631 | } |
| 10632 | |
| 10633 | |
| 10634 | static const char * nl80211_get_radio_name(void *priv) |
| 10635 | { |
| 10636 | struct i802_bss *bss = priv; |
| 10637 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10638 | return drv->phyname; |
| 10639 | } |
| 10640 | |
| 10641 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10642 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 10643 | const u8 *pmkid) |
| 10644 | { |
| 10645 | struct nl_msg *msg; |
| 10646 | |
| 10647 | msg = nlmsg_alloc(); |
| 10648 | if (!msg) |
| 10649 | return -ENOMEM; |
| 10650 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10651 | nl80211_cmd(bss->drv, msg, 0, cmd); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10652 | |
| 10653 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 10654 | if (pmkid) |
| 10655 | NLA_PUT(msg, NL80211_ATTR_PMKID, 16, pmkid); |
| 10656 | if (bssid) |
| 10657 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 10658 | |
| 10659 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 10660 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10661 | nlmsg_free(msg); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10662 | return -ENOBUFS; |
| 10663 | } |
| 10664 | |
| 10665 | |
| 10666 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 10667 | { |
| 10668 | struct i802_bss *bss = priv; |
| 10669 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 10670 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 10671 | } |
| 10672 | |
| 10673 | |
| 10674 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 10675 | { |
| 10676 | struct i802_bss *bss = priv; |
| 10677 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 10678 | MAC2STR(bssid)); |
| 10679 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 10680 | } |
| 10681 | |
| 10682 | |
| 10683 | static int nl80211_flush_pmkid(void *priv) |
| 10684 | { |
| 10685 | struct i802_bss *bss = priv; |
| 10686 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 10687 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 10688 | } |
| 10689 | |
| 10690 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10691 | static void clean_survey_results(struct survey_results *survey_results) |
| 10692 | { |
| 10693 | struct freq_survey *survey, *tmp; |
| 10694 | |
| 10695 | if (dl_list_empty(&survey_results->survey_list)) |
| 10696 | return; |
| 10697 | |
| 10698 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 10699 | struct freq_survey, list) { |
| 10700 | dl_list_del(&survey->list); |
| 10701 | os_free(survey); |
| 10702 | } |
| 10703 | } |
| 10704 | |
| 10705 | |
| 10706 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 10707 | struct dl_list *survey_list) |
| 10708 | { |
| 10709 | struct freq_survey *survey; |
| 10710 | |
| 10711 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 10712 | if (!survey) |
| 10713 | return; |
| 10714 | |
| 10715 | survey->ifidx = ifidx; |
| 10716 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 10717 | survey->filled = 0; |
| 10718 | |
| 10719 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 10720 | survey->nf = (int8_t) |
| 10721 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 10722 | survey->filled |= SURVEY_HAS_NF; |
| 10723 | } |
| 10724 | |
| 10725 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 10726 | survey->channel_time = |
| 10727 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 10728 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 10729 | } |
| 10730 | |
| 10731 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 10732 | survey->channel_time_busy = |
| 10733 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 10734 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 10735 | } |
| 10736 | |
| 10737 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 10738 | survey->channel_time_rx = |
| 10739 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 10740 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 10741 | } |
| 10742 | |
| 10743 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 10744 | survey->channel_time_tx = |
| 10745 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 10746 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 10747 | } |
| 10748 | |
| 10749 | 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)", |
| 10750 | survey->freq, |
| 10751 | survey->nf, |
| 10752 | (unsigned long int) survey->channel_time, |
| 10753 | (unsigned long int) survey->channel_time_busy, |
| 10754 | (unsigned long int) survey->channel_time_tx, |
| 10755 | (unsigned long int) survey->channel_time_rx, |
| 10756 | survey->filled); |
| 10757 | |
| 10758 | dl_list_add_tail(survey_list, &survey->list); |
| 10759 | } |
| 10760 | |
| 10761 | |
| 10762 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 10763 | unsigned int freq_filter) |
| 10764 | { |
| 10765 | if (!freq_filter) |
| 10766 | return 1; |
| 10767 | |
| 10768 | return freq_filter == surveyed_freq; |
| 10769 | } |
| 10770 | |
| 10771 | |
| 10772 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 10773 | { |
| 10774 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10775 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10776 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 10777 | struct survey_results *survey_results; |
| 10778 | u32 surveyed_freq = 0; |
| 10779 | u32 ifidx; |
| 10780 | |
| 10781 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 10782 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 10783 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 10784 | }; |
| 10785 | |
| 10786 | survey_results = (struct survey_results *) arg; |
| 10787 | |
| 10788 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10789 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10790 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 10791 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 10792 | return NL_SKIP; |
| 10793 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10794 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 10795 | |
| 10796 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 10797 | return NL_SKIP; |
| 10798 | |
| 10799 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 10800 | tb[NL80211_ATTR_SURVEY_INFO], |
| 10801 | survey_policy)) |
| 10802 | return NL_SKIP; |
| 10803 | |
| 10804 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 10805 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 10806 | return NL_SKIP; |
| 10807 | } |
| 10808 | |
| 10809 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 10810 | |
| 10811 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 10812 | survey_results->freq_filter)) |
| 10813 | return NL_SKIP; |
| 10814 | |
| 10815 | if (survey_results->freq_filter && |
| 10816 | survey_results->freq_filter != surveyed_freq) { |
| 10817 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 10818 | surveyed_freq); |
| 10819 | return NL_SKIP; |
| 10820 | } |
| 10821 | |
| 10822 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 10823 | |
| 10824 | return NL_SKIP; |
| 10825 | } |
| 10826 | |
| 10827 | |
| 10828 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 10829 | { |
| 10830 | struct i802_bss *bss = priv; |
| 10831 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10832 | struct nl_msg *msg; |
| 10833 | int err = -ENOBUFS; |
| 10834 | union wpa_event_data data; |
| 10835 | struct survey_results *survey_results; |
| 10836 | |
| 10837 | os_memset(&data, 0, sizeof(data)); |
| 10838 | survey_results = &data.survey_results; |
| 10839 | |
| 10840 | dl_list_init(&survey_results->survey_list); |
| 10841 | |
| 10842 | msg = nlmsg_alloc(); |
| 10843 | if (!msg) |
| 10844 | goto nla_put_failure; |
| 10845 | |
| 10846 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
| 10847 | |
| 10848 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 10849 | |
| 10850 | if (freq) |
| 10851 | data.survey_results.freq_filter = freq; |
| 10852 | |
| 10853 | do { |
| 10854 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 10855 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 10856 | survey_results); |
| 10857 | } while (err > 0); |
| 10858 | |
| 10859 | if (err) { |
| 10860 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
| 10861 | goto out_clean; |
| 10862 | } |
| 10863 | |
| 10864 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
| 10865 | |
| 10866 | out_clean: |
| 10867 | clean_survey_results(survey_results); |
| 10868 | nla_put_failure: |
| 10869 | return err; |
| 10870 | } |
| 10871 | |
| 10872 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10873 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, const u8 *kck, |
| 10874 | const u8 *replay_ctr) |
| 10875 | { |
| 10876 | struct i802_bss *bss = priv; |
| 10877 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10878 | struct nlattr *replay_nested; |
| 10879 | struct nl_msg *msg; |
| 10880 | |
| 10881 | msg = nlmsg_alloc(); |
| 10882 | if (!msg) |
| 10883 | return; |
| 10884 | |
| 10885 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10886 | |
| 10887 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 10888 | |
| 10889 | replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10890 | if (!replay_nested) |
| 10891 | goto nla_put_failure; |
| 10892 | |
| 10893 | NLA_PUT(msg, NL80211_REKEY_DATA_KEK, NL80211_KEK_LEN, kek); |
| 10894 | NLA_PUT(msg, NL80211_REKEY_DATA_KCK, NL80211_KCK_LEN, kck); |
| 10895 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 10896 | replay_ctr); |
| 10897 | |
| 10898 | nla_nest_end(msg, replay_nested); |
| 10899 | |
| 10900 | send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10901 | return; |
| 10902 | nla_put_failure: |
| 10903 | nlmsg_free(msg); |
| 10904 | } |
| 10905 | |
| 10906 | |
| 10907 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 10908 | const u8 *addr, int qos) |
| 10909 | { |
| 10910 | /* send data frame to poll STA and check whether |
| 10911 | * this frame is ACKed */ |
| 10912 | struct { |
| 10913 | struct ieee80211_hdr hdr; |
| 10914 | u16 qos_ctl; |
| 10915 | } STRUCT_PACKED nulldata; |
| 10916 | size_t size; |
| 10917 | |
| 10918 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 10919 | |
| 10920 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 10921 | |
| 10922 | if (qos) { |
| 10923 | nulldata.hdr.frame_control = |
| 10924 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 10925 | WLAN_FC_STYPE_QOS_NULL); |
| 10926 | size = sizeof(nulldata); |
| 10927 | } else { |
| 10928 | nulldata.hdr.frame_control = |
| 10929 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 10930 | WLAN_FC_STYPE_NULLFUNC); |
| 10931 | size = sizeof(struct ieee80211_hdr); |
| 10932 | } |
| 10933 | |
| 10934 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 10935 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 10936 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 10937 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 10938 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10939 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
| 10940 | 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10941 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 10942 | "send poll frame"); |
| 10943 | } |
| 10944 | |
| 10945 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 10946 | int qos) |
| 10947 | { |
| 10948 | struct i802_bss *bss = priv; |
| 10949 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10950 | struct nl_msg *msg; |
| 10951 | |
| 10952 | if (!drv->poll_command_supported) { |
| 10953 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 10954 | return; |
| 10955 | } |
| 10956 | |
| 10957 | msg = nlmsg_alloc(); |
| 10958 | if (!msg) |
| 10959 | return; |
| 10960 | |
| 10961 | nl80211_cmd(drv, msg, 0, NL80211_CMD_PROBE_CLIENT); |
| 10962 | |
| 10963 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 10964 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 10965 | |
| 10966 | send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10967 | return; |
| 10968 | nla_put_failure: |
| 10969 | nlmsg_free(msg); |
| 10970 | } |
| 10971 | |
| 10972 | |
| 10973 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 10974 | { |
| 10975 | struct nl_msg *msg; |
| 10976 | |
| 10977 | msg = nlmsg_alloc(); |
| 10978 | if (!msg) |
| 10979 | return -ENOMEM; |
| 10980 | |
| 10981 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_SET_POWER_SAVE); |
| 10982 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 10983 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, |
| 10984 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED); |
| 10985 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 10986 | nla_put_failure: |
| 10987 | nlmsg_free(msg); |
| 10988 | return -ENOBUFS; |
| 10989 | } |
| 10990 | |
| 10991 | |
| 10992 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 10993 | int ctwindow) |
| 10994 | { |
| 10995 | struct i802_bss *bss = priv; |
| 10996 | |
| 10997 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 10998 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 10999 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11000 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 11001 | #ifdef ANDROID_P2P |
| 11002 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11003 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11004 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11005 | #endif /* ANDROID_P2P */ |
| 11006 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11007 | |
| 11008 | if (legacy_ps == -1) |
| 11009 | return 0; |
| 11010 | if (legacy_ps != 0 && legacy_ps != 1) |
| 11011 | return -1; /* Not yet supported */ |
| 11012 | |
| 11013 | return nl80211_set_power_save(bss, legacy_ps); |
| 11014 | } |
| 11015 | |
| 11016 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11017 | static int nl80211_start_radar_detection(void *priv, |
| 11018 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11019 | { |
| 11020 | struct i802_bss *bss = priv; |
| 11021 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11022 | struct nl_msg *msg; |
| 11023 | int ret; |
| 11024 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11025 | 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)", |
| 11026 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 11027 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 11028 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11029 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 11030 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 11031 | "detection"); |
| 11032 | return -1; |
| 11033 | } |
| 11034 | |
| 11035 | msg = nlmsg_alloc(); |
| 11036 | if (!msg) |
| 11037 | return -1; |
| 11038 | |
| 11039 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_RADAR_DETECT); |
| 11040 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11041 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11042 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11043 | if (freq->vht_enabled) { |
| 11044 | switch (freq->bandwidth) { |
| 11045 | case 20: |
| 11046 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11047 | NL80211_CHAN_WIDTH_20); |
| 11048 | break; |
| 11049 | case 40: |
| 11050 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11051 | NL80211_CHAN_WIDTH_40); |
| 11052 | break; |
| 11053 | case 80: |
| 11054 | if (freq->center_freq2) |
| 11055 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11056 | NL80211_CHAN_WIDTH_80P80); |
| 11057 | else |
| 11058 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11059 | NL80211_CHAN_WIDTH_80); |
| 11060 | break; |
| 11061 | case 160: |
| 11062 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11063 | NL80211_CHAN_WIDTH_160); |
| 11064 | break; |
| 11065 | default: |
| 11066 | return -1; |
| 11067 | } |
| 11068 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); |
| 11069 | if (freq->center_freq2) |
| 11070 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 11071 | freq->center_freq2); |
| 11072 | } else if (freq->ht_enabled) { |
| 11073 | switch (freq->sec_channel_offset) { |
| 11074 | case -1: |
| 11075 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11076 | NL80211_CHAN_HT40MINUS); |
| 11077 | break; |
| 11078 | case 1: |
| 11079 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11080 | NL80211_CHAN_HT40PLUS); |
| 11081 | break; |
| 11082 | default: |
| 11083 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11084 | NL80211_CHAN_HT20); |
| 11085 | break; |
| 11086 | } |
| 11087 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11088 | |
| 11089 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11090 | if (ret == 0) |
| 11091 | return 0; |
| 11092 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 11093 | "%d (%s)", ret, strerror(-ret)); |
| 11094 | nla_put_failure: |
| 11095 | return -1; |
| 11096 | } |
| 11097 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11098 | #ifdef CONFIG_TDLS |
| 11099 | |
| 11100 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 11101 | u8 dialog_token, u16 status_code, |
| 11102 | const u8 *buf, size_t len) |
| 11103 | { |
| 11104 | struct i802_bss *bss = priv; |
| 11105 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11106 | struct nl_msg *msg; |
| 11107 | |
| 11108 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 11109 | return -EOPNOTSUPP; |
| 11110 | |
| 11111 | if (!dst) |
| 11112 | return -EINVAL; |
| 11113 | |
| 11114 | msg = nlmsg_alloc(); |
| 11115 | if (!msg) |
| 11116 | return -ENOMEM; |
| 11117 | |
| 11118 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_MGMT); |
| 11119 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11120 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 11121 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_ACTION, action_code); |
| 11122 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token); |
| 11123 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status_code); |
| 11124 | NLA_PUT(msg, NL80211_ATTR_IE, len, buf); |
| 11125 | |
| 11126 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11127 | |
| 11128 | nla_put_failure: |
| 11129 | nlmsg_free(msg); |
| 11130 | return -ENOBUFS; |
| 11131 | } |
| 11132 | |
| 11133 | |
| 11134 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 11135 | { |
| 11136 | struct i802_bss *bss = priv; |
| 11137 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11138 | struct nl_msg *msg; |
| 11139 | enum nl80211_tdls_operation nl80211_oper; |
| 11140 | |
| 11141 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 11142 | return -EOPNOTSUPP; |
| 11143 | |
| 11144 | switch (oper) { |
| 11145 | case TDLS_DISCOVERY_REQ: |
| 11146 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 11147 | break; |
| 11148 | case TDLS_SETUP: |
| 11149 | nl80211_oper = NL80211_TDLS_SETUP; |
| 11150 | break; |
| 11151 | case TDLS_TEARDOWN: |
| 11152 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 11153 | break; |
| 11154 | case TDLS_ENABLE_LINK: |
| 11155 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 11156 | break; |
| 11157 | case TDLS_DISABLE_LINK: |
| 11158 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 11159 | break; |
| 11160 | case TDLS_ENABLE: |
| 11161 | return 0; |
| 11162 | case TDLS_DISABLE: |
| 11163 | return 0; |
| 11164 | default: |
| 11165 | return -EINVAL; |
| 11166 | } |
| 11167 | |
| 11168 | msg = nlmsg_alloc(); |
| 11169 | if (!msg) |
| 11170 | return -ENOMEM; |
| 11171 | |
| 11172 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_OPER); |
| 11173 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper); |
| 11174 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11175 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 11176 | |
| 11177 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11178 | |
| 11179 | nla_put_failure: |
| 11180 | nlmsg_free(msg); |
| 11181 | return -ENOBUFS; |
| 11182 | } |
| 11183 | |
| 11184 | #endif /* CONFIG TDLS */ |
| 11185 | |
| 11186 | |
| 11187 | #ifdef ANDROID |
| 11188 | |
| 11189 | typedef struct android_wifi_priv_cmd { |
| 11190 | char *buf; |
| 11191 | int used_len; |
| 11192 | int total_len; |
| 11193 | } android_wifi_priv_cmd; |
| 11194 | |
| 11195 | static int drv_errors = 0; |
| 11196 | |
| 11197 | static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data *drv) |
| 11198 | { |
| 11199 | drv_errors++; |
| 11200 | if (drv_errors > DRV_NUMBER_SEQUENTIAL_ERRORS) { |
| 11201 | drv_errors = 0; |
| 11202 | wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); |
| 11203 | } |
| 11204 | } |
| 11205 | |
| 11206 | |
| 11207 | static int android_priv_cmd(struct i802_bss *bss, const char *cmd) |
| 11208 | { |
| 11209 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11210 | struct ifreq ifr; |
| 11211 | android_wifi_priv_cmd priv_cmd; |
| 11212 | char buf[MAX_DRV_CMD_SIZE]; |
| 11213 | int ret; |
| 11214 | |
| 11215 | os_memset(&ifr, 0, sizeof(ifr)); |
| 11216 | os_memset(&priv_cmd, 0, sizeof(priv_cmd)); |
| 11217 | os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); |
| 11218 | |
| 11219 | os_memset(buf, 0, sizeof(buf)); |
| 11220 | os_strlcpy(buf, cmd, sizeof(buf)); |
| 11221 | |
| 11222 | priv_cmd.buf = buf; |
| 11223 | priv_cmd.used_len = sizeof(buf); |
| 11224 | priv_cmd.total_len = sizeof(buf); |
| 11225 | ifr.ifr_data = &priv_cmd; |
| 11226 | |
| 11227 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); |
| 11228 | if (ret < 0) { |
| 11229 | wpa_printf(MSG_ERROR, "%s: failed to issue private commands", |
| 11230 | __func__); |
| 11231 | wpa_driver_send_hang_msg(drv); |
| 11232 | return ret; |
| 11233 | } |
| 11234 | |
| 11235 | drv_errors = 0; |
| 11236 | return 0; |
| 11237 | } |
| 11238 | |
| 11239 | |
| 11240 | static int android_pno_start(struct i802_bss *bss, |
| 11241 | struct wpa_driver_scan_params *params) |
| 11242 | { |
| 11243 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11244 | struct ifreq ifr; |
| 11245 | android_wifi_priv_cmd priv_cmd; |
| 11246 | int ret = 0, i = 0, bp; |
| 11247 | char buf[WEXT_PNO_MAX_COMMAND_SIZE]; |
| 11248 | |
| 11249 | bp = WEXT_PNOSETUP_HEADER_SIZE; |
| 11250 | os_memcpy(buf, WEXT_PNOSETUP_HEADER, bp); |
| 11251 | buf[bp++] = WEXT_PNO_TLV_PREFIX; |
| 11252 | buf[bp++] = WEXT_PNO_TLV_VERSION; |
| 11253 | buf[bp++] = WEXT_PNO_TLV_SUBVERSION; |
| 11254 | buf[bp++] = WEXT_PNO_TLV_RESERVED; |
| 11255 | |
| 11256 | while (i < WEXT_PNO_AMOUNT && (size_t) i < params->num_ssids) { |
| 11257 | /* Check that there is enough space needed for 1 more SSID, the |
| 11258 | * other sections and null termination */ |
| 11259 | if ((bp + WEXT_PNO_SSID_HEADER_SIZE + MAX_SSID_LEN + |
| 11260 | WEXT_PNO_NONSSID_SECTIONS_SIZE + 1) >= (int) sizeof(buf)) |
| 11261 | break; |
| 11262 | wpa_hexdump_ascii(MSG_DEBUG, "For PNO Scan", |
| 11263 | params->ssids[i].ssid, |
| 11264 | params->ssids[i].ssid_len); |
| 11265 | buf[bp++] = WEXT_PNO_SSID_SECTION; |
| 11266 | buf[bp++] = params->ssids[i].ssid_len; |
| 11267 | os_memcpy(&buf[bp], params->ssids[i].ssid, |
| 11268 | params->ssids[i].ssid_len); |
| 11269 | bp += params->ssids[i].ssid_len; |
| 11270 | i++; |
| 11271 | } |
| 11272 | |
| 11273 | buf[bp++] = WEXT_PNO_SCAN_INTERVAL_SECTION; |
| 11274 | os_snprintf(&buf[bp], WEXT_PNO_SCAN_INTERVAL_LENGTH + 1, "%x", |
| 11275 | WEXT_PNO_SCAN_INTERVAL); |
| 11276 | bp += WEXT_PNO_SCAN_INTERVAL_LENGTH; |
| 11277 | |
| 11278 | buf[bp++] = WEXT_PNO_REPEAT_SECTION; |
| 11279 | os_snprintf(&buf[bp], WEXT_PNO_REPEAT_LENGTH + 1, "%x", |
| 11280 | WEXT_PNO_REPEAT); |
| 11281 | bp += WEXT_PNO_REPEAT_LENGTH; |
| 11282 | |
| 11283 | buf[bp++] = WEXT_PNO_MAX_REPEAT_SECTION; |
| 11284 | os_snprintf(&buf[bp], WEXT_PNO_MAX_REPEAT_LENGTH + 1, "%x", |
| 11285 | WEXT_PNO_MAX_REPEAT); |
| 11286 | bp += WEXT_PNO_MAX_REPEAT_LENGTH + 1; |
| 11287 | |
| 11288 | memset(&ifr, 0, sizeof(ifr)); |
| 11289 | memset(&priv_cmd, 0, sizeof(priv_cmd)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 11290 | os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11291 | |
| 11292 | priv_cmd.buf = buf; |
| 11293 | priv_cmd.used_len = bp; |
| 11294 | priv_cmd.total_len = bp; |
| 11295 | ifr.ifr_data = &priv_cmd; |
| 11296 | |
| 11297 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); |
| 11298 | |
| 11299 | if (ret < 0) { |
| 11300 | wpa_printf(MSG_ERROR, "ioctl[SIOCSIWPRIV] (pnosetup): %d", |
| 11301 | ret); |
| 11302 | wpa_driver_send_hang_msg(drv); |
| 11303 | return ret; |
| 11304 | } |
| 11305 | |
| 11306 | drv_errors = 0; |
| 11307 | |
| 11308 | return android_priv_cmd(bss, "PNOFORCE 1"); |
| 11309 | } |
| 11310 | |
| 11311 | |
| 11312 | static int android_pno_stop(struct i802_bss *bss) |
| 11313 | { |
| 11314 | return android_priv_cmd(bss, "PNOFORCE 0"); |
| 11315 | } |
| 11316 | |
| 11317 | #endif /* ANDROID */ |
| 11318 | |
| 11319 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11320 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 11321 | enum wpa_alg alg, const u8 *addr, |
| 11322 | int key_idx, int set_tx, |
| 11323 | const u8 *seq, size_t seq_len, |
| 11324 | const u8 *key, size_t key_len) |
| 11325 | { |
| 11326 | struct i802_bss *bss = priv; |
| 11327 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 11328 | set_tx, seq, seq_len, key, key_len); |
| 11329 | } |
| 11330 | |
| 11331 | |
| 11332 | static int driver_nl80211_scan2(void *priv, |
| 11333 | struct wpa_driver_scan_params *params) |
| 11334 | { |
| 11335 | struct i802_bss *bss = priv; |
| 11336 | return wpa_driver_nl80211_scan(bss, params); |
| 11337 | } |
| 11338 | |
| 11339 | |
| 11340 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 11341 | int reason_code) |
| 11342 | { |
| 11343 | struct i802_bss *bss = priv; |
| 11344 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 11345 | } |
| 11346 | |
| 11347 | |
| 11348 | static int driver_nl80211_authenticate(void *priv, |
| 11349 | struct wpa_driver_auth_params *params) |
| 11350 | { |
| 11351 | struct i802_bss *bss = priv; |
| 11352 | return wpa_driver_nl80211_authenticate(bss, params); |
| 11353 | } |
| 11354 | |
| 11355 | |
| 11356 | static void driver_nl80211_deinit(void *priv) |
| 11357 | { |
| 11358 | struct i802_bss *bss = priv; |
| 11359 | wpa_driver_nl80211_deinit(bss); |
| 11360 | } |
| 11361 | |
| 11362 | |
| 11363 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 11364 | const char *ifname) |
| 11365 | { |
| 11366 | struct i802_bss *bss = priv; |
| 11367 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 11368 | } |
| 11369 | |
| 11370 | |
| 11371 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
| 11372 | size_t data_len, int noack) |
| 11373 | { |
| 11374 | struct i802_bss *bss = priv; |
| 11375 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
| 11376 | 0, 0, 0, 0); |
| 11377 | } |
| 11378 | |
| 11379 | |
| 11380 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 11381 | { |
| 11382 | struct i802_bss *bss = priv; |
| 11383 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 11384 | } |
| 11385 | |
| 11386 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11387 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 11388 | const char *ifname, int vlan_id) |
| 11389 | { |
| 11390 | struct i802_bss *bss = priv; |
| 11391 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 11392 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11393 | |
| 11394 | |
| 11395 | static int driver_nl80211_read_sta_data(void *priv, |
| 11396 | struct hostap_sta_driver_data *data, |
| 11397 | const u8 *addr) |
| 11398 | { |
| 11399 | struct i802_bss *bss = priv; |
| 11400 | return i802_read_sta_data(bss, data, addr); |
| 11401 | } |
| 11402 | |
| 11403 | |
| 11404 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 11405 | unsigned int wait_time, |
| 11406 | const u8 *dst, const u8 *src, |
| 11407 | const u8 *bssid, |
| 11408 | const u8 *data, size_t data_len, |
| 11409 | int no_cck) |
| 11410 | { |
| 11411 | struct i802_bss *bss = priv; |
| 11412 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 11413 | bssid, data, data_len, no_cck); |
| 11414 | } |
| 11415 | |
| 11416 | |
| 11417 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 11418 | { |
| 11419 | struct i802_bss *bss = priv; |
| 11420 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 11421 | } |
| 11422 | |
| 11423 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 11424 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 11425 | const u8 *ies, size_t ies_len) |
| 11426 | { |
| 11427 | int ret; |
| 11428 | struct nl_msg *msg; |
| 11429 | struct i802_bss *bss = priv; |
| 11430 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11431 | u16 mdid = WPA_GET_LE16(md); |
| 11432 | |
| 11433 | msg = nlmsg_alloc(); |
| 11434 | if (!msg) |
| 11435 | return -ENOMEM; |
| 11436 | |
| 11437 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
| 11438 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UPDATE_FT_IES); |
| 11439 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11440 | NLA_PUT(msg, NL80211_ATTR_IE, ies_len, ies); |
| 11441 | NLA_PUT_U16(msg, NL80211_ATTR_MDID, mdid); |
| 11442 | |
| 11443 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11444 | if (ret) { |
| 11445 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 11446 | "err=%d (%s)", ret, strerror(-ret)); |
| 11447 | } |
| 11448 | |
| 11449 | return ret; |
| 11450 | |
| 11451 | nla_put_failure: |
| 11452 | nlmsg_free(msg); |
| 11453 | return -ENOBUFS; |
| 11454 | } |
| 11455 | |
| 11456 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11457 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
| 11458 | { |
| 11459 | struct i802_bss *bss = priv; |
| 11460 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11461 | |
| 11462 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 11463 | return NULL; |
| 11464 | |
| 11465 | return bss->addr; |
| 11466 | } |
| 11467 | |
| 11468 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11469 | static const char * scan_state_str(enum scan_states scan_state) |
| 11470 | { |
| 11471 | switch (scan_state) { |
| 11472 | case NO_SCAN: |
| 11473 | return "NO_SCAN"; |
| 11474 | case SCAN_REQUESTED: |
| 11475 | return "SCAN_REQUESTED"; |
| 11476 | case SCAN_STARTED: |
| 11477 | return "SCAN_STARTED"; |
| 11478 | case SCAN_COMPLETED: |
| 11479 | return "SCAN_COMPLETED"; |
| 11480 | case SCAN_ABORTED: |
| 11481 | return "SCAN_ABORTED"; |
| 11482 | case SCHED_SCAN_STARTED: |
| 11483 | return "SCHED_SCAN_STARTED"; |
| 11484 | case SCHED_SCAN_STOPPED: |
| 11485 | return "SCHED_SCAN_STOPPED"; |
| 11486 | case SCHED_SCAN_RESULTS: |
| 11487 | return "SCHED_SCAN_RESULTS"; |
| 11488 | } |
| 11489 | |
| 11490 | return "??"; |
| 11491 | } |
| 11492 | |
| 11493 | |
| 11494 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 11495 | { |
| 11496 | struct i802_bss *bss = priv; |
| 11497 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11498 | int res; |
| 11499 | char *pos, *end; |
| 11500 | |
| 11501 | pos = buf; |
| 11502 | end = buf + buflen; |
| 11503 | |
| 11504 | res = os_snprintf(pos, end - pos, |
| 11505 | "ifindex=%d\n" |
| 11506 | "ifname=%s\n" |
| 11507 | "brname=%s\n" |
| 11508 | "addr=" MACSTR "\n" |
| 11509 | "freq=%d\n" |
| 11510 | "%s%s%s%s%s", |
| 11511 | bss->ifindex, |
| 11512 | bss->ifname, |
| 11513 | bss->brname, |
| 11514 | MAC2STR(bss->addr), |
| 11515 | bss->freq, |
| 11516 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 11517 | bss->added_if_into_bridge ? |
| 11518 | "added_if_into_bridge=1\n" : "", |
| 11519 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 11520 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 11521 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
| 11522 | if (res < 0 || res >= end - pos) |
| 11523 | return pos - buf; |
| 11524 | pos += res; |
| 11525 | |
| 11526 | if (bss->wdev_id_set) { |
| 11527 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 11528 | (unsigned long long) bss->wdev_id); |
| 11529 | if (res < 0 || res >= end - pos) |
| 11530 | return pos - buf; |
| 11531 | pos += res; |
| 11532 | } |
| 11533 | |
| 11534 | res = os_snprintf(pos, end - pos, |
| 11535 | "phyname=%s\n" |
| 11536 | "drv_ifindex=%d\n" |
| 11537 | "operstate=%d\n" |
| 11538 | "scan_state=%s\n" |
| 11539 | "auth_bssid=" MACSTR "\n" |
| 11540 | "auth_attempt_bssid=" MACSTR "\n" |
| 11541 | "bssid=" MACSTR "\n" |
| 11542 | "prev_bssid=" MACSTR "\n" |
| 11543 | "associated=%d\n" |
| 11544 | "assoc_freq=%u\n" |
| 11545 | "monitor_sock=%d\n" |
| 11546 | "monitor_ifidx=%d\n" |
| 11547 | "monitor_refcount=%d\n" |
| 11548 | "last_mgmt_freq=%u\n" |
| 11549 | "eapol_tx_sock=%d\n" |
| 11550 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
| 11551 | drv->phyname, |
| 11552 | drv->ifindex, |
| 11553 | drv->operstate, |
| 11554 | scan_state_str(drv->scan_state), |
| 11555 | MAC2STR(drv->auth_bssid), |
| 11556 | MAC2STR(drv->auth_attempt_bssid), |
| 11557 | MAC2STR(drv->bssid), |
| 11558 | MAC2STR(drv->prev_bssid), |
| 11559 | drv->associated, |
| 11560 | drv->assoc_freq, |
| 11561 | drv->monitor_sock, |
| 11562 | drv->monitor_ifidx, |
| 11563 | drv->monitor_refcount, |
| 11564 | drv->last_mgmt_freq, |
| 11565 | drv->eapol_tx_sock, |
| 11566 | drv->ignore_if_down_event ? |
| 11567 | "ignore_if_down_event=1\n" : "", |
| 11568 | drv->scan_complete_events ? |
| 11569 | "scan_complete_events=1\n" : "", |
| 11570 | drv->disabled_11b_rates ? |
| 11571 | "disabled_11b_rates=1\n" : "", |
| 11572 | drv->pending_remain_on_chan ? |
| 11573 | "pending_remain_on_chan=1\n" : "", |
| 11574 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 11575 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 11576 | drv->poll_command_supported ? |
| 11577 | "poll_command_supported=1\n" : "", |
| 11578 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 11579 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 11580 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 11581 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 11582 | drv->ignore_next_local_disconnect ? |
| 11583 | "ignore_next_local_disconnect=1\n" : "", |
| 11584 | drv->allow_p2p_device ? "allow_p2p_device=1\n" : ""); |
| 11585 | if (res < 0 || res >= end - pos) |
| 11586 | return pos - buf; |
| 11587 | pos += res; |
| 11588 | |
| 11589 | if (drv->has_capability) { |
| 11590 | res = os_snprintf(pos, end - pos, |
| 11591 | "capa.key_mgmt=0x%x\n" |
| 11592 | "capa.enc=0x%x\n" |
| 11593 | "capa.auth=0x%x\n" |
| 11594 | "capa.flags=0x%x\n" |
| 11595 | "capa.max_scan_ssids=%d\n" |
| 11596 | "capa.max_sched_scan_ssids=%d\n" |
| 11597 | "capa.sched_scan_supported=%d\n" |
| 11598 | "capa.max_match_sets=%d\n" |
| 11599 | "capa.max_remain_on_chan=%u\n" |
| 11600 | "capa.max_stations=%u\n" |
| 11601 | "capa.probe_resp_offloads=0x%x\n" |
| 11602 | "capa.max_acl_mac_addrs=%u\n" |
| 11603 | "capa.num_multichan_concurrent=%u\n", |
| 11604 | drv->capa.key_mgmt, |
| 11605 | drv->capa.enc, |
| 11606 | drv->capa.auth, |
| 11607 | drv->capa.flags, |
| 11608 | drv->capa.max_scan_ssids, |
| 11609 | drv->capa.max_sched_scan_ssids, |
| 11610 | drv->capa.sched_scan_supported, |
| 11611 | drv->capa.max_match_sets, |
| 11612 | drv->capa.max_remain_on_chan, |
| 11613 | drv->capa.max_stations, |
| 11614 | drv->capa.probe_resp_offloads, |
| 11615 | drv->capa.max_acl_mac_addrs, |
| 11616 | drv->capa.num_multichan_concurrent); |
| 11617 | if (res < 0 || res >= end - pos) |
| 11618 | return pos - buf; |
| 11619 | pos += res; |
| 11620 | } |
| 11621 | |
| 11622 | return pos - buf; |
| 11623 | } |
| 11624 | |
| 11625 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11626 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 11627 | { |
| 11628 | if (settings->head) |
| 11629 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, |
| 11630 | settings->head_len, settings->head); |
| 11631 | |
| 11632 | if (settings->tail) |
| 11633 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, |
| 11634 | settings->tail_len, settings->tail); |
| 11635 | |
| 11636 | if (settings->beacon_ies) |
| 11637 | NLA_PUT(msg, NL80211_ATTR_IE, |
| 11638 | settings->beacon_ies_len, settings->beacon_ies); |
| 11639 | |
| 11640 | if (settings->proberesp_ies) |
| 11641 | NLA_PUT(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 11642 | settings->proberesp_ies_len, settings->proberesp_ies); |
| 11643 | |
| 11644 | if (settings->assocresp_ies) |
| 11645 | NLA_PUT(msg, |
| 11646 | NL80211_ATTR_IE_ASSOC_RESP, |
| 11647 | settings->assocresp_ies_len, settings->assocresp_ies); |
| 11648 | |
| 11649 | if (settings->probe_resp) |
| 11650 | NLA_PUT(msg, NL80211_ATTR_PROBE_RESP, |
| 11651 | settings->probe_resp_len, settings->probe_resp); |
| 11652 | |
| 11653 | return 0; |
| 11654 | |
| 11655 | nla_put_failure: |
| 11656 | return -ENOBUFS; |
| 11657 | } |
| 11658 | |
| 11659 | |
| 11660 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 11661 | { |
| 11662 | struct nl_msg *msg; |
| 11663 | struct i802_bss *bss = priv; |
| 11664 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11665 | struct nlattr *beacon_csa; |
| 11666 | int ret = -ENOBUFS; |
| 11667 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 11668 | 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] | 11669 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 11670 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 11671 | settings->freq_params.center_freq1, |
| 11672 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11673 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11674 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11675 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 11676 | return -EOPNOTSUPP; |
| 11677 | } |
| 11678 | |
| 11679 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 11680 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 11681 | return -EOPNOTSUPP; |
| 11682 | |
| 11683 | /* check settings validity */ |
| 11684 | if (!settings->beacon_csa.tail || |
| 11685 | ((settings->beacon_csa.tail_len <= |
| 11686 | settings->counter_offset_beacon) || |
| 11687 | (settings->beacon_csa.tail[settings->counter_offset_beacon] != |
| 11688 | settings->cs_count))) |
| 11689 | return -EINVAL; |
| 11690 | |
| 11691 | if (settings->beacon_csa.probe_resp && |
| 11692 | ((settings->beacon_csa.probe_resp_len <= |
| 11693 | settings->counter_offset_presp) || |
| 11694 | (settings->beacon_csa.probe_resp[settings->counter_offset_presp] != |
| 11695 | settings->cs_count))) |
| 11696 | return -EINVAL; |
| 11697 | |
| 11698 | msg = nlmsg_alloc(); |
| 11699 | if (!msg) |
| 11700 | return -ENOMEM; |
| 11701 | |
| 11702 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CHANNEL_SWITCH); |
| 11703 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11704 | NLA_PUT_U32(msg, NL80211_ATTR_CH_SWITCH_COUNT, settings->cs_count); |
| 11705 | ret = nl80211_put_freq_params(msg, &settings->freq_params); |
| 11706 | if (ret) |
| 11707 | goto error; |
| 11708 | |
| 11709 | if (settings->block_tx) |
| 11710 | NLA_PUT_FLAG(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX); |
| 11711 | |
| 11712 | /* beacon_after params */ |
| 11713 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 11714 | if (ret) |
| 11715 | goto error; |
| 11716 | |
| 11717 | /* beacon_csa params */ |
| 11718 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 11719 | if (!beacon_csa) |
| 11720 | goto nla_put_failure; |
| 11721 | |
| 11722 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 11723 | if (ret) |
| 11724 | goto error; |
| 11725 | |
| 11726 | NLA_PUT_U16(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 11727 | settings->counter_offset_beacon); |
| 11728 | |
| 11729 | if (settings->beacon_csa.probe_resp) |
| 11730 | NLA_PUT_U16(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 11731 | settings->counter_offset_presp); |
| 11732 | |
| 11733 | nla_nest_end(msg, beacon_csa); |
| 11734 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11735 | if (ret) { |
| 11736 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 11737 | ret, strerror(-ret)); |
| 11738 | } |
| 11739 | return ret; |
| 11740 | |
| 11741 | nla_put_failure: |
| 11742 | ret = -ENOBUFS; |
| 11743 | error: |
| 11744 | nlmsg_free(msg); |
| 11745 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 11746 | return ret; |
| 11747 | } |
| 11748 | |
| 11749 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11750 | #ifdef CONFIG_TESTING_OPTIONS |
| 11751 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 11752 | { |
| 11753 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11754 | struct wpabuf *buf = arg; |
| 11755 | |
| 11756 | if (!buf) |
| 11757 | return NL_SKIP; |
| 11758 | |
| 11759 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 11760 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 11761 | return NL_SKIP; |
| 11762 | } |
| 11763 | |
| 11764 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 11765 | genlmsg_attrlen(gnlh, 0)); |
| 11766 | |
| 11767 | return NL_SKIP; |
| 11768 | } |
| 11769 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 11770 | |
| 11771 | |
| 11772 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 11773 | { |
| 11774 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 11775 | struct nlattr *nl_vendor_reply, *nl; |
| 11776 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11777 | struct wpabuf *buf = arg; |
| 11778 | int rem; |
| 11779 | |
| 11780 | if (!buf) |
| 11781 | return NL_SKIP; |
| 11782 | |
| 11783 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11784 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11785 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 11786 | |
| 11787 | if (!nl_vendor_reply) |
| 11788 | return NL_SKIP; |
| 11789 | |
| 11790 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 11791 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 11792 | return NL_SKIP; |
| 11793 | } |
| 11794 | |
| 11795 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 11796 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 11797 | } |
| 11798 | |
| 11799 | return NL_SKIP; |
| 11800 | } |
| 11801 | |
| 11802 | |
| 11803 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 11804 | unsigned int subcmd, const u8 *data, |
| 11805 | size_t data_len, struct wpabuf *buf) |
| 11806 | { |
| 11807 | struct i802_bss *bss = priv; |
| 11808 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11809 | struct nl_msg *msg; |
| 11810 | int ret; |
| 11811 | |
| 11812 | msg = nlmsg_alloc(); |
| 11813 | if (!msg) |
| 11814 | return -ENOMEM; |
| 11815 | |
| 11816 | #ifdef CONFIG_TESTING_OPTIONS |
| 11817 | if (vendor_id == 0xffffffff) { |
| 11818 | nl80211_cmd(drv, msg, 0, subcmd); |
| 11819 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 11820 | 0) |
| 11821 | goto nla_put_failure; |
| 11822 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 11823 | if (ret) |
| 11824 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 11825 | ret); |
| 11826 | return ret; |
| 11827 | } |
| 11828 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 11829 | |
| 11830 | nl80211_cmd(drv, msg, 0, NL80211_CMD_VENDOR); |
| 11831 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 11832 | goto nla_put_failure; |
| 11833 | NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_ID, vendor_id); |
| 11834 | NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd); |
| 11835 | if (data) |
| 11836 | NLA_PUT(msg, NL80211_ATTR_VENDOR_DATA, data_len, data); |
| 11837 | |
| 11838 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 11839 | if (ret) |
| 11840 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 11841 | ret); |
| 11842 | return ret; |
| 11843 | |
| 11844 | nla_put_failure: |
| 11845 | nlmsg_free(msg); |
| 11846 | return -ENOBUFS; |
| 11847 | } |
| 11848 | |
| 11849 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11850 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 11851 | u8 qos_map_set_len) |
| 11852 | { |
| 11853 | struct i802_bss *bss = priv; |
| 11854 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11855 | struct nl_msg *msg; |
| 11856 | int ret; |
| 11857 | |
| 11858 | msg = nlmsg_alloc(); |
| 11859 | if (!msg) |
| 11860 | return -ENOMEM; |
| 11861 | |
| 11862 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 11863 | qos_map_set, qos_map_set_len); |
| 11864 | |
| 11865 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_QOS_MAP); |
| 11866 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11867 | NLA_PUT(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set); |
| 11868 | |
| 11869 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11870 | if (ret) |
| 11871 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 11872 | |
| 11873 | return ret; |
| 11874 | |
| 11875 | nla_put_failure: |
| 11876 | nlmsg_free(msg); |
| 11877 | return -ENOBUFS; |
| 11878 | } |
| 11879 | |
| 11880 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11881 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 11882 | .name = "nl80211", |
| 11883 | .desc = "Linux nl80211/cfg80211", |
| 11884 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 11885 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11886 | .set_key = driver_nl80211_set_key, |
| 11887 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11888 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 11889 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11890 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11891 | .deauthenticate = driver_nl80211_deauthenticate, |
| 11892 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11893 | .associate = wpa_driver_nl80211_associate, |
| 11894 | .global_init = nl80211_global_init, |
| 11895 | .global_deinit = nl80211_global_deinit, |
| 11896 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11897 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11898 | .get_capa = wpa_driver_nl80211_get_capa, |
| 11899 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 11900 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 11901 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 11902 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11903 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 11904 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11905 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11906 | .if_remove = driver_nl80211_if_remove, |
| 11907 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11908 | .get_hw_feature_data = wpa_driver_nl80211_get_hw_feature_data, |
| 11909 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11910 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11911 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 11912 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11913 | .hapd_init = i802_init, |
| 11914 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11915 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11916 | .get_seqnum = i802_get_seqnum, |
| 11917 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11918 | .get_inact_sec = i802_get_inact_sec, |
| 11919 | .sta_clear_stats = i802_sta_clear_stats, |
| 11920 | .set_rts = i802_set_rts, |
| 11921 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11922 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11923 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11924 | .sta_deauth = i802_sta_deauth, |
| 11925 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11926 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11927 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11928 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11929 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 11930 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 11931 | .cancel_remain_on_channel = |
| 11932 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11933 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11934 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11935 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11936 | .resume = wpa_driver_nl80211_resume, |
| 11937 | .send_ft_action = nl80211_send_ft_action, |
| 11938 | .signal_monitor = nl80211_signal_monitor, |
| 11939 | .signal_poll = nl80211_signal_poll, |
| 11940 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11941 | .shared_freq = wpa_driver_nl80211_shared_freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11942 | .set_param = nl80211_set_param, |
| 11943 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11944 | .add_pmkid = nl80211_add_pmkid, |
| 11945 | .remove_pmkid = nl80211_remove_pmkid, |
| 11946 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11947 | .set_rekey_info = nl80211_set_rekey_info, |
| 11948 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11949 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11950 | .start_dfs_cac = nl80211_start_radar_detection, |
| 11951 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11952 | #ifdef CONFIG_TDLS |
| 11953 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 11954 | .tdls_oper = nl80211_tdls_oper, |
| 11955 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 11956 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11957 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11958 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11959 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11960 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11961 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11962 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11963 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11964 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11965 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11966 | #ifdef ANDROID |
| 11967 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11968 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11969 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11970 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11971 | }; |