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 | 6cb1f65 | 2014-03-21 10:54:03 -0700 | [diff] [blame^] | 2903 | if (drv->scan_for_auth) { |
| 2904 | /* |
| 2905 | * Cannot indicate EVENT_SCAN_STARTED here since we skip |
| 2906 | * EVENT_SCAN_RESULTS in scan_for_auth case and the |
| 2907 | * upper layer implementation could get confused about |
| 2908 | * scanning state. |
| 2909 | */ |
| 2910 | wpa_printf(MSG_DEBUG, "nl80211: Do not indicate scan-start event due to internal scan_for_auth"); |
| 2911 | break; |
| 2912 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2913 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_STARTED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2914 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2915 | case NL80211_CMD_START_SCHED_SCAN: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2916 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan started"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2917 | drv->scan_state = SCHED_SCAN_STARTED; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2918 | break; |
| 2919 | case NL80211_CMD_SCHED_SCAN_STOPPED: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2920 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan stopped"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2921 | drv->scan_state = SCHED_SCAN_STOPPED; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2922 | wpa_supplicant_event(drv->ctx, EVENT_SCHED_SCAN_STOPPED, NULL); |
| 2923 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2924 | case NL80211_CMD_NEW_SCAN_RESULTS: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2925 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2926 | "nl80211: New scan results available"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2927 | drv->scan_state = SCAN_COMPLETED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2928 | drv->scan_complete_events = 1; |
| 2929 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, |
| 2930 | drv->ctx); |
| 2931 | send_scan_event(drv, 0, tb); |
| 2932 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2933 | case NL80211_CMD_SCHED_SCAN_RESULTS: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2934 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2935 | "nl80211: New sched scan results available"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2936 | drv->scan_state = SCHED_SCAN_RESULTS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2937 | send_scan_event(drv, 0, tb); |
| 2938 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2939 | case NL80211_CMD_SCAN_ABORTED: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2940 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan aborted"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2941 | drv->scan_state = SCAN_ABORTED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2942 | /* |
| 2943 | * Need to indicate that scan results are available in order |
| 2944 | * not to make wpa_supplicant stop its scanning. |
| 2945 | */ |
| 2946 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, |
| 2947 | drv->ctx); |
| 2948 | send_scan_event(drv, 1, tb); |
| 2949 | break; |
| 2950 | case NL80211_CMD_AUTHENTICATE: |
| 2951 | case NL80211_CMD_ASSOCIATE: |
| 2952 | case NL80211_CMD_DEAUTHENTICATE: |
| 2953 | case NL80211_CMD_DISASSOCIATE: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2954 | case NL80211_CMD_FRAME_TX_STATUS: |
| 2955 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
| 2956 | case NL80211_CMD_UNPROT_DISASSOCIATE: |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2957 | mlme_event(bss, cmd, tb[NL80211_ATTR_FRAME], |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2958 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
| 2959 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2960 | tb[NL80211_ATTR_COOKIE], |
| 2961 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2962 | break; |
| 2963 | case NL80211_CMD_CONNECT: |
| 2964 | case NL80211_CMD_ROAM: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2965 | mlme_event_connect(drv, cmd, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2966 | tb[NL80211_ATTR_STATUS_CODE], |
| 2967 | tb[NL80211_ATTR_MAC], |
| 2968 | tb[NL80211_ATTR_REQ_IE], |
| 2969 | tb[NL80211_ATTR_RESP_IE]); |
| 2970 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2971 | case NL80211_CMD_CH_SWITCH_NOTIFY: |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2972 | mlme_event_ch_switch(drv, |
| 2973 | tb[NL80211_ATTR_IFINDEX], |
| 2974 | tb[NL80211_ATTR_WIPHY_FREQ], |
| 2975 | tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 2976 | tb[NL80211_ATTR_CHANNEL_WIDTH], |
| 2977 | tb[NL80211_ATTR_CENTER_FREQ1], |
| 2978 | tb[NL80211_ATTR_CENTER_FREQ2]); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2979 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2980 | case NL80211_CMD_DISCONNECT: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2981 | mlme_event_disconnect(drv, tb[NL80211_ATTR_REASON_CODE], |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2982 | tb[NL80211_ATTR_MAC], |
| 2983 | tb[NL80211_ATTR_DISCONNECTED_BY_AP]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2984 | break; |
| 2985 | case NL80211_CMD_MICHAEL_MIC_FAILURE: |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2986 | mlme_event_michael_mic_failure(bss, tb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2987 | break; |
| 2988 | case NL80211_CMD_JOIN_IBSS: |
| 2989 | mlme_event_join_ibss(drv, tb); |
| 2990 | break; |
| 2991 | case NL80211_CMD_REMAIN_ON_CHANNEL: |
| 2992 | mlme_event_remain_on_channel(drv, 0, tb); |
| 2993 | break; |
| 2994 | case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: |
| 2995 | mlme_event_remain_on_channel(drv, 1, tb); |
| 2996 | break; |
| 2997 | case NL80211_CMD_NOTIFY_CQM: |
| 2998 | nl80211_cqm_event(drv, tb); |
| 2999 | break; |
| 3000 | case NL80211_CMD_REG_CHANGE: |
| 3001 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory domain change"); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3002 | if (tb[NL80211_ATTR_REG_INITIATOR] == NULL) |
| 3003 | break; |
| 3004 | os_memset(&data, 0, sizeof(data)); |
| 3005 | switch (nla_get_u8(tb[NL80211_ATTR_REG_INITIATOR])) { |
| 3006 | case NL80211_REGDOM_SET_BY_CORE: |
| 3007 | data.channel_list_changed.initiator = |
| 3008 | REGDOM_SET_BY_CORE; |
| 3009 | break; |
| 3010 | case NL80211_REGDOM_SET_BY_USER: |
| 3011 | data.channel_list_changed.initiator = |
| 3012 | REGDOM_SET_BY_USER; |
| 3013 | break; |
| 3014 | case NL80211_REGDOM_SET_BY_DRIVER: |
| 3015 | data.channel_list_changed.initiator = |
| 3016 | REGDOM_SET_BY_DRIVER; |
| 3017 | break; |
| 3018 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
| 3019 | data.channel_list_changed.initiator = |
| 3020 | REGDOM_SET_BY_COUNTRY_IE; |
| 3021 | break; |
| 3022 | default: |
| 3023 | wpa_printf(MSG_DEBUG, "nl80211: Unknown reg change initiator %d received", |
| 3024 | nla_get_u8(tb[NL80211_ATTR_REG_INITIATOR])); |
| 3025 | break; |
| 3026 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3027 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3028 | &data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3029 | break; |
| 3030 | case NL80211_CMD_REG_BEACON_HINT: |
| 3031 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory beacon hint"); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 3032 | os_memset(&data, 0, sizeof(data)); |
| 3033 | data.channel_list_changed.initiator = REGDOM_BEACON_HINT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3034 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 3035 | &data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3036 | break; |
| 3037 | case NL80211_CMD_NEW_STATION: |
| 3038 | nl80211_new_station_event(drv, tb); |
| 3039 | break; |
| 3040 | case NL80211_CMD_DEL_STATION: |
| 3041 | nl80211_del_station_event(drv, tb); |
| 3042 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3043 | case NL80211_CMD_SET_REKEY_OFFLOAD: |
| 3044 | nl80211_rekey_offload_event(drv, tb); |
| 3045 | break; |
| 3046 | case NL80211_CMD_PMKSA_CANDIDATE: |
| 3047 | nl80211_pmksa_candidate_event(drv, tb); |
| 3048 | break; |
| 3049 | case NL80211_CMD_PROBE_CLIENT: |
| 3050 | nl80211_client_probe_event(drv, tb); |
| 3051 | break; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3052 | case NL80211_CMD_TDLS_OPER: |
| 3053 | nl80211_tdls_oper_event(drv, tb); |
| 3054 | break; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3055 | case NL80211_CMD_CONN_FAILED: |
| 3056 | nl80211_connect_failed_event(drv, tb); |
| 3057 | break; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3058 | case NL80211_CMD_FT_EVENT: |
| 3059 | mlme_event_ft_event(drv, tb); |
| 3060 | break; |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 3061 | case NL80211_CMD_RADAR_DETECT: |
| 3062 | nl80211_radar_event(drv, tb); |
| 3063 | break; |
Dmitry Shmidt | 5393a0f | 2013-08-08 11:23:34 -0700 | [diff] [blame] | 3064 | case NL80211_CMD_STOP_AP: |
| 3065 | nl80211_stop_ap(drv, tb); |
| 3066 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3067 | case NL80211_CMD_VENDOR: |
| 3068 | nl80211_vendor_event(drv, tb); |
| 3069 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3070 | default: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3071 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Ignored unknown event " |
| 3072 | "(cmd=%d)", cmd); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3073 | break; |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | |
| 3078 | static int process_drv_event(struct nl_msg *msg, void *arg) |
| 3079 | { |
| 3080 | struct wpa_driver_nl80211_data *drv = arg; |
| 3081 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3082 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3083 | struct i802_bss *bss; |
| 3084 | int ifidx = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3085 | |
| 3086 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3087 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3088 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3089 | if (tb[NL80211_ATTR_IFINDEX]) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3090 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 3091 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3092 | for (bss = drv->first_bss; bss; bss = bss->next) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3093 | if (ifidx == -1 || ifidx == bss->ifindex) { |
| 3094 | do_process_drv_event(bss, gnlh->cmd, tb); |
| 3095 | return NL_SKIP; |
| 3096 | } |
| 3097 | wpa_printf(MSG_DEBUG, |
| 3098 | "nl80211: Ignored event (cmd=%d) for foreign interface (ifindex %d)", |
| 3099 | gnlh->cmd, ifidx); |
| 3100 | } else if (tb[NL80211_ATTR_WDEV]) { |
| 3101 | u64 wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 3102 | wpa_printf(MSG_DEBUG, "nl80211: Process event on P2P device"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3103 | for (bss = drv->first_bss; bss; bss = bss->next) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3104 | if (bss->wdev_id_set && wdev_id == bss->wdev_id) { |
| 3105 | do_process_drv_event(bss, gnlh->cmd, tb); |
| 3106 | return NL_SKIP; |
| 3107 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3108 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3109 | wpa_printf(MSG_DEBUG, |
| 3110 | "nl80211: Ignored event (cmd=%d) for foreign interface (wdev 0x%llx)", |
| 3111 | gnlh->cmd, (long long unsigned int) wdev_id); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3112 | } |
| 3113 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3114 | return NL_SKIP; |
| 3115 | } |
| 3116 | |
| 3117 | |
| 3118 | static int process_global_event(struct nl_msg *msg, void *arg) |
| 3119 | { |
| 3120 | struct nl80211_global *global = arg; |
| 3121 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3122 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3123 | struct wpa_driver_nl80211_data *drv, *tmp; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3124 | int ifidx = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3125 | struct i802_bss *bss; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3126 | u64 wdev_id = 0; |
| 3127 | int wdev_id_set = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3128 | |
| 3129 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3130 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3131 | |
| 3132 | if (tb[NL80211_ATTR_IFINDEX]) |
| 3133 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3134 | else if (tb[NL80211_ATTR_WDEV]) { |
| 3135 | wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 3136 | wdev_id_set = 1; |
| 3137 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3138 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3139 | dl_list_for_each_safe(drv, tmp, &global->interfaces, |
| 3140 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3141 | for (bss = drv->first_bss; bss; bss = bss->next) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3142 | if ((ifidx == -1 && !wdev_id_set) || |
| 3143 | ifidx == bss->ifindex || |
| 3144 | (wdev_id_set && bss->wdev_id_set && |
| 3145 | wdev_id == bss->wdev_id)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3146 | do_process_drv_event(bss, gnlh->cmd, tb); |
| 3147 | return NL_SKIP; |
| 3148 | } |
| 3149 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | return NL_SKIP; |
| 3153 | } |
| 3154 | |
| 3155 | |
| 3156 | static int process_bss_event(struct nl_msg *msg, void *arg) |
| 3157 | { |
| 3158 | struct i802_bss *bss = arg; |
| 3159 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3160 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 3161 | |
| 3162 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3163 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3164 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3165 | wpa_printf(MSG_DEBUG, "nl80211: BSS Event %d (%s) received for %s", |
| 3166 | gnlh->cmd, nl80211_command_to_string(gnlh->cmd), |
| 3167 | bss->ifname); |
| 3168 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3169 | switch (gnlh->cmd) { |
| 3170 | case NL80211_CMD_FRAME: |
| 3171 | case NL80211_CMD_FRAME_TX_STATUS: |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3172 | mlme_event(bss, gnlh->cmd, tb[NL80211_ATTR_FRAME], |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3173 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
| 3174 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3175 | tb[NL80211_ATTR_COOKIE], |
| 3176 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3177 | break; |
| 3178 | case NL80211_CMD_UNEXPECTED_FRAME: |
| 3179 | nl80211_spurious_frame(bss, tb, 0); |
| 3180 | break; |
| 3181 | case NL80211_CMD_UNEXPECTED_4ADDR_FRAME: |
| 3182 | nl80211_spurious_frame(bss, tb, 1); |
| 3183 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3184 | default: |
| 3185 | wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event " |
| 3186 | "(cmd=%d)", gnlh->cmd); |
| 3187 | break; |
| 3188 | } |
| 3189 | |
| 3190 | return NL_SKIP; |
| 3191 | } |
| 3192 | |
| 3193 | |
| 3194 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 3195 | void *handle) |
| 3196 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3197 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3198 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3199 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3200 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3201 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3202 | res = nl_recvmsgs(handle, cb); |
| 3203 | if (res) { |
| 3204 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 3205 | __func__, res); |
| 3206 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | |
| 3210 | /** |
| 3211 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 3212 | * @priv: driver_nl80211 private data |
| 3213 | * @alpha2_arg: country to which to switch to |
| 3214 | * Returns: 0 on success, -1 on failure |
| 3215 | * |
| 3216 | * This asks nl80211 to set the regulatory domain for given |
| 3217 | * country ISO / IEC alpha2. |
| 3218 | */ |
| 3219 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 3220 | { |
| 3221 | struct i802_bss *bss = priv; |
| 3222 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3223 | char alpha2[3]; |
| 3224 | struct nl_msg *msg; |
| 3225 | |
| 3226 | msg = nlmsg_alloc(); |
| 3227 | if (!msg) |
| 3228 | return -ENOMEM; |
| 3229 | |
| 3230 | alpha2[0] = alpha2_arg[0]; |
| 3231 | alpha2[1] = alpha2_arg[1]; |
| 3232 | alpha2[2] = '\0'; |
| 3233 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3234 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3235 | |
| 3236 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); |
| 3237 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 3238 | return -EINVAL; |
| 3239 | return 0; |
| 3240 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3241 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3242 | return -EINVAL; |
| 3243 | } |
| 3244 | |
| 3245 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3246 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 3247 | { |
| 3248 | char *alpha2 = arg; |
| 3249 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 3250 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3251 | |
| 3252 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3253 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3254 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 3255 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 3256 | return NL_SKIP; |
| 3257 | } |
| 3258 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 3259 | return NL_SKIP; |
| 3260 | } |
| 3261 | |
| 3262 | |
| 3263 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 3264 | { |
| 3265 | struct i802_bss *bss = priv; |
| 3266 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3267 | struct nl_msg *msg; |
| 3268 | int ret; |
| 3269 | |
| 3270 | msg = nlmsg_alloc(); |
| 3271 | if (!msg) |
| 3272 | return -ENOMEM; |
| 3273 | |
| 3274 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 3275 | alpha2[0] = '\0'; |
| 3276 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 3277 | if (!alpha2[0]) |
| 3278 | ret = -1; |
| 3279 | |
| 3280 | return ret; |
| 3281 | } |
| 3282 | |
| 3283 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3284 | static int protocol_feature_handler(struct nl_msg *msg, void *arg) |
| 3285 | { |
| 3286 | u32 *feat = arg; |
| 3287 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 3288 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3289 | |
| 3290 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3291 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3292 | |
| 3293 | if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]) |
| 3294 | *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]); |
| 3295 | |
| 3296 | return NL_SKIP; |
| 3297 | } |
| 3298 | |
| 3299 | |
| 3300 | static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv) |
| 3301 | { |
| 3302 | u32 feat = 0; |
| 3303 | struct nl_msg *msg; |
| 3304 | |
| 3305 | msg = nlmsg_alloc(); |
| 3306 | if (!msg) |
| 3307 | goto nla_put_failure; |
| 3308 | |
| 3309 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 3310 | if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0) |
| 3311 | return feat; |
| 3312 | |
| 3313 | msg = NULL; |
| 3314 | nla_put_failure: |
| 3315 | nlmsg_free(msg); |
| 3316 | return 0; |
| 3317 | } |
| 3318 | |
| 3319 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3320 | struct wiphy_info_data { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3321 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3322 | struct wpa_driver_capa *capa; |
| 3323 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3324 | unsigned int num_multichan_concurrent; |
| 3325 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3326 | unsigned int error:1; |
| 3327 | unsigned int device_ap_sme:1; |
| 3328 | unsigned int poll_command_supported:1; |
| 3329 | unsigned int data_tx_status:1; |
| 3330 | unsigned int monitor_supported:1; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3331 | unsigned int auth_supported:1; |
| 3332 | unsigned int connect_supported:1; |
| 3333 | unsigned int p2p_go_supported:1; |
| 3334 | unsigned int p2p_client_supported:1; |
| 3335 | unsigned int p2p_concurrent:1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3336 | unsigned int channel_switch_supported:1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3337 | unsigned int set_qos_map_supported:1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3338 | }; |
| 3339 | |
| 3340 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3341 | static unsigned int probe_resp_offload_support(int supp_protocols) |
| 3342 | { |
| 3343 | unsigned int prot = 0; |
| 3344 | |
| 3345 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS) |
| 3346 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS; |
| 3347 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2) |
| 3348 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2; |
| 3349 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P) |
| 3350 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P; |
| 3351 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U) |
| 3352 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING; |
| 3353 | |
| 3354 | return prot; |
| 3355 | } |
| 3356 | |
| 3357 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3358 | static void wiphy_info_supported_iftypes(struct wiphy_info_data *info, |
| 3359 | struct nlattr *tb) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3360 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3361 | struct nlattr *nl_mode; |
| 3362 | int i; |
| 3363 | |
| 3364 | if (tb == NULL) |
| 3365 | return; |
| 3366 | |
| 3367 | nla_for_each_nested(nl_mode, tb, i) { |
| 3368 | switch (nla_type(nl_mode)) { |
| 3369 | case NL80211_IFTYPE_AP: |
| 3370 | info->capa->flags |= WPA_DRIVER_FLAGS_AP; |
| 3371 | break; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3372 | case NL80211_IFTYPE_ADHOC: |
| 3373 | info->capa->flags |= WPA_DRIVER_FLAGS_IBSS; |
| 3374 | break; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3375 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3376 | info->capa->flags |= |
| 3377 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE; |
| 3378 | break; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3379 | case NL80211_IFTYPE_P2P_GO: |
| 3380 | info->p2p_go_supported = 1; |
| 3381 | break; |
| 3382 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3383 | info->p2p_client_supported = 1; |
| 3384 | break; |
| 3385 | case NL80211_IFTYPE_MONITOR: |
| 3386 | info->monitor_supported = 1; |
| 3387 | break; |
| 3388 | } |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | |
| 3393 | static int wiphy_info_iface_comb_process(struct wiphy_info_data *info, |
| 3394 | struct nlattr *nl_combi) |
| 3395 | { |
| 3396 | struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB]; |
| 3397 | struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT]; |
| 3398 | struct nlattr *nl_limit, *nl_mode; |
| 3399 | int err, rem_limit, rem_mode; |
| 3400 | int combination_has_p2p = 0, combination_has_mgd = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3401 | static struct nla_policy |
| 3402 | iface_combination_policy[NUM_NL80211_IFACE_COMB] = { |
| 3403 | [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED }, |
| 3404 | [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 }, |
| 3405 | [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG }, |
| 3406 | [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 }, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 3407 | [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 }, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3408 | }, |
| 3409 | iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = { |
| 3410 | [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED }, |
| 3411 | [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 }, |
| 3412 | }; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3413 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3414 | err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB, |
| 3415 | nl_combi, iface_combination_policy); |
| 3416 | if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] || |
| 3417 | !tb_comb[NL80211_IFACE_COMB_MAXNUM] || |
| 3418 | !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) |
| 3419 | return 0; /* broken combination */ |
| 3420 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 3421 | if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]) |
| 3422 | info->capa->flags |= WPA_DRIVER_FLAGS_RADAR; |
| 3423 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3424 | nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], |
| 3425 | rem_limit) { |
| 3426 | err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT, |
| 3427 | nl_limit, iface_limit_policy); |
| 3428 | if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) |
| 3429 | return 0; /* broken combination */ |
| 3430 | |
| 3431 | nla_for_each_nested(nl_mode, |
| 3432 | tb_limit[NL80211_IFACE_LIMIT_TYPES], |
| 3433 | rem_mode) { |
| 3434 | int ift = nla_type(nl_mode); |
| 3435 | if (ift == NL80211_IFTYPE_P2P_GO || |
| 3436 | ift == NL80211_IFTYPE_P2P_CLIENT) |
| 3437 | combination_has_p2p = 1; |
| 3438 | if (ift == NL80211_IFTYPE_STATION) |
| 3439 | combination_has_mgd = 1; |
| 3440 | } |
| 3441 | if (combination_has_p2p && combination_has_mgd) |
| 3442 | break; |
| 3443 | } |
| 3444 | |
| 3445 | if (combination_has_p2p && combination_has_mgd) { |
| 3446 | info->p2p_concurrent = 1; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3447 | info->num_multichan_concurrent = |
| 3448 | nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3449 | return 1; |
| 3450 | } |
| 3451 | |
| 3452 | return 0; |
| 3453 | } |
| 3454 | |
| 3455 | |
| 3456 | static void wiphy_info_iface_comb(struct wiphy_info_data *info, |
| 3457 | struct nlattr *tb) |
| 3458 | { |
| 3459 | struct nlattr *nl_combi; |
| 3460 | int rem_combi; |
| 3461 | |
| 3462 | if (tb == NULL) |
| 3463 | return; |
| 3464 | |
| 3465 | nla_for_each_nested(nl_combi, tb, rem_combi) { |
| 3466 | if (wiphy_info_iface_comb_process(info, nl_combi) > 0) |
| 3467 | break; |
| 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | |
| 3472 | static void wiphy_info_supp_cmds(struct wiphy_info_data *info, |
| 3473 | struct nlattr *tb) |
| 3474 | { |
| 3475 | struct nlattr *nl_cmd; |
| 3476 | int i; |
| 3477 | |
| 3478 | if (tb == NULL) |
| 3479 | return; |
| 3480 | |
| 3481 | nla_for_each_nested(nl_cmd, tb, i) { |
| 3482 | switch (nla_get_u32(nl_cmd)) { |
| 3483 | case NL80211_CMD_AUTHENTICATE: |
| 3484 | info->auth_supported = 1; |
| 3485 | break; |
| 3486 | case NL80211_CMD_CONNECT: |
| 3487 | info->connect_supported = 1; |
| 3488 | break; |
| 3489 | case NL80211_CMD_START_SCHED_SCAN: |
| 3490 | info->capa->sched_scan_supported = 1; |
| 3491 | break; |
| 3492 | case NL80211_CMD_PROBE_CLIENT: |
| 3493 | info->poll_command_supported = 1; |
| 3494 | break; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3495 | case NL80211_CMD_CHANNEL_SWITCH: |
| 3496 | info->channel_switch_supported = 1; |
| 3497 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3498 | case NL80211_CMD_SET_QOS_MAP: |
| 3499 | info->set_qos_map_supported = 1; |
| 3500 | break; |
| 3501 | } |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | |
| 3506 | static void wiphy_info_cipher_suites(struct wiphy_info_data *info, |
| 3507 | struct nlattr *tb) |
| 3508 | { |
| 3509 | int i, num; |
| 3510 | u32 *ciphers; |
| 3511 | |
| 3512 | if (tb == NULL) |
| 3513 | return; |
| 3514 | |
| 3515 | num = nla_len(tb) / sizeof(u32); |
| 3516 | ciphers = nla_data(tb); |
| 3517 | for (i = 0; i < num; i++) { |
| 3518 | u32 c = ciphers[i]; |
| 3519 | |
| 3520 | wpa_printf(MSG_DEBUG, "nl80211: Supported cipher %02x-%02x-%02x:%d", |
| 3521 | c >> 24, (c >> 16) & 0xff, |
| 3522 | (c >> 8) & 0xff, c & 0xff); |
| 3523 | switch (c) { |
| 3524 | case WLAN_CIPHER_SUITE_CCMP_256: |
| 3525 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP_256; |
| 3526 | break; |
| 3527 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 3528 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP_256; |
| 3529 | break; |
| 3530 | case WLAN_CIPHER_SUITE_CCMP: |
| 3531 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_CCMP; |
| 3532 | break; |
| 3533 | case WLAN_CIPHER_SUITE_GCMP: |
| 3534 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_GCMP; |
| 3535 | break; |
| 3536 | case WLAN_CIPHER_SUITE_TKIP: |
| 3537 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_TKIP; |
| 3538 | break; |
| 3539 | case WLAN_CIPHER_SUITE_WEP104: |
| 3540 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP104; |
| 3541 | break; |
| 3542 | case WLAN_CIPHER_SUITE_WEP40: |
| 3543 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_WEP40; |
| 3544 | break; |
| 3545 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 3546 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP; |
| 3547 | break; |
| 3548 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 3549 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_128; |
| 3550 | break; |
| 3551 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 3552 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_GMAC_256; |
| 3553 | break; |
| 3554 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 3555 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_BIP_CMAC_256; |
| 3556 | break; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3557 | case WLAN_CIPHER_SUITE_NO_GROUP_ADDR: |
| 3558 | info->capa->enc |= WPA_DRIVER_CAPA_ENC_GTK_NOT_USED; |
| 3559 | break; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3560 | } |
| 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | |
| 3565 | static void wiphy_info_max_roc(struct wpa_driver_capa *capa, |
| 3566 | struct nlattr *tb) |
| 3567 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3568 | if (tb) |
| 3569 | capa->max_remain_on_chan = nla_get_u32(tb); |
| 3570 | } |
| 3571 | |
| 3572 | |
| 3573 | static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls, |
| 3574 | struct nlattr *ext_setup) |
| 3575 | { |
| 3576 | if (tdls == NULL) |
| 3577 | return; |
| 3578 | |
| 3579 | wpa_printf(MSG_DEBUG, "nl80211: TDLS supported"); |
| 3580 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT; |
| 3581 | |
| 3582 | if (ext_setup) { |
| 3583 | wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup"); |
| 3584 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP; |
| 3585 | } |
| 3586 | } |
| 3587 | |
| 3588 | |
| 3589 | static void wiphy_info_feature_flags(struct wiphy_info_data *info, |
| 3590 | struct nlattr *tb) |
| 3591 | { |
| 3592 | u32 flags; |
| 3593 | struct wpa_driver_capa *capa = info->capa; |
| 3594 | |
| 3595 | if (tb == NULL) |
| 3596 | return; |
| 3597 | |
| 3598 | flags = nla_get_u32(tb); |
| 3599 | |
| 3600 | if (flags & NL80211_FEATURE_SK_TX_STATUS) |
| 3601 | info->data_tx_status = 1; |
| 3602 | |
| 3603 | if (flags & NL80211_FEATURE_INACTIVITY_TIMER) |
| 3604 | capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER; |
| 3605 | |
| 3606 | if (flags & NL80211_FEATURE_SAE) |
| 3607 | capa->flags |= WPA_DRIVER_FLAGS_SAE; |
| 3608 | |
| 3609 | if (flags & NL80211_FEATURE_NEED_OBSS_SCAN) |
| 3610 | capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN; |
| 3611 | } |
| 3612 | |
| 3613 | |
| 3614 | static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa, |
| 3615 | struct nlattr *tb) |
| 3616 | { |
| 3617 | u32 protocols; |
| 3618 | |
| 3619 | if (tb == NULL) |
| 3620 | return; |
| 3621 | |
| 3622 | protocols = nla_get_u32(tb); |
| 3623 | wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP " |
| 3624 | "mode"); |
| 3625 | capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD; |
| 3626 | capa->probe_resp_offloads = probe_resp_offload_support(protocols); |
| 3627 | } |
| 3628 | |
| 3629 | |
| 3630 | static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
| 3631 | { |
| 3632 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 3633 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 3634 | struct wiphy_info_data *info = arg; |
| 3635 | struct wpa_driver_capa *capa = info->capa; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3636 | struct wpa_driver_nl80211_data *drv = info->drv; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3637 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3638 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 3639 | genlmsg_attrlen(gnlh, 0), NULL); |
| 3640 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3641 | if (tb[NL80211_ATTR_WIPHY_NAME]) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3642 | os_strlcpy(drv->phyname, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3643 | nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]), |
| 3644 | sizeof(drv->phyname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3645 | if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3646 | capa->max_scan_ssids = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3647 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]); |
| 3648 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3649 | if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]) |
| 3650 | capa->max_sched_scan_ssids = |
| 3651 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]); |
| 3652 | |
| 3653 | if (tb[NL80211_ATTR_MAX_MATCH_SETS]) |
| 3654 | capa->max_match_sets = |
| 3655 | nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]); |
| 3656 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3657 | if (tb[NL80211_ATTR_MAC_ACL_MAX]) |
| 3658 | capa->max_acl_mac_addrs = |
| 3659 | nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]); |
| 3660 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3661 | wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]); |
| 3662 | wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]); |
| 3663 | wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3664 | wiphy_info_cipher_suites(info, tb[NL80211_ATTR_CIPHER_SUITES]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3665 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3666 | if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) { |
| 3667 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based " |
| 3668 | "off-channel TX"); |
| 3669 | capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 3670 | } |
| 3671 | |
| 3672 | if (tb[NL80211_ATTR_ROAM_SUPPORT]) { |
| 3673 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming"); |
| 3674 | capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 3675 | } |
| 3676 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3677 | wiphy_info_max_roc(capa, |
| 3678 | tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3679 | |
| 3680 | if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD]) |
| 3681 | capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3682 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3683 | wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT], |
| 3684 | tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]); |
Dmitry Shmidt | ad266fb | 2012-08-24 17:03:35 -0700 | [diff] [blame] | 3685 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3686 | if (tb[NL80211_ATTR_DEVICE_AP_SME]) |
| 3687 | info->device_ap_sme = 1; |
| 3688 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3689 | wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]); |
| 3690 | wiphy_info_probe_resp_offload(capa, |
| 3691 | tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3692 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3693 | if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] && |
| 3694 | drv->extended_capa == NULL) { |
| 3695 | drv->extended_capa = |
| 3696 | os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 3697 | if (drv->extended_capa) { |
| 3698 | os_memcpy(drv->extended_capa, |
| 3699 | nla_data(tb[NL80211_ATTR_EXT_CAPA]), |
| 3700 | nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 3701 | drv->extended_capa_len = |
| 3702 | nla_len(tb[NL80211_ATTR_EXT_CAPA]); |
| 3703 | } |
| 3704 | drv->extended_capa_mask = |
| 3705 | os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 3706 | if (drv->extended_capa_mask) { |
| 3707 | os_memcpy(drv->extended_capa_mask, |
| 3708 | nla_data(tb[NL80211_ATTR_EXT_CAPA]), |
| 3709 | nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 3710 | } else { |
| 3711 | os_free(drv->extended_capa); |
| 3712 | drv->extended_capa = NULL; |
| 3713 | drv->extended_capa_len = 0; |
| 3714 | } |
| 3715 | } |
| 3716 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3717 | if (tb[NL80211_ATTR_VENDOR_DATA]) { |
| 3718 | struct nlattr *nl; |
| 3719 | int rem; |
| 3720 | |
| 3721 | nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_DATA], rem) { |
| 3722 | struct nl80211_vendor_cmd_info *vinfo; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3723 | if (nla_len(nl) != sizeof(*vinfo)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3724 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info"); |
| 3725 | continue; |
| 3726 | } |
| 3727 | vinfo = nla_data(nl); |
| 3728 | wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u", |
| 3729 | vinfo->vendor_id, vinfo->subcmd); |
| 3730 | } |
| 3731 | } |
| 3732 | |
| 3733 | if (tb[NL80211_ATTR_VENDOR_EVENTS]) { |
| 3734 | struct nlattr *nl; |
| 3735 | int rem; |
| 3736 | |
| 3737 | nla_for_each_nested(nl, tb[NL80211_ATTR_VENDOR_EVENTS], rem) { |
| 3738 | struct nl80211_vendor_cmd_info *vinfo; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3739 | if (nla_len(nl) != sizeof(*vinfo)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3740 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected vendor data info"); |
| 3741 | continue; |
| 3742 | } |
| 3743 | vinfo = nla_data(nl); |
| 3744 | wpa_printf(MSG_DEBUG, "nl80211: Supported vendor event: vendor_id=0x%x subcmd=%u", |
| 3745 | vinfo->vendor_id, vinfo->subcmd); |
| 3746 | } |
| 3747 | } |
| 3748 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3749 | return NL_SKIP; |
| 3750 | } |
| 3751 | |
| 3752 | |
| 3753 | static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv, |
| 3754 | struct wiphy_info_data *info) |
| 3755 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3756 | u32 feat; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3757 | struct nl_msg *msg; |
| 3758 | |
| 3759 | os_memset(info, 0, sizeof(*info)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3760 | info->capa = &drv->capa; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3761 | info->drv = drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3762 | |
| 3763 | msg = nlmsg_alloc(); |
| 3764 | if (!msg) |
| 3765 | return -1; |
| 3766 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3767 | feat = get_nl80211_protocol_features(drv); |
| 3768 | if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) |
| 3769 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY); |
| 3770 | else |
| 3771 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3772 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3773 | NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3774 | if (nl80211_set_iface_id(msg, drv->first_bss) < 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3775 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3776 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3777 | if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info)) |
| 3778 | return -1; |
| 3779 | |
| 3780 | if (info->auth_supported) |
| 3781 | drv->capa.flags |= WPA_DRIVER_FLAGS_SME; |
| 3782 | else if (!info->connect_supported) { |
| 3783 | wpa_printf(MSG_INFO, "nl80211: Driver does not support " |
| 3784 | "authentication/association or connect commands"); |
| 3785 | info->error = 1; |
| 3786 | } |
| 3787 | |
| 3788 | if (info->p2p_go_supported && info->p2p_client_supported) |
| 3789 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE; |
| 3790 | if (info->p2p_concurrent) { |
| 3791 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 3792 | "interface (driver advertised support)"); |
| 3793 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 3794 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 3795 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3796 | if (info->num_multichan_concurrent > 1) { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3797 | wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel " |
| 3798 | "concurrent (driver advertised support)"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3799 | drv->capa.num_multichan_concurrent = |
| 3800 | info->num_multichan_concurrent; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3801 | } |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3802 | |
| 3803 | /* default to 5000 since early versions of mac80211 don't set it */ |
| 3804 | if (!drv->capa.max_remain_on_chan) |
| 3805 | drv->capa.max_remain_on_chan = 5000; |
| 3806 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3807 | if (info->channel_switch_supported) |
| 3808 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_CSA; |
| 3809 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3810 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3811 | nla_put_failure: |
| 3812 | nlmsg_free(msg); |
| 3813 | return -1; |
| 3814 | } |
| 3815 | |
| 3816 | |
| 3817 | static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv) |
| 3818 | { |
| 3819 | struct wiphy_info_data info; |
| 3820 | if (wpa_driver_nl80211_get_info(drv, &info)) |
| 3821 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3822 | |
| 3823 | if (info.error) |
| 3824 | return -1; |
| 3825 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3826 | drv->has_capability = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3827 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 3828 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | |
| 3829 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
| 3830 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3831 | drv->capa.auth = WPA_DRIVER_AUTH_OPEN | |
| 3832 | WPA_DRIVER_AUTH_SHARED | |
| 3833 | WPA_DRIVER_AUTH_LEAP; |
| 3834 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3835 | drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES; |
| 3836 | drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3837 | drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
Dmitry Shmidt | ad266fb | 2012-08-24 17:03:35 -0700 | [diff] [blame] | 3838 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 3839 | /* |
| 3840 | * As all cfg80211 drivers must support cases where the AP interface is |
| 3841 | * removed without the knowledge of wpa_supplicant/hostapd, e.g., in |
| 3842 | * case that the user space daemon has crashed, they must be able to |
| 3843 | * cleanup all stations and key entries in the AP tear down flow. Thus, |
| 3844 | * this flag can/should always be set for cfg80211 drivers. |
| 3845 | */ |
| 3846 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT; |
| 3847 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3848 | if (!info.device_ap_sme) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3849 | drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3850 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3851 | /* |
| 3852 | * No AP SME is currently assumed to also indicate no AP MLME |
| 3853 | * in the driver/firmware. |
| 3854 | */ |
| 3855 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME; |
| 3856 | } |
| 3857 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3858 | drv->device_ap_sme = info.device_ap_sme; |
| 3859 | drv->poll_command_supported = info.poll_command_supported; |
| 3860 | drv->data_tx_status = info.data_tx_status; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3861 | if (info.set_qos_map_supported) |
| 3862 | drv->capa.flags |= WPA_DRIVER_FLAGS_QOS_MAPPING; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3863 | |
| 3864 | /* |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 3865 | * If poll command and tx status are supported, mac80211 is new enough |
| 3866 | * to have everything we need to not need monitor interfaces. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3867 | */ |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 3868 | drv->use_monitor = !info.poll_command_supported || !info.data_tx_status; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3869 | |
| 3870 | if (drv->device_ap_sme && drv->use_monitor) { |
| 3871 | /* |
| 3872 | * Non-mac80211 drivers may not support monitor interface. |
| 3873 | * Make sure we do not get stuck with incorrect capability here |
| 3874 | * by explicitly testing this. |
| 3875 | */ |
| 3876 | if (!info.monitor_supported) { |
| 3877 | wpa_printf(MSG_DEBUG, "nl80211: Disable use_monitor " |
| 3878 | "with device_ap_sme since no monitor mode " |
| 3879 | "support detected"); |
| 3880 | drv->use_monitor = 0; |
| 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | /* |
| 3885 | * If we aren't going to use monitor interfaces, but the |
| 3886 | * driver doesn't support data TX status, we won't get TX |
| 3887 | * status for EAPOL frames. |
| 3888 | */ |
| 3889 | if (!drv->use_monitor && !info.data_tx_status) |
| 3890 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3891 | |
| 3892 | return 0; |
| 3893 | } |
| 3894 | |
| 3895 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3896 | #ifdef ANDROID |
| 3897 | static int android_genl_ctrl_resolve(struct nl_handle *handle, |
| 3898 | const char *name) |
| 3899 | { |
| 3900 | /* |
| 3901 | * Android ICS has very minimal genl_ctrl_resolve() implementation, so |
| 3902 | * need to work around that. |
| 3903 | */ |
| 3904 | struct nl_cache *cache = NULL; |
| 3905 | struct genl_family *nl80211 = NULL; |
| 3906 | int id = -1; |
| 3907 | |
| 3908 | if (genl_ctrl_alloc_cache(handle, &cache) < 0) { |
| 3909 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " |
| 3910 | "netlink cache"); |
| 3911 | goto fail; |
| 3912 | } |
| 3913 | |
| 3914 | nl80211 = genl_ctrl_search_by_name(cache, name); |
| 3915 | if (nl80211 == NULL) |
| 3916 | goto fail; |
| 3917 | |
| 3918 | id = genl_family_get_id(nl80211); |
| 3919 | |
| 3920 | fail: |
| 3921 | if (nl80211) |
| 3922 | genl_family_put(nl80211); |
| 3923 | if (cache) |
| 3924 | nl_cache_free(cache); |
| 3925 | |
| 3926 | return id; |
| 3927 | } |
| 3928 | #define genl_ctrl_resolve android_genl_ctrl_resolve |
| 3929 | #endif /* ANDROID */ |
| 3930 | |
| 3931 | |
| 3932 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3933 | { |
| 3934 | int ret; |
| 3935 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3936 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 3937 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3938 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 3939 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3940 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3941 | } |
| 3942 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3943 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 3944 | if (global->nl == NULL) |
| 3945 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3946 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3947 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 3948 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3949 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 3950 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3951 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3952 | } |
| 3953 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3954 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 3955 | if (global->nl_event == NULL) |
| 3956 | goto err; |
| 3957 | |
| 3958 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
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 scan 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", "mlme"); |
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_ERROR, "nl80211: Could not add multicast " |
| 3973 | "membership for mlme events: %d (%s)", |
| 3974 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3975 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3976 | } |
| 3977 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3978 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3979 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3980 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3981 | if (ret < 0) { |
| 3982 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 3983 | "membership for regulatory events: %d (%s)", |
| 3984 | ret, strerror(-ret)); |
| 3985 | /* Continue without regulatory events */ |
| 3986 | } |
| 3987 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3988 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 3989 | if (ret >= 0) |
| 3990 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 3991 | if (ret < 0) { |
| 3992 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 3993 | "membership for vendor events: %d (%s)", |
| 3994 | ret, strerror(-ret)); |
| 3995 | /* Continue without vendor events */ |
| 3996 | } |
| 3997 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3998 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 3999 | no_seq_check, NULL); |
| 4000 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 4001 | process_global_event, global); |
| 4002 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4003 | nl80211_register_eloop_read(&global->nl_event, |
| 4004 | wpa_driver_nl80211_event_receive, |
| 4005 | global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4006 | |
| 4007 | return 0; |
| 4008 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4009 | err: |
| 4010 | nl_destroy_handles(&global->nl_event); |
| 4011 | nl_destroy_handles(&global->nl); |
| 4012 | nl_cb_put(global->nl_cb); |
| 4013 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4014 | return -1; |
| 4015 | } |
| 4016 | |
| 4017 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4018 | static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data *drv) |
| 4019 | { |
| 4020 | drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 4021 | if (!drv->nl_cb) { |
| 4022 | wpa_printf(MSG_ERROR, "nl80211: Failed to alloc cb struct"); |
| 4023 | return -1; |
| 4024 | } |
| 4025 | |
| 4026 | nl_cb_set(drv->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 4027 | no_seq_check, NULL); |
| 4028 | nl_cb_set(drv->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 4029 | process_drv_event, drv); |
| 4030 | |
| 4031 | return 0; |
| 4032 | } |
| 4033 | |
| 4034 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4035 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 4036 | { |
| 4037 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
| 4038 | /* |
| 4039 | * This may be for any interface; use ifdown event to disable |
| 4040 | * interface. |
| 4041 | */ |
| 4042 | } |
| 4043 | |
| 4044 | |
| 4045 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 4046 | { |
| 4047 | struct wpa_driver_nl80211_data *drv = ctx; |
| 4048 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4049 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4050 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 4051 | "after rfkill unblock"); |
| 4052 | return; |
| 4053 | } |
| 4054 | /* rtnetlink ifup handler will report interface as enabled */ |
| 4055 | } |
| 4056 | |
| 4057 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4058 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 4059 | void *eloop_ctx, |
| 4060 | void *handle) |
| 4061 | { |
| 4062 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 4063 | u8 data[2048]; |
| 4064 | struct msghdr msg; |
| 4065 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4066 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4067 | struct cmsghdr *cmsg; |
| 4068 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 4069 | union wpa_event_data event; |
| 4070 | |
| 4071 | memset(&msg, 0, sizeof(msg)); |
| 4072 | msg.msg_iov = &entry; |
| 4073 | msg.msg_iovlen = 1; |
| 4074 | entry.iov_base = data; |
| 4075 | entry.iov_len = sizeof(data); |
| 4076 | msg.msg_control = &control; |
| 4077 | msg.msg_controllen = sizeof(control); |
| 4078 | |
| 4079 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 4080 | /* if error or not fitting 802.3 header, return */ |
| 4081 | if (res < 14) |
| 4082 | return; |
| 4083 | |
| 4084 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 4085 | { |
| 4086 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 4087 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 4088 | int *ack; |
| 4089 | |
| 4090 | found_wifi = 1; |
| 4091 | ack = (void *)CMSG_DATA(cmsg); |
| 4092 | acked = *ack; |
| 4093 | } |
| 4094 | |
| 4095 | if (cmsg->cmsg_level == SOL_PACKET && |
| 4096 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 4097 | struct sock_extended_err *err = |
| 4098 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 4099 | |
| 4100 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 4101 | found_ee = 1; |
| 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | if (!found_ee || !found_wifi) |
| 4106 | return; |
| 4107 | |
| 4108 | memset(&event, 0, sizeof(event)); |
| 4109 | event.eapol_tx_status.dst = data; |
| 4110 | event.eapol_tx_status.data = data + 14; |
| 4111 | event.eapol_tx_status.data_len = res - 14; |
| 4112 | event.eapol_tx_status.ack = acked; |
| 4113 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 4114 | } |
| 4115 | |
| 4116 | |
| 4117 | static int nl80211_init_bss(struct i802_bss *bss) |
| 4118 | { |
| 4119 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 4120 | if (!bss->nl_cb) |
| 4121 | return -1; |
| 4122 | |
| 4123 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 4124 | no_seq_check, NULL); |
| 4125 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 4126 | process_bss_event, bss); |
| 4127 | |
| 4128 | return 0; |
| 4129 | } |
| 4130 | |
| 4131 | |
| 4132 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 4133 | { |
| 4134 | nl_cb_put(bss->nl_cb); |
| 4135 | bss->nl_cb = NULL; |
| 4136 | } |
| 4137 | |
| 4138 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4139 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 4140 | void *global_priv, int hostapd, |
| 4141 | const u8 *set_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4142 | { |
| 4143 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4144 | struct rfkill_config *rcfg; |
| 4145 | struct i802_bss *bss; |
| 4146 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4147 | if (global_priv == NULL) |
| 4148 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4149 | drv = os_zalloc(sizeof(*drv)); |
| 4150 | if (drv == NULL) |
| 4151 | return NULL; |
| 4152 | drv->global = global_priv; |
| 4153 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4154 | drv->hostapd = !!hostapd; |
| 4155 | drv->eapol_sock = -1; |
| 4156 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 4157 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4158 | |
| 4159 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 4160 | if (!drv->first_bss) { |
| 4161 | os_free(drv); |
| 4162 | return NULL; |
| 4163 | } |
| 4164 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4165 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4166 | bss->ctx = ctx; |
| 4167 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4168 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 4169 | drv->monitor_ifidx = -1; |
| 4170 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4171 | drv->eapol_tx_sock = -1; |
| 4172 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4173 | |
| 4174 | if (wpa_driver_nl80211_init_nl(drv)) { |
| 4175 | os_free(drv); |
| 4176 | return NULL; |
| 4177 | } |
| 4178 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4179 | if (nl80211_init_bss(bss)) |
| 4180 | goto failed; |
| 4181 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4182 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 4183 | if (rcfg == NULL) |
| 4184 | goto failed; |
| 4185 | rcfg->ctx = drv; |
| 4186 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); |
| 4187 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 4188 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 4189 | drv->rfkill = rfkill_init(rcfg); |
| 4190 | if (drv->rfkill == NULL) { |
| 4191 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 4192 | os_free(rcfg); |
| 4193 | } |
| 4194 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4195 | if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0) |
| 4196 | drv->start_iface_up = 1; |
| 4197 | |
| 4198 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4199 | goto failed; |
| 4200 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4201 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 4202 | if (drv->eapol_tx_sock < 0) |
| 4203 | goto failed; |
| 4204 | |
| 4205 | if (drv->data_tx_status) { |
| 4206 | int enabled = 1; |
| 4207 | |
| 4208 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 4209 | &enabled, sizeof(enabled)) < 0) { |
| 4210 | wpa_printf(MSG_DEBUG, |
| 4211 | "nl80211: wifi status sockopt failed\n"); |
| 4212 | drv->data_tx_status = 0; |
| 4213 | if (!drv->use_monitor) |
| 4214 | drv->capa.flags &= |
| 4215 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 4216 | } else { |
| 4217 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 4218 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 4219 | drv, NULL); |
| 4220 | } |
| 4221 | } |
| 4222 | |
| 4223 | if (drv->global) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4224 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4225 | drv->in_interface_list = 1; |
| 4226 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4227 | |
| 4228 | return bss; |
| 4229 | |
| 4230 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4231 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4232 | return NULL; |
| 4233 | } |
| 4234 | |
| 4235 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4236 | /** |
| 4237 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 4238 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 4239 | * e.g., wpa_supplicant_event() |
| 4240 | * @ifname: interface name, e.g., wlan0 |
| 4241 | * @global_priv: private driver global data from global_init() |
| 4242 | * Returns: Pointer to private data, %NULL on failure |
| 4243 | */ |
| 4244 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 4245 | void *global_priv) |
| 4246 | { |
| 4247 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL); |
| 4248 | } |
| 4249 | |
| 4250 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4251 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4252 | struct nl_handle *nl_handle, |
| 4253 | u16 type, const u8 *match, size_t match_len) |
| 4254 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4255 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4256 | struct nl_msg *msg; |
| 4257 | int ret = -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4258 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4259 | |
| 4260 | msg = nlmsg_alloc(); |
| 4261 | if (!msg) |
| 4262 | return -1; |
| 4263 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4264 | buf[0] = '\0'; |
| 4265 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
| 4266 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x nl_handle=%p match=%s", |
| 4267 | type, nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4268 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4269 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_ACTION); |
| 4270 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4271 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 4272 | goto nla_put_failure; |
| 4273 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4274 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, type); |
| 4275 | NLA_PUT(msg, NL80211_ATTR_FRAME_MATCH, match_len, match); |
| 4276 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4277 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4278 | msg = NULL; |
| 4279 | if (ret) { |
| 4280 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 4281 | "failed (type=%u): ret=%d (%s)", |
| 4282 | type, ret, strerror(-ret)); |
| 4283 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 4284 | match, match_len); |
| 4285 | goto nla_put_failure; |
| 4286 | } |
| 4287 | ret = 0; |
| 4288 | nla_put_failure: |
| 4289 | nlmsg_free(msg); |
| 4290 | return ret; |
| 4291 | } |
| 4292 | |
| 4293 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4294 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 4295 | { |
| 4296 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4297 | |
| 4298 | if (bss->nl_mgmt) { |
| 4299 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 4300 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 4301 | return -1; |
| 4302 | } |
| 4303 | |
| 4304 | bss->nl_mgmt = nl_create_handle(drv->nl_cb, "mgmt"); |
| 4305 | if (bss->nl_mgmt == NULL) |
| 4306 | return -1; |
| 4307 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4308 | return 0; |
| 4309 | } |
| 4310 | |
| 4311 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4312 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 4313 | { |
| 4314 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 4315 | wpa_driver_nl80211_event_receive, |
| 4316 | bss->nl_cb); |
| 4317 | } |
| 4318 | |
| 4319 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4320 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4321 | const u8 *match, size_t match_len) |
| 4322 | { |
| 4323 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4324 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4325 | type, match, match_len); |
| 4326 | } |
| 4327 | |
| 4328 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4329 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4330 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4331 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4332 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4333 | |
| 4334 | if (nl80211_alloc_mgmt_handle(bss)) |
| 4335 | return -1; |
| 4336 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 4337 | "handle %p", bss->nl_mgmt); |
| 4338 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4339 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 4340 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 4341 | |
| 4342 | /* register for any AUTH message */ |
| 4343 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 4344 | } |
| 4345 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 4346 | #ifdef CONFIG_INTERWORKING |
| 4347 | /* QoS Map Configure */ |
| 4348 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4349 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 4350 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4351 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4352 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4353 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4354 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4355 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4356 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4357 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4358 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4359 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4360 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4361 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4362 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4363 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4364 | /* Protected GAS Initial Request */ |
| 4365 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 4366 | ret = -1; |
| 4367 | /* Protected GAS Initial Response */ |
| 4368 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 4369 | ret = -1; |
| 4370 | /* Protected GAS Comeback Request */ |
| 4371 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 4372 | ret = -1; |
| 4373 | /* Protected GAS Comeback Response */ |
| 4374 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 4375 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4376 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 4377 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4378 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4379 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4380 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 4381 | 6) < 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 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4384 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4385 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 4386 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4387 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4388 | #endif /* CONFIG_P2P */ |
| 4389 | #ifdef CONFIG_IEEE80211W |
| 4390 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4391 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4392 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4393 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4394 | #ifdef CONFIG_TDLS |
| 4395 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 4396 | /* TDLS Discovery Response */ |
| 4397 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 4398 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4399 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4400 | } |
| 4401 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4402 | |
| 4403 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4404 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4405 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4406 | else |
| 4407 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 4408 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 4409 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4410 | /* WNM - BSS Transition Management Request */ |
| 4411 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4412 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4413 | /* WNM-Sleep Mode Response */ |
| 4414 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4415 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4416 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4417 | #ifdef CONFIG_HS20 |
| 4418 | /* WNM-Notification */ |
| 4419 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
| 4420 | return -1; |
| 4421 | #endif /* CONFIG_HS20 */ |
| 4422 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4423 | nl80211_mgmt_handle_register_eloop(bss); |
| 4424 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4425 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4429 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 4430 | { |
| 4431 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4432 | struct nl_msg *msg; |
| 4433 | int ret = -1; |
| 4434 | |
| 4435 | msg = nlmsg_alloc(); |
| 4436 | if (!msg) |
| 4437 | return -1; |
| 4438 | |
| 4439 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 4440 | |
| 4441 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 4442 | |
| 4443 | ret = send_and_recv(drv->global, bss->nl_mgmt, msg, NULL, NULL); |
| 4444 | msg = NULL; |
| 4445 | if (ret) { |
| 4446 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 4447 | "failed: ret=%d (%s)", |
| 4448 | ret, strerror(-ret)); |
| 4449 | goto nla_put_failure; |
| 4450 | } |
| 4451 | ret = 0; |
| 4452 | nla_put_failure: |
| 4453 | nlmsg_free(msg); |
| 4454 | return ret; |
| 4455 | } |
| 4456 | |
| 4457 | |
| 4458 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 4459 | { |
| 4460 | static const int stypes[] = { |
| 4461 | WLAN_FC_STYPE_AUTH, |
| 4462 | WLAN_FC_STYPE_ASSOC_REQ, |
| 4463 | WLAN_FC_STYPE_REASSOC_REQ, |
| 4464 | WLAN_FC_STYPE_DISASSOC, |
| 4465 | WLAN_FC_STYPE_DEAUTH, |
| 4466 | WLAN_FC_STYPE_ACTION, |
| 4467 | WLAN_FC_STYPE_PROBE_REQ, |
| 4468 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 4469 | * it, but it wouldn't really be the right thing anyway as |
| 4470 | * it isn't per interface ... maybe just dump the scan |
| 4471 | * results periodically for OLBC? |
| 4472 | */ |
| 4473 | // WLAN_FC_STYPE_BEACON, |
| 4474 | }; |
| 4475 | unsigned int i; |
| 4476 | |
| 4477 | if (nl80211_alloc_mgmt_handle(bss)) |
| 4478 | return -1; |
| 4479 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 4480 | "handle %p", bss->nl_mgmt); |
| 4481 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4482 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4483 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 4484 | (WLAN_FC_TYPE_MGMT << 2) | |
| 4485 | (stypes[i] << 4), |
| 4486 | NULL, 0) < 0) { |
| 4487 | goto out_err; |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | if (nl80211_register_spurious_class3(bss)) |
| 4492 | goto out_err; |
| 4493 | |
| 4494 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 4495 | goto out_err; |
| 4496 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4497 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4498 | return 0; |
| 4499 | |
| 4500 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4501 | nl_destroy_handles(&bss->nl_mgmt); |
| 4502 | return -1; |
| 4503 | } |
| 4504 | |
| 4505 | |
| 4506 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 4507 | { |
| 4508 | if (nl80211_alloc_mgmt_handle(bss)) |
| 4509 | return -1; |
| 4510 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 4511 | "handle %p (device SME)", bss->nl_mgmt); |
| 4512 | |
| 4513 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 4514 | (WLAN_FC_TYPE_MGMT << 2) | |
| 4515 | (WLAN_FC_STYPE_ACTION << 4), |
| 4516 | NULL, 0) < 0) |
| 4517 | goto out_err; |
| 4518 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4519 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4520 | return 0; |
| 4521 | |
| 4522 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4523 | nl_destroy_handles(&bss->nl_mgmt); |
| 4524 | return -1; |
| 4525 | } |
| 4526 | |
| 4527 | |
| 4528 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 4529 | { |
| 4530 | if (bss->nl_mgmt == NULL) |
| 4531 | return; |
| 4532 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 4533 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4534 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4535 | |
| 4536 | nl80211_put_wiphy_data_ap(bss); |
| 4537 | } |
| 4538 | |
| 4539 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4540 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 4541 | { |
| 4542 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 4543 | } |
| 4544 | |
| 4545 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4546 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 4547 | { |
| 4548 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4549 | struct nl_msg *msg; |
| 4550 | int ret; |
| 4551 | |
| 4552 | msg = nlmsg_alloc(); |
| 4553 | if (!msg) |
| 4554 | return; |
| 4555 | |
| 4556 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE); |
| 4557 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 4558 | |
| 4559 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4560 | msg = NULL; |
| 4561 | |
| 4562 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 4563 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4564 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4565 | |
| 4566 | nla_put_failure: |
| 4567 | nlmsg_free(msg); |
| 4568 | } |
| 4569 | |
| 4570 | |
| 4571 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 4572 | { |
| 4573 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4574 | struct nl_msg *msg; |
| 4575 | int ret = -1; |
| 4576 | |
| 4577 | msg = nlmsg_alloc(); |
| 4578 | if (!msg) |
| 4579 | return -1; |
| 4580 | |
| 4581 | if (start) |
| 4582 | nl80211_cmd(drv, msg, 0, NL80211_CMD_START_P2P_DEVICE); |
| 4583 | else |
| 4584 | nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_P2P_DEVICE); |
| 4585 | |
| 4586 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 4587 | |
| 4588 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4589 | msg = NULL; |
| 4590 | |
| 4591 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 4592 | start ? "Start" : "Stop", |
| 4593 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4594 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4595 | |
| 4596 | nla_put_failure: |
| 4597 | nlmsg_free(msg); |
| 4598 | return ret; |
| 4599 | } |
| 4600 | |
| 4601 | |
| 4602 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 4603 | { |
| 4604 | enum nl80211_iftype nlmode; |
| 4605 | |
| 4606 | nlmode = nl80211_get_ifmode(bss); |
| 4607 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 4608 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 4609 | bss->ifname, up); |
| 4610 | } |
| 4611 | |
| 4612 | /* P2P Device has start/stop which is equivalent */ |
| 4613 | return nl80211_set_p2pdev(bss, up); |
| 4614 | } |
| 4615 | |
| 4616 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4617 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4618 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
| 4619 | const u8 *set_addr, int first) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4620 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4621 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4622 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4623 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4624 | |
| 4625 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4626 | bss->ifindex = drv->ifindex; |
| 4627 | bss->wdev_id = drv->global->if_add_wdevid; |
| 4628 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 4629 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4630 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 4631 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4632 | drv->global->if_add_wdevid_set = 0; |
| 4633 | |
| 4634 | if (wpa_driver_nl80211_capa(drv)) |
| 4635 | return -1; |
| 4636 | |
| 4637 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 4638 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4639 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4640 | if (set_addr && |
| 4641 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 4642 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 4643 | set_addr))) |
| 4644 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4645 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4646 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 4647 | drv->start_mode_ap = 1; |
| 4648 | |
| 4649 | if (drv->hostapd) |
| 4650 | nlmode = NL80211_IFTYPE_AP; |
| 4651 | else if (bss->if_dynamic) |
| 4652 | nlmode = nl80211_get_ifmode(bss); |
| 4653 | else |
| 4654 | nlmode = NL80211_IFTYPE_STATION; |
| 4655 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4656 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4657 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4658 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4659 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4660 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4661 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4662 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4663 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4664 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 4665 | int ret = i802_set_iface_flags(bss, 1); |
| 4666 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4667 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 4668 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4669 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4670 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 4671 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 4672 | return ret; |
| 4673 | } else { |
| 4674 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 4675 | "interface '%s' due to rfkill", bss->ifname); |
| 4676 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 4677 | return 0; |
| 4678 | drv->if_disabled = 1; |
| 4679 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4682 | if (!drv->hostapd) |
| 4683 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 4684 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4685 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4686 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 4687 | bss->addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4688 | return -1; |
| 4689 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4690 | if (send_rfkill_event) { |
| 4691 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 4692 | drv, drv->ctx); |
| 4693 | } |
| 4694 | |
| 4695 | return 0; |
| 4696 | } |
| 4697 | |
| 4698 | |
| 4699 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 4700 | { |
| 4701 | struct nl_msg *msg; |
| 4702 | |
| 4703 | msg = nlmsg_alloc(); |
| 4704 | if (!msg) |
| 4705 | return -ENOMEM; |
| 4706 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4707 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 4708 | drv->ifindex); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4709 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4710 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 4711 | |
| 4712 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4713 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4714 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4715 | return -ENOBUFS; |
| 4716 | } |
| 4717 | |
| 4718 | |
| 4719 | /** |
| 4720 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4721 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4722 | * |
| 4723 | * Shut down driver interface and processing of driver events. Free |
| 4724 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 4725 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4726 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4727 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4728 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4729 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4730 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4731 | if (drv->data_tx_status) |
| 4732 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 4733 | if (drv->eapol_tx_sock >= 0) |
| 4734 | close(drv->eapol_tx_sock); |
| 4735 | |
| 4736 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4737 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4738 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4739 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 4740 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4741 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 4742 | "interface %s from bridge %s: %s", |
| 4743 | bss->ifname, bss->brname, strerror(errno)); |
| 4744 | } |
| 4745 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4746 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4747 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 4748 | "bridge %s: %s", |
| 4749 | bss->brname, strerror(errno)); |
| 4750 | } |
| 4751 | |
| 4752 | nl80211_remove_monitor_interface(drv); |
| 4753 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4754 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4755 | wpa_driver_nl80211_del_beacon(drv); |
| 4756 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4757 | if (drv->eapol_sock >= 0) { |
| 4758 | eloop_unregister_read_sock(drv->eapol_sock); |
| 4759 | close(drv->eapol_sock); |
| 4760 | } |
| 4761 | |
| 4762 | if (drv->if_indices != drv->default_if_indices) |
| 4763 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4764 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4765 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4766 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 4767 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4768 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 4769 | IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4770 | rfkill_deinit(drv->rfkill); |
| 4771 | |
| 4772 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 4773 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4774 | if (!drv->start_iface_up) |
| 4775 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4776 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4777 | if (!drv->hostapd || !drv->start_mode_ap) |
| 4778 | wpa_driver_nl80211_set_mode(bss, |
| 4779 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4780 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4781 | } else { |
| 4782 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 4783 | nl80211_del_p2pdev(bss); |
| 4784 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4785 | nl_cb_put(drv->nl_cb); |
| 4786 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4787 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4788 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4789 | os_free(drv->filter_ssids); |
| 4790 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4791 | os_free(drv->auth_ie); |
| 4792 | |
| 4793 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4794 | dl_list_del(&drv->list); |
| 4795 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 4796 | os_free(drv->extended_capa); |
| 4797 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4798 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4799 | os_free(drv); |
| 4800 | } |
| 4801 | |
| 4802 | |
| 4803 | /** |
| 4804 | * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion |
| 4805 | * @eloop_ctx: Driver private data |
| 4806 | * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init() |
| 4807 | * |
| 4808 | * This function can be used as registered timeout when starting a scan to |
| 4809 | * generate a scan completed event if the driver does not report this. |
| 4810 | */ |
| 4811 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
| 4812 | { |
| 4813 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4814 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4815 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4816 | drv->ap_scan_as_station); |
| 4817 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4818 | } |
| 4819 | wpa_printf(MSG_DEBUG, "Scan timeout - try to get results"); |
| 4820 | wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL); |
| 4821 | } |
| 4822 | |
| 4823 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4824 | static struct nl_msg * |
| 4825 | nl80211_scan_common(struct wpa_driver_nl80211_data *drv, u8 cmd, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4826 | struct wpa_driver_scan_params *params, u64 *wdev_id) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4827 | { |
| 4828 | struct nl_msg *msg; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4829 | size_t i; |
| 4830 | |
| 4831 | msg = nlmsg_alloc(); |
| 4832 | if (!msg) |
| 4833 | return NULL; |
| 4834 | |
| 4835 | nl80211_cmd(drv, msg, 0, cmd); |
| 4836 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4837 | if (!wdev_id) |
| 4838 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 4839 | else |
| 4840 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, *wdev_id); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4841 | |
| 4842 | if (params->num_ssids) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4843 | struct nlattr *ssids; |
| 4844 | |
| 4845 | ssids = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4846 | if (ssids == NULL) |
| 4847 | goto fail; |
| 4848 | for (i = 0; i < params->num_ssids; i++) { |
| 4849 | wpa_hexdump_ascii(MSG_MSGDUMP, "nl80211: Scan SSID", |
| 4850 | params->ssids[i].ssid, |
| 4851 | params->ssids[i].ssid_len); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4852 | if (nla_put(msg, i + 1, params->ssids[i].ssid_len, |
| 4853 | params->ssids[i].ssid) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4854 | goto fail; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4855 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4856 | nla_nest_end(msg, ssids); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4857 | } |
| 4858 | |
| 4859 | if (params->extra_ies) { |
| 4860 | wpa_hexdump(MSG_MSGDUMP, "nl80211: Scan extra IEs", |
| 4861 | params->extra_ies, params->extra_ies_len); |
| 4862 | if (nla_put(msg, NL80211_ATTR_IE, params->extra_ies_len, |
| 4863 | params->extra_ies) < 0) |
| 4864 | goto fail; |
| 4865 | } |
| 4866 | |
| 4867 | if (params->freqs) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4868 | struct nlattr *freqs; |
| 4869 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4870 | if (freqs == NULL) |
| 4871 | goto fail; |
| 4872 | for (i = 0; params->freqs[i]; i++) { |
| 4873 | wpa_printf(MSG_MSGDUMP, "nl80211: Scan frequency %u " |
| 4874 | "MHz", params->freqs[i]); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4875 | if (nla_put_u32(msg, i + 1, params->freqs[i]) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4876 | goto fail; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4877 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4878 | nla_nest_end(msg, freqs); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | os_free(drv->filter_ssids); |
| 4882 | drv->filter_ssids = params->filter_ssids; |
| 4883 | params->filter_ssids = NULL; |
| 4884 | drv->num_filter_ssids = params->num_filter_ssids; |
| 4885 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4886 | if (params->only_new_results) { |
| 4887 | wpa_printf(MSG_DEBUG, "nl80211: Add NL80211_SCAN_FLAG_FLUSH"); |
| 4888 | NLA_PUT_U32(msg, NL80211_ATTR_SCAN_FLAGS, |
| 4889 | NL80211_SCAN_FLAG_FLUSH); |
| 4890 | } |
| 4891 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4892 | return msg; |
| 4893 | |
| 4894 | fail: |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4895 | nla_put_failure: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4896 | nlmsg_free(msg); |
| 4897 | return NULL; |
| 4898 | } |
| 4899 | |
| 4900 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4901 | /** |
| 4902 | * wpa_driver_nl80211_scan - Request the driver to initiate scan |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4903 | * @bss: Pointer to private driver data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4904 | * @params: Scan parameters |
| 4905 | * Returns: 0 on success, -1 on failure |
| 4906 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4907 | static int wpa_driver_nl80211_scan(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4908 | struct wpa_driver_scan_params *params) |
| 4909 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4910 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4911 | int ret = -1, timeout; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4912 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4913 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4914 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: scan request"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4915 | drv->scan_for_auth = 0; |
| 4916 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4917 | msg = nl80211_scan_common(drv, NL80211_CMD_TRIGGER_SCAN, params, |
| 4918 | bss->wdev_id_set ? &bss->wdev_id : NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4919 | if (!msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4920 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4921 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4922 | if (params->p2p_probe) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4923 | struct nlattr *rates; |
| 4924 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4925 | wpa_printf(MSG_DEBUG, "nl80211: P2P probe - mask SuppRates"); |
| 4926 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4927 | rates = nla_nest_start(msg, NL80211_ATTR_SCAN_SUPP_RATES); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4928 | if (rates == NULL) |
| 4929 | goto nla_put_failure; |
| 4930 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4931 | /* |
| 4932 | * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates |
| 4933 | * by masking out everything else apart from the OFDM rates 6, |
| 4934 | * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz |
| 4935 | * rates are left enabled. |
| 4936 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4937 | NLA_PUT(msg, NL80211_BAND_2GHZ, 8, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4938 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4939 | nla_nest_end(msg, rates); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4940 | |
| 4941 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); |
| 4942 | } |
| 4943 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4944 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4945 | msg = NULL; |
| 4946 | if (ret) { |
| 4947 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger failed: ret=%d " |
| 4948 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4949 | if (drv->hostapd && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 4950 | enum nl80211_iftype old_mode = drv->nlmode; |
| 4951 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4952 | /* |
| 4953 | * mac80211 does not allow scan requests in AP mode, so |
| 4954 | * try to do this in station mode. |
| 4955 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4956 | if (wpa_driver_nl80211_set_mode( |
| 4957 | bss, NL80211_IFTYPE_STATION)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4958 | goto nla_put_failure; |
| 4959 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4960 | if (wpa_driver_nl80211_scan(bss, params)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4961 | wpa_driver_nl80211_set_mode(bss, drv->nlmode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4962 | goto nla_put_failure; |
| 4963 | } |
| 4964 | |
| 4965 | /* Restore AP mode when processing scan results */ |
Dmitry Shmidt | ed003d2 | 2014-02-06 10:09:12 -0800 | [diff] [blame] | 4966 | drv->ap_scan_as_station = old_mode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4967 | ret = 0; |
| 4968 | } else |
| 4969 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4972 | drv->scan_state = SCAN_REQUESTED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4973 | /* Not all drivers generate "scan completed" wireless event, so try to |
| 4974 | * read results after a timeout. */ |
| 4975 | timeout = 10; |
| 4976 | if (drv->scan_complete_events) { |
| 4977 | /* |
| 4978 | * The driver seems to deliver events to notify when scan is |
| 4979 | * complete, so use longer timeout to avoid race conditions |
| 4980 | * with scanning and following association request. |
| 4981 | */ |
| 4982 | timeout = 30; |
| 4983 | } |
| 4984 | wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d " |
| 4985 | "seconds", ret, timeout); |
| 4986 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 4987 | eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout, |
| 4988 | drv, drv->ctx); |
| 4989 | |
| 4990 | nla_put_failure: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4991 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4992 | return ret; |
| 4993 | } |
| 4994 | |
| 4995 | |
| 4996 | /** |
| 4997 | * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan |
| 4998 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 4999 | * @params: Scan parameters |
| 5000 | * @interval: Interval between scan cycles in milliseconds |
| 5001 | * Returns: 0 on success, -1 on failure or if not supported |
| 5002 | */ |
| 5003 | static int wpa_driver_nl80211_sched_scan(void *priv, |
| 5004 | struct wpa_driver_scan_params *params, |
| 5005 | u32 interval) |
| 5006 | { |
| 5007 | struct i802_bss *bss = priv; |
| 5008 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5009 | int ret = -1; |
| 5010 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5011 | size_t i; |
| 5012 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 5013 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: sched_scan request"); |
| 5014 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5015 | #ifdef ANDROID |
| 5016 | if (!drv->capa.sched_scan_supported) |
| 5017 | return android_pno_start(bss, params); |
| 5018 | #endif /* ANDROID */ |
| 5019 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5020 | msg = nl80211_scan_common(drv, NL80211_CMD_START_SCHED_SCAN, params, |
| 5021 | bss->wdev_id_set ? &bss->wdev_id : NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5022 | if (!msg) |
| 5023 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5024 | |
| 5025 | NLA_PUT_U32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, interval); |
| 5026 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5027 | if ((drv->num_filter_ssids && |
| 5028 | (int) drv->num_filter_ssids <= drv->capa.max_match_sets) || |
| 5029 | params->filter_rssi) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5030 | struct nlattr *match_sets; |
| 5031 | match_sets = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5032 | if (match_sets == NULL) |
| 5033 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5034 | |
| 5035 | for (i = 0; i < drv->num_filter_ssids; i++) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5036 | struct nlattr *match_set_ssid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5037 | wpa_hexdump_ascii(MSG_MSGDUMP, |
| 5038 | "nl80211: Sched scan filter SSID", |
| 5039 | drv->filter_ssids[i].ssid, |
| 5040 | drv->filter_ssids[i].ssid_len); |
| 5041 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5042 | match_set_ssid = nla_nest_start(msg, i + 1); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5043 | if (match_set_ssid == NULL) |
| 5044 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5045 | NLA_PUT(msg, NL80211_ATTR_SCHED_SCAN_MATCH_SSID, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5046 | drv->filter_ssids[i].ssid_len, |
| 5047 | drv->filter_ssids[i].ssid); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 5048 | if (params->filter_rssi) |
| 5049 | NLA_PUT_U32(msg, |
| 5050 | NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, |
| 5051 | params->filter_rssi); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5052 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5053 | nla_nest_end(msg, match_set_ssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5054 | } |
| 5055 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 5056 | /* |
| 5057 | * Due to backward compatibility code, newer kernels treat this |
| 5058 | * matchset (with only an RSSI filter) as the default for all |
| 5059 | * other matchsets, unless it's the only one, in which case the |
| 5060 | * matchset will actually allow all SSIDs above the RSSI. |
| 5061 | */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5062 | if (params->filter_rssi) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5063 | struct nlattr *match_set_rssi; |
| 5064 | match_set_rssi = nla_nest_start(msg, 0); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5065 | if (match_set_rssi == NULL) |
| 5066 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5067 | NLA_PUT_U32(msg, NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5068 | params->filter_rssi); |
| 5069 | wpa_printf(MSG_MSGDUMP, |
| 5070 | "nl80211: Sched scan RSSI filter %d dBm", |
| 5071 | params->filter_rssi); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5072 | nla_nest_end(msg, match_set_rssi); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5073 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5074 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5075 | nla_nest_end(msg, match_sets); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5079 | |
| 5080 | /* TODO: if we get an error here, we should fall back to normal scan */ |
| 5081 | |
| 5082 | msg = NULL; |
| 5083 | if (ret) { |
| 5084 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan start failed: " |
| 5085 | "ret=%d (%s)", ret, strerror(-ret)); |
| 5086 | goto nla_put_failure; |
| 5087 | } |
| 5088 | |
| 5089 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan requested (ret=%d) - " |
| 5090 | "scan interval %d msec", ret, interval); |
| 5091 | |
| 5092 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5093 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5094 | return ret; |
| 5095 | } |
| 5096 | |
| 5097 | |
| 5098 | /** |
| 5099 | * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan |
| 5100 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 5101 | * Returns: 0 on success, -1 on failure or if not supported |
| 5102 | */ |
| 5103 | static int wpa_driver_nl80211_stop_sched_scan(void *priv) |
| 5104 | { |
| 5105 | struct i802_bss *bss = priv; |
| 5106 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5107 | int ret = 0; |
| 5108 | struct nl_msg *msg; |
| 5109 | |
| 5110 | #ifdef ANDROID |
| 5111 | if (!drv->capa.sched_scan_supported) |
| 5112 | return android_pno_stop(bss); |
| 5113 | #endif /* ANDROID */ |
| 5114 | |
| 5115 | msg = nlmsg_alloc(); |
| 5116 | if (!msg) |
| 5117 | return -1; |
| 5118 | |
| 5119 | nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_SCHED_SCAN); |
| 5120 | |
| 5121 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 5122 | |
| 5123 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5124 | msg = NULL; |
| 5125 | if (ret) { |
| 5126 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop failed: " |
| 5127 | "ret=%d (%s)", ret, strerror(-ret)); |
| 5128 | goto nla_put_failure; |
| 5129 | } |
| 5130 | |
| 5131 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop sent (ret=%d)", ret); |
| 5132 | |
| 5133 | nla_put_failure: |
| 5134 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5135 | return ret; |
| 5136 | } |
| 5137 | |
| 5138 | |
| 5139 | static const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie) |
| 5140 | { |
| 5141 | const u8 *end, *pos; |
| 5142 | |
| 5143 | if (ies == NULL) |
| 5144 | return NULL; |
| 5145 | |
| 5146 | pos = ies; |
| 5147 | end = ies + ies_len; |
| 5148 | |
| 5149 | while (pos + 1 < end) { |
| 5150 | if (pos + 2 + pos[1] > end) |
| 5151 | break; |
| 5152 | if (pos[0] == ie) |
| 5153 | return pos; |
| 5154 | pos += 2 + pos[1]; |
| 5155 | } |
| 5156 | |
| 5157 | return NULL; |
| 5158 | } |
| 5159 | |
| 5160 | |
| 5161 | static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv, |
| 5162 | const u8 *ie, size_t ie_len) |
| 5163 | { |
| 5164 | const u8 *ssid; |
| 5165 | size_t i; |
| 5166 | |
| 5167 | if (drv->filter_ssids == NULL) |
| 5168 | return 0; |
| 5169 | |
| 5170 | ssid = nl80211_get_ie(ie, ie_len, WLAN_EID_SSID); |
| 5171 | if (ssid == NULL) |
| 5172 | return 1; |
| 5173 | |
| 5174 | for (i = 0; i < drv->num_filter_ssids; i++) { |
| 5175 | if (ssid[1] == drv->filter_ssids[i].ssid_len && |
| 5176 | os_memcmp(ssid + 2, drv->filter_ssids[i].ssid, ssid[1]) == |
| 5177 | 0) |
| 5178 | return 0; |
| 5179 | } |
| 5180 | |
| 5181 | return 1; |
| 5182 | } |
| 5183 | |
| 5184 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5185 | static int bss_info_handler(struct nl_msg *msg, void *arg) |
| 5186 | { |
| 5187 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5188 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5189 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 5190 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 5191 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 5192 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 5193 | [NL80211_BSS_TSF] = { .type = NLA_U64 }, |
| 5194 | [NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 }, |
| 5195 | [NL80211_BSS_CAPABILITY] = { .type = NLA_U16 }, |
| 5196 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 5197 | [NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 }, |
| 5198 | [NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 }, |
| 5199 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 5200 | [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 }, |
| 5201 | [NL80211_BSS_BEACON_IES] = { .type = NLA_UNSPEC }, |
| 5202 | }; |
| 5203 | struct nl80211_bss_info_arg *_arg = arg; |
| 5204 | struct wpa_scan_results *res = _arg->res; |
| 5205 | struct wpa_scan_res **tmp; |
| 5206 | struct wpa_scan_res *r; |
| 5207 | const u8 *ie, *beacon_ie; |
| 5208 | size_t ie_len, beacon_ie_len; |
| 5209 | u8 *pos; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5210 | size_t i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5211 | |
| 5212 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5213 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5214 | if (!tb[NL80211_ATTR_BSS]) |
| 5215 | return NL_SKIP; |
| 5216 | if (nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 5217 | bss_policy)) |
| 5218 | return NL_SKIP; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5219 | if (bss[NL80211_BSS_STATUS]) { |
| 5220 | enum nl80211_bss_status status; |
| 5221 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 5222 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 5223 | bss[NL80211_BSS_FREQUENCY]) { |
| 5224 | _arg->assoc_freq = |
| 5225 | nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 5226 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 5227 | _arg->assoc_freq); |
| 5228 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5229 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 5230 | bss[NL80211_BSS_BSSID]) { |
| 5231 | os_memcpy(_arg->assoc_bssid, |
| 5232 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 5233 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 5234 | MACSTR, MAC2STR(_arg->assoc_bssid)); |
| 5235 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5236 | } |
| 5237 | if (!res) |
| 5238 | return NL_SKIP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5239 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 5240 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 5241 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 5242 | } else { |
| 5243 | ie = NULL; |
| 5244 | ie_len = 0; |
| 5245 | } |
| 5246 | if (bss[NL80211_BSS_BEACON_IES]) { |
| 5247 | beacon_ie = nla_data(bss[NL80211_BSS_BEACON_IES]); |
| 5248 | beacon_ie_len = nla_len(bss[NL80211_BSS_BEACON_IES]); |
| 5249 | } else { |
| 5250 | beacon_ie = NULL; |
| 5251 | beacon_ie_len = 0; |
| 5252 | } |
| 5253 | |
| 5254 | if (nl80211_scan_filtered(_arg->drv, ie ? ie : beacon_ie, |
| 5255 | ie ? ie_len : beacon_ie_len)) |
| 5256 | return NL_SKIP; |
| 5257 | |
| 5258 | r = os_zalloc(sizeof(*r) + ie_len + beacon_ie_len); |
| 5259 | if (r == NULL) |
| 5260 | return NL_SKIP; |
| 5261 | if (bss[NL80211_BSS_BSSID]) |
| 5262 | os_memcpy(r->bssid, nla_data(bss[NL80211_BSS_BSSID]), |
| 5263 | ETH_ALEN); |
| 5264 | if (bss[NL80211_BSS_FREQUENCY]) |
| 5265 | r->freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 5266 | if (bss[NL80211_BSS_BEACON_INTERVAL]) |
| 5267 | r->beacon_int = nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]); |
| 5268 | if (bss[NL80211_BSS_CAPABILITY]) |
| 5269 | r->caps = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); |
| 5270 | r->flags |= WPA_SCAN_NOISE_INVALID; |
| 5271 | if (bss[NL80211_BSS_SIGNAL_MBM]) { |
| 5272 | r->level = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]); |
| 5273 | r->level /= 100; /* mBm to dBm */ |
| 5274 | r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID; |
| 5275 | } else if (bss[NL80211_BSS_SIGNAL_UNSPEC]) { |
| 5276 | r->level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5277 | r->flags |= WPA_SCAN_QUAL_INVALID; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5278 | } else |
| 5279 | r->flags |= WPA_SCAN_LEVEL_INVALID | WPA_SCAN_QUAL_INVALID; |
| 5280 | if (bss[NL80211_BSS_TSF]) |
| 5281 | r->tsf = nla_get_u64(bss[NL80211_BSS_TSF]); |
| 5282 | if (bss[NL80211_BSS_SEEN_MS_AGO]) |
| 5283 | r->age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); |
| 5284 | r->ie_len = ie_len; |
| 5285 | pos = (u8 *) (r + 1); |
| 5286 | if (ie) { |
| 5287 | os_memcpy(pos, ie, ie_len); |
| 5288 | pos += ie_len; |
| 5289 | } |
| 5290 | r->beacon_ie_len = beacon_ie_len; |
| 5291 | if (beacon_ie) |
| 5292 | os_memcpy(pos, beacon_ie, beacon_ie_len); |
| 5293 | |
| 5294 | if (bss[NL80211_BSS_STATUS]) { |
| 5295 | enum nl80211_bss_status status; |
| 5296 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 5297 | switch (status) { |
| 5298 | case NL80211_BSS_STATUS_AUTHENTICATED: |
| 5299 | r->flags |= WPA_SCAN_AUTHENTICATED; |
| 5300 | break; |
| 5301 | case NL80211_BSS_STATUS_ASSOCIATED: |
| 5302 | r->flags |= WPA_SCAN_ASSOCIATED; |
| 5303 | break; |
| 5304 | default: |
| 5305 | break; |
| 5306 | } |
| 5307 | } |
| 5308 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5309 | /* |
| 5310 | * cfg80211 maintains separate BSS table entries for APs if the same |
| 5311 | * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does |
| 5312 | * not use frequency as a separate key in the BSS table, so filter out |
| 5313 | * duplicated entries. Prefer associated BSS entry in such a case in |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5314 | * order to get the correct frequency into the BSS table. Similarly, |
| 5315 | * prefer newer entries over older. |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5316 | */ |
| 5317 | for (i = 0; i < res->num; i++) { |
| 5318 | const u8 *s1, *s2; |
| 5319 | if (os_memcmp(res->res[i]->bssid, r->bssid, ETH_ALEN) != 0) |
| 5320 | continue; |
| 5321 | |
| 5322 | s1 = nl80211_get_ie((u8 *) (res->res[i] + 1), |
| 5323 | res->res[i]->ie_len, WLAN_EID_SSID); |
| 5324 | s2 = nl80211_get_ie((u8 *) (r + 1), r->ie_len, WLAN_EID_SSID); |
| 5325 | if (s1 == NULL || s2 == NULL || s1[1] != s2[1] || |
| 5326 | os_memcmp(s1, s2, 2 + s1[1]) != 0) |
| 5327 | continue; |
| 5328 | |
| 5329 | /* Same BSSID,SSID was already included in scan results */ |
| 5330 | wpa_printf(MSG_DEBUG, "nl80211: Remove duplicated scan result " |
| 5331 | "for " MACSTR, MAC2STR(r->bssid)); |
| 5332 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5333 | if (((r->flags & WPA_SCAN_ASSOCIATED) && |
| 5334 | !(res->res[i]->flags & WPA_SCAN_ASSOCIATED)) || |
| 5335 | r->age < res->res[i]->age) { |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 5336 | os_free(res->res[i]); |
| 5337 | res->res[i] = r; |
| 5338 | } else |
| 5339 | os_free(r); |
| 5340 | return NL_SKIP; |
| 5341 | } |
| 5342 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5343 | tmp = os_realloc_array(res->res, res->num + 1, |
| 5344 | sizeof(struct wpa_scan_res *)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5345 | if (tmp == NULL) { |
| 5346 | os_free(r); |
| 5347 | return NL_SKIP; |
| 5348 | } |
| 5349 | tmp[res->num++] = r; |
| 5350 | res->res = tmp; |
| 5351 | |
| 5352 | return NL_SKIP; |
| 5353 | } |
| 5354 | |
| 5355 | |
| 5356 | static void clear_state_mismatch(struct wpa_driver_nl80211_data *drv, |
| 5357 | const u8 *addr) |
| 5358 | { |
| 5359 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 5360 | wpa_printf(MSG_DEBUG, "nl80211: Clear possible state " |
| 5361 | "mismatch (" MACSTR ")", MAC2STR(addr)); |
| 5362 | wpa_driver_nl80211_mlme(drv, addr, |
| 5363 | NL80211_CMD_DEAUTHENTICATE, |
| 5364 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1); |
| 5365 | } |
| 5366 | } |
| 5367 | |
| 5368 | |
| 5369 | static void wpa_driver_nl80211_check_bss_status( |
| 5370 | struct wpa_driver_nl80211_data *drv, struct wpa_scan_results *res) |
| 5371 | { |
| 5372 | size_t i; |
| 5373 | |
| 5374 | for (i = 0; i < res->num; i++) { |
| 5375 | struct wpa_scan_res *r = res->res[i]; |
| 5376 | if (r->flags & WPA_SCAN_AUTHENTICATED) { |
| 5377 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " |
| 5378 | "indicates BSS status with " MACSTR |
| 5379 | " as authenticated", |
| 5380 | MAC2STR(r->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5381 | if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5382 | os_memcmp(r->bssid, drv->bssid, ETH_ALEN) != 0 && |
| 5383 | os_memcmp(r->bssid, drv->auth_bssid, ETH_ALEN) != |
| 5384 | 0) { |
| 5385 | wpa_printf(MSG_DEBUG, "nl80211: Unknown BSSID" |
| 5386 | " in local state (auth=" MACSTR |
| 5387 | " assoc=" MACSTR ")", |
| 5388 | MAC2STR(drv->auth_bssid), |
| 5389 | MAC2STR(drv->bssid)); |
| 5390 | clear_state_mismatch(drv, r->bssid); |
| 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | if (r->flags & WPA_SCAN_ASSOCIATED) { |
| 5395 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " |
| 5396 | "indicate BSS status with " MACSTR |
| 5397 | " as associated", |
| 5398 | MAC2STR(r->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5399 | if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5400 | !drv->associated) { |
| 5401 | wpa_printf(MSG_DEBUG, "nl80211: Local state " |
| 5402 | "(not associated) does not match " |
| 5403 | "with BSS state"); |
| 5404 | clear_state_mismatch(drv, r->bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5405 | } else if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5406 | os_memcmp(drv->bssid, r->bssid, ETH_ALEN) != |
| 5407 | 0) { |
| 5408 | wpa_printf(MSG_DEBUG, "nl80211: Local state " |
| 5409 | "(associated with " MACSTR ") does " |
| 5410 | "not match with BSS state", |
| 5411 | MAC2STR(drv->bssid)); |
| 5412 | clear_state_mismatch(drv, r->bssid); |
| 5413 | clear_state_mismatch(drv, drv->bssid); |
| 5414 | } |
| 5415 | } |
| 5416 | } |
| 5417 | } |
| 5418 | |
| 5419 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5420 | static struct wpa_scan_results * |
| 5421 | nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv) |
| 5422 | { |
| 5423 | struct nl_msg *msg; |
| 5424 | struct wpa_scan_results *res; |
| 5425 | int ret; |
| 5426 | struct nl80211_bss_info_arg arg; |
| 5427 | |
| 5428 | res = os_zalloc(sizeof(*res)); |
| 5429 | if (res == NULL) |
| 5430 | return NULL; |
| 5431 | msg = nlmsg_alloc(); |
| 5432 | if (!msg) |
| 5433 | goto nla_put_failure; |
| 5434 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5435 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5436 | if (nl80211_set_iface_id(msg, drv->first_bss) < 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5437 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5438 | |
| 5439 | arg.drv = drv; |
| 5440 | arg.res = res; |
| 5441 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
| 5442 | msg = NULL; |
| 5443 | if (ret == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5444 | wpa_printf(MSG_DEBUG, "nl80211: Received scan results (%lu " |
| 5445 | "BSSes)", (unsigned long) res->num); |
| 5446 | nl80211_get_noise_for_scan_results(drv, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5447 | return res; |
| 5448 | } |
| 5449 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 5450 | "(%s)", ret, strerror(-ret)); |
| 5451 | nla_put_failure: |
| 5452 | nlmsg_free(msg); |
| 5453 | wpa_scan_results_free(res); |
| 5454 | return NULL; |
| 5455 | } |
| 5456 | |
| 5457 | |
| 5458 | /** |
| 5459 | * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results |
| 5460 | * @priv: Pointer to private wext data from wpa_driver_nl80211_init() |
| 5461 | * Returns: Scan results on success, -1 on failure |
| 5462 | */ |
| 5463 | static struct wpa_scan_results * |
| 5464 | wpa_driver_nl80211_get_scan_results(void *priv) |
| 5465 | { |
| 5466 | struct i802_bss *bss = priv; |
| 5467 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5468 | struct wpa_scan_results *res; |
| 5469 | |
| 5470 | res = nl80211_get_scan_results(drv); |
| 5471 | if (res) |
| 5472 | wpa_driver_nl80211_check_bss_status(drv, res); |
| 5473 | return res; |
| 5474 | } |
| 5475 | |
| 5476 | |
| 5477 | static void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv) |
| 5478 | { |
| 5479 | struct wpa_scan_results *res; |
| 5480 | size_t i; |
| 5481 | |
| 5482 | res = nl80211_get_scan_results(drv); |
| 5483 | if (res == NULL) { |
| 5484 | wpa_printf(MSG_DEBUG, "nl80211: Failed to get scan results"); |
| 5485 | return; |
| 5486 | } |
| 5487 | |
| 5488 | wpa_printf(MSG_DEBUG, "nl80211: Scan result dump"); |
| 5489 | for (i = 0; i < res->num; i++) { |
| 5490 | struct wpa_scan_res *r = res->res[i]; |
| 5491 | wpa_printf(MSG_DEBUG, "nl80211: %d/%d " MACSTR "%s%s", |
| 5492 | (int) i, (int) res->num, MAC2STR(r->bssid), |
| 5493 | r->flags & WPA_SCAN_AUTHENTICATED ? " [auth]" : "", |
| 5494 | r->flags & WPA_SCAN_ASSOCIATED ? " [assoc]" : ""); |
| 5495 | } |
| 5496 | |
| 5497 | wpa_scan_results_free(res); |
| 5498 | } |
| 5499 | |
| 5500 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5501 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 5502 | { |
| 5503 | switch (alg) { |
| 5504 | case WPA_ALG_WEP: |
| 5505 | if (key_len == 5) |
| 5506 | return WLAN_CIPHER_SUITE_WEP40; |
| 5507 | return WLAN_CIPHER_SUITE_WEP104; |
| 5508 | case WPA_ALG_TKIP: |
| 5509 | return WLAN_CIPHER_SUITE_TKIP; |
| 5510 | case WPA_ALG_CCMP: |
| 5511 | return WLAN_CIPHER_SUITE_CCMP; |
| 5512 | case WPA_ALG_GCMP: |
| 5513 | return WLAN_CIPHER_SUITE_GCMP; |
| 5514 | case WPA_ALG_CCMP_256: |
| 5515 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 5516 | case WPA_ALG_GCMP_256: |
| 5517 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 5518 | case WPA_ALG_IGTK: |
| 5519 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 5520 | case WPA_ALG_BIP_GMAC_128: |
| 5521 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 5522 | case WPA_ALG_BIP_GMAC_256: |
| 5523 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 5524 | case WPA_ALG_BIP_CMAC_256: |
| 5525 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 5526 | case WPA_ALG_SMS4: |
| 5527 | return WLAN_CIPHER_SUITE_SMS4; |
| 5528 | case WPA_ALG_KRK: |
| 5529 | return WLAN_CIPHER_SUITE_KRK; |
| 5530 | case WPA_ALG_NONE: |
| 5531 | case WPA_ALG_PMK: |
| 5532 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 5533 | alg); |
| 5534 | return 0; |
| 5535 | } |
| 5536 | |
| 5537 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 5538 | alg); |
| 5539 | return 0; |
| 5540 | } |
| 5541 | |
| 5542 | |
| 5543 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 5544 | { |
| 5545 | switch (cipher) { |
| 5546 | case WPA_CIPHER_CCMP_256: |
| 5547 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 5548 | case WPA_CIPHER_GCMP_256: |
| 5549 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 5550 | case WPA_CIPHER_CCMP: |
| 5551 | return WLAN_CIPHER_SUITE_CCMP; |
| 5552 | case WPA_CIPHER_GCMP: |
| 5553 | return WLAN_CIPHER_SUITE_GCMP; |
| 5554 | case WPA_CIPHER_TKIP: |
| 5555 | return WLAN_CIPHER_SUITE_TKIP; |
| 5556 | case WPA_CIPHER_WEP104: |
| 5557 | return WLAN_CIPHER_SUITE_WEP104; |
| 5558 | case WPA_CIPHER_WEP40: |
| 5559 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5560 | case WPA_CIPHER_GTK_NOT_USED: |
| 5561 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5562 | } |
| 5563 | |
| 5564 | return 0; |
| 5565 | } |
| 5566 | |
| 5567 | |
| 5568 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 5569 | int max_suites) |
| 5570 | { |
| 5571 | int num_suites = 0; |
| 5572 | |
| 5573 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 5574 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 5575 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 5576 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 5577 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 5578 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 5579 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 5580 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 5581 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 5582 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 5583 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 5584 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 5585 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 5586 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 5587 | |
| 5588 | return num_suites; |
| 5589 | } |
| 5590 | |
| 5591 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5592 | 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] | 5593 | enum wpa_alg alg, const u8 *addr, |
| 5594 | int key_idx, int set_tx, |
| 5595 | const u8 *seq, size_t seq_len, |
| 5596 | const u8 *key, size_t key_len) |
| 5597 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5598 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5599 | int ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5600 | struct nl_msg *msg; |
| 5601 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5602 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5603 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5604 | /* Ignore for P2P Device */ |
| 5605 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 5606 | return 0; |
| 5607 | |
| 5608 | ifindex = if_nametoindex(ifname); |
| 5609 | 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] | 5610 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5611 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5612 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5613 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5614 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5615 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5616 | tdls = 1; |
| 5617 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5618 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5619 | |
| 5620 | msg = nlmsg_alloc(); |
| 5621 | if (!msg) |
| 5622 | return -ENOMEM; |
| 5623 | |
| 5624 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5625 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5626 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5627 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5628 | NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 5629 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5630 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 5631 | wpa_alg_to_cipher_suite(alg, key_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5632 | } |
| 5633 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 5634 | if (seq && seq_len) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5635 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 5636 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 5637 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5638 | |
| 5639 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 5640 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
| 5641 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5642 | |
| 5643 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 5644 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
| 5645 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, |
| 5646 | NL80211_KEYTYPE_GROUP); |
| 5647 | } |
| 5648 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5649 | struct nlattr *types; |
| 5650 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5651 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5652 | |
| 5653 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5654 | if (!types) |
| 5655 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5656 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST); |
| 5657 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5658 | } |
| 5659 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 5660 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 5661 | |
| 5662 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5663 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 5664 | ret = 0; |
| 5665 | if (ret) |
| 5666 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 5667 | ret, strerror(-ret)); |
| 5668 | |
| 5669 | /* |
| 5670 | * If we failed or don't need to set the default TX key (below), |
| 5671 | * we're done here. |
| 5672 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5673 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5674 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5675 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5676 | !is_broadcast_ether_addr(addr)) |
| 5677 | return ret; |
| 5678 | |
| 5679 | msg = nlmsg_alloc(); |
| 5680 | if (!msg) |
| 5681 | return -ENOMEM; |
| 5682 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5683 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5684 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 5685 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 5686 | if (alg == WPA_ALG_IGTK) |
| 5687 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT); |
| 5688 | else |
| 5689 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT); |
| 5690 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5691 | struct nlattr *types; |
| 5692 | |
| 5693 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5694 | if (!types) |
| 5695 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5696 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST); |
| 5697 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5698 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5699 | struct nlattr *types; |
| 5700 | |
| 5701 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5702 | if (!types) |
| 5703 | goto nla_put_failure; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5704 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST); |
| 5705 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5709 | if (ret == -ENOENT) |
| 5710 | ret = 0; |
| 5711 | if (ret) |
| 5712 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 5713 | "err=%d %s)", ret, strerror(-ret)); |
| 5714 | return ret; |
| 5715 | |
| 5716 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5717 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5718 | return -ENOBUFS; |
| 5719 | } |
| 5720 | |
| 5721 | |
| 5722 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 5723 | int key_idx, int defkey, |
| 5724 | const u8 *seq, size_t seq_len, |
| 5725 | const u8 *key, size_t key_len) |
| 5726 | { |
| 5727 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
| 5728 | if (!key_attr) |
| 5729 | return -1; |
| 5730 | |
| 5731 | if (defkey && alg == WPA_ALG_IGTK) |
| 5732 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_MGMT); |
| 5733 | else if (defkey) |
| 5734 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); |
| 5735 | |
| 5736 | NLA_PUT_U8(msg, NL80211_KEY_IDX, key_idx); |
| 5737 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5738 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 5739 | wpa_alg_to_cipher_suite(alg, key_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5740 | |
| 5741 | if (seq && seq_len) |
| 5742 | NLA_PUT(msg, NL80211_KEY_SEQ, seq_len, seq); |
| 5743 | |
| 5744 | NLA_PUT(msg, NL80211_KEY_DATA, key_len, key); |
| 5745 | |
| 5746 | nla_nest_end(msg, key_attr); |
| 5747 | |
| 5748 | return 0; |
| 5749 | nla_put_failure: |
| 5750 | return -1; |
| 5751 | } |
| 5752 | |
| 5753 | |
| 5754 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 5755 | struct nl_msg *msg) |
| 5756 | { |
| 5757 | int i, privacy = 0; |
| 5758 | struct nlattr *nl_keys, *nl_key; |
| 5759 | |
| 5760 | for (i = 0; i < 4; i++) { |
| 5761 | if (!params->wep_key[i]) |
| 5762 | continue; |
| 5763 | privacy = 1; |
| 5764 | break; |
| 5765 | } |
| 5766 | if (params->wps == WPS_MODE_PRIVACY) |
| 5767 | privacy = 1; |
| 5768 | if (params->pairwise_suite && |
| 5769 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 5770 | privacy = 1; |
| 5771 | |
| 5772 | if (!privacy) |
| 5773 | return 0; |
| 5774 | |
| 5775 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); |
| 5776 | |
| 5777 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 5778 | if (!nl_keys) |
| 5779 | goto nla_put_failure; |
| 5780 | |
| 5781 | for (i = 0; i < 4; i++) { |
| 5782 | if (!params->wep_key[i]) |
| 5783 | continue; |
| 5784 | |
| 5785 | nl_key = nla_nest_start(msg, i); |
| 5786 | if (!nl_key) |
| 5787 | goto nla_put_failure; |
| 5788 | |
| 5789 | NLA_PUT(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 5790 | params->wep_key[i]); |
| 5791 | if (params->wep_key_len[i] == 5) |
| 5792 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 5793 | WLAN_CIPHER_SUITE_WEP40); |
| 5794 | else |
| 5795 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 5796 | WLAN_CIPHER_SUITE_WEP104); |
| 5797 | |
| 5798 | NLA_PUT_U8(msg, NL80211_KEY_IDX, i); |
| 5799 | |
| 5800 | if (i == params->wep_tx_keyidx) |
| 5801 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); |
| 5802 | |
| 5803 | nla_nest_end(msg, nl_key); |
| 5804 | } |
| 5805 | nla_nest_end(msg, nl_keys); |
| 5806 | |
| 5807 | return 0; |
| 5808 | |
| 5809 | nla_put_failure: |
| 5810 | return -ENOBUFS; |
| 5811 | } |
| 5812 | |
| 5813 | |
| 5814 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 5815 | const u8 *addr, int cmd, u16 reason_code, |
| 5816 | int local_state_change) |
| 5817 | { |
| 5818 | int ret = -1; |
| 5819 | struct nl_msg *msg; |
| 5820 | |
| 5821 | msg = nlmsg_alloc(); |
| 5822 | if (!msg) |
| 5823 | return -1; |
| 5824 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5825 | nl80211_cmd(drv, msg, 0, cmd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5826 | |
| 5827 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 5828 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5829 | if (addr) |
| 5830 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5831 | if (local_state_change) |
| 5832 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); |
| 5833 | |
| 5834 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5835 | msg = NULL; |
| 5836 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5837 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 5838 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 5839 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5840 | goto nla_put_failure; |
| 5841 | } |
| 5842 | ret = 0; |
| 5843 | |
| 5844 | nla_put_failure: |
| 5845 | nlmsg_free(msg); |
| 5846 | return ret; |
| 5847 | } |
| 5848 | |
| 5849 | |
| 5850 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5851 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5852 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5853 | int ret; |
| 5854 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5855 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5856 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5857 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5858 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 5859 | reason_code, 0); |
| 5860 | /* |
| 5861 | * For locally generated disconnect, supplicant already generates a |
| 5862 | * DEAUTH event, so ignore the event from NL80211. |
| 5863 | */ |
| 5864 | drv->ignore_next_local_disconnect = ret == 0; |
| 5865 | |
| 5866 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5870 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 5871 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5872 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5873 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5874 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5875 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5876 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 5877 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5878 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5879 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) |
| 5880 | return nl80211_leave_ibss(drv); |
| 5881 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 5882 | reason_code, 0); |
| 5883 | } |
| 5884 | |
| 5885 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5886 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 5887 | struct wpa_driver_auth_params *params) |
| 5888 | { |
| 5889 | int i; |
| 5890 | |
| 5891 | drv->auth_freq = params->freq; |
| 5892 | drv->auth_alg = params->auth_alg; |
| 5893 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 5894 | drv->auth_local_state_change = params->local_state_change; |
| 5895 | drv->auth_p2p = params->p2p; |
| 5896 | |
| 5897 | if (params->bssid) |
| 5898 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 5899 | else |
| 5900 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 5901 | |
| 5902 | if (params->ssid) { |
| 5903 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 5904 | drv->auth_ssid_len = params->ssid_len; |
| 5905 | } else |
| 5906 | drv->auth_ssid_len = 0; |
| 5907 | |
| 5908 | |
| 5909 | os_free(drv->auth_ie); |
| 5910 | drv->auth_ie = NULL; |
| 5911 | drv->auth_ie_len = 0; |
| 5912 | if (params->ie) { |
| 5913 | drv->auth_ie = os_malloc(params->ie_len); |
| 5914 | if (drv->auth_ie) { |
| 5915 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 5916 | drv->auth_ie_len = params->ie_len; |
| 5917 | } |
| 5918 | } |
| 5919 | |
| 5920 | for (i = 0; i < 4; i++) { |
| 5921 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 5922 | params->wep_key_len[i] <= 16) { |
| 5923 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 5924 | params->wep_key_len[i]); |
| 5925 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 5926 | } else |
| 5927 | drv->auth_wep_key_len[i] = 0; |
| 5928 | } |
| 5929 | } |
| 5930 | |
| 5931 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5932 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5933 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5934 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5935 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5936 | int ret = -1, i; |
| 5937 | struct nl_msg *msg; |
| 5938 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5939 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5940 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5941 | int is_retry; |
| 5942 | |
| 5943 | is_retry = drv->retry_auth; |
| 5944 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 5945 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5946 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5947 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5948 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5949 | if (params->bssid) |
| 5950 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 5951 | else |
| 5952 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5953 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5954 | nlmode = params->p2p ? |
| 5955 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 5956 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5957 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5958 | return -1; |
| 5959 | |
| 5960 | retry: |
| 5961 | msg = nlmsg_alloc(); |
| 5962 | if (!msg) |
| 5963 | return -1; |
| 5964 | |
| 5965 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 5966 | drv->ifindex); |
| 5967 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5968 | nl80211_cmd(drv, msg, 0, NL80211_CMD_AUTHENTICATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5969 | |
| 5970 | for (i = 0; i < 4; i++) { |
| 5971 | if (!params->wep_key[i]) |
| 5972 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5973 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5974 | NULL, i, |
| 5975 | i == params->wep_tx_keyidx, NULL, 0, |
| 5976 | params->wep_key[i], |
| 5977 | params->wep_key_len[i]); |
| 5978 | if (params->wep_tx_keyidx != i) |
| 5979 | continue; |
| 5980 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
| 5981 | params->wep_key[i], params->wep_key_len[i])) { |
| 5982 | nlmsg_free(msg); |
| 5983 | return -1; |
| 5984 | } |
| 5985 | } |
| 5986 | |
| 5987 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 5988 | if (params->bssid) { |
| 5989 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5990 | MAC2STR(params->bssid)); |
| 5991 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 5992 | } |
| 5993 | if (params->freq) { |
| 5994 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 5995 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
| 5996 | } |
| 5997 | if (params->ssid) { |
| 5998 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5999 | params->ssid, params->ssid_len); |
| 6000 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 6001 | params->ssid); |
| 6002 | } |
| 6003 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
| 6004 | if (params->ie) |
| 6005 | NLA_PUT(msg, NL80211_ATTR_IE, params->ie_len, params->ie); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6006 | if (params->sae_data) { |
| 6007 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 6008 | params->sae_data_len); |
| 6009 | NLA_PUT(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 6010 | params->sae_data); |
| 6011 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6012 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 6013 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 6014 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 6015 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 6016 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 6017 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 6018 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 6019 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6020 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 6021 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6022 | else |
| 6023 | goto nla_put_failure; |
| 6024 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 6025 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); |
| 6026 | if (params->local_state_change) { |
| 6027 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
| 6028 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); |
| 6029 | } |
| 6030 | |
| 6031 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6032 | msg = NULL; |
| 6033 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6034 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 6035 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 6036 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6037 | count++; |
| 6038 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 6039 | !params->local_state_change) { |
| 6040 | /* |
| 6041 | * mac80211 does not currently accept new |
| 6042 | * authentication if we are already authenticated. As a |
| 6043 | * workaround, force deauthentication and try again. |
| 6044 | */ |
| 6045 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 6046 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 6047 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6048 | wpa_driver_nl80211_deauthenticate( |
| 6049 | bss, params->bssid, |
| 6050 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 6051 | nlmsg_free(msg); |
| 6052 | goto retry; |
| 6053 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6054 | |
| 6055 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 6056 | /* |
| 6057 | * cfg80211 has likely expired the BSS entry even |
| 6058 | * though it was previously available in our internal |
| 6059 | * BSS table. To recover quickly, start a single |
| 6060 | * channel scan on the specified channel. |
| 6061 | */ |
| 6062 | struct wpa_driver_scan_params scan; |
| 6063 | int freqs[2]; |
| 6064 | |
| 6065 | os_memset(&scan, 0, sizeof(scan)); |
| 6066 | scan.num_ssids = 1; |
| 6067 | if (params->ssid) { |
| 6068 | scan.ssids[0].ssid = params->ssid; |
| 6069 | scan.ssids[0].ssid_len = params->ssid_len; |
| 6070 | } |
| 6071 | freqs[0] = params->freq; |
| 6072 | freqs[1] = 0; |
| 6073 | scan.freqs = freqs; |
| 6074 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 6075 | "channel scan to refresh cfg80211 BSS " |
| 6076 | "entry"); |
| 6077 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 6078 | if (ret == 0) { |
| 6079 | nl80211_copy_auth_params(drv, params); |
| 6080 | drv->scan_for_auth = 1; |
| 6081 | } |
| 6082 | } else if (is_retry) { |
| 6083 | /* |
| 6084 | * Need to indicate this with an event since the return |
| 6085 | * value from the retry is not delivered to core code. |
| 6086 | */ |
| 6087 | union wpa_event_data event; |
| 6088 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 6089 | "failed"); |
| 6090 | os_memset(&event, 0, sizeof(event)); |
| 6091 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 6092 | ETH_ALEN); |
| 6093 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 6094 | &event); |
| 6095 | } |
| 6096 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6097 | goto nla_put_failure; |
| 6098 | } |
| 6099 | ret = 0; |
| 6100 | wpa_printf(MSG_DEBUG, "nl80211: Authentication request send " |
| 6101 | "successfully"); |
| 6102 | |
| 6103 | nla_put_failure: |
| 6104 | nlmsg_free(msg); |
| 6105 | return ret; |
| 6106 | } |
| 6107 | |
| 6108 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6109 | static int wpa_driver_nl80211_authenticate_retry( |
| 6110 | struct wpa_driver_nl80211_data *drv) |
| 6111 | { |
| 6112 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6113 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6114 | int i; |
| 6115 | |
| 6116 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 6117 | |
| 6118 | os_memset(¶ms, 0, sizeof(params)); |
| 6119 | params.freq = drv->auth_freq; |
| 6120 | params.auth_alg = drv->auth_alg; |
| 6121 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 6122 | params.local_state_change = drv->auth_local_state_change; |
| 6123 | params.p2p = drv->auth_p2p; |
| 6124 | |
| 6125 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 6126 | params.bssid = drv->auth_bssid_; |
| 6127 | |
| 6128 | if (drv->auth_ssid_len) { |
| 6129 | params.ssid = drv->auth_ssid; |
| 6130 | params.ssid_len = drv->auth_ssid_len; |
| 6131 | } |
| 6132 | |
| 6133 | params.ie = drv->auth_ie; |
| 6134 | params.ie_len = drv->auth_ie_len; |
| 6135 | |
| 6136 | for (i = 0; i < 4; i++) { |
| 6137 | if (drv->auth_wep_key_len[i]) { |
| 6138 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 6139 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | drv->retry_auth = 1; |
| 6144 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 6145 | } |
| 6146 | |
| 6147 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6148 | struct phy_info_arg { |
| 6149 | u16 *num_modes; |
| 6150 | struct hostapd_hw_modes *modes; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6151 | int last_mode, last_chan_idx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6152 | }; |
| 6153 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6154 | static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa, |
| 6155 | struct nlattr *ampdu_factor, |
| 6156 | struct nlattr *ampdu_density, |
| 6157 | struct nlattr *mcs_set) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6158 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6159 | if (capa) |
| 6160 | mode->ht_capab = nla_get_u16(capa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6161 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6162 | if (ampdu_factor) |
| 6163 | mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6164 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6165 | if (ampdu_density) |
| 6166 | mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2; |
| 6167 | |
| 6168 | if (mcs_set && nla_len(mcs_set) >= 16) { |
| 6169 | u8 *mcs; |
| 6170 | mcs = nla_data(mcs_set); |
| 6171 | os_memcpy(mode->mcs_set, mcs, 16); |
| 6172 | } |
| 6173 | } |
| 6174 | |
| 6175 | |
| 6176 | static void phy_info_vht_capa(struct hostapd_hw_modes *mode, |
| 6177 | struct nlattr *capa, |
| 6178 | struct nlattr *mcs_set) |
| 6179 | { |
| 6180 | if (capa) |
| 6181 | mode->vht_capab = nla_get_u32(capa); |
| 6182 | |
| 6183 | if (mcs_set && nla_len(mcs_set) >= 8) { |
| 6184 | u8 *mcs; |
| 6185 | mcs = nla_data(mcs_set); |
| 6186 | os_memcpy(mode->vht_mcs_set, mcs, 8); |
| 6187 | } |
| 6188 | } |
| 6189 | |
| 6190 | |
| 6191 | static void phy_info_freq(struct hostapd_hw_modes *mode, |
| 6192 | struct hostapd_channel_data *chan, |
| 6193 | struct nlattr *tb_freq[]) |
| 6194 | { |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 6195 | u8 channel; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6196 | chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); |
| 6197 | chan->flag = 0; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 6198 | if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES) |
| 6199 | chan->chan = channel; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6200 | |
| 6201 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) |
| 6202 | chan->flag |= HOSTAPD_CHAN_DISABLED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6203 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR]) |
| 6204 | chan->flag |= HOSTAPD_CHAN_PASSIVE_SCAN | HOSTAPD_CHAN_NO_IBSS; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6205 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) |
| 6206 | chan->flag |= HOSTAPD_CHAN_RADAR; |
| 6207 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6208 | if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) { |
| 6209 | enum nl80211_dfs_state state = |
| 6210 | nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]); |
| 6211 | |
| 6212 | switch (state) { |
| 6213 | case NL80211_DFS_USABLE: |
| 6214 | chan->flag |= HOSTAPD_CHAN_DFS_USABLE; |
| 6215 | break; |
| 6216 | case NL80211_DFS_AVAILABLE: |
| 6217 | chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE; |
| 6218 | break; |
| 6219 | case NL80211_DFS_UNAVAILABLE: |
| 6220 | chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE; |
| 6221 | break; |
| 6222 | } |
| 6223 | } |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | |
| 6227 | static int phy_info_freqs(struct phy_info_arg *phy_info, |
| 6228 | struct hostapd_hw_modes *mode, struct nlattr *tb) |
| 6229 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6230 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 6231 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, |
| 6232 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6233 | [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6234 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, |
| 6235 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6236 | [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6237 | }; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6238 | int new_channels = 0; |
| 6239 | struct hostapd_channel_data *channel; |
| 6240 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6241 | struct nlattr *nl_freq; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6242 | int rem_freq, idx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6243 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6244 | if (tb == NULL) |
| 6245 | return NL_OK; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6246 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6247 | nla_for_each_nested(nl_freq, tb, rem_freq) { |
| 6248 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, |
| 6249 | nla_data(nl_freq), nla_len(nl_freq), freq_policy); |
| 6250 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 6251 | continue; |
| 6252 | new_channels++; |
| 6253 | } |
| 6254 | |
| 6255 | channel = os_realloc_array(mode->channels, |
| 6256 | mode->num_channels + new_channels, |
| 6257 | sizeof(struct hostapd_channel_data)); |
| 6258 | if (!channel) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6259 | return NL_SKIP; |
| 6260 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6261 | mode->channels = channel; |
| 6262 | mode->num_channels += new_channels; |
| 6263 | |
| 6264 | idx = phy_info->last_chan_idx; |
| 6265 | |
| 6266 | nla_for_each_nested(nl_freq, tb, rem_freq) { |
| 6267 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, |
| 6268 | nla_data(nl_freq), nla_len(nl_freq), freq_policy); |
| 6269 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 6270 | continue; |
| 6271 | phy_info_freq(mode, &mode->channels[idx], tb_freq); |
| 6272 | idx++; |
| 6273 | } |
| 6274 | phy_info->last_chan_idx = idx; |
| 6275 | |
| 6276 | return NL_OK; |
| 6277 | } |
| 6278 | |
| 6279 | |
| 6280 | static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb) |
| 6281 | { |
| 6282 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { |
| 6283 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, |
| 6284 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = |
| 6285 | { .type = NLA_FLAG }, |
| 6286 | }; |
| 6287 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; |
| 6288 | struct nlattr *nl_rate; |
| 6289 | int rem_rate, idx; |
| 6290 | |
| 6291 | if (tb == NULL) |
| 6292 | return NL_OK; |
| 6293 | |
| 6294 | nla_for_each_nested(nl_rate, tb, rem_rate) { |
| 6295 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, |
| 6296 | nla_data(nl_rate), nla_len(nl_rate), |
| 6297 | rate_policy); |
| 6298 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 6299 | continue; |
| 6300 | mode->num_rates++; |
| 6301 | } |
| 6302 | |
| 6303 | mode->rates = os_calloc(mode->num_rates, sizeof(int)); |
| 6304 | if (!mode->rates) |
| 6305 | return NL_SKIP; |
| 6306 | |
| 6307 | idx = 0; |
| 6308 | |
| 6309 | nla_for_each_nested(nl_rate, tb, rem_rate) { |
| 6310 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, |
| 6311 | nla_data(nl_rate), nla_len(nl_rate), |
| 6312 | rate_policy); |
| 6313 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 6314 | continue; |
| 6315 | mode->rates[idx] = nla_get_u32( |
| 6316 | tb_rate[NL80211_BITRATE_ATTR_RATE]); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6317 | idx++; |
| 6318 | } |
| 6319 | |
| 6320 | return NL_OK; |
| 6321 | } |
| 6322 | |
| 6323 | |
| 6324 | static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band) |
| 6325 | { |
| 6326 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; |
| 6327 | struct hostapd_hw_modes *mode; |
| 6328 | int ret; |
| 6329 | |
| 6330 | if (phy_info->last_mode != nl_band->nla_type) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6331 | mode = os_realloc_array(phy_info->modes, |
| 6332 | *phy_info->num_modes + 1, |
| 6333 | sizeof(*mode)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6334 | if (!mode) |
| 6335 | return NL_SKIP; |
| 6336 | phy_info->modes = mode; |
| 6337 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6338 | mode = &phy_info->modes[*(phy_info->num_modes)]; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6339 | os_memset(mode, 0, sizeof(*mode)); |
| 6340 | mode->mode = NUM_HOSTAPD_MODES; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6341 | mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN | |
| 6342 | HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN; |
| 6343 | |
| 6344 | /* |
| 6345 | * Unsupported VHT MCS stream is defined as value 3, so the VHT |
| 6346 | * MCS RX/TX map must be initialized with 0xffff to mark all 8 |
| 6347 | * possible streams as unsupported. This will be overridden if |
| 6348 | * driver advertises VHT support. |
| 6349 | */ |
| 6350 | mode->vht_mcs_set[0] = 0xff; |
| 6351 | mode->vht_mcs_set[1] = 0xff; |
| 6352 | mode->vht_mcs_set[4] = 0xff; |
| 6353 | mode->vht_mcs_set[5] = 0xff; |
| 6354 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6355 | *(phy_info->num_modes) += 1; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6356 | phy_info->last_mode = nl_band->nla_type; |
| 6357 | phy_info->last_chan_idx = 0; |
| 6358 | } else |
| 6359 | mode = &phy_info->modes[*(phy_info->num_modes) - 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6360 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6361 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), |
| 6362 | nla_len(nl_band), NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6363 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6364 | phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA], |
| 6365 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR], |
| 6366 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY], |
| 6367 | tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); |
| 6368 | phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA], |
| 6369 | tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]); |
| 6370 | ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]); |
| 6371 | if (ret != NL_OK) |
| 6372 | return ret; |
| 6373 | ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]); |
| 6374 | if (ret != NL_OK) |
| 6375 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6376 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6377 | return NL_OK; |
| 6378 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6379 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6380 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6381 | static int phy_info_handler(struct nl_msg *msg, void *arg) |
| 6382 | { |
| 6383 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 6384 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6385 | struct phy_info_arg *phy_info = arg; |
| 6386 | struct nlattr *nl_band; |
| 6387 | int rem_band; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6388 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6389 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6390 | genlmsg_attrlen(gnlh, 0), NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6391 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6392 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) |
| 6393 | return NL_SKIP; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6394 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6395 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) |
| 6396 | { |
| 6397 | int res = phy_info_band(phy_info, nl_band); |
| 6398 | if (res != NL_OK) |
| 6399 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | return NL_SKIP; |
| 6403 | } |
| 6404 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6405 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6406 | static struct hostapd_hw_modes * |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 6407 | wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes, |
| 6408 | u16 *num_modes) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6409 | { |
| 6410 | u16 m; |
| 6411 | struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; |
| 6412 | int i, mode11g_idx = -1; |
| 6413 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 6414 | /* heuristic to set up modes */ |
| 6415 | for (m = 0; m < *num_modes; m++) { |
| 6416 | if (!modes[m].num_channels) |
| 6417 | continue; |
| 6418 | if (modes[m].channels[0].freq < 4000) { |
| 6419 | modes[m].mode = HOSTAPD_MODE_IEEE80211B; |
| 6420 | for (i = 0; i < modes[m].num_rates; i++) { |
| 6421 | if (modes[m].rates[i] > 200) { |
| 6422 | modes[m].mode = HOSTAPD_MODE_IEEE80211G; |
| 6423 | break; |
| 6424 | } |
| 6425 | } |
| 6426 | } else if (modes[m].channels[0].freq > 50000) |
| 6427 | modes[m].mode = HOSTAPD_MODE_IEEE80211AD; |
| 6428 | else |
| 6429 | modes[m].mode = HOSTAPD_MODE_IEEE80211A; |
| 6430 | } |
| 6431 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6432 | /* If only 802.11g mode is included, use it to construct matching |
| 6433 | * 802.11b mode data. */ |
| 6434 | |
| 6435 | for (m = 0; m < *num_modes; m++) { |
| 6436 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) |
| 6437 | return modes; /* 802.11b already included */ |
| 6438 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) |
| 6439 | mode11g_idx = m; |
| 6440 | } |
| 6441 | |
| 6442 | if (mode11g_idx < 0) |
| 6443 | return modes; /* 2.4 GHz band not supported at all */ |
| 6444 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6445 | nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6446 | if (nmodes == NULL) |
| 6447 | return modes; /* Could not add 802.11b mode */ |
| 6448 | |
| 6449 | mode = &nmodes[*num_modes]; |
| 6450 | os_memset(mode, 0, sizeof(*mode)); |
| 6451 | (*num_modes)++; |
| 6452 | modes = nmodes; |
| 6453 | |
| 6454 | mode->mode = HOSTAPD_MODE_IEEE80211B; |
| 6455 | |
| 6456 | mode11g = &modes[mode11g_idx]; |
| 6457 | mode->num_channels = mode11g->num_channels; |
| 6458 | mode->channels = os_malloc(mode11g->num_channels * |
| 6459 | sizeof(struct hostapd_channel_data)); |
| 6460 | if (mode->channels == NULL) { |
| 6461 | (*num_modes)--; |
| 6462 | return modes; /* Could not add 802.11b mode */ |
| 6463 | } |
| 6464 | os_memcpy(mode->channels, mode11g->channels, |
| 6465 | mode11g->num_channels * sizeof(struct hostapd_channel_data)); |
| 6466 | |
| 6467 | mode->num_rates = 0; |
| 6468 | mode->rates = os_malloc(4 * sizeof(int)); |
| 6469 | if (mode->rates == NULL) { |
| 6470 | os_free(mode->channels); |
| 6471 | (*num_modes)--; |
| 6472 | return modes; /* Could not add 802.11b mode */ |
| 6473 | } |
| 6474 | |
| 6475 | for (i = 0; i < mode11g->num_rates; i++) { |
| 6476 | if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && |
| 6477 | mode11g->rates[i] != 55 && mode11g->rates[i] != 110) |
| 6478 | continue; |
| 6479 | mode->rates[mode->num_rates] = mode11g->rates[i]; |
| 6480 | mode->num_rates++; |
| 6481 | if (mode->num_rates == 4) |
| 6482 | break; |
| 6483 | } |
| 6484 | |
| 6485 | if (mode->num_rates == 0) { |
| 6486 | os_free(mode->channels); |
| 6487 | os_free(mode->rates); |
| 6488 | (*num_modes)--; |
| 6489 | return modes; /* No 802.11b rates */ |
| 6490 | } |
| 6491 | |
| 6492 | wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " |
| 6493 | "information"); |
| 6494 | |
| 6495 | return modes; |
| 6496 | } |
| 6497 | |
| 6498 | |
| 6499 | static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start, |
| 6500 | int end) |
| 6501 | { |
| 6502 | int c; |
| 6503 | |
| 6504 | for (c = 0; c < mode->num_channels; c++) { |
| 6505 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 6506 | if (chan->freq - 10 >= start && chan->freq + 10 <= end) |
| 6507 | chan->flag |= HOSTAPD_CHAN_HT40; |
| 6508 | } |
| 6509 | } |
| 6510 | |
| 6511 | |
| 6512 | static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start, |
| 6513 | int end) |
| 6514 | { |
| 6515 | int c; |
| 6516 | |
| 6517 | for (c = 0; c < mode->num_channels; c++) { |
| 6518 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 6519 | if (!(chan->flag & HOSTAPD_CHAN_HT40)) |
| 6520 | continue; |
| 6521 | if (chan->freq - 30 >= start && chan->freq - 10 <= end) |
| 6522 | chan->flag |= HOSTAPD_CHAN_HT40MINUS; |
| 6523 | if (chan->freq + 10 >= start && chan->freq + 30 <= end) |
| 6524 | chan->flag |= HOSTAPD_CHAN_HT40PLUS; |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6529 | 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] | 6530 | struct phy_info_arg *results) |
| 6531 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6532 | u16 m; |
| 6533 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6534 | for (m = 0; m < *results->num_modes; m++) { |
| 6535 | int c; |
| 6536 | struct hostapd_hw_modes *mode = &results->modes[m]; |
| 6537 | |
| 6538 | for (c = 0; c < mode->num_channels; c++) { |
| 6539 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 6540 | if ((u32) chan->freq - 10 >= start && |
| 6541 | (u32) chan->freq + 10 <= end) |
| 6542 | chan->max_tx_power = max_eirp; |
| 6543 | } |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6548 | static void nl80211_reg_rule_ht40(u32 start, u32 end, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6549 | struct phy_info_arg *results) |
| 6550 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6551 | u16 m; |
| 6552 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6553 | for (m = 0; m < *results->num_modes; m++) { |
| 6554 | if (!(results->modes[m].ht_capab & |
| 6555 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 6556 | continue; |
| 6557 | nl80211_set_ht40_mode(&results->modes[m], start, end); |
| 6558 | } |
| 6559 | } |
| 6560 | |
| 6561 | |
| 6562 | static void nl80211_reg_rule_sec(struct nlattr *tb[], |
| 6563 | struct phy_info_arg *results) |
| 6564 | { |
| 6565 | u32 start, end, max_bw; |
| 6566 | u16 m; |
| 6567 | |
| 6568 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || |
| 6569 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || |
| 6570 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) |
| 6571 | return; |
| 6572 | |
| 6573 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; |
| 6574 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; |
| 6575 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; |
| 6576 | |
| 6577 | if (max_bw < 20) |
| 6578 | return; |
| 6579 | |
| 6580 | for (m = 0; m < *results->num_modes; m++) { |
| 6581 | if (!(results->modes[m].ht_capab & |
| 6582 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 6583 | continue; |
| 6584 | nl80211_set_ht40_mode_sec(&results->modes[m], start, end); |
| 6585 | } |
| 6586 | } |
| 6587 | |
| 6588 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6589 | static void nl80211_set_vht_mode(struct hostapd_hw_modes *mode, int start, |
| 6590 | int end) |
| 6591 | { |
| 6592 | int c; |
| 6593 | |
| 6594 | for (c = 0; c < mode->num_channels; c++) { |
| 6595 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 6596 | if (chan->freq - 10 >= start && chan->freq + 70 <= end) |
| 6597 | chan->flag |= HOSTAPD_CHAN_VHT_10_70; |
| 6598 | |
| 6599 | if (chan->freq - 30 >= start && chan->freq + 50 <= end) |
| 6600 | chan->flag |= HOSTAPD_CHAN_VHT_30_50; |
| 6601 | |
| 6602 | if (chan->freq - 50 >= start && chan->freq + 30 <= end) |
| 6603 | chan->flag |= HOSTAPD_CHAN_VHT_50_30; |
| 6604 | |
| 6605 | if (chan->freq - 70 >= start && chan->freq + 10 <= end) |
| 6606 | chan->flag |= HOSTAPD_CHAN_VHT_70_10; |
| 6607 | } |
| 6608 | } |
| 6609 | |
| 6610 | |
| 6611 | static void nl80211_reg_rule_vht(struct nlattr *tb[], |
| 6612 | struct phy_info_arg *results) |
| 6613 | { |
| 6614 | u32 start, end, max_bw; |
| 6615 | u16 m; |
| 6616 | |
| 6617 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || |
| 6618 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || |
| 6619 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) |
| 6620 | return; |
| 6621 | |
| 6622 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; |
| 6623 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; |
| 6624 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; |
| 6625 | |
| 6626 | if (max_bw < 80) |
| 6627 | return; |
| 6628 | |
| 6629 | for (m = 0; m < *results->num_modes; m++) { |
| 6630 | if (!(results->modes[m].ht_capab & |
| 6631 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 6632 | continue; |
| 6633 | /* TODO: use a real VHT support indication */ |
| 6634 | if (!results->modes[m].vht_capab) |
| 6635 | continue; |
| 6636 | |
| 6637 | nl80211_set_vht_mode(&results->modes[m], start, end); |
| 6638 | } |
| 6639 | } |
| 6640 | |
| 6641 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 6642 | static const char * dfs_domain_name(enum nl80211_dfs_regions region) |
| 6643 | { |
| 6644 | switch (region) { |
| 6645 | case NL80211_DFS_UNSET: |
| 6646 | return "DFS-UNSET"; |
| 6647 | case NL80211_DFS_FCC: |
| 6648 | return "DFS-FCC"; |
| 6649 | case NL80211_DFS_ETSI: |
| 6650 | return "DFS-ETSI"; |
| 6651 | case NL80211_DFS_JP: |
| 6652 | return "DFS-JP"; |
| 6653 | default: |
| 6654 | return "DFS-invalid"; |
| 6655 | } |
| 6656 | } |
| 6657 | |
| 6658 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6659 | static int nl80211_get_reg(struct nl_msg *msg, void *arg) |
| 6660 | { |
| 6661 | struct phy_info_arg *results = arg; |
| 6662 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 6663 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6664 | struct nlattr *nl_rule; |
| 6665 | struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1]; |
| 6666 | int rem_rule; |
| 6667 | static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 6668 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6669 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6670 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6671 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6672 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6673 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6674 | }; |
| 6675 | |
| 6676 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6677 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6678 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2] || |
| 6679 | !tb_msg[NL80211_ATTR_REG_RULES]) { |
| 6680 | wpa_printf(MSG_DEBUG, "nl80211: No regulatory information " |
| 6681 | "available"); |
| 6682 | return NL_SKIP; |
| 6683 | } |
| 6684 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 6685 | if (tb_msg[NL80211_ATTR_DFS_REGION]) { |
| 6686 | enum nl80211_dfs_regions dfs_domain; |
| 6687 | dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]); |
| 6688 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s (%s)", |
| 6689 | (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), |
| 6690 | dfs_domain_name(dfs_domain)); |
| 6691 | } else { |
| 6692 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s", |
| 6693 | (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2])); |
| 6694 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6695 | |
| 6696 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) |
| 6697 | { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6698 | u32 start, end, max_eirp = 0, max_bw = 0, flags = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6699 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, |
| 6700 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6701 | if (tb_rule[NL80211_ATTR_FREQ_RANGE_START] == NULL || |
| 6702 | tb_rule[NL80211_ATTR_FREQ_RANGE_END] == NULL) |
| 6703 | continue; |
| 6704 | start = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]) / 1000; |
| 6705 | end = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]) / 1000; |
| 6706 | if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6707 | max_eirp = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) / 100; |
| 6708 | if (tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6709 | 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] | 6710 | if (tb_rule[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6711 | flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6712 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6713 | wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz %u mBm%s%s%s%s%s%s%s%s", |
| 6714 | start, end, max_bw, max_eirp, |
| 6715 | flags & NL80211_RRF_NO_OFDM ? " (no OFDM)" : "", |
| 6716 | flags & NL80211_RRF_NO_CCK ? " (no CCK)" : "", |
| 6717 | flags & NL80211_RRF_NO_INDOOR ? " (no indoor)" : "", |
| 6718 | flags & NL80211_RRF_NO_OUTDOOR ? " (no outdoor)" : |
| 6719 | "", |
| 6720 | flags & NL80211_RRF_DFS ? " (DFS)" : "", |
| 6721 | flags & NL80211_RRF_PTP_ONLY ? " (PTP only)" : "", |
| 6722 | flags & NL80211_RRF_PTMP_ONLY ? " (PTMP only)" : "", |
| 6723 | flags & NL80211_RRF_NO_IR ? " (no IR)" : ""); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6724 | if (max_bw >= 40) |
| 6725 | nl80211_reg_rule_ht40(start, end, results); |
| 6726 | if (tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6727 | nl80211_reg_rule_max_eirp(start, end, max_eirp, |
| 6728 | results); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6729 | } |
| 6730 | |
| 6731 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) |
| 6732 | { |
| 6733 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, |
| 6734 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); |
| 6735 | nl80211_reg_rule_sec(tb_rule, results); |
| 6736 | } |
| 6737 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6738 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) |
| 6739 | { |
| 6740 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, |
| 6741 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); |
| 6742 | nl80211_reg_rule_vht(tb_rule, results); |
| 6743 | } |
| 6744 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6745 | return NL_SKIP; |
| 6746 | } |
| 6747 | |
| 6748 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6749 | static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data *drv, |
| 6750 | struct phy_info_arg *results) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6751 | { |
| 6752 | struct nl_msg *msg; |
| 6753 | |
| 6754 | msg = nlmsg_alloc(); |
| 6755 | if (!msg) |
| 6756 | return -ENOMEM; |
| 6757 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6758 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6759 | return send_and_recv_msgs(drv, msg, nl80211_get_reg, results); |
| 6760 | } |
| 6761 | |
| 6762 | |
| 6763 | static struct hostapd_hw_modes * |
| 6764 | wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags) |
| 6765 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6766 | u32 feat; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6767 | struct i802_bss *bss = priv; |
| 6768 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6769 | struct nl_msg *msg; |
| 6770 | struct phy_info_arg result = { |
| 6771 | .num_modes = num_modes, |
| 6772 | .modes = NULL, |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6773 | .last_mode = -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6774 | }; |
| 6775 | |
| 6776 | *num_modes = 0; |
| 6777 | *flags = 0; |
| 6778 | |
| 6779 | msg = nlmsg_alloc(); |
| 6780 | if (!msg) |
| 6781 | return NULL; |
| 6782 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6783 | feat = get_nl80211_protocol_features(drv); |
| 6784 | if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) |
| 6785 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY); |
| 6786 | else |
| 6787 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6788 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 6789 | NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 6790 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 6791 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6792 | |
| 6793 | if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6794 | nl80211_set_regulatory_flags(drv, &result); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 6795 | return wpa_driver_nl80211_postprocess_modes(result.modes, |
| 6796 | num_modes); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6797 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6798 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6799 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6800 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6801 | return NULL; |
| 6802 | } |
| 6803 | |
| 6804 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6805 | static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data *drv, |
| 6806 | const void *data, size_t len, |
| 6807 | int encrypt, int noack) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6808 | { |
| 6809 | __u8 rtap_hdr[] = { |
| 6810 | 0x00, 0x00, /* radiotap version */ |
| 6811 | 0x0e, 0x00, /* radiotap length */ |
| 6812 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ |
| 6813 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ |
| 6814 | 0x00, /* padding */ |
| 6815 | 0x00, 0x00, /* RX and TX flags to indicate that */ |
| 6816 | 0x00, 0x00, /* this is the injected frame directly */ |
| 6817 | }; |
| 6818 | struct iovec iov[2] = { |
| 6819 | { |
| 6820 | .iov_base = &rtap_hdr, |
| 6821 | .iov_len = sizeof(rtap_hdr), |
| 6822 | }, |
| 6823 | { |
| 6824 | .iov_base = (void *) data, |
| 6825 | .iov_len = len, |
| 6826 | } |
| 6827 | }; |
| 6828 | struct msghdr msg = { |
| 6829 | .msg_name = NULL, |
| 6830 | .msg_namelen = 0, |
| 6831 | .msg_iov = iov, |
| 6832 | .msg_iovlen = 2, |
| 6833 | .msg_control = NULL, |
| 6834 | .msg_controllen = 0, |
| 6835 | .msg_flags = 0, |
| 6836 | }; |
| 6837 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6838 | u16 txflags = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6839 | |
| 6840 | if (encrypt) |
| 6841 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; |
| 6842 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 6843 | if (drv->monitor_sock < 0) { |
| 6844 | wpa_printf(MSG_DEBUG, "nl80211: No monitor socket available " |
| 6845 | "for %s", __func__); |
| 6846 | return -1; |
| 6847 | } |
| 6848 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6849 | if (noack) |
| 6850 | txflags |= IEEE80211_RADIOTAP_F_TX_NOACK; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6851 | WPA_PUT_LE16(&rtap_hdr[12], txflags); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6852 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6853 | res = sendmsg(drv->monitor_sock, &msg, 0); |
| 6854 | if (res < 0) { |
| 6855 | wpa_printf(MSG_INFO, "nl80211: sendmsg: %s", strerror(errno)); |
| 6856 | return -1; |
| 6857 | } |
| 6858 | return 0; |
| 6859 | } |
| 6860 | |
| 6861 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6862 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 6863 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6864 | int encrypt, int noack, |
| 6865 | unsigned int freq, int no_cck, |
| 6866 | int offchanok, unsigned int wait_time) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6867 | { |
| 6868 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6869 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6870 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6871 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6872 | if (freq == 0) { |
| 6873 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 6874 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6875 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6876 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6877 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6878 | if (drv->use_monitor) { |
| 6879 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_mntr", |
| 6880 | freq, bss->freq); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6881 | return wpa_driver_nl80211_send_mntr(drv, data, len, |
| 6882 | encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6883 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6884 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6885 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6886 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
| 6887 | &cookie, no_cck, noack, offchanok); |
| 6888 | if (res == 0 && !noack) { |
| 6889 | const struct ieee80211_mgmt *mgmt; |
| 6890 | u16 fc; |
| 6891 | |
| 6892 | mgmt = (const struct ieee80211_mgmt *) data; |
| 6893 | fc = le_to_host16(mgmt->frame_control); |
| 6894 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 6895 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 6896 | wpa_printf(MSG_MSGDUMP, |
| 6897 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 6898 | (long long unsigned int) |
| 6899 | drv->send_action_cookie, |
| 6900 | (long long unsigned int) cookie); |
| 6901 | drv->send_action_cookie = cookie; |
| 6902 | } |
| 6903 | } |
| 6904 | |
| 6905 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6906 | } |
| 6907 | |
| 6908 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6909 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 6910 | size_t data_len, int noack, |
| 6911 | unsigned int freq, int no_cck, |
| 6912 | int offchanok, |
| 6913 | unsigned int wait_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6914 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6915 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6916 | struct ieee80211_mgmt *mgmt; |
| 6917 | int encrypt = 1; |
| 6918 | u16 fc; |
| 6919 | |
| 6920 | mgmt = (struct ieee80211_mgmt *) data; |
| 6921 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6922 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x nlmode=%d", |
| 6923 | noack, freq, no_cck, offchanok, wait_time, fc, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6924 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6925 | if ((is_sta_interface(drv->nlmode) || |
| 6926 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6927 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 6928 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 6929 | /* |
| 6930 | * The use of last_mgmt_freq is a bit of a hack, |
| 6931 | * but it works due to the single-threaded nature |
| 6932 | * of wpa_supplicant. |
| 6933 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6934 | if (freq == 0) { |
| 6935 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 6936 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6937 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6938 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6939 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6940 | data, data_len, NULL, 1, noack, |
| 6941 | 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6942 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6943 | |
| 6944 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6945 | if (freq == 0) { |
| 6946 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 6947 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6948 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6949 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6950 | return nl80211_send_frame_cmd(bss, freq, |
| 6951 | (int) freq == bss->freq ? 0 : |
| 6952 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6953 | data, data_len, |
| 6954 | &drv->send_action_cookie, |
| 6955 | no_cck, noack, offchanok); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6956 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 6957 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6958 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 6959 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 6960 | /* |
| 6961 | * Only one of the authentication frame types is encrypted. |
| 6962 | * In order for static WEP encryption to work properly (i.e., |
| 6963 | * to not encrypt the frame), we need to tell mac80211 about |
| 6964 | * the frames that must not be encrypted. |
| 6965 | */ |
| 6966 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 6967 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 6968 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 6969 | encrypt = 0; |
| 6970 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6971 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6972 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6973 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6974 | noack, freq, no_cck, offchanok, |
| 6975 | wait_time); |
| 6976 | } |
| 6977 | |
| 6978 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6979 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 6980 | int slot, int ht_opmode, int ap_isolate, |
| 6981 | int *basic_rates) |
| 6982 | { |
| 6983 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6984 | struct nl_msg *msg; |
| 6985 | |
| 6986 | msg = nlmsg_alloc(); |
| 6987 | if (!msg) |
| 6988 | return -ENOMEM; |
| 6989 | |
| 6990 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_BSS); |
| 6991 | |
| 6992 | if (cts >= 0) |
| 6993 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts); |
| 6994 | if (preamble >= 0) |
| 6995 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble); |
| 6996 | if (slot >= 0) |
| 6997 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot); |
| 6998 | if (ht_opmode >= 0) |
| 6999 | NLA_PUT_U16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode); |
| 7000 | if (ap_isolate >= 0) |
| 7001 | NLA_PUT_U8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate); |
| 7002 | |
| 7003 | if (basic_rates) { |
| 7004 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 7005 | u8 rates_len = 0; |
| 7006 | int i; |
| 7007 | |
| 7008 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; |
| 7009 | i++) |
| 7010 | rates[rates_len++] = basic_rates[i] / 5; |
| 7011 | |
| 7012 | NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 7013 | } |
| 7014 | |
| 7015 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 7016 | |
| 7017 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7018 | nla_put_failure: |
| 7019 | nlmsg_free(msg); |
| 7020 | return -ENOBUFS; |
| 7021 | } |
| 7022 | |
| 7023 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7024 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 7025 | struct hostapd_acl_params *params) |
| 7026 | { |
| 7027 | struct i802_bss *bss = priv; |
| 7028 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7029 | struct nl_msg *msg; |
| 7030 | struct nlattr *acl; |
| 7031 | unsigned int i; |
| 7032 | int ret = 0; |
| 7033 | |
| 7034 | if (!(drv->capa.max_acl_mac_addrs)) |
| 7035 | return -ENOTSUP; |
| 7036 | |
| 7037 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 7038 | return -ENOTSUP; |
| 7039 | |
| 7040 | msg = nlmsg_alloc(); |
| 7041 | if (!msg) |
| 7042 | return -ENOMEM; |
| 7043 | |
| 7044 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 7045 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 7046 | |
| 7047 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_MAC_ACL); |
| 7048 | |
| 7049 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7050 | |
| 7051 | NLA_PUT_U32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 7052 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 7053 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED); |
| 7054 | |
| 7055 | acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); |
| 7056 | if (acl == NULL) |
| 7057 | goto nla_put_failure; |
| 7058 | |
| 7059 | for (i = 0; i < params->num_mac_acl; i++) |
| 7060 | NLA_PUT(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr); |
| 7061 | |
| 7062 | nla_nest_end(msg, acl); |
| 7063 | |
| 7064 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7065 | msg = NULL; |
| 7066 | if (ret) { |
| 7067 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 7068 | ret, strerror(-ret)); |
| 7069 | } |
| 7070 | |
| 7071 | nla_put_failure: |
| 7072 | nlmsg_free(msg); |
| 7073 | |
| 7074 | return ret; |
| 7075 | } |
| 7076 | |
| 7077 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7078 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 7079 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7080 | { |
| 7081 | struct i802_bss *bss = priv; |
| 7082 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7083 | struct nl_msg *msg; |
| 7084 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 7085 | int ret; |
| 7086 | int beacon_set; |
| 7087 | int ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7088 | int num_suites; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7089 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7090 | u32 ver; |
| 7091 | |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7092 | beacon_set = bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7093 | |
| 7094 | msg = nlmsg_alloc(); |
| 7095 | if (!msg) |
| 7096 | return -ENOMEM; |
| 7097 | |
| 7098 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 7099 | beacon_set); |
| 7100 | if (beacon_set) |
| 7101 | cmd = NL80211_CMD_SET_BEACON; |
| 7102 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7103 | nl80211_cmd(drv, msg, 0, cmd); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7104 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 7105 | params->head, params->head_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7106 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, params->head); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7107 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 7108 | params->tail, params->tail_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7109 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, params->tail); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7110 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7111 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7112 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7113 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7114 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7115 | NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7116 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 7117 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7118 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 7119 | params->ssid); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7120 | if (params->proberesp && params->proberesp_len) { |
| 7121 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 7122 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7123 | NLA_PUT(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 7124 | params->proberesp); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7125 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7126 | switch (params->hide_ssid) { |
| 7127 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7128 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
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_NOT_IN_USE); |
| 7131 | break; |
| 7132 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7133 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7134 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 7135 | NL80211_HIDDEN_SSID_ZERO_LEN); |
| 7136 | break; |
| 7137 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7138 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7139 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 7140 | NL80211_HIDDEN_SSID_ZERO_CONTENTS); |
| 7141 | break; |
| 7142 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7143 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7144 | if (params->privacy) |
| 7145 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7146 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7147 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 7148 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 7149 | /* Leave out the attribute */ |
| 7150 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) |
| 7151 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, |
| 7152 | NL80211_AUTHTYPE_SHARED_KEY); |
| 7153 | else |
| 7154 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, |
| 7155 | NL80211_AUTHTYPE_OPEN_SYSTEM); |
| 7156 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7157 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7158 | ver = 0; |
| 7159 | if (params->wpa_version & WPA_PROTO_WPA) |
| 7160 | ver |= NL80211_WPA_VERSION_1; |
| 7161 | if (params->wpa_version & WPA_PROTO_RSN) |
| 7162 | ver |= NL80211_WPA_VERSION_2; |
| 7163 | if (ver) |
| 7164 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); |
| 7165 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7166 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 7167 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7168 | num_suites = 0; |
| 7169 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 7170 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 7171 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 7172 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
| 7173 | if (num_suites) { |
| 7174 | NLA_PUT(msg, NL80211_ATTR_AKM_SUITES, |
| 7175 | num_suites * sizeof(u32), suites); |
| 7176 | } |
| 7177 | |
| 7178 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X && |
| 7179 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) |
| 7180 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT); |
| 7181 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7182 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 7183 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7184 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 7185 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7186 | if (num_suites) { |
| 7187 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 7188 | num_suites * sizeof(u32), suites); |
| 7189 | } |
| 7190 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7191 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 7192 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7193 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
| 7194 | if (suite) |
| 7195 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7196 | |
| 7197 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7198 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 7199 | params->beacon_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7200 | NLA_PUT(msg, NL80211_ATTR_IE, wpabuf_len(params->beacon_ies), |
| 7201 | wpabuf_head(params->beacon_ies)); |
| 7202 | } |
| 7203 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7204 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 7205 | params->proberesp_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7206 | NLA_PUT(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 7207 | wpabuf_len(params->proberesp_ies), |
| 7208 | wpabuf_head(params->proberesp_ies)); |
| 7209 | } |
| 7210 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7211 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 7212 | params->assocresp_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7213 | NLA_PUT(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 7214 | wpabuf_len(params->assocresp_ies), |
| 7215 | wpabuf_head(params->assocresp_ies)); |
| 7216 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7217 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7218 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 7219 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 7220 | params->ap_max_inactivity); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7221 | NLA_PUT_U16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 7222 | params->ap_max_inactivity); |
| 7223 | } |
| 7224 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7225 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7226 | if (ret) { |
| 7227 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 7228 | ret, strerror(-ret)); |
| 7229 | } else { |
| 7230 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7231 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 7232 | params->short_slot_time, params->ht_opmode, |
| 7233 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7234 | } |
| 7235 | return ret; |
| 7236 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7237 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7238 | return -ENOBUFS; |
| 7239 | } |
| 7240 | |
| 7241 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7242 | static int nl80211_put_freq_params(struct nl_msg *msg, |
| 7243 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7244 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7245 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); |
| 7246 | if (freq->vht_enabled) { |
| 7247 | switch (freq->bandwidth) { |
| 7248 | case 20: |
| 7249 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7250 | NL80211_CHAN_WIDTH_20); |
| 7251 | break; |
| 7252 | case 40: |
| 7253 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7254 | NL80211_CHAN_WIDTH_40); |
| 7255 | break; |
| 7256 | case 80: |
| 7257 | if (freq->center_freq2) |
| 7258 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7259 | NL80211_CHAN_WIDTH_80P80); |
| 7260 | else |
| 7261 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7262 | NL80211_CHAN_WIDTH_80); |
| 7263 | break; |
| 7264 | case 160: |
| 7265 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 7266 | NL80211_CHAN_WIDTH_160); |
| 7267 | break; |
| 7268 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7269 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7270 | } |
| 7271 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); |
| 7272 | if (freq->center_freq2) |
| 7273 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 7274 | freq->center_freq2); |
| 7275 | } else if (freq->ht_enabled) { |
| 7276 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7277 | case -1: |
| 7278 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 7279 | NL80211_CHAN_HT40MINUS); |
| 7280 | break; |
| 7281 | case 1: |
| 7282 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 7283 | NL80211_CHAN_HT40PLUS); |
| 7284 | break; |
| 7285 | default: |
| 7286 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 7287 | NL80211_CHAN_HT20); |
| 7288 | break; |
| 7289 | } |
| 7290 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7291 | return 0; |
| 7292 | |
| 7293 | nla_put_failure: |
| 7294 | return -ENOBUFS; |
| 7295 | } |
| 7296 | |
| 7297 | |
| 7298 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
| 7299 | struct hostapd_freq_params *freq) |
| 7300 | { |
| 7301 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7302 | struct nl_msg *msg; |
| 7303 | int ret; |
| 7304 | |
| 7305 | wpa_printf(MSG_DEBUG, |
| 7306 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 7307 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7308 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7309 | msg = nlmsg_alloc(); |
| 7310 | if (!msg) |
| 7311 | return -1; |
| 7312 | |
| 7313 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
| 7314 | |
| 7315 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7316 | if (nl80211_put_freq_params(msg, freq) < 0) |
| 7317 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7318 | |
| 7319 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7320 | msg = NULL; |
| 7321 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7322 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7323 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7324 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7325 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7326 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7327 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7328 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7329 | return -1; |
| 7330 | } |
| 7331 | |
| 7332 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7333 | static u32 sta_flags_nl80211(int flags) |
| 7334 | { |
| 7335 | u32 f = 0; |
| 7336 | |
| 7337 | if (flags & WPA_STA_AUTHORIZED) |
| 7338 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 7339 | if (flags & WPA_STA_WMM) |
| 7340 | f |= BIT(NL80211_STA_FLAG_WME); |
| 7341 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 7342 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 7343 | if (flags & WPA_STA_MFP) |
| 7344 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 7345 | if (flags & WPA_STA_TDLS_PEER) |
| 7346 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 7347 | |
| 7348 | return f; |
| 7349 | } |
| 7350 | |
| 7351 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7352 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 7353 | struct hostapd_sta_add_params *params) |
| 7354 | { |
| 7355 | struct i802_bss *bss = priv; |
| 7356 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7357 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7358 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7359 | int ret = -ENOBUFS; |
| 7360 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7361 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 7362 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7363 | return -EOPNOTSUPP; |
| 7364 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7365 | msg = nlmsg_alloc(); |
| 7366 | if (!msg) |
| 7367 | return -ENOMEM; |
| 7368 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7369 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 7370 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7371 | nl80211_cmd(drv, msg, 0, params->set ? NL80211_CMD_SET_STATION : |
| 7372 | NL80211_CMD_NEW_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7373 | |
| 7374 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 7375 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7376 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len, |
| 7377 | params->supp_rates); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7378 | wpa_hexdump(MSG_DEBUG, " * supported rates", params->supp_rates, |
| 7379 | params->supp_rates_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7380 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 7381 | if (params->aid) { |
| 7382 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 7383 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid); |
| 7384 | } else { |
| 7385 | /* |
| 7386 | * cfg80211 validates that AID is non-zero, so we have |
| 7387 | * to make this a non-zero value for the TDLS case where |
| 7388 | * a dummy STA entry is used for now. |
| 7389 | */ |
| 7390 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); |
| 7391 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, 1); |
| 7392 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7393 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 7394 | params->listen_interval); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7395 | NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 7396 | params->listen_interval); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7397 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 7398 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
| 7399 | NLA_PUT_U16(msg, NL80211_ATTR_PEER_AID, params->aid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7400 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7401 | if (params->ht_capabilities) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7402 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 7403 | (u8 *) params->ht_capabilities, |
| 7404 | sizeof(*params->ht_capabilities)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7405 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, |
| 7406 | sizeof(*params->ht_capabilities), |
| 7407 | params->ht_capabilities); |
| 7408 | } |
| 7409 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7410 | if (params->vht_capabilities) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7411 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 7412 | (u8 *) params->vht_capabilities, |
| 7413 | sizeof(*params->vht_capabilities)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7414 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 7415 | sizeof(*params->vht_capabilities), |
| 7416 | params->vht_capabilities); |
| 7417 | } |
| 7418 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 7419 | if (params->vht_opmode_enabled) { |
| 7420 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
| 7421 | NLA_PUT_U8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 7422 | params->vht_opmode); |
| 7423 | } |
| 7424 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7425 | wpa_printf(MSG_DEBUG, " * capability=0x%x", params->capability); |
| 7426 | NLA_PUT_U16(msg, NL80211_ATTR_STA_CAPABILITY, params->capability); |
| 7427 | |
| 7428 | if (params->ext_capab) { |
| 7429 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 7430 | params->ext_capab, params->ext_capab_len); |
| 7431 | NLA_PUT(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 7432 | params->ext_capab_len, params->ext_capab); |
| 7433 | } |
| 7434 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 7435 | if (params->supp_channels) { |
| 7436 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 7437 | params->supp_channels, params->supp_channels_len); |
| 7438 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 7439 | params->supp_channels_len, params->supp_channels); |
| 7440 | } |
| 7441 | |
| 7442 | if (params->supp_oper_classes) { |
| 7443 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 7444 | params->supp_oper_classes, |
| 7445 | params->supp_oper_classes_len); |
| 7446 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 7447 | params->supp_oper_classes_len, |
| 7448 | params->supp_oper_classes); |
| 7449 | } |
| 7450 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7451 | os_memset(&upd, 0, sizeof(upd)); |
| 7452 | upd.mask = sta_flags_nl80211(params->flags); |
| 7453 | upd.set = upd.mask; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7454 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 7455 | upd.set, upd.mask); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7456 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 7457 | |
| 7458 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7459 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 7460 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7461 | if (!wme) |
| 7462 | goto nla_put_failure; |
| 7463 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7464 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7465 | NLA_PUT_U8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7466 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7467 | NLA_PUT_U8(msg, NL80211_STA_WME_MAX_SP, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 7468 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7469 | WMM_QOSINFO_STA_SP_MASK); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7470 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7471 | } |
| 7472 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7473 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7474 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7475 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7476 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 7477 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 7478 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7479 | if (ret == -EEXIST) |
| 7480 | ret = 0; |
| 7481 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7482 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7483 | return ret; |
| 7484 | } |
| 7485 | |
| 7486 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7487 | 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] | 7488 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7489 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7490 | struct nl_msg *msg; |
| 7491 | int ret; |
| 7492 | |
| 7493 | msg = nlmsg_alloc(); |
| 7494 | if (!msg) |
| 7495 | return -ENOMEM; |
| 7496 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7497 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7498 | |
| 7499 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 7500 | if_nametoindex(bss->ifname)); |
| 7501 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7502 | |
| 7503 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7504 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 7505 | " --> %d (%s)", |
| 7506 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7507 | if (ret == -ENOENT) |
| 7508 | return 0; |
| 7509 | return ret; |
| 7510 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7511 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7512 | return -ENOBUFS; |
| 7513 | } |
| 7514 | |
| 7515 | |
| 7516 | static void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, |
| 7517 | int ifidx) |
| 7518 | { |
| 7519 | struct nl_msg *msg; |
| 7520 | |
| 7521 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 7522 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7523 | /* stop listening for EAPOL on this interface */ |
| 7524 | del_ifidx(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7525 | |
| 7526 | msg = nlmsg_alloc(); |
| 7527 | if (!msg) |
| 7528 | goto nla_put_failure; |
| 7529 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7530 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7531 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); |
| 7532 | |
| 7533 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 7534 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7535 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7536 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7537 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7538 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 7539 | } |
| 7540 | |
| 7541 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7542 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 7543 | { |
| 7544 | switch (mode) { |
| 7545 | case NL80211_IFTYPE_ADHOC: |
| 7546 | return "ADHOC"; |
| 7547 | case NL80211_IFTYPE_STATION: |
| 7548 | return "STATION"; |
| 7549 | case NL80211_IFTYPE_AP: |
| 7550 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 7551 | case NL80211_IFTYPE_AP_VLAN: |
| 7552 | return "AP_VLAN"; |
| 7553 | case NL80211_IFTYPE_WDS: |
| 7554 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7555 | case NL80211_IFTYPE_MONITOR: |
| 7556 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 7557 | case NL80211_IFTYPE_MESH_POINT: |
| 7558 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7559 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7560 | return "P2P_CLIENT"; |
| 7561 | case NL80211_IFTYPE_P2P_GO: |
| 7562 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7563 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7564 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7565 | default: |
| 7566 | return "unknown"; |
| 7567 | } |
| 7568 | } |
| 7569 | |
| 7570 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7571 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 7572 | const char *ifname, |
| 7573 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7574 | const u8 *addr, int wds, |
| 7575 | int (*handler)(struct nl_msg *, void *), |
| 7576 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7577 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7578 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7579 | int ifidx; |
| 7580 | int ret = -ENOBUFS; |
| 7581 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7582 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 7583 | iftype, nl80211_iftype_str(iftype)); |
| 7584 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7585 | msg = nlmsg_alloc(); |
| 7586 | if (!msg) |
| 7587 | return -1; |
| 7588 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7589 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_INTERFACE); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7590 | if (nl80211_set_iface_id(msg, drv->first_bss) < 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7591 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7592 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname); |
| 7593 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype); |
| 7594 | |
| 7595 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7596 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7597 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7598 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7599 | if (!flags) |
| 7600 | goto nla_put_failure; |
| 7601 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7602 | NLA_PUT_FLAG(msg, NL80211_MNTR_FLAG_COOK_FRAMES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7603 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7604 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7605 | } else if (wds) { |
| 7606 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, wds); |
| 7607 | } |
| 7608 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7609 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7610 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7611 | if (ret) { |
| 7612 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7613 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7614 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 7615 | ifname, ret, strerror(-ret)); |
| 7616 | return ret; |
| 7617 | } |
| 7618 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7619 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 7620 | return 0; |
| 7621 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7622 | ifidx = if_nametoindex(ifname); |
| 7623 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 7624 | ifname, ifidx); |
| 7625 | |
| 7626 | if (ifidx <= 0) |
| 7627 | return -1; |
| 7628 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7629 | /* start listening for EAPOL on this interface */ |
| 7630 | add_ifidx(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7631 | |
| 7632 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7633 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7634 | nl80211_remove_iface(drv, ifidx); |
| 7635 | return -1; |
| 7636 | } |
| 7637 | |
| 7638 | return ifidx; |
| 7639 | } |
| 7640 | |
| 7641 | |
| 7642 | static int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 7643 | const char *ifname, enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7644 | const u8 *addr, int wds, |
| 7645 | int (*handler)(struct nl_msg *, void *), |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7646 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7647 | { |
| 7648 | int ret; |
| 7649 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7650 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 7651 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7652 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7653 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7654 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7655 | if (use_existing) { |
| 7656 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 7657 | ifname); |
| 7658 | return -ENFILE; |
| 7659 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7660 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 7661 | |
| 7662 | /* Try to remove the interface that was already there. */ |
| 7663 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 7664 | |
| 7665 | /* Try to create the interface again */ |
| 7666 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7667 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7668 | } |
| 7669 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7670 | if (ret >= 0 && is_p2p_net_interface(iftype)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7671 | nl80211_disable_11b_rates(drv, ret, 1); |
| 7672 | |
| 7673 | return ret; |
| 7674 | } |
| 7675 | |
| 7676 | |
| 7677 | static void handle_tx_callback(void *ctx, u8 *buf, size_t len, int ok) |
| 7678 | { |
| 7679 | struct ieee80211_hdr *hdr; |
| 7680 | u16 fc; |
| 7681 | union wpa_event_data event; |
| 7682 | |
| 7683 | hdr = (struct ieee80211_hdr *) buf; |
| 7684 | fc = le_to_host16(hdr->frame_control); |
| 7685 | |
| 7686 | os_memset(&event, 0, sizeof(event)); |
| 7687 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); |
| 7688 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); |
| 7689 | event.tx_status.dst = hdr->addr1; |
| 7690 | event.tx_status.data = buf; |
| 7691 | event.tx_status.data_len = len; |
| 7692 | event.tx_status.ack = ok; |
| 7693 | wpa_supplicant_event(ctx, EVENT_TX_STATUS, &event); |
| 7694 | } |
| 7695 | |
| 7696 | |
| 7697 | static void from_unknown_sta(struct wpa_driver_nl80211_data *drv, |
| 7698 | u8 *buf, size_t len) |
| 7699 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7700 | struct ieee80211_hdr *hdr = (void *)buf; |
| 7701 | u16 fc; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7702 | union wpa_event_data event; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7703 | |
| 7704 | if (len < sizeof(*hdr)) |
| 7705 | return; |
| 7706 | |
| 7707 | fc = le_to_host16(hdr->frame_control); |
| 7708 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7709 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7710 | event.rx_from_unknown.bssid = get_hdr_bssid(hdr, len); |
| 7711 | event.rx_from_unknown.addr = hdr->addr2; |
| 7712 | event.rx_from_unknown.wds = (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) == |
| 7713 | (WLAN_FC_FROMDS | WLAN_FC_TODS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7714 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); |
| 7715 | } |
| 7716 | |
| 7717 | |
| 7718 | static void handle_frame(struct wpa_driver_nl80211_data *drv, |
| 7719 | u8 *buf, size_t len, int datarate, int ssi_signal) |
| 7720 | { |
| 7721 | struct ieee80211_hdr *hdr; |
| 7722 | u16 fc; |
| 7723 | union wpa_event_data event; |
| 7724 | |
| 7725 | hdr = (struct ieee80211_hdr *) buf; |
| 7726 | fc = le_to_host16(hdr->frame_control); |
| 7727 | |
| 7728 | switch (WLAN_FC_GET_TYPE(fc)) { |
| 7729 | case WLAN_FC_TYPE_MGMT: |
| 7730 | os_memset(&event, 0, sizeof(event)); |
| 7731 | event.rx_mgmt.frame = buf; |
| 7732 | event.rx_mgmt.frame_len = len; |
| 7733 | event.rx_mgmt.datarate = datarate; |
| 7734 | event.rx_mgmt.ssi_signal = ssi_signal; |
| 7735 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 7736 | break; |
| 7737 | case WLAN_FC_TYPE_CTRL: |
| 7738 | /* can only get here with PS-Poll frames */ |
| 7739 | wpa_printf(MSG_DEBUG, "CTRL"); |
| 7740 | from_unknown_sta(drv, buf, len); |
| 7741 | break; |
| 7742 | case WLAN_FC_TYPE_DATA: |
| 7743 | from_unknown_sta(drv, buf, len); |
| 7744 | break; |
| 7745 | } |
| 7746 | } |
| 7747 | |
| 7748 | |
| 7749 | static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx) |
| 7750 | { |
| 7751 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 7752 | int len; |
| 7753 | unsigned char buf[3000]; |
| 7754 | struct ieee80211_radiotap_iterator iter; |
| 7755 | int ret; |
| 7756 | int datarate = 0, ssi_signal = 0; |
| 7757 | int injected = 0, failed = 0, rxflags = 0; |
| 7758 | |
| 7759 | len = recv(sock, buf, sizeof(buf), 0); |
| 7760 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7761 | wpa_printf(MSG_ERROR, "nl80211: Monitor socket recv failed: %s", |
| 7762 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7763 | return; |
| 7764 | } |
| 7765 | |
| 7766 | if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7767 | wpa_printf(MSG_INFO, "nl80211: received invalid radiotap frame"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7768 | return; |
| 7769 | } |
| 7770 | |
| 7771 | while (1) { |
| 7772 | ret = ieee80211_radiotap_iterator_next(&iter); |
| 7773 | if (ret == -ENOENT) |
| 7774 | break; |
| 7775 | if (ret) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7776 | wpa_printf(MSG_INFO, "nl80211: received invalid radiotap frame (%d)", |
| 7777 | ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7778 | return; |
| 7779 | } |
| 7780 | switch (iter.this_arg_index) { |
| 7781 | case IEEE80211_RADIOTAP_FLAGS: |
| 7782 | if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS) |
| 7783 | len -= 4; |
| 7784 | break; |
| 7785 | case IEEE80211_RADIOTAP_RX_FLAGS: |
| 7786 | rxflags = 1; |
| 7787 | break; |
| 7788 | case IEEE80211_RADIOTAP_TX_FLAGS: |
| 7789 | injected = 1; |
| 7790 | failed = le_to_host16((*(uint16_t *) iter.this_arg)) & |
| 7791 | IEEE80211_RADIOTAP_F_TX_FAIL; |
| 7792 | break; |
| 7793 | case IEEE80211_RADIOTAP_DATA_RETRIES: |
| 7794 | break; |
| 7795 | case IEEE80211_RADIOTAP_CHANNEL: |
| 7796 | /* TODO: convert from freq/flags to channel number */ |
| 7797 | break; |
| 7798 | case IEEE80211_RADIOTAP_RATE: |
| 7799 | datarate = *iter.this_arg * 5; |
| 7800 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7801 | case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: |
| 7802 | ssi_signal = (s8) *iter.this_arg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7803 | break; |
| 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | if (rxflags && injected) |
| 7808 | return; |
| 7809 | |
| 7810 | if (!injected) |
| 7811 | handle_frame(drv, buf + iter.max_length, |
| 7812 | len - iter.max_length, datarate, ssi_signal); |
| 7813 | else |
| 7814 | handle_tx_callback(drv->ctx, buf + iter.max_length, |
| 7815 | len - iter.max_length, !failed); |
| 7816 | } |
| 7817 | |
| 7818 | |
| 7819 | /* |
| 7820 | * we post-process the filter code later and rewrite |
| 7821 | * this to the offset to the last instruction |
| 7822 | */ |
| 7823 | #define PASS 0xFF |
| 7824 | #define FAIL 0xFE |
| 7825 | |
| 7826 | static struct sock_filter msock_filter_insns[] = { |
| 7827 | /* |
| 7828 | * do a little-endian load of the radiotap length field |
| 7829 | */ |
| 7830 | /* load lower byte into A */ |
| 7831 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), |
| 7832 | /* put it into X (== index register) */ |
| 7833 | BPF_STMT(BPF_MISC| BPF_TAX, 0), |
| 7834 | /* load upper byte into A */ |
| 7835 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 3), |
| 7836 | /* left-shift it by 8 */ |
| 7837 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8), |
| 7838 | /* or with X */ |
| 7839 | BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0), |
| 7840 | /* put result into X */ |
| 7841 | BPF_STMT(BPF_MISC| BPF_TAX, 0), |
| 7842 | |
| 7843 | /* |
| 7844 | * Allow management frames through, this also gives us those |
| 7845 | * management frames that we sent ourselves with status |
| 7846 | */ |
| 7847 | /* load the lower byte of the IEEE 802.11 frame control field */ |
| 7848 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 7849 | /* mask off frame type and version */ |
| 7850 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF), |
| 7851 | /* accept frame if it's both 0, fall through otherwise */ |
| 7852 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0), |
| 7853 | |
| 7854 | /* |
| 7855 | * TODO: add a bit to radiotap RX flags that indicates |
| 7856 | * that the sending station is not associated, then |
| 7857 | * add a filter here that filters on our DA and that flag |
| 7858 | * to allow us to deauth frames to that bad station. |
| 7859 | * |
| 7860 | * For now allow all To DS data frames through. |
| 7861 | */ |
| 7862 | /* load the IEEE 802.11 frame control field */ |
| 7863 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 0), |
| 7864 | /* mask off frame type, version and DS status */ |
| 7865 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0F03), |
| 7866 | /* accept frame if version 0, type 2 and To DS, fall through otherwise |
| 7867 | */ |
| 7868 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0801, PASS, 0), |
| 7869 | |
| 7870 | #if 0 |
| 7871 | /* |
| 7872 | * drop non-data frames |
| 7873 | */ |
| 7874 | /* load the lower byte of the frame control field */ |
| 7875 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 7876 | /* mask off QoS bit */ |
| 7877 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0c), |
| 7878 | /* drop non-data frames */ |
| 7879 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 8, 0, FAIL), |
| 7880 | #endif |
| 7881 | /* load the upper byte of the frame control field */ |
| 7882 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), |
| 7883 | /* mask off toDS/fromDS */ |
| 7884 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x03), |
| 7885 | /* accept WDS frames */ |
| 7886 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 3, PASS, 0), |
| 7887 | |
| 7888 | /* |
| 7889 | * add header length to index |
| 7890 | */ |
| 7891 | /* load the lower byte of the frame control field */ |
| 7892 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 7893 | /* mask off QoS bit */ |
| 7894 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x80), |
| 7895 | /* right shift it by 6 to give 0 or 2 */ |
| 7896 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 6), |
| 7897 | /* add data frame header length */ |
| 7898 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 24), |
| 7899 | /* add index, was start of 802.11 header */ |
| 7900 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 7901 | /* move to index, now start of LL header */ |
| 7902 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 7903 | |
| 7904 | /* |
| 7905 | * Accept empty data frames, we use those for |
| 7906 | * polling activity. |
| 7907 | */ |
| 7908 | BPF_STMT(BPF_LD | BPF_W | BPF_LEN, 0), |
| 7909 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0), |
| 7910 | |
| 7911 | /* |
| 7912 | * Accept EAPOL frames |
| 7913 | */ |
| 7914 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), |
| 7915 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL), |
| 7916 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 4), |
| 7917 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL), |
| 7918 | |
| 7919 | /* keep these last two statements or change the code below */ |
| 7920 | /* return 0 == "DROP" */ |
| 7921 | BPF_STMT(BPF_RET | BPF_K, 0), |
| 7922 | /* return ~0 == "keep all" */ |
| 7923 | BPF_STMT(BPF_RET | BPF_K, ~0), |
| 7924 | }; |
| 7925 | |
| 7926 | static struct sock_fprog msock_filter = { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7927 | .len = ARRAY_SIZE(msock_filter_insns), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7928 | .filter = msock_filter_insns, |
| 7929 | }; |
| 7930 | |
| 7931 | |
| 7932 | static int add_monitor_filter(int s) |
| 7933 | { |
| 7934 | int idx; |
| 7935 | |
| 7936 | /* rewrite all PASS/FAIL jump offsets */ |
| 7937 | for (idx = 0; idx < msock_filter.len; idx++) { |
| 7938 | struct sock_filter *insn = &msock_filter_insns[idx]; |
| 7939 | |
| 7940 | if (BPF_CLASS(insn->code) == BPF_JMP) { |
| 7941 | if (insn->code == (BPF_JMP|BPF_JA)) { |
| 7942 | if (insn->k == PASS) |
| 7943 | insn->k = msock_filter.len - idx - 2; |
| 7944 | else if (insn->k == FAIL) |
| 7945 | insn->k = msock_filter.len - idx - 3; |
| 7946 | } |
| 7947 | |
| 7948 | if (insn->jt == PASS) |
| 7949 | insn->jt = msock_filter.len - idx - 2; |
| 7950 | else if (insn->jt == FAIL) |
| 7951 | insn->jt = msock_filter.len - idx - 3; |
| 7952 | |
| 7953 | if (insn->jf == PASS) |
| 7954 | insn->jf = msock_filter.len - idx - 2; |
| 7955 | else if (insn->jf == FAIL) |
| 7956 | insn->jf = msock_filter.len - idx - 3; |
| 7957 | } |
| 7958 | } |
| 7959 | |
| 7960 | if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, |
| 7961 | &msock_filter, sizeof(msock_filter))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7962 | wpa_printf(MSG_ERROR, "nl80211: setsockopt(SO_ATTACH_FILTER) failed: %s", |
| 7963 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7964 | return -1; |
| 7965 | } |
| 7966 | |
| 7967 | return 0; |
| 7968 | } |
| 7969 | |
| 7970 | |
| 7971 | static void nl80211_remove_monitor_interface( |
| 7972 | struct wpa_driver_nl80211_data *drv) |
| 7973 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7974 | if (drv->monitor_refcount > 0) |
| 7975 | drv->monitor_refcount--; |
| 7976 | wpa_printf(MSG_DEBUG, "nl80211: Remove monitor interface: refcount=%d", |
| 7977 | drv->monitor_refcount); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7978 | if (drv->monitor_refcount > 0) |
| 7979 | return; |
| 7980 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7981 | if (drv->monitor_ifidx >= 0) { |
| 7982 | nl80211_remove_iface(drv, drv->monitor_ifidx); |
| 7983 | drv->monitor_ifidx = -1; |
| 7984 | } |
| 7985 | if (drv->monitor_sock >= 0) { |
| 7986 | eloop_unregister_read_sock(drv->monitor_sock); |
| 7987 | close(drv->monitor_sock); |
| 7988 | drv->monitor_sock = -1; |
| 7989 | } |
| 7990 | } |
| 7991 | |
| 7992 | |
| 7993 | static int |
| 7994 | nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) |
| 7995 | { |
| 7996 | char buf[IFNAMSIZ]; |
| 7997 | struct sockaddr_ll ll; |
| 7998 | int optval; |
| 7999 | socklen_t optlen; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8000 | |
| 8001 | if (drv->monitor_ifidx >= 0) { |
| 8002 | drv->monitor_refcount++; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8003 | wpa_printf(MSG_DEBUG, "nl80211: Re-use existing monitor interface: refcount=%d", |
| 8004 | drv->monitor_refcount); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8005 | return 0; |
| 8006 | } |
| 8007 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8008 | if (os_strncmp(drv->first_bss->ifname, "p2p-", 4) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8009 | /* |
| 8010 | * P2P interface name is of the format p2p-%s-%d. For monitor |
| 8011 | * interface name corresponding to P2P GO, replace "p2p-" with |
| 8012 | * "mon-" to retain the same interface name length and to |
| 8013 | * indicate that it is a monitor interface. |
| 8014 | */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8015 | snprintf(buf, IFNAMSIZ, "mon-%s", drv->first_bss->ifname + 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8016 | } else { |
| 8017 | /* Non-P2P interface with AP functionality. */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8018 | snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8019 | } |
| 8020 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8021 | buf[IFNAMSIZ - 1] = '\0'; |
| 8022 | |
| 8023 | drv->monitor_ifidx = |
| 8024 | nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8025 | 0, NULL, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8026 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 8027 | if (drv->monitor_ifidx == -EOPNOTSUPP) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8028 | /* |
| 8029 | * This is backward compatibility for a few versions of |
| 8030 | * the kernel only that didn't advertise the right |
| 8031 | * attributes for the only driver that then supported |
| 8032 | * AP mode w/o monitor -- ath6kl. |
| 8033 | */ |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 8034 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support " |
| 8035 | "monitor interface type - try to run without it"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8036 | drv->device_ap_sme = 1; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 8037 | } |
| 8038 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8039 | if (drv->monitor_ifidx < 0) |
| 8040 | return -1; |
| 8041 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8042 | if (linux_set_iface_flags(drv->global->ioctl_sock, buf, 1)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8043 | goto error; |
| 8044 | |
| 8045 | memset(&ll, 0, sizeof(ll)); |
| 8046 | ll.sll_family = AF_PACKET; |
| 8047 | ll.sll_ifindex = drv->monitor_ifidx; |
| 8048 | drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 8049 | if (drv->monitor_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8050 | wpa_printf(MSG_ERROR, "nl80211: socket[PF_PACKET,SOCK_RAW] failed: %s", |
| 8051 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8052 | goto error; |
| 8053 | } |
| 8054 | |
| 8055 | if (add_monitor_filter(drv->monitor_sock)) { |
| 8056 | wpa_printf(MSG_INFO, "Failed to set socket filter for monitor " |
| 8057 | "interface; do filtering in user space"); |
| 8058 | /* This works, but will cost in performance. */ |
| 8059 | } |
| 8060 | |
| 8061 | if (bind(drv->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8062 | wpa_printf(MSG_ERROR, "nl80211: monitor socket bind failed: %s", |
| 8063 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8064 | goto error; |
| 8065 | } |
| 8066 | |
| 8067 | optlen = sizeof(optval); |
| 8068 | optval = 20; |
| 8069 | if (setsockopt |
| 8070 | (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8071 | wpa_printf(MSG_ERROR, "nl80211: Failed to set socket priority: %s", |
| 8072 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8073 | goto error; |
| 8074 | } |
| 8075 | |
| 8076 | if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read, |
| 8077 | drv, NULL)) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8078 | wpa_printf(MSG_INFO, "nl80211: Could not register monitor read socket"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8079 | goto error; |
| 8080 | } |
| 8081 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8082 | drv->monitor_refcount++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8083 | return 0; |
| 8084 | error: |
| 8085 | nl80211_remove_monitor_interface(drv); |
| 8086 | return -1; |
| 8087 | } |
| 8088 | |
| 8089 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8090 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 8091 | { |
| 8092 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8093 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8094 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 8095 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8096 | |
| 8097 | /* |
| 8098 | * Disable Probe Request reporting unless we need it in this way for |
| 8099 | * devices that include the AP SME, in the other case (unless using |
| 8100 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 8101 | */ |
| 8102 | if (!drv->device_ap_sme) |
| 8103 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 8104 | |
| 8105 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 8106 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 8107 | return -1; |
| 8108 | |
| 8109 | if (drv->device_ap_sme && !drv->use_monitor) |
| 8110 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 8111 | return -1; |
| 8112 | |
| 8113 | if (!drv->device_ap_sme && drv->use_monitor && |
| 8114 | nl80211_create_monitor_interface(drv) && |
| 8115 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8116 | return -1; |
| 8117 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8118 | if (drv->device_ap_sme && |
| 8119 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 8120 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 8121 | "Probe Request frame reporting in AP mode"); |
| 8122 | /* Try to survive without this */ |
| 8123 | } |
| 8124 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8125 | return 0; |
| 8126 | } |
| 8127 | |
| 8128 | |
| 8129 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 8130 | { |
| 8131 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8132 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8133 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 8134 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8135 | if (drv->device_ap_sme) { |
| 8136 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 8137 | if (!drv->use_monitor) |
| 8138 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 8139 | } else if (drv->use_monitor) |
| 8140 | nl80211_remove_monitor_interface(drv); |
| 8141 | else |
| 8142 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 8143 | |
| 8144 | bss->beacon_set = 0; |
| 8145 | } |
| 8146 | |
| 8147 | |
| 8148 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 8149 | const u8 *addr, const u8 *data, |
| 8150 | size_t data_len) |
| 8151 | { |
| 8152 | struct sockaddr_ll ll; |
| 8153 | int ret; |
| 8154 | |
| 8155 | if (bss->drv->eapol_tx_sock < 0) { |
| 8156 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 8157 | return -1; |
| 8158 | } |
| 8159 | |
| 8160 | os_memset(&ll, 0, sizeof(ll)); |
| 8161 | ll.sll_family = AF_PACKET; |
| 8162 | ll.sll_ifindex = bss->ifindex; |
| 8163 | ll.sll_protocol = htons(ETH_P_PAE); |
| 8164 | ll.sll_halen = ETH_ALEN; |
| 8165 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 8166 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 8167 | (struct sockaddr *) &ll, sizeof(ll)); |
| 8168 | if (ret < 0) |
| 8169 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 8170 | strerror(errno)); |
| 8171 | |
| 8172 | return ret; |
| 8173 | } |
| 8174 | |
| 8175 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8176 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 8177 | |
| 8178 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 8179 | void *priv, const u8 *addr, const u8 *data, |
| 8180 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 8181 | { |
| 8182 | struct i802_bss *bss = priv; |
| 8183 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8184 | struct ieee80211_hdr *hdr; |
| 8185 | size_t len; |
| 8186 | u8 *pos; |
| 8187 | int res; |
| 8188 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 8189 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8190 | if (drv->device_ap_sme || !drv->use_monitor) |
| 8191 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 8192 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8193 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 8194 | data_len; |
| 8195 | hdr = os_zalloc(len); |
| 8196 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8197 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 8198 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8199 | return -1; |
| 8200 | } |
| 8201 | |
| 8202 | hdr->frame_control = |
| 8203 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 8204 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 8205 | if (encrypt) |
| 8206 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 8207 | if (qos) { |
| 8208 | hdr->frame_control |= |
| 8209 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 8210 | } |
| 8211 | |
| 8212 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 8213 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 8214 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 8215 | pos = (u8 *) (hdr + 1); |
| 8216 | |
| 8217 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8218 | /* Set highest priority in QoS header */ |
| 8219 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8220 | pos[1] = 0; |
| 8221 | pos += 2; |
| 8222 | } |
| 8223 | |
| 8224 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 8225 | pos += sizeof(rfc1042_header); |
| 8226 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 8227 | pos += 2; |
| 8228 | memcpy(pos, data, data_len); |
| 8229 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8230 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
| 8231 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8232 | if (res < 0) { |
| 8233 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 8234 | "failed: %d (%s)", |
| 8235 | (unsigned long) len, errno, strerror(errno)); |
| 8236 | } |
| 8237 | os_free(hdr); |
| 8238 | |
| 8239 | return res; |
| 8240 | } |
| 8241 | |
| 8242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8243 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
| 8244 | int total_flags, |
| 8245 | int flags_or, int flags_and) |
| 8246 | { |
| 8247 | struct i802_bss *bss = priv; |
| 8248 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8249 | struct nl_msg *msg; |
| 8250 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8251 | struct nl80211_sta_flag_update upd; |
| 8252 | |
| 8253 | msg = nlmsg_alloc(); |
| 8254 | if (!msg) |
| 8255 | return -ENOMEM; |
| 8256 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8257 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8258 | |
| 8259 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 8260 | if_nametoindex(bss->ifname)); |
| 8261 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 8262 | |
| 8263 | /* |
| 8264 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 8265 | * can be removed eventually. |
| 8266 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8267 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
| 8268 | if (!flags) |
| 8269 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8270 | if (total_flags & WPA_STA_AUTHORIZED) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8271 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8272 | |
| 8273 | if (total_flags & WPA_STA_WMM) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8274 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_WME); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8275 | |
| 8276 | if (total_flags & WPA_STA_SHORT_PREAMBLE) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8277 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_SHORT_PREAMBLE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8278 | |
| 8279 | if (total_flags & WPA_STA_MFP) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8280 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_MFP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8281 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8282 | if (total_flags & WPA_STA_TDLS_PEER) |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8283 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8284 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8285 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8286 | |
| 8287 | os_memset(&upd, 0, sizeof(upd)); |
| 8288 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 8289 | upd.set = sta_flags_nl80211(flags_or); |
| 8290 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 8291 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8292 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8293 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8294 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8295 | return -ENOBUFS; |
| 8296 | } |
| 8297 | |
| 8298 | |
| 8299 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 8300 | struct wpa_driver_associate_params *params) |
| 8301 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8302 | enum nl80211_iftype nlmode, old_mode; |
| 8303 | struct hostapd_freq_params freq = { |
| 8304 | .freq = params->freq, |
| 8305 | }; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8306 | |
| 8307 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8308 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 8309 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8310 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 8311 | } else |
| 8312 | nlmode = NL80211_IFTYPE_AP; |
| 8313 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8314 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8315 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8316 | nl80211_remove_monitor_interface(drv); |
| 8317 | return -1; |
| 8318 | } |
| 8319 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8320 | if (wpa_driver_nl80211_set_freq(drv->first_bss, &freq)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8321 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8322 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8323 | nl80211_remove_monitor_interface(drv); |
| 8324 | return -1; |
| 8325 | } |
| 8326 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8327 | return 0; |
| 8328 | } |
| 8329 | |
| 8330 | |
| 8331 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv) |
| 8332 | { |
| 8333 | struct nl_msg *msg; |
| 8334 | int ret = -1; |
| 8335 | |
| 8336 | msg = nlmsg_alloc(); |
| 8337 | if (!msg) |
| 8338 | return -1; |
| 8339 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8340 | nl80211_cmd(drv, msg, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8341 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 8342 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8343 | msg = NULL; |
| 8344 | if (ret) { |
| 8345 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 8346 | "(%s)", ret, strerror(-ret)); |
| 8347 | goto nla_put_failure; |
| 8348 | } |
| 8349 | |
| 8350 | ret = 0; |
| 8351 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS request sent successfully"); |
| 8352 | |
| 8353 | nla_put_failure: |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8354 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8355 | NL80211_IFTYPE_STATION)) { |
| 8356 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 8357 | "station mode"); |
| 8358 | } |
| 8359 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8360 | nlmsg_free(msg); |
| 8361 | return ret; |
| 8362 | } |
| 8363 | |
| 8364 | |
| 8365 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 8366 | struct wpa_driver_associate_params *params) |
| 8367 | { |
| 8368 | struct nl_msg *msg; |
| 8369 | int ret = -1; |
| 8370 | int count = 0; |
| 8371 | |
| 8372 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 8373 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8374 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8375 | NL80211_IFTYPE_ADHOC)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8376 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 8377 | "IBSS mode"); |
| 8378 | return -1; |
| 8379 | } |
| 8380 | |
| 8381 | retry: |
| 8382 | msg = nlmsg_alloc(); |
| 8383 | if (!msg) |
| 8384 | return -1; |
| 8385 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8386 | nl80211_cmd(drv, msg, 0, NL80211_CMD_JOIN_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8387 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 8388 | |
| 8389 | if (params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 8390 | goto nla_put_failure; |
| 8391 | |
| 8392 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 8393 | params->ssid, params->ssid_len); |
| 8394 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 8395 | params->ssid); |
| 8396 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 8397 | drv->ssid_len = params->ssid_len; |
| 8398 | |
| 8399 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 8400 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
| 8401 | |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 8402 | if (params->beacon_int > 0) { |
| 8403 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", params->beacon_int); |
| 8404 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 8405 | params->beacon_int); |
| 8406 | } |
| 8407 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8408 | ret = nl80211_set_conn_keys(params, msg); |
| 8409 | if (ret) |
| 8410 | goto nla_put_failure; |
| 8411 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8412 | if (params->bssid && params->fixed_bssid) { |
| 8413 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 8414 | MAC2STR(params->bssid)); |
| 8415 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 8416 | } |
| 8417 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8418 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 8419 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 8420 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 8421 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8422 | wpa_printf(MSG_DEBUG, " * control port"); |
| 8423 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
| 8424 | } |
| 8425 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8426 | if (params->wpa_ie) { |
| 8427 | wpa_hexdump(MSG_DEBUG, |
| 8428 | " * Extra IEs for Beacon/Probe Response frames", |
| 8429 | params->wpa_ie, params->wpa_ie_len); |
| 8430 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 8431 | params->wpa_ie); |
| 8432 | } |
| 8433 | |
| 8434 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8435 | msg = NULL; |
| 8436 | if (ret) { |
| 8437 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 8438 | ret, strerror(-ret)); |
| 8439 | count++; |
| 8440 | if (ret == -EALREADY && count == 1) { |
| 8441 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 8442 | "forced leave"); |
| 8443 | nl80211_leave_ibss(drv); |
| 8444 | nlmsg_free(msg); |
| 8445 | goto retry; |
| 8446 | } |
| 8447 | |
| 8448 | goto nla_put_failure; |
| 8449 | } |
| 8450 | ret = 0; |
| 8451 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS request sent successfully"); |
| 8452 | |
| 8453 | nla_put_failure: |
| 8454 | nlmsg_free(msg); |
| 8455 | return ret; |
| 8456 | } |
| 8457 | |
| 8458 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8459 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 8460 | struct wpa_driver_associate_params *params, |
| 8461 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8462 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8463 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8464 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8465 | if (params->bssid) { |
| 8466 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 8467 | MAC2STR(params->bssid)); |
| 8468 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 8469 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8470 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 8471 | if (params->bssid_hint) { |
| 8472 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 8473 | MAC2STR(params->bssid_hint)); |
| 8474 | NLA_PUT(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 8475 | params->bssid_hint); |
| 8476 | } |
| 8477 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8478 | if (params->freq) { |
| 8479 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 8480 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8481 | drv->assoc_freq = params->freq; |
| 8482 | } else |
| 8483 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8484 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 8485 | if (params->freq_hint) { |
| 8486 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
| 8487 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 8488 | params->freq_hint); |
| 8489 | } |
| 8490 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8491 | if (params->bg_scan_period >= 0) { |
| 8492 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 8493 | params->bg_scan_period); |
| 8494 | NLA_PUT_U16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 8495 | params->bg_scan_period); |
| 8496 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8497 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8498 | if (params->ssid) { |
| 8499 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 8500 | params->ssid, params->ssid_len); |
| 8501 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 8502 | params->ssid); |
| 8503 | if (params->ssid_len > sizeof(drv->ssid)) |
| 8504 | goto nla_put_failure; |
| 8505 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 8506 | drv->ssid_len = params->ssid_len; |
| 8507 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8508 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8509 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
| 8510 | if (params->wpa_ie) |
| 8511 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 8512 | params->wpa_ie); |
| 8513 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8514 | if (params->wpa_proto) { |
| 8515 | enum nl80211_wpa_versions ver = 0; |
| 8516 | |
| 8517 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 8518 | ver |= NL80211_WPA_VERSION_1; |
| 8519 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 8520 | ver |= NL80211_WPA_VERSION_2; |
| 8521 | |
| 8522 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
| 8523 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); |
| 8524 | } |
| 8525 | |
| 8526 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 8527 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 8528 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
| 8529 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); |
| 8530 | } |
| 8531 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8532 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 8533 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 8534 | /* |
| 8535 | * This is likely to work even though many drivers do not |
| 8536 | * advertise support for operations without GTK. |
| 8537 | */ |
| 8538 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 8539 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8540 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 8541 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
| 8542 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); |
| 8543 | } |
| 8544 | |
| 8545 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 8546 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 8547 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 8548 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
| 8549 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM) { |
| 8550 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 8551 | |
| 8552 | switch (params->key_mgmt_suite) { |
| 8553 | case WPA_KEY_MGMT_CCKM: |
| 8554 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 8555 | break; |
| 8556 | case WPA_KEY_MGMT_IEEE8021X: |
| 8557 | mgmt = WLAN_AKM_SUITE_8021X; |
| 8558 | break; |
| 8559 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 8560 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 8561 | break; |
| 8562 | case WPA_KEY_MGMT_FT_PSK: |
| 8563 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 8564 | break; |
| 8565 | case WPA_KEY_MGMT_PSK: |
| 8566 | default: |
| 8567 | mgmt = WLAN_AKM_SUITE_PSK; |
| 8568 | break; |
| 8569 | } |
| 8570 | NLA_PUT_U32(msg, NL80211_ATTR_AKM_SUITES, mgmt); |
| 8571 | } |
| 8572 | |
| 8573 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
| 8574 | |
| 8575 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) |
| 8576 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); |
| 8577 | |
| 8578 | if (params->disable_ht) |
| 8579 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT); |
| 8580 | |
| 8581 | if (params->htcaps && params->htcaps_mask) { |
| 8582 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 8583 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps); |
| 8584 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 8585 | params->htcaps_mask); |
| 8586 | } |
| 8587 | |
| 8588 | #ifdef CONFIG_VHT_OVERRIDES |
| 8589 | if (params->disable_vht) { |
| 8590 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 8591 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_VHT); |
| 8592 | } |
| 8593 | |
| 8594 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 8595 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 8596 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, sz, params->vhtcaps); |
| 8597 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 8598 | params->vhtcaps_mask); |
| 8599 | } |
| 8600 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 8601 | |
| 8602 | if (params->p2p) |
| 8603 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 8604 | |
| 8605 | return 0; |
| 8606 | nla_put_failure: |
| 8607 | return -1; |
| 8608 | } |
| 8609 | |
| 8610 | |
| 8611 | static int wpa_driver_nl80211_try_connect( |
| 8612 | struct wpa_driver_nl80211_data *drv, |
| 8613 | struct wpa_driver_associate_params *params) |
| 8614 | { |
| 8615 | struct nl_msg *msg; |
| 8616 | enum nl80211_auth_type type; |
| 8617 | int ret; |
| 8618 | int algs; |
| 8619 | |
| 8620 | msg = nlmsg_alloc(); |
| 8621 | if (!msg) |
| 8622 | return -1; |
| 8623 | |
| 8624 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 8625 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CONNECT); |
| 8626 | |
| 8627 | ret = nl80211_connect_common(drv, params, msg); |
| 8628 | if (ret) |
| 8629 | goto nla_put_failure; |
| 8630 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8631 | algs = 0; |
| 8632 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 8633 | algs++; |
| 8634 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 8635 | algs++; |
| 8636 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 8637 | algs++; |
| 8638 | if (algs > 1) { |
| 8639 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 8640 | "selection"); |
| 8641 | goto skip_auth_type; |
| 8642 | } |
| 8643 | |
| 8644 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 8645 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 8646 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 8647 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 8648 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 8649 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 8650 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 8651 | type = NL80211_AUTHTYPE_FT; |
| 8652 | else |
| 8653 | goto nla_put_failure; |
| 8654 | |
| 8655 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 8656 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); |
| 8657 | |
| 8658 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8659 | ret = nl80211_set_conn_keys(params, msg); |
| 8660 | if (ret) |
| 8661 | goto nla_put_failure; |
| 8662 | |
| 8663 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8664 | msg = NULL; |
| 8665 | if (ret) { |
| 8666 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 8667 | "(%s)", ret, strerror(-ret)); |
| 8668 | goto nla_put_failure; |
| 8669 | } |
| 8670 | ret = 0; |
| 8671 | wpa_printf(MSG_DEBUG, "nl80211: Connect request send successfully"); |
| 8672 | |
| 8673 | nla_put_failure: |
| 8674 | nlmsg_free(msg); |
| 8675 | return ret; |
| 8676 | |
| 8677 | } |
| 8678 | |
| 8679 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8680 | static int wpa_driver_nl80211_connect( |
| 8681 | struct wpa_driver_nl80211_data *drv, |
| 8682 | struct wpa_driver_associate_params *params) |
| 8683 | { |
| 8684 | int ret = wpa_driver_nl80211_try_connect(drv, params); |
| 8685 | if (ret == -EALREADY) { |
| 8686 | /* |
| 8687 | * cfg80211 does not currently accept new connections if |
| 8688 | * we are already connected. As a workaround, force |
| 8689 | * disconnection and try again. |
| 8690 | */ |
| 8691 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 8692 | "disconnecting before reassociation " |
| 8693 | "attempt"); |
| 8694 | if (wpa_driver_nl80211_disconnect( |
| 8695 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 8696 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8697 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 8698 | } |
| 8699 | return ret; |
| 8700 | } |
| 8701 | |
| 8702 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8703 | static int wpa_driver_nl80211_associate( |
| 8704 | void *priv, struct wpa_driver_associate_params *params) |
| 8705 | { |
| 8706 | struct i802_bss *bss = priv; |
| 8707 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8708 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8709 | struct nl_msg *msg; |
| 8710 | |
| 8711 | if (params->mode == IEEE80211_MODE_AP) |
| 8712 | return wpa_driver_nl80211_ap(drv, params); |
| 8713 | |
| 8714 | if (params->mode == IEEE80211_MODE_IBSS) |
| 8715 | return wpa_driver_nl80211_ibss(drv, params); |
| 8716 | |
| 8717 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8718 | enum nl80211_iftype nlmode = params->p2p ? |
| 8719 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 8720 | |
| 8721 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8722 | return -1; |
| 8723 | return wpa_driver_nl80211_connect(drv, params); |
| 8724 | } |
| 8725 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8726 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8727 | |
| 8728 | msg = nlmsg_alloc(); |
| 8729 | if (!msg) |
| 8730 | return -1; |
| 8731 | |
| 8732 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 8733 | drv->ifindex); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8734 | nl80211_cmd(drv, msg, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8735 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8736 | ret = nl80211_connect_common(drv, params, msg); |
| 8737 | if (ret) |
| 8738 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8739 | |
| 8740 | if (params->prev_bssid) { |
| 8741 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 8742 | MAC2STR(params->prev_bssid)); |
| 8743 | NLA_PUT(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 8744 | params->prev_bssid); |
| 8745 | } |
| 8746 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8747 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8748 | msg = NULL; |
| 8749 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8750 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 8751 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 8752 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8753 | nl80211_dump_scan(drv); |
| 8754 | goto nla_put_failure; |
| 8755 | } |
| 8756 | ret = 0; |
| 8757 | wpa_printf(MSG_DEBUG, "nl80211: Association request send " |
| 8758 | "successfully"); |
| 8759 | |
| 8760 | nla_put_failure: |
| 8761 | nlmsg_free(msg); |
| 8762 | return ret; |
| 8763 | } |
| 8764 | |
| 8765 | |
| 8766 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8767 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8768 | { |
| 8769 | struct nl_msg *msg; |
| 8770 | int ret = -ENOBUFS; |
| 8771 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8772 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 8773 | ifindex, mode, nl80211_iftype_str(mode)); |
| 8774 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8775 | msg = nlmsg_alloc(); |
| 8776 | if (!msg) |
| 8777 | return -ENOMEM; |
| 8778 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8779 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_INTERFACE); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8780 | if (nl80211_set_iface_id(msg, drv->first_bss) < 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8781 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8782 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, mode); |
| 8783 | |
| 8784 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8785 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8786 | if (!ret) |
| 8787 | return 0; |
| 8788 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8789 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8790 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 8791 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 8792 | return ret; |
| 8793 | } |
| 8794 | |
| 8795 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8796 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 8797 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8798 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8799 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8800 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8801 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8802 | int was_ap = is_ap_interface(drv->nlmode); |
| 8803 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8804 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8805 | res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8806 | if (res && nlmode == nl80211_get_ifmode(bss)) |
| 8807 | res = 0; |
| 8808 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8809 | if (res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8810 | drv->nlmode = nlmode; |
| 8811 | ret = 0; |
| 8812 | goto done; |
| 8813 | } |
| 8814 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8815 | if (res == -ENODEV) |
| 8816 | return -1; |
| 8817 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8818 | if (nlmode == drv->nlmode) { |
| 8819 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 8820 | "requested mode - ignore error"); |
| 8821 | ret = 0; |
| 8822 | goto done; /* Already in the requested mode */ |
| 8823 | } |
| 8824 | |
| 8825 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 8826 | * take the device down, try to set the mode again, and bring the |
| 8827 | * device back up. |
| 8828 | */ |
| 8829 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 8830 | "interface down"); |
| 8831 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8832 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8833 | if (res == -EACCES || res == -ENODEV) |
| 8834 | break; |
| 8835 | if (res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8836 | /* Try to set the mode again while the interface is |
| 8837 | * down */ |
| 8838 | ret = nl80211_set_mode(drv, drv->ifindex, nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8839 | if (ret == -EACCES) |
| 8840 | break; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8841 | res = i802_set_iface_flags(bss, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8842 | if (res && !ret) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8843 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8844 | else if (ret != -EBUSY) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8845 | break; |
| 8846 | } else |
| 8847 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 8848 | "interface down"); |
| 8849 | os_sleep(0, 100000); |
| 8850 | } |
| 8851 | |
| 8852 | if (!ret) { |
| 8853 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 8854 | "interface is down"); |
| 8855 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8856 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8857 | } |
| 8858 | |
| 8859 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8860 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8861 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 8862 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8863 | return ret; |
| 8864 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8865 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8866 | if (is_p2p_net_interface(nlmode)) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8867 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 8868 | else if (drv->disabled_11b_rates) |
| 8869 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 8870 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8871 | if (is_ap_interface(nlmode)) { |
| 8872 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 8873 | /* Setup additional AP mode functionality if needed */ |
| 8874 | if (nl80211_setup_ap(bss)) |
| 8875 | return -1; |
| 8876 | } else if (was_ap) { |
| 8877 | /* Remove additional AP mode functionality */ |
| 8878 | nl80211_teardown_ap(bss); |
| 8879 | } else { |
| 8880 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 8881 | } |
| 8882 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8883 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8884 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 8885 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 8886 | "frame processing - ignore for now"); |
| 8887 | |
| 8888 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8889 | } |
| 8890 | |
| 8891 | |
| 8892 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 8893 | struct wpa_driver_capa *capa) |
| 8894 | { |
| 8895 | struct i802_bss *bss = priv; |
| 8896 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8897 | if (!drv->has_capability) |
| 8898 | return -1; |
| 8899 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 8900 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 8901 | capa->extended_capa = drv->extended_capa; |
| 8902 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 8903 | capa->extended_capa_len = drv->extended_capa_len; |
| 8904 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8905 | |
| 8906 | if ((capa->flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && |
| 8907 | !drv->allow_p2p_device) { |
| 8908 | wpa_printf(MSG_DEBUG, "nl80211: Do not indicate P2P_DEVICE support (p2p_device=1 driver param not specified)"); |
| 8909 | capa->flags &= ~WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE; |
| 8910 | } |
| 8911 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8912 | return 0; |
| 8913 | } |
| 8914 | |
| 8915 | |
| 8916 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 8917 | { |
| 8918 | struct i802_bss *bss = priv; |
| 8919 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8920 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8921 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 8922 | bss->ifname, drv->operstate, state, |
| 8923 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8924 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8925 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8926 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 8927 | } |
| 8928 | |
| 8929 | |
| 8930 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 8931 | { |
| 8932 | struct i802_bss *bss = priv; |
| 8933 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8934 | struct nl_msg *msg; |
| 8935 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8936 | int ret = -ENOBUFS; |
| 8937 | |
| 8938 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 8939 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 8940 | return 0; |
| 8941 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8942 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8943 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 8944 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 8945 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8946 | msg = nlmsg_alloc(); |
| 8947 | if (!msg) |
| 8948 | return -ENOMEM; |
| 8949 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8950 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8951 | |
| 8952 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 8953 | if_nametoindex(bss->ifname)); |
| 8954 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
| 8955 | |
| 8956 | os_memset(&upd, 0, sizeof(upd)); |
| 8957 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 8958 | if (authorized) |
| 8959 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 8960 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 8961 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8962 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8963 | msg = NULL; |
| 8964 | if (!ret) |
| 8965 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8966 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8967 | nlmsg_free(msg); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8968 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 8969 | ret, strerror(-ret)); |
| 8970 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8971 | } |
| 8972 | |
| 8973 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8974 | /* Set kernel driver on given frequency (MHz) */ |
| 8975 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8976 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8977 | struct i802_bss *bss = priv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8978 | return wpa_driver_nl80211_set_freq(bss, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8979 | } |
| 8980 | |
| 8981 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8982 | static inline int min_int(int a, int b) |
| 8983 | { |
| 8984 | if (a < b) |
| 8985 | return a; |
| 8986 | return b; |
| 8987 | } |
| 8988 | |
| 8989 | |
| 8990 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 8991 | { |
| 8992 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8993 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8994 | |
| 8995 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8996 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8997 | |
| 8998 | /* |
| 8999 | * TODO: validate the key index and mac address! |
| 9000 | * Otherwise, there's a race condition as soon as |
| 9001 | * the kernel starts sending key notifications. |
| 9002 | */ |
| 9003 | |
| 9004 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 9005 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 9006 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 9007 | return NL_SKIP; |
| 9008 | } |
| 9009 | |
| 9010 | |
| 9011 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 9012 | int idx, u8 *seq) |
| 9013 | { |
| 9014 | struct i802_bss *bss = priv; |
| 9015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9016 | struct nl_msg *msg; |
| 9017 | |
| 9018 | msg = nlmsg_alloc(); |
| 9019 | if (!msg) |
| 9020 | return -ENOMEM; |
| 9021 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9022 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9023 | |
| 9024 | if (addr) |
| 9025 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 9026 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx); |
| 9027 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface)); |
| 9028 | |
| 9029 | memset(seq, 0, 6); |
| 9030 | |
| 9031 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
| 9032 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9033 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9034 | return -ENOBUFS; |
| 9035 | } |
| 9036 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9037 | |
| 9038 | static int i802_set_rts(void *priv, int rts) |
| 9039 | { |
| 9040 | struct i802_bss *bss = priv; |
| 9041 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9042 | struct nl_msg *msg; |
| 9043 | int ret = -ENOBUFS; |
| 9044 | u32 val; |
| 9045 | |
| 9046 | msg = nlmsg_alloc(); |
| 9047 | if (!msg) |
| 9048 | return -ENOMEM; |
| 9049 | |
| 9050 | if (rts >= 2347) |
| 9051 | val = (u32) -1; |
| 9052 | else |
| 9053 | val = rts; |
| 9054 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9055 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9056 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 9057 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val); |
| 9058 | |
| 9059 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9060 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9061 | if (!ret) |
| 9062 | return 0; |
| 9063 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9064 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9065 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 9066 | "%d (%s)", rts, ret, strerror(-ret)); |
| 9067 | return ret; |
| 9068 | } |
| 9069 | |
| 9070 | |
| 9071 | static int i802_set_frag(void *priv, int frag) |
| 9072 | { |
| 9073 | struct i802_bss *bss = priv; |
| 9074 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9075 | struct nl_msg *msg; |
| 9076 | int ret = -ENOBUFS; |
| 9077 | u32 val; |
| 9078 | |
| 9079 | msg = nlmsg_alloc(); |
| 9080 | if (!msg) |
| 9081 | return -ENOMEM; |
| 9082 | |
| 9083 | if (frag >= 2346) |
| 9084 | val = (u32) -1; |
| 9085 | else |
| 9086 | val = frag; |
| 9087 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9088 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9089 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 9090 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val); |
| 9091 | |
| 9092 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9093 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9094 | if (!ret) |
| 9095 | return 0; |
| 9096 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9097 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9098 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 9099 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 9100 | return ret; |
| 9101 | } |
| 9102 | |
| 9103 | |
| 9104 | static int i802_flush(void *priv) |
| 9105 | { |
| 9106 | struct i802_bss *bss = priv; |
| 9107 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9108 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9109 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9110 | |
| 9111 | msg = nlmsg_alloc(); |
| 9112 | if (!msg) |
| 9113 | return -1; |
| 9114 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9115 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 9116 | bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9117 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9118 | |
| 9119 | /* |
| 9120 | * XXX: FIX! this needs to flush all VLANs too |
| 9121 | */ |
| 9122 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 9123 | if_nametoindex(bss->ifname)); |
| 9124 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9125 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9126 | if (res) { |
| 9127 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 9128 | "(%s)", res, strerror(-res)); |
| 9129 | } |
| 9130 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9131 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9132 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9133 | return -ENOBUFS; |
| 9134 | } |
| 9135 | |
| 9136 | |
| 9137 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 9138 | { |
| 9139 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9140 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9141 | struct hostap_sta_driver_data *data = arg; |
| 9142 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 9143 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 9144 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 9145 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 9146 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 9147 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 9148 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 9149 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9150 | }; |
| 9151 | |
| 9152 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9153 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9154 | |
| 9155 | /* |
| 9156 | * TODO: validate the interface and mac address! |
| 9157 | * Otherwise, there's a race condition as soon as |
| 9158 | * the kernel starts sending station notifications. |
| 9159 | */ |
| 9160 | |
| 9161 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 9162 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 9163 | return NL_SKIP; |
| 9164 | } |
| 9165 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 9166 | tb[NL80211_ATTR_STA_INFO], |
| 9167 | stats_policy)) { |
| 9168 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 9169 | return NL_SKIP; |
| 9170 | } |
| 9171 | |
| 9172 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 9173 | data->inactive_msec = |
| 9174 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
| 9175 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 9176 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 9177 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 9178 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
| 9179 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 9180 | data->rx_packets = |
| 9181 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 9182 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 9183 | data->tx_packets = |
| 9184 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 9185 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 9186 | data->tx_retry_failed = |
| 9187 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9188 | |
| 9189 | return NL_SKIP; |
| 9190 | } |
| 9191 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9192 | static int i802_read_sta_data(struct i802_bss *bss, |
| 9193 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9194 | const u8 *addr) |
| 9195 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9196 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9197 | struct nl_msg *msg; |
| 9198 | |
| 9199 | os_memset(data, 0, sizeof(*data)); |
| 9200 | msg = nlmsg_alloc(); |
| 9201 | if (!msg) |
| 9202 | return -ENOMEM; |
| 9203 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9204 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9205 | |
| 9206 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 9207 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 9208 | |
| 9209 | return send_and_recv_msgs(drv, msg, get_sta_handler, data); |
| 9210 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9211 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9212 | return -ENOBUFS; |
| 9213 | } |
| 9214 | |
| 9215 | |
| 9216 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 9217 | int cw_min, int cw_max, int burst_time) |
| 9218 | { |
| 9219 | struct i802_bss *bss = priv; |
| 9220 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9221 | struct nl_msg *msg; |
| 9222 | struct nlattr *txq, *params; |
| 9223 | |
| 9224 | msg = nlmsg_alloc(); |
| 9225 | if (!msg) |
| 9226 | return -1; |
| 9227 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9228 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9229 | |
| 9230 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 9231 | |
| 9232 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 9233 | if (!txq) |
| 9234 | goto nla_put_failure; |
| 9235 | |
| 9236 | /* We are only sending parameters for a single TXQ at a time */ |
| 9237 | params = nla_nest_start(msg, 1); |
| 9238 | if (!params) |
| 9239 | goto nla_put_failure; |
| 9240 | |
| 9241 | switch (queue) { |
| 9242 | case 0: |
| 9243 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO); |
| 9244 | break; |
| 9245 | case 1: |
| 9246 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI); |
| 9247 | break; |
| 9248 | case 2: |
| 9249 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE); |
| 9250 | break; |
| 9251 | case 3: |
| 9252 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK); |
| 9253 | break; |
| 9254 | } |
| 9255 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 9256 | * 32 usec, so need to convert the value here. */ |
| 9257 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32); |
| 9258 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min); |
| 9259 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max); |
| 9260 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs); |
| 9261 | |
| 9262 | nla_nest_end(msg, params); |
| 9263 | |
| 9264 | nla_nest_end(msg, txq); |
| 9265 | |
| 9266 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 9267 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9268 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9269 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9270 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9271 | return -1; |
| 9272 | } |
| 9273 | |
| 9274 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9275 | 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] | 9276 | const char *ifname, int vlan_id) |
| 9277 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9278 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9279 | struct nl_msg *msg; |
| 9280 | int ret = -ENOBUFS; |
| 9281 | |
| 9282 | msg = nlmsg_alloc(); |
| 9283 | if (!msg) |
| 9284 | return -ENOMEM; |
| 9285 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9286 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 9287 | ", ifname=%s[%d], vlan_id=%d)", |
| 9288 | bss->ifname, if_nametoindex(bss->ifname), |
| 9289 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9290 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9291 | |
| 9292 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 9293 | if_nametoindex(bss->ifname)); |
| 9294 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 9295 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, |
| 9296 | if_nametoindex(ifname)); |
| 9297 | |
| 9298 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9299 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9300 | if (ret < 0) { |
| 9301 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 9302 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 9303 | MAC2STR(addr), ifname, vlan_id, ret, |
| 9304 | strerror(-ret)); |
| 9305 | } |
| 9306 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9307 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9308 | return ret; |
| 9309 | } |
| 9310 | |
| 9311 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9312 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 9313 | { |
| 9314 | struct hostap_sta_driver_data data; |
| 9315 | int ret; |
| 9316 | |
| 9317 | data.inactive_msec = (unsigned long) -1; |
| 9318 | ret = i802_read_sta_data(priv, &data, addr); |
| 9319 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 9320 | return -1; |
| 9321 | return data.inactive_msec / 1000; |
| 9322 | } |
| 9323 | |
| 9324 | |
| 9325 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 9326 | { |
| 9327 | #if 0 |
| 9328 | /* TODO */ |
| 9329 | #endif |
| 9330 | return 0; |
| 9331 | } |
| 9332 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9333 | |
| 9334 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 9335 | int reason) |
| 9336 | { |
| 9337 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9338 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9339 | struct ieee80211_mgmt mgmt; |
| 9340 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9341 | if (drv->device_ap_sme) |
| 9342 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 9343 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9344 | memset(&mgmt, 0, sizeof(mgmt)); |
| 9345 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 9346 | WLAN_FC_STYPE_DEAUTH); |
| 9347 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 9348 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 9349 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 9350 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 9351 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 9352 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9353 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
| 9354 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9355 | } |
| 9356 | |
| 9357 | |
| 9358 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 9359 | int reason) |
| 9360 | { |
| 9361 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9362 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9363 | struct ieee80211_mgmt mgmt; |
| 9364 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9365 | if (drv->device_ap_sme) |
| 9366 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 9367 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9368 | memset(&mgmt, 0, sizeof(mgmt)); |
| 9369 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 9370 | WLAN_FC_STYPE_DISASSOC); |
| 9371 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 9372 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 9373 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 9374 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 9375 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 9376 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9377 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
| 9378 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9379 | } |
| 9380 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9381 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9382 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 9383 | { |
| 9384 | int i; |
| 9385 | int *old; |
| 9386 | |
| 9387 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", |
| 9388 | ifidx); |
| 9389 | for (i = 0; i < drv->num_if_indices; i++) { |
| 9390 | if (drv->if_indices[i] == 0) { |
| 9391 | drv->if_indices[i] = ifidx; |
| 9392 | return; |
| 9393 | } |
| 9394 | } |
| 9395 | |
| 9396 | if (drv->if_indices != drv->default_if_indices) |
| 9397 | old = drv->if_indices; |
| 9398 | else |
| 9399 | old = NULL; |
| 9400 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9401 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 9402 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9403 | if (!drv->if_indices) { |
| 9404 | if (!old) |
| 9405 | drv->if_indices = drv->default_if_indices; |
| 9406 | else |
| 9407 | drv->if_indices = old; |
| 9408 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 9409 | "interfaces"); |
| 9410 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 9411 | return; |
| 9412 | } else if (!old) |
| 9413 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 9414 | sizeof(drv->default_if_indices)); |
| 9415 | drv->if_indices[drv->num_if_indices] = ifidx; |
| 9416 | drv->num_if_indices++; |
| 9417 | } |
| 9418 | |
| 9419 | |
| 9420 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 9421 | { |
| 9422 | int i; |
| 9423 | |
| 9424 | for (i = 0; i < drv->num_if_indices; i++) { |
| 9425 | if (drv->if_indices[i] == ifidx) { |
| 9426 | drv->if_indices[i] = 0; |
| 9427 | break; |
| 9428 | } |
| 9429 | } |
| 9430 | } |
| 9431 | |
| 9432 | |
| 9433 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 9434 | { |
| 9435 | int i; |
| 9436 | |
| 9437 | for (i = 0; i < drv->num_if_indices; i++) |
| 9438 | if (drv->if_indices[i] == ifidx) |
| 9439 | return 1; |
| 9440 | |
| 9441 | return 0; |
| 9442 | } |
| 9443 | |
| 9444 | |
| 9445 | 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] | 9446 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9447 | { |
| 9448 | struct i802_bss *bss = priv; |
| 9449 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9450 | char name[IFNAMSIZ + 1]; |
| 9451 | |
| 9452 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 9453 | if (ifname_wds) |
| 9454 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 9455 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9456 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 9457 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 9458 | if (val) { |
| 9459 | if (!if_nametoindex(name)) { |
| 9460 | if (nl80211_create_iface(drv, name, |
| 9461 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9462 | bss->addr, 1, NULL, NULL, 0) < |
| 9463 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9464 | return -1; |
| 9465 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9466 | linux_br_add_if(drv->global->ioctl_sock, |
| 9467 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9468 | return -1; |
| 9469 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9470 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 9471 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 9472 | "interface %s up", name); |
| 9473 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9474 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 9475 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 9476 | if (bridge_ifname) |
| 9477 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 9478 | name); |
| 9479 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9480 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9481 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 9482 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9483 | } |
| 9484 | } |
| 9485 | |
| 9486 | |
| 9487 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 9488 | { |
| 9489 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 9490 | struct sockaddr_ll lladdr; |
| 9491 | unsigned char buf[3000]; |
| 9492 | int len; |
| 9493 | socklen_t fromlen = sizeof(lladdr); |
| 9494 | |
| 9495 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 9496 | (struct sockaddr *)&lladdr, &fromlen); |
| 9497 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9498 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 9499 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9500 | return; |
| 9501 | } |
| 9502 | |
| 9503 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
| 9504 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 9505 | } |
| 9506 | |
| 9507 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9508 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 9509 | struct i802_bss *bss, |
| 9510 | const char *brname, const char *ifname) |
| 9511 | { |
| 9512 | int ifindex; |
| 9513 | char in_br[IFNAMSIZ]; |
| 9514 | |
| 9515 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
| 9516 | ifindex = if_nametoindex(brname); |
| 9517 | if (ifindex == 0) { |
| 9518 | /* |
| 9519 | * Bridge was configured, but the bridge device does |
| 9520 | * not exist. Try to add it now. |
| 9521 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9522 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9523 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 9524 | "bridge interface %s: %s", |
| 9525 | brname, strerror(errno)); |
| 9526 | return -1; |
| 9527 | } |
| 9528 | bss->added_bridge = 1; |
| 9529 | add_ifidx(drv, if_nametoindex(brname)); |
| 9530 | } |
| 9531 | |
| 9532 | if (linux_br_get(in_br, ifname) == 0) { |
| 9533 | if (os_strcmp(in_br, brname) == 0) |
| 9534 | return 0; /* already in the bridge */ |
| 9535 | |
| 9536 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 9537 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9538 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 9539 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9540 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 9541 | "remove interface %s from bridge " |
| 9542 | "%s: %s", |
| 9543 | ifname, brname, strerror(errno)); |
| 9544 | return -1; |
| 9545 | } |
| 9546 | } |
| 9547 | |
| 9548 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 9549 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9550 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9551 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 9552 | "into bridge %s: %s", |
| 9553 | ifname, brname, strerror(errno)); |
| 9554 | return -1; |
| 9555 | } |
| 9556 | bss->added_if_into_bridge = 1; |
| 9557 | |
| 9558 | return 0; |
| 9559 | } |
| 9560 | |
| 9561 | |
| 9562 | static void *i802_init(struct hostapd_data *hapd, |
| 9563 | struct wpa_init_params *params) |
| 9564 | { |
| 9565 | struct wpa_driver_nl80211_data *drv; |
| 9566 | struct i802_bss *bss; |
| 9567 | size_t i; |
| 9568 | char brname[IFNAMSIZ]; |
| 9569 | int ifindex, br_ifindex; |
| 9570 | int br_added = 0; |
| 9571 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9572 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 9573 | params->global_priv, 1, |
| 9574 | params->bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9575 | if (bss == NULL) |
| 9576 | return NULL; |
| 9577 | |
| 9578 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9579 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9580 | if (linux_br_get(brname, params->ifname) == 0) { |
| 9581 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
| 9582 | params->ifname, brname); |
| 9583 | br_ifindex = if_nametoindex(brname); |
| 9584 | } else { |
| 9585 | brname[0] = '\0'; |
| 9586 | br_ifindex = 0; |
| 9587 | } |
| 9588 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9589 | for (i = 0; i < params->num_bridge; i++) { |
| 9590 | if (params->bridge[i]) { |
| 9591 | ifindex = if_nametoindex(params->bridge[i]); |
| 9592 | if (ifindex) |
| 9593 | add_ifidx(drv, ifindex); |
| 9594 | if (ifindex == br_ifindex) |
| 9595 | br_added = 1; |
| 9596 | } |
| 9597 | } |
| 9598 | if (!br_added && br_ifindex && |
| 9599 | (params->num_bridge == 0 || !params->bridge[0])) |
| 9600 | add_ifidx(drv, br_ifindex); |
| 9601 | |
| 9602 | /* start listening for EAPOL on the default AP interface */ |
| 9603 | add_ifidx(drv, drv->ifindex); |
| 9604 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9605 | if (params->num_bridge && params->bridge[0] && |
| 9606 | i802_check_bridge(drv, bss, params->bridge[0], params->ifname) < 0) |
| 9607 | goto failed; |
| 9608 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9609 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 9610 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9611 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 9612 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9613 | goto failed; |
| 9614 | } |
| 9615 | |
| 9616 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 9617 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9618 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9619 | goto failed; |
| 9620 | } |
| 9621 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9622 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 9623 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9624 | goto failed; |
| 9625 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9626 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 9627 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9628 | return bss; |
| 9629 | |
| 9630 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9631 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9632 | return NULL; |
| 9633 | } |
| 9634 | |
| 9635 | |
| 9636 | static void i802_deinit(void *priv) |
| 9637 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9638 | struct i802_bss *bss = priv; |
| 9639 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9640 | } |
| 9641 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9642 | |
| 9643 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 9644 | enum wpa_driver_if_type type) |
| 9645 | { |
| 9646 | switch (type) { |
| 9647 | case WPA_IF_STATION: |
| 9648 | return NL80211_IFTYPE_STATION; |
| 9649 | case WPA_IF_P2P_CLIENT: |
| 9650 | case WPA_IF_P2P_GROUP: |
| 9651 | return NL80211_IFTYPE_P2P_CLIENT; |
| 9652 | case WPA_IF_AP_VLAN: |
| 9653 | return NL80211_IFTYPE_AP_VLAN; |
| 9654 | case WPA_IF_AP_BSS: |
| 9655 | return NL80211_IFTYPE_AP; |
| 9656 | case WPA_IF_P2P_GO: |
| 9657 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9658 | case WPA_IF_P2P_DEVICE: |
| 9659 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9660 | } |
| 9661 | return -1; |
| 9662 | } |
| 9663 | |
| 9664 | |
| 9665 | #ifdef CONFIG_P2P |
| 9666 | |
| 9667 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 9668 | { |
| 9669 | struct wpa_driver_nl80211_data *drv; |
| 9670 | dl_list_for_each(drv, &global->interfaces, |
| 9671 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9672 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9673 | return 1; |
| 9674 | } |
| 9675 | return 0; |
| 9676 | } |
| 9677 | |
| 9678 | |
| 9679 | static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data *drv, |
| 9680 | u8 *new_addr) |
| 9681 | { |
| 9682 | unsigned int idx; |
| 9683 | |
| 9684 | if (!drv->global) |
| 9685 | return -1; |
| 9686 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9687 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9688 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9689 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9690 | new_addr[0] ^= idx << 2; |
| 9691 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 9692 | break; |
| 9693 | } |
| 9694 | if (idx == 64) |
| 9695 | return -1; |
| 9696 | |
| 9697 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new P2P Interface Address " |
| 9698 | MACSTR, MAC2STR(new_addr)); |
| 9699 | |
| 9700 | return 0; |
| 9701 | } |
| 9702 | |
| 9703 | #endif /* CONFIG_P2P */ |
| 9704 | |
| 9705 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9706 | struct wdev_info { |
| 9707 | u64 wdev_id; |
| 9708 | int wdev_id_set; |
| 9709 | u8 macaddr[ETH_ALEN]; |
| 9710 | }; |
| 9711 | |
| 9712 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 9713 | { |
| 9714 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9715 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9716 | struct wdev_info *wi = arg; |
| 9717 | |
| 9718 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9719 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9720 | if (tb[NL80211_ATTR_WDEV]) { |
| 9721 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 9722 | wi->wdev_id_set = 1; |
| 9723 | } |
| 9724 | |
| 9725 | if (tb[NL80211_ATTR_MAC]) |
| 9726 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 9727 | ETH_ALEN); |
| 9728 | |
| 9729 | return NL_SKIP; |
| 9730 | } |
| 9731 | |
| 9732 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9733 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 9734 | const char *ifname, const u8 *addr, |
| 9735 | void *bss_ctx, void **drv_priv, |
| 9736 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9737 | const char *bridge, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9738 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9739 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9740 | struct i802_bss *bss = priv; |
| 9741 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9742 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9743 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9744 | |
| 9745 | if (addr) |
| 9746 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9747 | nlmode = wpa_driver_nl80211_if_type(type); |
| 9748 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 9749 | struct wdev_info p2pdev_info; |
| 9750 | |
| 9751 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 9752 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 9753 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9754 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9755 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 9756 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 9757 | ifname); |
| 9758 | return -1; |
| 9759 | } |
| 9760 | |
| 9761 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 9762 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 9763 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 9764 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 9765 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 9766 | ifname, |
| 9767 | (long long unsigned int) p2pdev_info.wdev_id); |
| 9768 | } else { |
| 9769 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9770 | 0, NULL, NULL, use_existing); |
| 9771 | if (use_existing && ifidx == -ENFILE) { |
| 9772 | added = 0; |
| 9773 | ifidx = if_nametoindex(ifname); |
| 9774 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9775 | return -1; |
| 9776 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9777 | } |
| 9778 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9779 | if (!addr) { |
| 9780 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 9781 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 9782 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 9783 | bss->ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9784 | if (added) |
| 9785 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9786 | return -1; |
| 9787 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9788 | } |
| 9789 | |
| 9790 | #ifdef CONFIG_P2P |
| 9791 | if (!addr && |
| 9792 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
| 9793 | type == WPA_IF_P2P_GO)) { |
| 9794 | /* Enforce unique P2P Interface Address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9795 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9796 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9797 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9798 | new_addr) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9799 | nl80211_remove_iface(drv, ifidx); |
| 9800 | return -1; |
| 9801 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9802 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9803 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
| 9804 | "for P2P group interface"); |
| 9805 | if (nl80211_p2p_interface_addr(drv, new_addr) < 0) { |
| 9806 | nl80211_remove_iface(drv, ifidx); |
| 9807 | return -1; |
| 9808 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9809 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9810 | new_addr) < 0) { |
| 9811 | nl80211_remove_iface(drv, ifidx); |
| 9812 | return -1; |
| 9813 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9814 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9815 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9816 | } |
| 9817 | #endif /* CONFIG_P2P */ |
| 9818 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9819 | if (type == WPA_IF_AP_BSS) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9820 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 9821 | if (new_bss == NULL) { |
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 | return -1; |
| 9825 | } |
| 9826 | |
| 9827 | if (bridge && |
| 9828 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 9829 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 9830 | "interface %s to a bridge %s", |
| 9831 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9832 | if (added) |
| 9833 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9834 | os_free(new_bss); |
| 9835 | return -1; |
| 9836 | } |
| 9837 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9838 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 9839 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9840 | nl80211_remove_iface(drv, ifidx); |
| 9841 | os_free(new_bss); |
| 9842 | return -1; |
| 9843 | } |
| 9844 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9845 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9846 | new_bss->ifindex = ifidx; |
| 9847 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9848 | new_bss->next = drv->first_bss->next; |
| 9849 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 9850 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9851 | new_bss->added_if = added; |
| 9852 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9853 | if (drv_priv) |
| 9854 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9855 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9856 | |
| 9857 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 9858 | if (nl80211_setup_ap(new_bss)) |
| 9859 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9860 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9861 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9862 | if (drv->global) |
| 9863 | drv->global->if_add_ifindex = ifidx; |
| 9864 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9865 | return 0; |
| 9866 | } |
| 9867 | |
| 9868 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9869 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9870 | enum wpa_driver_if_type type, |
| 9871 | const char *ifname) |
| 9872 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9873 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9874 | int ifindex = if_nametoindex(ifname); |
| 9875 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9876 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 9877 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 9878 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9879 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 9880 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 9881 | if (type != WPA_IF_AP_BSS) |
| 9882 | return 0; |
| 9883 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9884 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9885 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 9886 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9887 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 9888 | "interface %s from bridge %s: %s", |
| 9889 | bss->ifname, bss->brname, strerror(errno)); |
| 9890 | } |
| 9891 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9892 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9893 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 9894 | "bridge %s: %s", |
| 9895 | bss->brname, strerror(errno)); |
| 9896 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9897 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9898 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9899 | struct i802_bss *tbss; |
| 9900 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9901 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 9902 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9903 | if (tbss->next == bss) { |
| 9904 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9905 | /* Unsubscribe management frames */ |
| 9906 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9907 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9908 | os_free(bss); |
| 9909 | bss = NULL; |
| 9910 | break; |
| 9911 | } |
| 9912 | } |
| 9913 | if (bss) |
| 9914 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 9915 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9916 | } else { |
| 9917 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 9918 | nl80211_teardown_ap(bss); |
| 9919 | if (!bss->added_if && !drv->first_bss->next) |
| 9920 | wpa_driver_nl80211_del_beacon(drv); |
| 9921 | nl80211_destroy_bss(bss); |
| 9922 | if (!bss->added_if) |
| 9923 | i802_set_iface_flags(bss, 0); |
| 9924 | if (drv->first_bss->next) { |
| 9925 | drv->first_bss = drv->first_bss->next; |
| 9926 | drv->ctx = drv->first_bss->ctx; |
| 9927 | os_free(bss); |
| 9928 | } else { |
| 9929 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 9930 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9931 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9932 | |
| 9933 | return 0; |
| 9934 | } |
| 9935 | |
| 9936 | |
| 9937 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 9938 | { |
| 9939 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9940 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9941 | u64 *cookie = arg; |
| 9942 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9943 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9944 | if (tb[NL80211_ATTR_COOKIE]) |
| 9945 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 9946 | return NL_SKIP; |
| 9947 | } |
| 9948 | |
| 9949 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9950 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9951 | unsigned int freq, unsigned int wait, |
| 9952 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9953 | u64 *cookie_out, int no_cck, int no_ack, |
| 9954 | int offchanok) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9955 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9956 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9957 | struct nl_msg *msg; |
| 9958 | u64 cookie; |
| 9959 | int ret = -1; |
| 9960 | |
| 9961 | msg = nlmsg_alloc(); |
| 9962 | if (!msg) |
| 9963 | return -1; |
| 9964 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9965 | 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] | 9966 | "no_ack=%d offchanok=%d", |
| 9967 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 9968 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9969 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9970 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9971 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 9972 | goto nla_put_failure; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 9973 | if (freq) |
| 9974 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9975 | if (wait) |
| 9976 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, wait); |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 9977 | if (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 9978 | drv->test_use_roc_tx)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9979 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 9980 | if (no_cck) |
| 9981 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); |
| 9982 | if (no_ack) |
| 9983 | NLA_PUT_FLAG(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK); |
| 9984 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9985 | NLA_PUT(msg, NL80211_ATTR_FRAME, buf_len, buf); |
| 9986 | |
| 9987 | cookie = 0; |
| 9988 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 9989 | msg = NULL; |
| 9990 | if (ret) { |
| 9991 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9992 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 9993 | freq, wait); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9994 | goto nla_put_failure; |
| 9995 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 9996 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9997 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 9998 | (long long unsigned int) cookie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9999 | |
| 10000 | if (cookie_out) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10001 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10002 | |
| 10003 | nla_put_failure: |
| 10004 | nlmsg_free(msg); |
| 10005 | return ret; |
| 10006 | } |
| 10007 | |
| 10008 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10009 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 10010 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10011 | unsigned int wait_time, |
| 10012 | const u8 *dst, const u8 *src, |
| 10013 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10014 | const u8 *data, size_t data_len, |
| 10015 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10016 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10017 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10018 | int ret = -1; |
| 10019 | u8 *buf; |
| 10020 | struct ieee80211_hdr *hdr; |
| 10021 | |
| 10022 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 10023 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 10024 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10025 | |
| 10026 | buf = os_zalloc(24 + data_len); |
| 10027 | if (buf == NULL) |
| 10028 | return ret; |
| 10029 | os_memcpy(buf + 24, data, data_len); |
| 10030 | hdr = (struct ieee80211_hdr *) buf; |
| 10031 | hdr->frame_control = |
| 10032 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 10033 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 10034 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 10035 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 10036 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10037 | if (is_ap_interface(drv->nlmode) && |
| 10038 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 10039 | (int) freq == bss->freq || drv->device_ap_sme || |
| 10040 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10041 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 10042 | 0, freq, no_cck, 1, |
| 10043 | wait_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10044 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10045 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10046 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10047 | &drv->send_action_cookie, |
| 10048 | no_cck, 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10049 | |
| 10050 | os_free(buf); |
| 10051 | return ret; |
| 10052 | } |
| 10053 | |
| 10054 | |
| 10055 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 10056 | { |
| 10057 | struct i802_bss *bss = priv; |
| 10058 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10059 | struct nl_msg *msg; |
| 10060 | int ret; |
| 10061 | |
| 10062 | msg = nlmsg_alloc(); |
| 10063 | if (!msg) |
| 10064 | return; |
| 10065 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 10066 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
| 10067 | (long long unsigned int) drv->send_action_cookie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10068 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME_WAIT_CANCEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10069 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10070 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 10071 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10072 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie); |
| 10073 | |
| 10074 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10075 | msg = NULL; |
| 10076 | if (ret) |
| 10077 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 10078 | "(%s)", ret, strerror(-ret)); |
| 10079 | |
| 10080 | nla_put_failure: |
| 10081 | nlmsg_free(msg); |
| 10082 | } |
| 10083 | |
| 10084 | |
| 10085 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 10086 | unsigned int duration) |
| 10087 | { |
| 10088 | struct i802_bss *bss = priv; |
| 10089 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10090 | struct nl_msg *msg; |
| 10091 | int ret; |
| 10092 | u64 cookie; |
| 10093 | |
| 10094 | msg = nlmsg_alloc(); |
| 10095 | if (!msg) |
| 10096 | return -1; |
| 10097 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10098 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REMAIN_ON_CHANNEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10099 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10100 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 10101 | goto nla_put_failure; |
| 10102 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10103 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 10104 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 10105 | |
| 10106 | cookie = 0; |
| 10107 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10108 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10109 | if (ret == 0) { |
| 10110 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 10111 | "0x%llx for freq=%u MHz duration=%u", |
| 10112 | (long long unsigned int) cookie, freq, duration); |
| 10113 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10114 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10115 | return 0; |
| 10116 | } |
| 10117 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 10118 | "(freq=%d duration=%u): %d (%s)", |
| 10119 | freq, duration, ret, strerror(-ret)); |
| 10120 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10121 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10122 | return -1; |
| 10123 | } |
| 10124 | |
| 10125 | |
| 10126 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 10127 | { |
| 10128 | struct i802_bss *bss = priv; |
| 10129 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10130 | struct nl_msg *msg; |
| 10131 | int ret; |
| 10132 | |
| 10133 | if (!drv->pending_remain_on_chan) { |
| 10134 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 10135 | "to cancel"); |
| 10136 | return -1; |
| 10137 | } |
| 10138 | |
| 10139 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 10140 | "0x%llx", |
| 10141 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 10142 | |
| 10143 | msg = nlmsg_alloc(); |
| 10144 | if (!msg) |
| 10145 | return -1; |
| 10146 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10147 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10148 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10149 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 10150 | goto nla_put_failure; |
| 10151 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10152 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie); |
| 10153 | |
| 10154 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10155 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10156 | if (ret == 0) |
| 10157 | return 0; |
| 10158 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 10159 | "%d (%s)", ret, strerror(-ret)); |
| 10160 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10161 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10162 | return -1; |
| 10163 | } |
| 10164 | |
| 10165 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10166 | 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] | 10167 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10168 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 10169 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10170 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10171 | if (bss->nl_preq && drv->device_ap_sme && |
| 10172 | is_ap_interface(drv->nlmode)) { |
| 10173 | /* |
| 10174 | * Do not disable Probe Request reporting that was |
| 10175 | * enabled in nl80211_setup_ap(). |
| 10176 | */ |
| 10177 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 10178 | "Probe Request reporting nl_preq=%p while " |
| 10179 | "in AP mode", bss->nl_preq); |
| 10180 | } else if (bss->nl_preq) { |
| 10181 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 10182 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10183 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10184 | } |
| 10185 | return 0; |
| 10186 | } |
| 10187 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10188 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10189 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10190 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10191 | return 0; |
| 10192 | } |
| 10193 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10194 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 10195 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10196 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10197 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 10198 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10199 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10200 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10201 | (WLAN_FC_TYPE_MGMT << 2) | |
| 10202 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10203 | NULL, 0) < 0) |
| 10204 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 10205 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10206 | nl80211_register_eloop_read(&bss->nl_preq, |
| 10207 | wpa_driver_nl80211_event_receive, |
| 10208 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10209 | |
| 10210 | return 0; |
| 10211 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10212 | out_err: |
| 10213 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10214 | return -1; |
| 10215 | } |
| 10216 | |
| 10217 | |
| 10218 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 10219 | int ifindex, int disabled) |
| 10220 | { |
| 10221 | struct nl_msg *msg; |
| 10222 | struct nlattr *bands, *band; |
| 10223 | int ret; |
| 10224 | |
| 10225 | msg = nlmsg_alloc(); |
| 10226 | if (!msg) |
| 10227 | return -1; |
| 10228 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10229 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10230 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 10231 | |
| 10232 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 10233 | if (!bands) |
| 10234 | goto nla_put_failure; |
| 10235 | |
| 10236 | /* |
| 10237 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 10238 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 10239 | * rates. All 5 GHz rates are left enabled. |
| 10240 | */ |
| 10241 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 10242 | if (!band) |
| 10243 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10244 | if (disabled) { |
| 10245 | NLA_PUT(msg, NL80211_TXRATE_LEGACY, 8, |
| 10246 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); |
| 10247 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10248 | nla_nest_end(msg, band); |
| 10249 | |
| 10250 | nla_nest_end(msg, bands); |
| 10251 | |
| 10252 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10253 | msg = NULL; |
| 10254 | if (ret) { |
| 10255 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 10256 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10257 | } else |
| 10258 | drv->disabled_11b_rates = disabled; |
| 10259 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10260 | return ret; |
| 10261 | |
| 10262 | nla_put_failure: |
| 10263 | nlmsg_free(msg); |
| 10264 | return -1; |
| 10265 | } |
| 10266 | |
| 10267 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10268 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 10269 | { |
| 10270 | struct i802_bss *bss = priv; |
| 10271 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10272 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10273 | return -1; |
| 10274 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10275 | |
| 10276 | /* |
| 10277 | * If the P2P GO interface was dynamically added, then it is |
| 10278 | * possible that the interface change to station is not possible. |
| 10279 | */ |
| 10280 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 10281 | return 0; |
| 10282 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10283 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10284 | } |
| 10285 | |
| 10286 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10287 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 10288 | { |
| 10289 | struct i802_bss *bss = priv; |
| 10290 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10291 | if (!is_ap_interface(drv->nlmode)) |
| 10292 | return -1; |
| 10293 | wpa_driver_nl80211_del_beacon(drv); |
| 10294 | bss->beacon_set = 0; |
| 10295 | return 0; |
| 10296 | } |
| 10297 | |
| 10298 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10299 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 10300 | { |
| 10301 | struct i802_bss *bss = priv; |
| 10302 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10303 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 10304 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10305 | |
| 10306 | /* |
| 10307 | * If the P2P Client interface was dynamically added, then it is |
| 10308 | * possible that the interface change to station is not possible. |
| 10309 | */ |
| 10310 | if (bss->if_dynamic) |
| 10311 | return 0; |
| 10312 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10313 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 10314 | } |
| 10315 | |
| 10316 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10317 | static void wpa_driver_nl80211_resume(void *priv) |
| 10318 | { |
| 10319 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10320 | |
| 10321 | if (i802_set_iface_flags(bss, 1)) |
| 10322 | 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] | 10323 | } |
| 10324 | |
| 10325 | |
| 10326 | static int nl80211_send_ft_action(void *priv, u8 action, const u8 *target_ap, |
| 10327 | const u8 *ies, size_t ies_len) |
| 10328 | { |
| 10329 | struct i802_bss *bss = priv; |
| 10330 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10331 | int ret; |
| 10332 | u8 *data, *pos; |
| 10333 | size_t data_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10334 | const u8 *own_addr = bss->addr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10335 | |
| 10336 | if (action != 1) { |
| 10337 | wpa_printf(MSG_ERROR, "nl80211: Unsupported send_ft_action " |
| 10338 | "action %d", action); |
| 10339 | return -1; |
| 10340 | } |
| 10341 | |
| 10342 | /* |
| 10343 | * Action frame payload: |
| 10344 | * Category[1] = 6 (Fast BSS Transition) |
| 10345 | * Action[1] = 1 (Fast BSS Transition Request) |
| 10346 | * STA Address |
| 10347 | * Target AP Address |
| 10348 | * FT IEs |
| 10349 | */ |
| 10350 | |
| 10351 | data_len = 2 + 2 * ETH_ALEN + ies_len; |
| 10352 | data = os_malloc(data_len); |
| 10353 | if (data == NULL) |
| 10354 | return -1; |
| 10355 | pos = data; |
| 10356 | *pos++ = 0x06; /* FT Action category */ |
| 10357 | *pos++ = action; |
| 10358 | os_memcpy(pos, own_addr, ETH_ALEN); |
| 10359 | pos += ETH_ALEN; |
| 10360 | os_memcpy(pos, target_ap, ETH_ALEN); |
| 10361 | pos += ETH_ALEN; |
| 10362 | os_memcpy(pos, ies, ies_len); |
| 10363 | |
| 10364 | ret = wpa_driver_nl80211_send_action(bss, drv->assoc_freq, 0, |
| 10365 | drv->bssid, own_addr, drv->bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10366 | data, data_len, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10367 | os_free(data); |
| 10368 | |
| 10369 | return ret; |
| 10370 | } |
| 10371 | |
| 10372 | |
| 10373 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 10374 | { |
| 10375 | struct i802_bss *bss = priv; |
| 10376 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 10377 | struct nl_msg *msg; |
| 10378 | struct nlattr *cqm; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10379 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10380 | |
| 10381 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 10382 | "hysteresis=%d", threshold, hysteresis); |
| 10383 | |
| 10384 | msg = nlmsg_alloc(); |
| 10385 | if (!msg) |
| 10386 | return -1; |
| 10387 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10388 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_CQM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10389 | |
| 10390 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 10391 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 10392 | cqm = nla_nest_start(msg, NL80211_ATTR_CQM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10393 | if (cqm == NULL) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10394 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10395 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 10396 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold); |
| 10397 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis); |
| 10398 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10399 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10400 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10401 | msg = NULL; |
| 10402 | |
| 10403 | nla_put_failure: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10404 | nlmsg_free(msg); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 10405 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10406 | } |
| 10407 | |
| 10408 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10409 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 10410 | { |
| 10411 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10412 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10413 | struct wpa_signal_info *sig_change = arg; |
| 10414 | |
| 10415 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10416 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10417 | |
| 10418 | sig_change->center_frq1 = -1; |
| 10419 | sig_change->center_frq2 = -1; |
| 10420 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 10421 | |
| 10422 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 10423 | sig_change->chanwidth = convert2width( |
| 10424 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 10425 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 10426 | sig_change->center_frq1 = |
| 10427 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 10428 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 10429 | sig_change->center_frq2 = |
| 10430 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 10431 | } |
| 10432 | |
| 10433 | return NL_SKIP; |
| 10434 | } |
| 10435 | |
| 10436 | |
| 10437 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 10438 | struct wpa_signal_info *sig) |
| 10439 | { |
| 10440 | struct nl_msg *msg; |
| 10441 | |
| 10442 | msg = nlmsg_alloc(); |
| 10443 | if (!msg) |
| 10444 | return -ENOMEM; |
| 10445 | |
| 10446 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_INTERFACE); |
| 10447 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 10448 | |
| 10449 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
| 10450 | |
| 10451 | nla_put_failure: |
| 10452 | nlmsg_free(msg); |
| 10453 | return -ENOBUFS; |
| 10454 | } |
| 10455 | |
| 10456 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10457 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 10458 | { |
| 10459 | struct i802_bss *bss = priv; |
| 10460 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10461 | int res; |
| 10462 | |
| 10463 | os_memset(si, 0, sizeof(*si)); |
| 10464 | res = nl80211_get_link_signal(drv, si); |
| 10465 | if (res != 0) |
| 10466 | return res; |
| 10467 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10468 | res = nl80211_get_channel_width(drv, si); |
| 10469 | if (res != 0) |
| 10470 | return res; |
| 10471 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10472 | return nl80211_get_link_noise(drv, si); |
| 10473 | } |
| 10474 | |
| 10475 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10476 | static int wpa_driver_nl80211_shared_freq(void *priv) |
| 10477 | { |
| 10478 | struct i802_bss *bss = priv; |
| 10479 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10480 | struct wpa_driver_nl80211_data *driver; |
| 10481 | int freq = 0; |
| 10482 | |
| 10483 | /* |
| 10484 | * If the same PHY is in connected state with some other interface, |
| 10485 | * then retrieve the assoc freq. |
| 10486 | */ |
| 10487 | wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s", |
| 10488 | drv->phyname); |
| 10489 | |
| 10490 | dl_list_for_each(driver, &drv->global->interfaces, |
| 10491 | struct wpa_driver_nl80211_data, list) { |
| 10492 | if (drv == driver || |
| 10493 | os_strcmp(drv->phyname, driver->phyname) != 0 || |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10494 | !driver->associated) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10495 | continue; |
| 10496 | |
| 10497 | wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s " |
| 10498 | MACSTR, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 10499 | driver->phyname, driver->first_bss->ifname, |
| 10500 | MAC2STR(driver->first_bss->addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10501 | if (is_ap_interface(driver->nlmode)) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 10502 | freq = driver->first_bss->freq; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10503 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10504 | freq = nl80211_get_assoc_freq(driver); |
| 10505 | wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d", |
| 10506 | drv->phyname, freq); |
| 10507 | } |
| 10508 | |
| 10509 | if (!freq) |
| 10510 | wpa_printf(MSG_DEBUG, "nl80211: No shared interface for " |
| 10511 | "PHY (%s) in associated state", drv->phyname); |
| 10512 | |
| 10513 | return freq; |
| 10514 | } |
| 10515 | |
| 10516 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10517 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 10518 | int encrypt) |
| 10519 | { |
| 10520 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 10521 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
| 10522 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10523 | } |
| 10524 | |
| 10525 | |
| 10526 | static int nl80211_set_param(void *priv, const char *param) |
| 10527 | { |
| 10528 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
| 10529 | if (param == NULL) |
| 10530 | return 0; |
| 10531 | |
| 10532 | #ifdef CONFIG_P2P |
| 10533 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 10534 | struct i802_bss *bss = priv; |
| 10535 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10536 | |
| 10537 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 10538 | "interface"); |
| 10539 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 10540 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 10541 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10542 | |
| 10543 | if (os_strstr(param, "p2p_device=1")) { |
| 10544 | struct i802_bss *bss = priv; |
| 10545 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10546 | drv->allow_p2p_device = 1; |
| 10547 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10548 | #endif /* CONFIG_P2P */ |
| 10549 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10550 | if (os_strstr(param, "use_monitor=1")) { |
| 10551 | struct i802_bss *bss = priv; |
| 10552 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10553 | drv->use_monitor = 1; |
| 10554 | } |
| 10555 | |
| 10556 | if (os_strstr(param, "force_connect_cmd=1")) { |
| 10557 | struct i802_bss *bss = priv; |
| 10558 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10559 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
| 10560 | } |
| 10561 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 10562 | if (os_strstr(param, "no_offchannel_tx=1")) { |
| 10563 | struct i802_bss *bss = priv; |
| 10564 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10565 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 10566 | drv->test_use_roc_tx = 1; |
| 10567 | } |
| 10568 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10569 | return 0; |
| 10570 | } |
| 10571 | |
| 10572 | |
| 10573 | static void * nl80211_global_init(void) |
| 10574 | { |
| 10575 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10576 | struct netlink_config *cfg; |
| 10577 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10578 | global = os_zalloc(sizeof(*global)); |
| 10579 | if (global == NULL) |
| 10580 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10581 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10582 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10583 | global->if_add_ifindex = -1; |
| 10584 | |
| 10585 | cfg = os_zalloc(sizeof(*cfg)); |
| 10586 | if (cfg == NULL) |
| 10587 | goto err; |
| 10588 | |
| 10589 | cfg->ctx = global; |
| 10590 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 10591 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 10592 | global->netlink = netlink_init(cfg); |
| 10593 | if (global->netlink == NULL) { |
| 10594 | os_free(cfg); |
| 10595 | goto err; |
| 10596 | } |
| 10597 | |
| 10598 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 10599 | goto err; |
| 10600 | |
| 10601 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 10602 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10603 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 10604 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10605 | goto err; |
| 10606 | } |
| 10607 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10608 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10609 | |
| 10610 | err: |
| 10611 | nl80211_global_deinit(global); |
| 10612 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10613 | } |
| 10614 | |
| 10615 | |
| 10616 | static void nl80211_global_deinit(void *priv) |
| 10617 | { |
| 10618 | struct nl80211_global *global = priv; |
| 10619 | if (global == NULL) |
| 10620 | return; |
| 10621 | if (!dl_list_empty(&global->interfaces)) { |
| 10622 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 10623 | "nl80211_global_deinit", |
| 10624 | dl_list_len(&global->interfaces)); |
| 10625 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10626 | |
| 10627 | if (global->netlink) |
| 10628 | netlink_deinit(global->netlink); |
| 10629 | |
| 10630 | nl_destroy_handles(&global->nl); |
| 10631 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 10632 | if (global->nl_event) |
| 10633 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10634 | |
| 10635 | nl_cb_put(global->nl_cb); |
| 10636 | |
| 10637 | if (global->ioctl_sock >= 0) |
| 10638 | close(global->ioctl_sock); |
| 10639 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10640 | os_free(global); |
| 10641 | } |
| 10642 | |
| 10643 | |
| 10644 | static const char * nl80211_get_radio_name(void *priv) |
| 10645 | { |
| 10646 | struct i802_bss *bss = priv; |
| 10647 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10648 | return drv->phyname; |
| 10649 | } |
| 10650 | |
| 10651 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10652 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 10653 | const u8 *pmkid) |
| 10654 | { |
| 10655 | struct nl_msg *msg; |
| 10656 | |
| 10657 | msg = nlmsg_alloc(); |
| 10658 | if (!msg) |
| 10659 | return -ENOMEM; |
| 10660 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10661 | nl80211_cmd(bss->drv, msg, 0, cmd); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10662 | |
| 10663 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 10664 | if (pmkid) |
| 10665 | NLA_PUT(msg, NL80211_ATTR_PMKID, 16, pmkid); |
| 10666 | if (bssid) |
| 10667 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 10668 | |
| 10669 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 10670 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10671 | nlmsg_free(msg); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10672 | return -ENOBUFS; |
| 10673 | } |
| 10674 | |
| 10675 | |
| 10676 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 10677 | { |
| 10678 | struct i802_bss *bss = priv; |
| 10679 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 10680 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 10681 | } |
| 10682 | |
| 10683 | |
| 10684 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 10685 | { |
| 10686 | struct i802_bss *bss = priv; |
| 10687 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 10688 | MAC2STR(bssid)); |
| 10689 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 10690 | } |
| 10691 | |
| 10692 | |
| 10693 | static int nl80211_flush_pmkid(void *priv) |
| 10694 | { |
| 10695 | struct i802_bss *bss = priv; |
| 10696 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 10697 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 10698 | } |
| 10699 | |
| 10700 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10701 | static void clean_survey_results(struct survey_results *survey_results) |
| 10702 | { |
| 10703 | struct freq_survey *survey, *tmp; |
| 10704 | |
| 10705 | if (dl_list_empty(&survey_results->survey_list)) |
| 10706 | return; |
| 10707 | |
| 10708 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 10709 | struct freq_survey, list) { |
| 10710 | dl_list_del(&survey->list); |
| 10711 | os_free(survey); |
| 10712 | } |
| 10713 | } |
| 10714 | |
| 10715 | |
| 10716 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 10717 | struct dl_list *survey_list) |
| 10718 | { |
| 10719 | struct freq_survey *survey; |
| 10720 | |
| 10721 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 10722 | if (!survey) |
| 10723 | return; |
| 10724 | |
| 10725 | survey->ifidx = ifidx; |
| 10726 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 10727 | survey->filled = 0; |
| 10728 | |
| 10729 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 10730 | survey->nf = (int8_t) |
| 10731 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 10732 | survey->filled |= SURVEY_HAS_NF; |
| 10733 | } |
| 10734 | |
| 10735 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 10736 | survey->channel_time = |
| 10737 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 10738 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 10739 | } |
| 10740 | |
| 10741 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 10742 | survey->channel_time_busy = |
| 10743 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 10744 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 10745 | } |
| 10746 | |
| 10747 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 10748 | survey->channel_time_rx = |
| 10749 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 10750 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 10751 | } |
| 10752 | |
| 10753 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 10754 | survey->channel_time_tx = |
| 10755 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 10756 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 10757 | } |
| 10758 | |
| 10759 | 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)", |
| 10760 | survey->freq, |
| 10761 | survey->nf, |
| 10762 | (unsigned long int) survey->channel_time, |
| 10763 | (unsigned long int) survey->channel_time_busy, |
| 10764 | (unsigned long int) survey->channel_time_tx, |
| 10765 | (unsigned long int) survey->channel_time_rx, |
| 10766 | survey->filled); |
| 10767 | |
| 10768 | dl_list_add_tail(survey_list, &survey->list); |
| 10769 | } |
| 10770 | |
| 10771 | |
| 10772 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 10773 | unsigned int freq_filter) |
| 10774 | { |
| 10775 | if (!freq_filter) |
| 10776 | return 1; |
| 10777 | |
| 10778 | return freq_filter == surveyed_freq; |
| 10779 | } |
| 10780 | |
| 10781 | |
| 10782 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 10783 | { |
| 10784 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10785 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10786 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 10787 | struct survey_results *survey_results; |
| 10788 | u32 surveyed_freq = 0; |
| 10789 | u32 ifidx; |
| 10790 | |
| 10791 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 10792 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 10793 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 10794 | }; |
| 10795 | |
| 10796 | survey_results = (struct survey_results *) arg; |
| 10797 | |
| 10798 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10799 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10800 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 10801 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 10802 | return NL_SKIP; |
| 10803 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10804 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 10805 | |
| 10806 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 10807 | return NL_SKIP; |
| 10808 | |
| 10809 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 10810 | tb[NL80211_ATTR_SURVEY_INFO], |
| 10811 | survey_policy)) |
| 10812 | return NL_SKIP; |
| 10813 | |
| 10814 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 10815 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 10816 | return NL_SKIP; |
| 10817 | } |
| 10818 | |
| 10819 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 10820 | |
| 10821 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 10822 | survey_results->freq_filter)) |
| 10823 | return NL_SKIP; |
| 10824 | |
| 10825 | if (survey_results->freq_filter && |
| 10826 | survey_results->freq_filter != surveyed_freq) { |
| 10827 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 10828 | surveyed_freq); |
| 10829 | return NL_SKIP; |
| 10830 | } |
| 10831 | |
| 10832 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 10833 | |
| 10834 | return NL_SKIP; |
| 10835 | } |
| 10836 | |
| 10837 | |
| 10838 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 10839 | { |
| 10840 | struct i802_bss *bss = priv; |
| 10841 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10842 | struct nl_msg *msg; |
| 10843 | int err = -ENOBUFS; |
| 10844 | union wpa_event_data data; |
| 10845 | struct survey_results *survey_results; |
| 10846 | |
| 10847 | os_memset(&data, 0, sizeof(data)); |
| 10848 | survey_results = &data.survey_results; |
| 10849 | |
| 10850 | dl_list_init(&survey_results->survey_list); |
| 10851 | |
| 10852 | msg = nlmsg_alloc(); |
| 10853 | if (!msg) |
| 10854 | goto nla_put_failure; |
| 10855 | |
| 10856 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
| 10857 | |
| 10858 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 10859 | |
| 10860 | if (freq) |
| 10861 | data.survey_results.freq_filter = freq; |
| 10862 | |
| 10863 | do { |
| 10864 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 10865 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 10866 | survey_results); |
| 10867 | } while (err > 0); |
| 10868 | |
| 10869 | if (err) { |
| 10870 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
| 10871 | goto out_clean; |
| 10872 | } |
| 10873 | |
| 10874 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
| 10875 | |
| 10876 | out_clean: |
| 10877 | clean_survey_results(survey_results); |
| 10878 | nla_put_failure: |
| 10879 | return err; |
| 10880 | } |
| 10881 | |
| 10882 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10883 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, const u8 *kck, |
| 10884 | const u8 *replay_ctr) |
| 10885 | { |
| 10886 | struct i802_bss *bss = priv; |
| 10887 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10888 | struct nlattr *replay_nested; |
| 10889 | struct nl_msg *msg; |
| 10890 | |
| 10891 | msg = nlmsg_alloc(); |
| 10892 | if (!msg) |
| 10893 | return; |
| 10894 | |
| 10895 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10896 | |
| 10897 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 10898 | |
| 10899 | replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10900 | if (!replay_nested) |
| 10901 | goto nla_put_failure; |
| 10902 | |
| 10903 | NLA_PUT(msg, NL80211_REKEY_DATA_KEK, NL80211_KEK_LEN, kek); |
| 10904 | NLA_PUT(msg, NL80211_REKEY_DATA_KCK, NL80211_KCK_LEN, kck); |
| 10905 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 10906 | replay_ctr); |
| 10907 | |
| 10908 | nla_nest_end(msg, replay_nested); |
| 10909 | |
| 10910 | send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10911 | return; |
| 10912 | nla_put_failure: |
| 10913 | nlmsg_free(msg); |
| 10914 | } |
| 10915 | |
| 10916 | |
| 10917 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 10918 | const u8 *addr, int qos) |
| 10919 | { |
| 10920 | /* send data frame to poll STA and check whether |
| 10921 | * this frame is ACKed */ |
| 10922 | struct { |
| 10923 | struct ieee80211_hdr hdr; |
| 10924 | u16 qos_ctl; |
| 10925 | } STRUCT_PACKED nulldata; |
| 10926 | size_t size; |
| 10927 | |
| 10928 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 10929 | |
| 10930 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 10931 | |
| 10932 | if (qos) { |
| 10933 | nulldata.hdr.frame_control = |
| 10934 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 10935 | WLAN_FC_STYPE_QOS_NULL); |
| 10936 | size = sizeof(nulldata); |
| 10937 | } else { |
| 10938 | nulldata.hdr.frame_control = |
| 10939 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 10940 | WLAN_FC_STYPE_NULLFUNC); |
| 10941 | size = sizeof(struct ieee80211_hdr); |
| 10942 | } |
| 10943 | |
| 10944 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 10945 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 10946 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 10947 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 10948 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10949 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
| 10950 | 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10951 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 10952 | "send poll frame"); |
| 10953 | } |
| 10954 | |
| 10955 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 10956 | int qos) |
| 10957 | { |
| 10958 | struct i802_bss *bss = priv; |
| 10959 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10960 | struct nl_msg *msg; |
| 10961 | |
| 10962 | if (!drv->poll_command_supported) { |
| 10963 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 10964 | return; |
| 10965 | } |
| 10966 | |
| 10967 | msg = nlmsg_alloc(); |
| 10968 | if (!msg) |
| 10969 | return; |
| 10970 | |
| 10971 | nl80211_cmd(drv, msg, 0, NL80211_CMD_PROBE_CLIENT); |
| 10972 | |
| 10973 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 10974 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 10975 | |
| 10976 | send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10977 | return; |
| 10978 | nla_put_failure: |
| 10979 | nlmsg_free(msg); |
| 10980 | } |
| 10981 | |
| 10982 | |
| 10983 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 10984 | { |
| 10985 | struct nl_msg *msg; |
| 10986 | |
| 10987 | msg = nlmsg_alloc(); |
| 10988 | if (!msg) |
| 10989 | return -ENOMEM; |
| 10990 | |
| 10991 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_SET_POWER_SAVE); |
| 10992 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 10993 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, |
| 10994 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED); |
| 10995 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 10996 | nla_put_failure: |
| 10997 | nlmsg_free(msg); |
| 10998 | return -ENOBUFS; |
| 10999 | } |
| 11000 | |
| 11001 | |
| 11002 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 11003 | int ctwindow) |
| 11004 | { |
| 11005 | struct i802_bss *bss = priv; |
| 11006 | |
| 11007 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 11008 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 11009 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11010 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 11011 | #ifdef ANDROID_P2P |
| 11012 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11013 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11014 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11015 | #endif /* ANDROID_P2P */ |
| 11016 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11017 | |
| 11018 | if (legacy_ps == -1) |
| 11019 | return 0; |
| 11020 | if (legacy_ps != 0 && legacy_ps != 1) |
| 11021 | return -1; /* Not yet supported */ |
| 11022 | |
| 11023 | return nl80211_set_power_save(bss, legacy_ps); |
| 11024 | } |
| 11025 | |
| 11026 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11027 | static int nl80211_start_radar_detection(void *priv, |
| 11028 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11029 | { |
| 11030 | struct i802_bss *bss = priv; |
| 11031 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11032 | struct nl_msg *msg; |
| 11033 | int ret; |
| 11034 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11035 | 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)", |
| 11036 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 11037 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 11038 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11039 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 11040 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 11041 | "detection"); |
| 11042 | return -1; |
| 11043 | } |
| 11044 | |
| 11045 | msg = nlmsg_alloc(); |
| 11046 | if (!msg) |
| 11047 | return -1; |
| 11048 | |
| 11049 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_RADAR_DETECT); |
| 11050 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11051 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11052 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 11053 | if (freq->vht_enabled) { |
| 11054 | switch (freq->bandwidth) { |
| 11055 | case 20: |
| 11056 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11057 | NL80211_CHAN_WIDTH_20); |
| 11058 | break; |
| 11059 | case 40: |
| 11060 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11061 | NL80211_CHAN_WIDTH_40); |
| 11062 | break; |
| 11063 | case 80: |
| 11064 | if (freq->center_freq2) |
| 11065 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11066 | NL80211_CHAN_WIDTH_80P80); |
| 11067 | else |
| 11068 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11069 | NL80211_CHAN_WIDTH_80); |
| 11070 | break; |
| 11071 | case 160: |
| 11072 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 11073 | NL80211_CHAN_WIDTH_160); |
| 11074 | break; |
| 11075 | default: |
| 11076 | return -1; |
| 11077 | } |
| 11078 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); |
| 11079 | if (freq->center_freq2) |
| 11080 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 11081 | freq->center_freq2); |
| 11082 | } else if (freq->ht_enabled) { |
| 11083 | switch (freq->sec_channel_offset) { |
| 11084 | case -1: |
| 11085 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11086 | NL80211_CHAN_HT40MINUS); |
| 11087 | break; |
| 11088 | case 1: |
| 11089 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11090 | NL80211_CHAN_HT40PLUS); |
| 11091 | break; |
| 11092 | default: |
| 11093 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11094 | NL80211_CHAN_HT20); |
| 11095 | break; |
| 11096 | } |
| 11097 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11098 | |
| 11099 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11100 | if (ret == 0) |
| 11101 | return 0; |
| 11102 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 11103 | "%d (%s)", ret, strerror(-ret)); |
| 11104 | nla_put_failure: |
| 11105 | return -1; |
| 11106 | } |
| 11107 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11108 | #ifdef CONFIG_TDLS |
| 11109 | |
| 11110 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 11111 | u8 dialog_token, u16 status_code, |
| 11112 | const u8 *buf, size_t len) |
| 11113 | { |
| 11114 | struct i802_bss *bss = priv; |
| 11115 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11116 | struct nl_msg *msg; |
| 11117 | |
| 11118 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 11119 | return -EOPNOTSUPP; |
| 11120 | |
| 11121 | if (!dst) |
| 11122 | return -EINVAL; |
| 11123 | |
| 11124 | msg = nlmsg_alloc(); |
| 11125 | if (!msg) |
| 11126 | return -ENOMEM; |
| 11127 | |
| 11128 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_MGMT); |
| 11129 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11130 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 11131 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_ACTION, action_code); |
| 11132 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token); |
| 11133 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status_code); |
| 11134 | NLA_PUT(msg, NL80211_ATTR_IE, len, buf); |
| 11135 | |
| 11136 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11137 | |
| 11138 | nla_put_failure: |
| 11139 | nlmsg_free(msg); |
| 11140 | return -ENOBUFS; |
| 11141 | } |
| 11142 | |
| 11143 | |
| 11144 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 11145 | { |
| 11146 | struct i802_bss *bss = priv; |
| 11147 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11148 | struct nl_msg *msg; |
| 11149 | enum nl80211_tdls_operation nl80211_oper; |
| 11150 | |
| 11151 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 11152 | return -EOPNOTSUPP; |
| 11153 | |
| 11154 | switch (oper) { |
| 11155 | case TDLS_DISCOVERY_REQ: |
| 11156 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 11157 | break; |
| 11158 | case TDLS_SETUP: |
| 11159 | nl80211_oper = NL80211_TDLS_SETUP; |
| 11160 | break; |
| 11161 | case TDLS_TEARDOWN: |
| 11162 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 11163 | break; |
| 11164 | case TDLS_ENABLE_LINK: |
| 11165 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 11166 | break; |
| 11167 | case TDLS_DISABLE_LINK: |
| 11168 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 11169 | break; |
| 11170 | case TDLS_ENABLE: |
| 11171 | return 0; |
| 11172 | case TDLS_DISABLE: |
| 11173 | return 0; |
| 11174 | default: |
| 11175 | return -EINVAL; |
| 11176 | } |
| 11177 | |
| 11178 | msg = nlmsg_alloc(); |
| 11179 | if (!msg) |
| 11180 | return -ENOMEM; |
| 11181 | |
| 11182 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_OPER); |
| 11183 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper); |
| 11184 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11185 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 11186 | |
| 11187 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11188 | |
| 11189 | nla_put_failure: |
| 11190 | nlmsg_free(msg); |
| 11191 | return -ENOBUFS; |
| 11192 | } |
| 11193 | |
| 11194 | #endif /* CONFIG TDLS */ |
| 11195 | |
| 11196 | |
| 11197 | #ifdef ANDROID |
| 11198 | |
| 11199 | typedef struct android_wifi_priv_cmd { |
| 11200 | char *buf; |
| 11201 | int used_len; |
| 11202 | int total_len; |
| 11203 | } android_wifi_priv_cmd; |
| 11204 | |
| 11205 | static int drv_errors = 0; |
| 11206 | |
| 11207 | static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data *drv) |
| 11208 | { |
| 11209 | drv_errors++; |
| 11210 | if (drv_errors > DRV_NUMBER_SEQUENTIAL_ERRORS) { |
| 11211 | drv_errors = 0; |
| 11212 | wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); |
| 11213 | } |
| 11214 | } |
| 11215 | |
| 11216 | |
| 11217 | static int android_priv_cmd(struct i802_bss *bss, const char *cmd) |
| 11218 | { |
| 11219 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11220 | struct ifreq ifr; |
| 11221 | android_wifi_priv_cmd priv_cmd; |
| 11222 | char buf[MAX_DRV_CMD_SIZE]; |
| 11223 | int ret; |
| 11224 | |
| 11225 | os_memset(&ifr, 0, sizeof(ifr)); |
| 11226 | os_memset(&priv_cmd, 0, sizeof(priv_cmd)); |
| 11227 | os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); |
| 11228 | |
| 11229 | os_memset(buf, 0, sizeof(buf)); |
| 11230 | os_strlcpy(buf, cmd, sizeof(buf)); |
| 11231 | |
| 11232 | priv_cmd.buf = buf; |
| 11233 | priv_cmd.used_len = sizeof(buf); |
| 11234 | priv_cmd.total_len = sizeof(buf); |
| 11235 | ifr.ifr_data = &priv_cmd; |
| 11236 | |
| 11237 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); |
| 11238 | if (ret < 0) { |
| 11239 | wpa_printf(MSG_ERROR, "%s: failed to issue private commands", |
| 11240 | __func__); |
| 11241 | wpa_driver_send_hang_msg(drv); |
| 11242 | return ret; |
| 11243 | } |
| 11244 | |
| 11245 | drv_errors = 0; |
| 11246 | return 0; |
| 11247 | } |
| 11248 | |
| 11249 | |
| 11250 | static int android_pno_start(struct i802_bss *bss, |
| 11251 | struct wpa_driver_scan_params *params) |
| 11252 | { |
| 11253 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11254 | struct ifreq ifr; |
| 11255 | android_wifi_priv_cmd priv_cmd; |
| 11256 | int ret = 0, i = 0, bp; |
| 11257 | char buf[WEXT_PNO_MAX_COMMAND_SIZE]; |
| 11258 | |
| 11259 | bp = WEXT_PNOSETUP_HEADER_SIZE; |
| 11260 | os_memcpy(buf, WEXT_PNOSETUP_HEADER, bp); |
| 11261 | buf[bp++] = WEXT_PNO_TLV_PREFIX; |
| 11262 | buf[bp++] = WEXT_PNO_TLV_VERSION; |
| 11263 | buf[bp++] = WEXT_PNO_TLV_SUBVERSION; |
| 11264 | buf[bp++] = WEXT_PNO_TLV_RESERVED; |
| 11265 | |
| 11266 | while (i < WEXT_PNO_AMOUNT && (size_t) i < params->num_ssids) { |
| 11267 | /* Check that there is enough space needed for 1 more SSID, the |
| 11268 | * other sections and null termination */ |
| 11269 | if ((bp + WEXT_PNO_SSID_HEADER_SIZE + MAX_SSID_LEN + |
| 11270 | WEXT_PNO_NONSSID_SECTIONS_SIZE + 1) >= (int) sizeof(buf)) |
| 11271 | break; |
| 11272 | wpa_hexdump_ascii(MSG_DEBUG, "For PNO Scan", |
| 11273 | params->ssids[i].ssid, |
| 11274 | params->ssids[i].ssid_len); |
| 11275 | buf[bp++] = WEXT_PNO_SSID_SECTION; |
| 11276 | buf[bp++] = params->ssids[i].ssid_len; |
| 11277 | os_memcpy(&buf[bp], params->ssids[i].ssid, |
| 11278 | params->ssids[i].ssid_len); |
| 11279 | bp += params->ssids[i].ssid_len; |
| 11280 | i++; |
| 11281 | } |
| 11282 | |
| 11283 | buf[bp++] = WEXT_PNO_SCAN_INTERVAL_SECTION; |
| 11284 | os_snprintf(&buf[bp], WEXT_PNO_SCAN_INTERVAL_LENGTH + 1, "%x", |
| 11285 | WEXT_PNO_SCAN_INTERVAL); |
| 11286 | bp += WEXT_PNO_SCAN_INTERVAL_LENGTH; |
| 11287 | |
| 11288 | buf[bp++] = WEXT_PNO_REPEAT_SECTION; |
| 11289 | os_snprintf(&buf[bp], WEXT_PNO_REPEAT_LENGTH + 1, "%x", |
| 11290 | WEXT_PNO_REPEAT); |
| 11291 | bp += WEXT_PNO_REPEAT_LENGTH; |
| 11292 | |
| 11293 | buf[bp++] = WEXT_PNO_MAX_REPEAT_SECTION; |
| 11294 | os_snprintf(&buf[bp], WEXT_PNO_MAX_REPEAT_LENGTH + 1, "%x", |
| 11295 | WEXT_PNO_MAX_REPEAT); |
| 11296 | bp += WEXT_PNO_MAX_REPEAT_LENGTH + 1; |
| 11297 | |
| 11298 | memset(&ifr, 0, sizeof(ifr)); |
| 11299 | memset(&priv_cmd, 0, sizeof(priv_cmd)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 11300 | os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11301 | |
| 11302 | priv_cmd.buf = buf; |
| 11303 | priv_cmd.used_len = bp; |
| 11304 | priv_cmd.total_len = bp; |
| 11305 | ifr.ifr_data = &priv_cmd; |
| 11306 | |
| 11307 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); |
| 11308 | |
| 11309 | if (ret < 0) { |
| 11310 | wpa_printf(MSG_ERROR, "ioctl[SIOCSIWPRIV] (pnosetup): %d", |
| 11311 | ret); |
| 11312 | wpa_driver_send_hang_msg(drv); |
| 11313 | return ret; |
| 11314 | } |
| 11315 | |
| 11316 | drv_errors = 0; |
| 11317 | |
| 11318 | return android_priv_cmd(bss, "PNOFORCE 1"); |
| 11319 | } |
| 11320 | |
| 11321 | |
| 11322 | static int android_pno_stop(struct i802_bss *bss) |
| 11323 | { |
| 11324 | return android_priv_cmd(bss, "PNOFORCE 0"); |
| 11325 | } |
| 11326 | |
| 11327 | #endif /* ANDROID */ |
| 11328 | |
| 11329 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11330 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 11331 | enum wpa_alg alg, const u8 *addr, |
| 11332 | int key_idx, int set_tx, |
| 11333 | const u8 *seq, size_t seq_len, |
| 11334 | const u8 *key, size_t key_len) |
| 11335 | { |
| 11336 | struct i802_bss *bss = priv; |
| 11337 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 11338 | set_tx, seq, seq_len, key, key_len); |
| 11339 | } |
| 11340 | |
| 11341 | |
| 11342 | static int driver_nl80211_scan2(void *priv, |
| 11343 | struct wpa_driver_scan_params *params) |
| 11344 | { |
| 11345 | struct i802_bss *bss = priv; |
| 11346 | return wpa_driver_nl80211_scan(bss, params); |
| 11347 | } |
| 11348 | |
| 11349 | |
| 11350 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 11351 | int reason_code) |
| 11352 | { |
| 11353 | struct i802_bss *bss = priv; |
| 11354 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 11355 | } |
| 11356 | |
| 11357 | |
| 11358 | static int driver_nl80211_authenticate(void *priv, |
| 11359 | struct wpa_driver_auth_params *params) |
| 11360 | { |
| 11361 | struct i802_bss *bss = priv; |
| 11362 | return wpa_driver_nl80211_authenticate(bss, params); |
| 11363 | } |
| 11364 | |
| 11365 | |
| 11366 | static void driver_nl80211_deinit(void *priv) |
| 11367 | { |
| 11368 | struct i802_bss *bss = priv; |
| 11369 | wpa_driver_nl80211_deinit(bss); |
| 11370 | } |
| 11371 | |
| 11372 | |
| 11373 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 11374 | const char *ifname) |
| 11375 | { |
| 11376 | struct i802_bss *bss = priv; |
| 11377 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 11378 | } |
| 11379 | |
| 11380 | |
| 11381 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
| 11382 | size_t data_len, int noack) |
| 11383 | { |
| 11384 | struct i802_bss *bss = priv; |
| 11385 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
| 11386 | 0, 0, 0, 0); |
| 11387 | } |
| 11388 | |
| 11389 | |
| 11390 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 11391 | { |
| 11392 | struct i802_bss *bss = priv; |
| 11393 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 11394 | } |
| 11395 | |
| 11396 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11397 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 11398 | const char *ifname, int vlan_id) |
| 11399 | { |
| 11400 | struct i802_bss *bss = priv; |
| 11401 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 11402 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11403 | |
| 11404 | |
| 11405 | static int driver_nl80211_read_sta_data(void *priv, |
| 11406 | struct hostap_sta_driver_data *data, |
| 11407 | const u8 *addr) |
| 11408 | { |
| 11409 | struct i802_bss *bss = priv; |
| 11410 | return i802_read_sta_data(bss, data, addr); |
| 11411 | } |
| 11412 | |
| 11413 | |
| 11414 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 11415 | unsigned int wait_time, |
| 11416 | const u8 *dst, const u8 *src, |
| 11417 | const u8 *bssid, |
| 11418 | const u8 *data, size_t data_len, |
| 11419 | int no_cck) |
| 11420 | { |
| 11421 | struct i802_bss *bss = priv; |
| 11422 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 11423 | bssid, data, data_len, no_cck); |
| 11424 | } |
| 11425 | |
| 11426 | |
| 11427 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 11428 | { |
| 11429 | struct i802_bss *bss = priv; |
| 11430 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 11431 | } |
| 11432 | |
| 11433 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 11434 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 11435 | const u8 *ies, size_t ies_len) |
| 11436 | { |
| 11437 | int ret; |
| 11438 | struct nl_msg *msg; |
| 11439 | struct i802_bss *bss = priv; |
| 11440 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11441 | u16 mdid = WPA_GET_LE16(md); |
| 11442 | |
| 11443 | msg = nlmsg_alloc(); |
| 11444 | if (!msg) |
| 11445 | return -ENOMEM; |
| 11446 | |
| 11447 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
| 11448 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UPDATE_FT_IES); |
| 11449 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11450 | NLA_PUT(msg, NL80211_ATTR_IE, ies_len, ies); |
| 11451 | NLA_PUT_U16(msg, NL80211_ATTR_MDID, mdid); |
| 11452 | |
| 11453 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11454 | if (ret) { |
| 11455 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 11456 | "err=%d (%s)", ret, strerror(-ret)); |
| 11457 | } |
| 11458 | |
| 11459 | return ret; |
| 11460 | |
| 11461 | nla_put_failure: |
| 11462 | nlmsg_free(msg); |
| 11463 | return -ENOBUFS; |
| 11464 | } |
| 11465 | |
| 11466 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11467 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
| 11468 | { |
| 11469 | struct i802_bss *bss = priv; |
| 11470 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11471 | |
| 11472 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 11473 | return NULL; |
| 11474 | |
| 11475 | return bss->addr; |
| 11476 | } |
| 11477 | |
| 11478 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11479 | static const char * scan_state_str(enum scan_states scan_state) |
| 11480 | { |
| 11481 | switch (scan_state) { |
| 11482 | case NO_SCAN: |
| 11483 | return "NO_SCAN"; |
| 11484 | case SCAN_REQUESTED: |
| 11485 | return "SCAN_REQUESTED"; |
| 11486 | case SCAN_STARTED: |
| 11487 | return "SCAN_STARTED"; |
| 11488 | case SCAN_COMPLETED: |
| 11489 | return "SCAN_COMPLETED"; |
| 11490 | case SCAN_ABORTED: |
| 11491 | return "SCAN_ABORTED"; |
| 11492 | case SCHED_SCAN_STARTED: |
| 11493 | return "SCHED_SCAN_STARTED"; |
| 11494 | case SCHED_SCAN_STOPPED: |
| 11495 | return "SCHED_SCAN_STOPPED"; |
| 11496 | case SCHED_SCAN_RESULTS: |
| 11497 | return "SCHED_SCAN_RESULTS"; |
| 11498 | } |
| 11499 | |
| 11500 | return "??"; |
| 11501 | } |
| 11502 | |
| 11503 | |
| 11504 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 11505 | { |
| 11506 | struct i802_bss *bss = priv; |
| 11507 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11508 | int res; |
| 11509 | char *pos, *end; |
| 11510 | |
| 11511 | pos = buf; |
| 11512 | end = buf + buflen; |
| 11513 | |
| 11514 | res = os_snprintf(pos, end - pos, |
| 11515 | "ifindex=%d\n" |
| 11516 | "ifname=%s\n" |
| 11517 | "brname=%s\n" |
| 11518 | "addr=" MACSTR "\n" |
| 11519 | "freq=%d\n" |
| 11520 | "%s%s%s%s%s", |
| 11521 | bss->ifindex, |
| 11522 | bss->ifname, |
| 11523 | bss->brname, |
| 11524 | MAC2STR(bss->addr), |
| 11525 | bss->freq, |
| 11526 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 11527 | bss->added_if_into_bridge ? |
| 11528 | "added_if_into_bridge=1\n" : "", |
| 11529 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 11530 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 11531 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
| 11532 | if (res < 0 || res >= end - pos) |
| 11533 | return pos - buf; |
| 11534 | pos += res; |
| 11535 | |
| 11536 | if (bss->wdev_id_set) { |
| 11537 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 11538 | (unsigned long long) bss->wdev_id); |
| 11539 | if (res < 0 || res >= end - pos) |
| 11540 | return pos - buf; |
| 11541 | pos += res; |
| 11542 | } |
| 11543 | |
| 11544 | res = os_snprintf(pos, end - pos, |
| 11545 | "phyname=%s\n" |
| 11546 | "drv_ifindex=%d\n" |
| 11547 | "operstate=%d\n" |
| 11548 | "scan_state=%s\n" |
| 11549 | "auth_bssid=" MACSTR "\n" |
| 11550 | "auth_attempt_bssid=" MACSTR "\n" |
| 11551 | "bssid=" MACSTR "\n" |
| 11552 | "prev_bssid=" MACSTR "\n" |
| 11553 | "associated=%d\n" |
| 11554 | "assoc_freq=%u\n" |
| 11555 | "monitor_sock=%d\n" |
| 11556 | "monitor_ifidx=%d\n" |
| 11557 | "monitor_refcount=%d\n" |
| 11558 | "last_mgmt_freq=%u\n" |
| 11559 | "eapol_tx_sock=%d\n" |
| 11560 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
| 11561 | drv->phyname, |
| 11562 | drv->ifindex, |
| 11563 | drv->operstate, |
| 11564 | scan_state_str(drv->scan_state), |
| 11565 | MAC2STR(drv->auth_bssid), |
| 11566 | MAC2STR(drv->auth_attempt_bssid), |
| 11567 | MAC2STR(drv->bssid), |
| 11568 | MAC2STR(drv->prev_bssid), |
| 11569 | drv->associated, |
| 11570 | drv->assoc_freq, |
| 11571 | drv->monitor_sock, |
| 11572 | drv->monitor_ifidx, |
| 11573 | drv->monitor_refcount, |
| 11574 | drv->last_mgmt_freq, |
| 11575 | drv->eapol_tx_sock, |
| 11576 | drv->ignore_if_down_event ? |
| 11577 | "ignore_if_down_event=1\n" : "", |
| 11578 | drv->scan_complete_events ? |
| 11579 | "scan_complete_events=1\n" : "", |
| 11580 | drv->disabled_11b_rates ? |
| 11581 | "disabled_11b_rates=1\n" : "", |
| 11582 | drv->pending_remain_on_chan ? |
| 11583 | "pending_remain_on_chan=1\n" : "", |
| 11584 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 11585 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 11586 | drv->poll_command_supported ? |
| 11587 | "poll_command_supported=1\n" : "", |
| 11588 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 11589 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 11590 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 11591 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 11592 | drv->ignore_next_local_disconnect ? |
| 11593 | "ignore_next_local_disconnect=1\n" : "", |
| 11594 | drv->allow_p2p_device ? "allow_p2p_device=1\n" : ""); |
| 11595 | if (res < 0 || res >= end - pos) |
| 11596 | return pos - buf; |
| 11597 | pos += res; |
| 11598 | |
| 11599 | if (drv->has_capability) { |
| 11600 | res = os_snprintf(pos, end - pos, |
| 11601 | "capa.key_mgmt=0x%x\n" |
| 11602 | "capa.enc=0x%x\n" |
| 11603 | "capa.auth=0x%x\n" |
| 11604 | "capa.flags=0x%x\n" |
| 11605 | "capa.max_scan_ssids=%d\n" |
| 11606 | "capa.max_sched_scan_ssids=%d\n" |
| 11607 | "capa.sched_scan_supported=%d\n" |
| 11608 | "capa.max_match_sets=%d\n" |
| 11609 | "capa.max_remain_on_chan=%u\n" |
| 11610 | "capa.max_stations=%u\n" |
| 11611 | "capa.probe_resp_offloads=0x%x\n" |
| 11612 | "capa.max_acl_mac_addrs=%u\n" |
| 11613 | "capa.num_multichan_concurrent=%u\n", |
| 11614 | drv->capa.key_mgmt, |
| 11615 | drv->capa.enc, |
| 11616 | drv->capa.auth, |
| 11617 | drv->capa.flags, |
| 11618 | drv->capa.max_scan_ssids, |
| 11619 | drv->capa.max_sched_scan_ssids, |
| 11620 | drv->capa.sched_scan_supported, |
| 11621 | drv->capa.max_match_sets, |
| 11622 | drv->capa.max_remain_on_chan, |
| 11623 | drv->capa.max_stations, |
| 11624 | drv->capa.probe_resp_offloads, |
| 11625 | drv->capa.max_acl_mac_addrs, |
| 11626 | drv->capa.num_multichan_concurrent); |
| 11627 | if (res < 0 || res >= end - pos) |
| 11628 | return pos - buf; |
| 11629 | pos += res; |
| 11630 | } |
| 11631 | |
| 11632 | return pos - buf; |
| 11633 | } |
| 11634 | |
| 11635 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11636 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 11637 | { |
| 11638 | if (settings->head) |
| 11639 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, |
| 11640 | settings->head_len, settings->head); |
| 11641 | |
| 11642 | if (settings->tail) |
| 11643 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, |
| 11644 | settings->tail_len, settings->tail); |
| 11645 | |
| 11646 | if (settings->beacon_ies) |
| 11647 | NLA_PUT(msg, NL80211_ATTR_IE, |
| 11648 | settings->beacon_ies_len, settings->beacon_ies); |
| 11649 | |
| 11650 | if (settings->proberesp_ies) |
| 11651 | NLA_PUT(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 11652 | settings->proberesp_ies_len, settings->proberesp_ies); |
| 11653 | |
| 11654 | if (settings->assocresp_ies) |
| 11655 | NLA_PUT(msg, |
| 11656 | NL80211_ATTR_IE_ASSOC_RESP, |
| 11657 | settings->assocresp_ies_len, settings->assocresp_ies); |
| 11658 | |
| 11659 | if (settings->probe_resp) |
| 11660 | NLA_PUT(msg, NL80211_ATTR_PROBE_RESP, |
| 11661 | settings->probe_resp_len, settings->probe_resp); |
| 11662 | |
| 11663 | return 0; |
| 11664 | |
| 11665 | nla_put_failure: |
| 11666 | return -ENOBUFS; |
| 11667 | } |
| 11668 | |
| 11669 | |
| 11670 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 11671 | { |
| 11672 | struct nl_msg *msg; |
| 11673 | struct i802_bss *bss = priv; |
| 11674 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11675 | struct nlattr *beacon_csa; |
| 11676 | int ret = -ENOBUFS; |
| 11677 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 11678 | 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] | 11679 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 11680 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 11681 | settings->freq_params.center_freq1, |
| 11682 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11683 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11684 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11685 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 11686 | return -EOPNOTSUPP; |
| 11687 | } |
| 11688 | |
| 11689 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 11690 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 11691 | return -EOPNOTSUPP; |
| 11692 | |
| 11693 | /* check settings validity */ |
| 11694 | if (!settings->beacon_csa.tail || |
| 11695 | ((settings->beacon_csa.tail_len <= |
| 11696 | settings->counter_offset_beacon) || |
| 11697 | (settings->beacon_csa.tail[settings->counter_offset_beacon] != |
| 11698 | settings->cs_count))) |
| 11699 | return -EINVAL; |
| 11700 | |
| 11701 | if (settings->beacon_csa.probe_resp && |
| 11702 | ((settings->beacon_csa.probe_resp_len <= |
| 11703 | settings->counter_offset_presp) || |
| 11704 | (settings->beacon_csa.probe_resp[settings->counter_offset_presp] != |
| 11705 | settings->cs_count))) |
| 11706 | return -EINVAL; |
| 11707 | |
| 11708 | msg = nlmsg_alloc(); |
| 11709 | if (!msg) |
| 11710 | return -ENOMEM; |
| 11711 | |
| 11712 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CHANNEL_SWITCH); |
| 11713 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11714 | NLA_PUT_U32(msg, NL80211_ATTR_CH_SWITCH_COUNT, settings->cs_count); |
| 11715 | ret = nl80211_put_freq_params(msg, &settings->freq_params); |
| 11716 | if (ret) |
| 11717 | goto error; |
| 11718 | |
| 11719 | if (settings->block_tx) |
| 11720 | NLA_PUT_FLAG(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX); |
| 11721 | |
| 11722 | /* beacon_after params */ |
| 11723 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 11724 | if (ret) |
| 11725 | goto error; |
| 11726 | |
| 11727 | /* beacon_csa params */ |
| 11728 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 11729 | if (!beacon_csa) |
| 11730 | goto nla_put_failure; |
| 11731 | |
| 11732 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 11733 | if (ret) |
| 11734 | goto error; |
| 11735 | |
| 11736 | NLA_PUT_U16(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 11737 | settings->counter_offset_beacon); |
| 11738 | |
| 11739 | if (settings->beacon_csa.probe_resp) |
| 11740 | NLA_PUT_U16(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 11741 | settings->counter_offset_presp); |
| 11742 | |
| 11743 | nla_nest_end(msg, beacon_csa); |
| 11744 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11745 | if (ret) { |
| 11746 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 11747 | ret, strerror(-ret)); |
| 11748 | } |
| 11749 | return ret; |
| 11750 | |
| 11751 | nla_put_failure: |
| 11752 | ret = -ENOBUFS; |
| 11753 | error: |
| 11754 | nlmsg_free(msg); |
| 11755 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 11756 | return ret; |
| 11757 | } |
| 11758 | |
| 11759 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11760 | #ifdef CONFIG_TESTING_OPTIONS |
| 11761 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 11762 | { |
| 11763 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11764 | struct wpabuf *buf = arg; |
| 11765 | |
| 11766 | if (!buf) |
| 11767 | return NL_SKIP; |
| 11768 | |
| 11769 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 11770 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 11771 | return NL_SKIP; |
| 11772 | } |
| 11773 | |
| 11774 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 11775 | genlmsg_attrlen(gnlh, 0)); |
| 11776 | |
| 11777 | return NL_SKIP; |
| 11778 | } |
| 11779 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 11780 | |
| 11781 | |
| 11782 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 11783 | { |
| 11784 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 11785 | struct nlattr *nl_vendor_reply, *nl; |
| 11786 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11787 | struct wpabuf *buf = arg; |
| 11788 | int rem; |
| 11789 | |
| 11790 | if (!buf) |
| 11791 | return NL_SKIP; |
| 11792 | |
| 11793 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11794 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11795 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 11796 | |
| 11797 | if (!nl_vendor_reply) |
| 11798 | return NL_SKIP; |
| 11799 | |
| 11800 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 11801 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 11802 | return NL_SKIP; |
| 11803 | } |
| 11804 | |
| 11805 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 11806 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 11807 | } |
| 11808 | |
| 11809 | return NL_SKIP; |
| 11810 | } |
| 11811 | |
| 11812 | |
| 11813 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 11814 | unsigned int subcmd, const u8 *data, |
| 11815 | size_t data_len, struct wpabuf *buf) |
| 11816 | { |
| 11817 | struct i802_bss *bss = priv; |
| 11818 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11819 | struct nl_msg *msg; |
| 11820 | int ret; |
| 11821 | |
| 11822 | msg = nlmsg_alloc(); |
| 11823 | if (!msg) |
| 11824 | return -ENOMEM; |
| 11825 | |
| 11826 | #ifdef CONFIG_TESTING_OPTIONS |
| 11827 | if (vendor_id == 0xffffffff) { |
| 11828 | nl80211_cmd(drv, msg, 0, subcmd); |
| 11829 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 11830 | 0) |
| 11831 | goto nla_put_failure; |
| 11832 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 11833 | if (ret) |
| 11834 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 11835 | ret); |
| 11836 | return ret; |
| 11837 | } |
| 11838 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 11839 | |
| 11840 | nl80211_cmd(drv, msg, 0, NL80211_CMD_VENDOR); |
| 11841 | if (nl80211_set_iface_id(msg, bss) < 0) |
| 11842 | goto nla_put_failure; |
| 11843 | NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_ID, vendor_id); |
| 11844 | NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd); |
| 11845 | if (data) |
| 11846 | NLA_PUT(msg, NL80211_ATTR_VENDOR_DATA, data_len, data); |
| 11847 | |
| 11848 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 11849 | if (ret) |
| 11850 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 11851 | ret); |
| 11852 | return ret; |
| 11853 | |
| 11854 | nla_put_failure: |
| 11855 | nlmsg_free(msg); |
| 11856 | return -ENOBUFS; |
| 11857 | } |
| 11858 | |
| 11859 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11860 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 11861 | u8 qos_map_set_len) |
| 11862 | { |
| 11863 | struct i802_bss *bss = priv; |
| 11864 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11865 | struct nl_msg *msg; |
| 11866 | int ret; |
| 11867 | |
| 11868 | msg = nlmsg_alloc(); |
| 11869 | if (!msg) |
| 11870 | return -ENOMEM; |
| 11871 | |
| 11872 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 11873 | qos_map_set, qos_map_set_len); |
| 11874 | |
| 11875 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_QOS_MAP); |
| 11876 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 11877 | NLA_PUT(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set); |
| 11878 | |
| 11879 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11880 | if (ret) |
| 11881 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 11882 | |
| 11883 | return ret; |
| 11884 | |
| 11885 | nla_put_failure: |
| 11886 | nlmsg_free(msg); |
| 11887 | return -ENOBUFS; |
| 11888 | } |
| 11889 | |
| 11890 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11891 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 11892 | .name = "nl80211", |
| 11893 | .desc = "Linux nl80211/cfg80211", |
| 11894 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 11895 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11896 | .set_key = driver_nl80211_set_key, |
| 11897 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11898 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 11899 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11900 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11901 | .deauthenticate = driver_nl80211_deauthenticate, |
| 11902 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11903 | .associate = wpa_driver_nl80211_associate, |
| 11904 | .global_init = nl80211_global_init, |
| 11905 | .global_deinit = nl80211_global_deinit, |
| 11906 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11907 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11908 | .get_capa = wpa_driver_nl80211_get_capa, |
| 11909 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 11910 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 11911 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 11912 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11913 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 11914 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11915 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11916 | .if_remove = driver_nl80211_if_remove, |
| 11917 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11918 | .get_hw_feature_data = wpa_driver_nl80211_get_hw_feature_data, |
| 11919 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11920 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11921 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 11922 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11923 | .hapd_init = i802_init, |
| 11924 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11925 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11926 | .get_seqnum = i802_get_seqnum, |
| 11927 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11928 | .get_inact_sec = i802_get_inact_sec, |
| 11929 | .sta_clear_stats = i802_sta_clear_stats, |
| 11930 | .set_rts = i802_set_rts, |
| 11931 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11932 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11933 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11934 | .sta_deauth = i802_sta_deauth, |
| 11935 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11936 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11937 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11938 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11939 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 11940 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 11941 | .cancel_remain_on_channel = |
| 11942 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11943 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11944 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11945 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11946 | .resume = wpa_driver_nl80211_resume, |
| 11947 | .send_ft_action = nl80211_send_ft_action, |
| 11948 | .signal_monitor = nl80211_signal_monitor, |
| 11949 | .signal_poll = nl80211_signal_poll, |
| 11950 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11951 | .shared_freq = wpa_driver_nl80211_shared_freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11952 | .set_param = nl80211_set_param, |
| 11953 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11954 | .add_pmkid = nl80211_add_pmkid, |
| 11955 | .remove_pmkid = nl80211_remove_pmkid, |
| 11956 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11957 | .set_rekey_info = nl80211_set_rekey_info, |
| 11958 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11959 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11960 | .start_dfs_cac = nl80211_start_radar_detection, |
| 11961 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11962 | #ifdef CONFIG_TDLS |
| 11963 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 11964 | .tdls_oper = nl80211_tdls_oper, |
| 11965 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 11966 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11967 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11968 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11969 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11970 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11971 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11972 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11973 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11974 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11975 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11976 | #ifdef ANDROID |
| 11977 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11978 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11979 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11980 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11981 | }; |