Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver interaction with Linux nl80211/cfg80211 |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2012, 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" |
| 31 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 32 | #include "common/ieee802_11_common.h" |
| 33 | #include "l2_packet/l2_packet.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | #include "netlink.h" |
| 35 | #include "linux_ioctl.h" |
| 36 | #include "radiotap.h" |
| 37 | #include "radiotap_iter.h" |
| 38 | #include "rfkill.h" |
| 39 | #include "driver.h" |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 40 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 41 | #ifndef SO_WIFI_STATUS |
| 42 | # if defined(__sparc__) |
| 43 | # define SO_WIFI_STATUS 0x0025 |
| 44 | # elif defined(__parisc__) |
| 45 | # define SO_WIFI_STATUS 0x4022 |
| 46 | # else |
| 47 | # define SO_WIFI_STATUS 41 |
| 48 | # endif |
| 49 | |
| 50 | # define SCM_WIFI_STATUS SO_WIFI_STATUS |
| 51 | #endif |
| 52 | |
| 53 | #ifndef SO_EE_ORIGIN_TXSTATUS |
| 54 | #define SO_EE_ORIGIN_TXSTATUS 4 |
| 55 | #endif |
| 56 | |
| 57 | #ifndef PACKET_TX_TIMESTAMP |
| 58 | #define PACKET_TX_TIMESTAMP 16 |
| 59 | #endif |
| 60 | |
| 61 | #ifdef ANDROID |
| 62 | #include "android_drv.h" |
| 63 | #endif /* ANDROID */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 64 | #ifdef CONFIG_LIBNL20 |
| 65 | /* libnl 2.0 compatibility code */ |
| 66 | #define nl_handle nl_sock |
| 67 | #define nl80211_handle_alloc nl_socket_alloc_cb |
| 68 | #define nl80211_handle_destroy nl_socket_free |
| 69 | #else |
| 70 | /* |
| 71 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely |
| 72 | * but when you free a socket again it will mess up its bitmap and |
| 73 | * and use the wrong number the next time it needs a socket ID. |
| 74 | * Therefore, we wrap the handle alloc/destroy and add our own pid |
| 75 | * accounting. |
| 76 | */ |
| 77 | static uint32_t port_bitmap[32] = { 0 }; |
| 78 | |
| 79 | static struct nl_handle *nl80211_handle_alloc(void *cb) |
| 80 | { |
| 81 | struct nl_handle *handle; |
| 82 | uint32_t pid = getpid() & 0x3FFFFF; |
| 83 | int i; |
| 84 | |
| 85 | handle = nl_handle_alloc_cb(cb); |
| 86 | |
| 87 | for (i = 0; i < 1024; i++) { |
| 88 | if (port_bitmap[i / 32] & (1 << (i % 32))) |
| 89 | continue; |
| 90 | port_bitmap[i / 32] |= 1 << (i % 32); |
| 91 | pid += i << 22; |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | nl_socket_set_local_port(handle, pid); |
| 96 | |
| 97 | return handle; |
| 98 | } |
| 99 | |
| 100 | static void nl80211_handle_destroy(struct nl_handle *handle) |
| 101 | { |
| 102 | uint32_t port = nl_socket_get_local_port(handle); |
| 103 | |
| 104 | port >>= 22; |
| 105 | port_bitmap[port / 32] &= ~(1 << (port % 32)); |
| 106 | |
| 107 | nl_handle_destroy(handle); |
| 108 | } |
| 109 | #endif /* CONFIG_LIBNL20 */ |
| 110 | |
| 111 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 112 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 113 | { |
| 114 | struct nl_handle *handle; |
| 115 | |
| 116 | handle = nl80211_handle_alloc(cb); |
| 117 | if (handle == NULL) { |
| 118 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 119 | "callbacks (%s)", dbg); |
| 120 | return NULL; |
| 121 | } |
| 122 | |
| 123 | if (genl_connect(handle)) { |
| 124 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 125 | "netlink (%s)", dbg); |
| 126 | nl80211_handle_destroy(handle); |
| 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | return handle; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | static void nl_destroy_handles(struct nl_handle **handle) |
| 135 | { |
| 136 | if (*handle == NULL) |
| 137 | return; |
| 138 | nl80211_handle_destroy(*handle); |
| 139 | *handle = NULL; |
| 140 | } |
| 141 | |
| 142 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 143 | #ifndef IFF_LOWER_UP |
| 144 | #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ |
| 145 | #endif |
| 146 | #ifndef IFF_DORMANT |
| 147 | #define IFF_DORMANT 0x20000 /* driver signals dormant */ |
| 148 | #endif |
| 149 | |
| 150 | #ifndef IF_OPER_DORMANT |
| 151 | #define IF_OPER_DORMANT 5 |
| 152 | #endif |
| 153 | #ifndef IF_OPER_UP |
| 154 | #define IF_OPER_UP 6 |
| 155 | #endif |
| 156 | |
| 157 | struct nl80211_global { |
| 158 | struct dl_list interfaces; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 159 | int if_add_ifindex; |
| 160 | struct netlink_data *netlink; |
| 161 | struct nl_cb *nl_cb; |
| 162 | struct nl_handle *nl; |
| 163 | int nl80211_id; |
| 164 | int ioctl_sock; /* socket for ioctl() use */ |
| 165 | |
| 166 | struct nl_handle *nl_event; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 169 | struct nl80211_wiphy_data { |
| 170 | struct dl_list list; |
| 171 | struct dl_list bsss; |
| 172 | struct dl_list drvs; |
| 173 | |
| 174 | struct nl_handle *nl_beacons; |
| 175 | struct nl_cb *nl_cb; |
| 176 | |
| 177 | int wiphy_idx; |
| 178 | }; |
| 179 | |
| 180 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 181 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 182 | struct i802_bss { |
| 183 | struct wpa_driver_nl80211_data *drv; |
| 184 | struct i802_bss *next; |
| 185 | int ifindex; |
| 186 | char ifname[IFNAMSIZ + 1]; |
| 187 | char brname[IFNAMSIZ]; |
| 188 | unsigned int beacon_set:1; |
| 189 | unsigned int added_if_into_bridge:1; |
| 190 | unsigned int added_bridge:1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 191 | unsigned int in_deinit:1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 192 | |
| 193 | u8 addr[ETH_ALEN]; |
| 194 | |
| 195 | int freq; |
| 196 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 197 | void *ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 198 | struct nl_handle *nl_preq, *nl_mgmt; |
| 199 | struct nl_cb *nl_cb; |
| 200 | |
| 201 | struct nl80211_wiphy_data *wiphy_data; |
| 202 | struct dl_list wiphy_list; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | struct wpa_driver_nl80211_data { |
| 206 | struct nl80211_global *global; |
| 207 | struct dl_list list; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 208 | struct dl_list wiphy_list; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 209 | char phyname[32]; |
| 210 | void *ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 211 | int ifindex; |
| 212 | int if_removed; |
| 213 | int if_disabled; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 214 | int ignore_if_down_event; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 215 | struct rfkill_data *rfkill; |
| 216 | struct wpa_driver_capa capa; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 217 | u8 *extended_capa, *extended_capa_mask; |
| 218 | unsigned int extended_capa_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 219 | int has_capability; |
| 220 | |
| 221 | int operstate; |
| 222 | |
| 223 | int scan_complete_events; |
| 224 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 225 | struct nl_cb *nl_cb; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 226 | |
| 227 | u8 auth_bssid[ETH_ALEN]; |
| 228 | u8 bssid[ETH_ALEN]; |
| 229 | int associated; |
| 230 | u8 ssid[32]; |
| 231 | size_t ssid_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 232 | enum nl80211_iftype nlmode; |
| 233 | enum nl80211_iftype ap_scan_as_station; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 234 | unsigned int assoc_freq; |
| 235 | |
| 236 | int monitor_sock; |
| 237 | int monitor_ifidx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 238 | int monitor_refcount; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 239 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 240 | unsigned int disabled_11b_rates:1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 241 | unsigned int pending_remain_on_chan:1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 242 | unsigned int in_interface_list:1; |
| 243 | unsigned int device_ap_sme:1; |
| 244 | unsigned int poll_command_supported:1; |
| 245 | unsigned int data_tx_status:1; |
| 246 | unsigned int scan_for_auth:1; |
| 247 | unsigned int retry_auth:1; |
| 248 | unsigned int use_monitor:1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 249 | unsigned int ignore_next_local_disconnect:1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 250 | |
| 251 | u64 remain_on_chan_cookie; |
| 252 | u64 send_action_cookie; |
| 253 | |
| 254 | unsigned int last_mgmt_freq; |
| 255 | |
| 256 | struct wpa_driver_scan_filter *filter_ssids; |
| 257 | size_t num_filter_ssids; |
| 258 | |
| 259 | struct i802_bss first_bss; |
| 260 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 261 | int eapol_tx_sock; |
| 262 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 263 | #ifdef HOSTAPD |
| 264 | int eapol_sock; /* socket for EAPOL frames */ |
| 265 | |
| 266 | int default_if_indices[16]; |
| 267 | int *if_indices; |
| 268 | int num_if_indices; |
| 269 | |
| 270 | int last_freq; |
| 271 | int last_freq_ht; |
| 272 | #endif /* HOSTAPD */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 273 | |
| 274 | /* From failed authentication command */ |
| 275 | int auth_freq; |
| 276 | u8 auth_bssid_[ETH_ALEN]; |
| 277 | u8 auth_ssid[32]; |
| 278 | size_t auth_ssid_len; |
| 279 | int auth_alg; |
| 280 | u8 *auth_ie; |
| 281 | size_t auth_ie_len; |
| 282 | u8 auth_wep_key[4][16]; |
| 283 | size_t auth_wep_key_len[4]; |
| 284 | int auth_wep_tx_keyidx; |
| 285 | int auth_local_state_change; |
| 286 | int auth_p2p; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 290 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 291 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, |
| 292 | void *timeout_ctx); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 293 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 294 | enum nl80211_iftype nlmode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 295 | static int |
| 296 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv); |
| 297 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 298 | const u8 *addr, int cmd, u16 reason_code, |
| 299 | int local_state_change); |
| 300 | static void nl80211_remove_monitor_interface( |
| 301 | struct wpa_driver_nl80211_data *drv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 302 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 303 | unsigned int freq, unsigned int wait, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 304 | const u8 *buf, size_t buf_len, u64 *cookie, |
| 305 | int no_cck, int no_ack, int offchanok); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 306 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 307 | int report); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 308 | #ifdef ANDROID |
| 309 | static int android_pno_start(struct i802_bss *bss, |
| 310 | struct wpa_driver_scan_params *params); |
| 311 | static int android_pno_stop(struct i802_bss *bss); |
| 312 | #endif /* ANDROID */ |
| 313 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 314 | 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] | 315 | 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] | 316 | int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow); |
| 317 | int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon, |
| 318 | const struct wpabuf *proberesp, |
| 319 | const struct wpabuf *assocresp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 320 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 321 | #endif |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 322 | #ifdef HOSTAPD |
| 323 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
| 324 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
| 325 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 326 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 327 | enum wpa_driver_if_type type, |
| 328 | const char *ifname); |
| 329 | #else /* HOSTAPD */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 330 | static inline void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 331 | { |
| 332 | } |
| 333 | |
| 334 | static inline void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 335 | { |
| 336 | } |
| 337 | |
| 338 | static inline int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 339 | { |
| 340 | return 0; |
| 341 | } |
| 342 | #endif /* HOSTAPD */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 343 | #ifdef ANDROID |
| 344 | extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf, |
| 345 | size_t buf_len); |
| 346 | #endif |
| 347 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 348 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
| 349 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 350 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 351 | int ifindex, int disabled); |
| 352 | |
| 353 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 354 | static int wpa_driver_nl80211_authenticate_retry( |
| 355 | struct wpa_driver_nl80211_data *drv); |
| 356 | |
| 357 | |
| 358 | static int is_ap_interface(enum nl80211_iftype nlmode) |
| 359 | { |
| 360 | return (nlmode == NL80211_IFTYPE_AP || |
| 361 | nlmode == NL80211_IFTYPE_P2P_GO); |
| 362 | } |
| 363 | |
| 364 | |
| 365 | static int is_sta_interface(enum nl80211_iftype nlmode) |
| 366 | { |
| 367 | return (nlmode == NL80211_IFTYPE_STATION || |
| 368 | nlmode == NL80211_IFTYPE_P2P_CLIENT); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | static int is_p2p_interface(enum nl80211_iftype nlmode) |
| 373 | { |
| 374 | return (nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 375 | nlmode == NL80211_IFTYPE_P2P_GO); |
| 376 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 377 | |
| 378 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 379 | struct nl80211_bss_info_arg { |
| 380 | struct wpa_driver_nl80211_data *drv; |
| 381 | struct wpa_scan_results *res; |
| 382 | unsigned int assoc_freq; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 383 | u8 assoc_bssid[ETH_ALEN]; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | static int bss_info_handler(struct nl_msg *msg, void *arg); |
| 387 | |
| 388 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 389 | /* nl80211 code */ |
| 390 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 391 | { |
| 392 | int *err = arg; |
| 393 | *err = 0; |
| 394 | return NL_STOP; |
| 395 | } |
| 396 | |
| 397 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 398 | { |
| 399 | int *ret = arg; |
| 400 | *ret = 0; |
| 401 | return NL_SKIP; |
| 402 | } |
| 403 | |
| 404 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 405 | void *arg) |
| 406 | { |
| 407 | int *ret = arg; |
| 408 | *ret = err->error; |
| 409 | return NL_SKIP; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 414 | { |
| 415 | return NL_OK; |
| 416 | } |
| 417 | |
| 418 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 419 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 420 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 421 | int (*valid_handler)(struct nl_msg *, void *), |
| 422 | void *valid_data) |
| 423 | { |
| 424 | struct nl_cb *cb; |
| 425 | int err = -ENOMEM; |
| 426 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 427 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 428 | if (!cb) |
| 429 | goto out; |
| 430 | |
| 431 | err = nl_send_auto_complete(nl_handle, msg); |
| 432 | if (err < 0) |
| 433 | goto out; |
| 434 | |
| 435 | err = 1; |
| 436 | |
| 437 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 438 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 439 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 440 | |
| 441 | if (valid_handler) |
| 442 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 443 | valid_handler, valid_data); |
| 444 | |
| 445 | while (err > 0) |
| 446 | nl_recvmsgs(nl_handle, cb); |
| 447 | out: |
| 448 | nl_cb_put(cb); |
| 449 | nlmsg_free(msg); |
| 450 | return err; |
| 451 | } |
| 452 | |
| 453 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 454 | static int send_and_recv_msgs_global(struct nl80211_global *global, |
| 455 | struct nl_msg *msg, |
| 456 | int (*valid_handler)(struct nl_msg *, void *), |
| 457 | void *valid_data) |
| 458 | { |
| 459 | return send_and_recv(global, global->nl, msg, valid_handler, |
| 460 | valid_data); |
| 461 | } |
| 462 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 463 | |
Jouni Malinen | 80da042 | 2012-08-09 15:29:25 -0700 | [diff] [blame] | 464 | #ifndef ANDROID |
| 465 | static |
| 466 | #endif |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 467 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 468 | struct nl_msg *msg, |
| 469 | int (*valid_handler)(struct nl_msg *, void *), |
| 470 | void *valid_data) |
| 471 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 472 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 473 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | |
| 477 | struct family_data { |
| 478 | const char *group; |
| 479 | int id; |
| 480 | }; |
| 481 | |
| 482 | |
| 483 | static int family_handler(struct nl_msg *msg, void *arg) |
| 484 | { |
| 485 | struct family_data *res = arg; |
| 486 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 487 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 488 | struct nlattr *mcgrp; |
| 489 | int i; |
| 490 | |
| 491 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 492 | genlmsg_attrlen(gnlh, 0), NULL); |
| 493 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 494 | return NL_SKIP; |
| 495 | |
| 496 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 497 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 498 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 499 | nla_len(mcgrp), NULL); |
| 500 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 501 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 502 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 503 | res->group, |
| 504 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 505 | continue; |
| 506 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 507 | break; |
| 508 | }; |
| 509 | |
| 510 | return NL_SKIP; |
| 511 | } |
| 512 | |
| 513 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 514 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 515 | const char *family, const char *group) |
| 516 | { |
| 517 | struct nl_msg *msg; |
| 518 | int ret = -1; |
| 519 | struct family_data res = { group, -ENOENT }; |
| 520 | |
| 521 | msg = nlmsg_alloc(); |
| 522 | if (!msg) |
| 523 | return -ENOMEM; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 524 | genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 525 | 0, 0, CTRL_CMD_GETFAMILY, 0); |
| 526 | NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, family); |
| 527 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 528 | ret = send_and_recv_msgs_global(global, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 529 | msg = NULL; |
| 530 | if (ret == 0) |
| 531 | ret = res.id; |
| 532 | |
| 533 | nla_put_failure: |
| 534 | nlmsg_free(msg); |
| 535 | return ret; |
| 536 | } |
| 537 | |
| 538 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 539 | static void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 540 | struct nl_msg *msg, int flags, uint8_t cmd) |
| 541 | { |
| 542 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 543 | 0, flags, cmd, 0); |
| 544 | } |
| 545 | |
| 546 | |
| 547 | struct wiphy_idx_data { |
| 548 | int wiphy_idx; |
| 549 | }; |
| 550 | |
| 551 | |
| 552 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 553 | { |
| 554 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 555 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 556 | struct wiphy_idx_data *info = arg; |
| 557 | |
| 558 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 559 | genlmsg_attrlen(gnlh, 0), NULL); |
| 560 | |
| 561 | if (tb[NL80211_ATTR_WIPHY]) |
| 562 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 563 | |
| 564 | return NL_SKIP; |
| 565 | } |
| 566 | |
| 567 | |
| 568 | static int nl80211_get_wiphy_index(struct i802_bss *bss) |
| 569 | { |
| 570 | struct nl_msg *msg; |
| 571 | struct wiphy_idx_data data = { |
| 572 | .wiphy_idx = -1, |
| 573 | }; |
| 574 | |
| 575 | msg = nlmsg_alloc(); |
| 576 | if (!msg) |
| 577 | return -1; |
| 578 | |
| 579 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_GET_INTERFACE); |
| 580 | |
| 581 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 582 | |
| 583 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 584 | return data.wiphy_idx; |
| 585 | msg = NULL; |
| 586 | nla_put_failure: |
| 587 | nlmsg_free(msg); |
| 588 | return -1; |
| 589 | } |
| 590 | |
| 591 | |
| 592 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 593 | struct nl80211_wiphy_data *w) |
| 594 | { |
| 595 | struct nl_msg *msg; |
| 596 | int ret = -1; |
| 597 | |
| 598 | msg = nlmsg_alloc(); |
| 599 | if (!msg) |
| 600 | return -1; |
| 601 | |
| 602 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS); |
| 603 | |
| 604 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx); |
| 605 | |
| 606 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
| 607 | msg = NULL; |
| 608 | if (ret) { |
| 609 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 610 | "failed: ret=%d (%s)", |
| 611 | ret, strerror(-ret)); |
| 612 | goto nla_put_failure; |
| 613 | } |
| 614 | ret = 0; |
| 615 | nla_put_failure: |
| 616 | nlmsg_free(msg); |
| 617 | return ret; |
| 618 | } |
| 619 | |
| 620 | |
| 621 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 622 | { |
| 623 | struct nl80211_wiphy_data *w = eloop_ctx; |
| 624 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 625 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 626 | |
| 627 | nl_recvmsgs(handle, w->nl_cb); |
| 628 | } |
| 629 | |
| 630 | |
| 631 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 632 | { |
| 633 | struct nl80211_wiphy_data *w = arg; |
| 634 | struct wpa_driver_nl80211_data *drv; |
| 635 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 636 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 637 | union wpa_event_data event; |
| 638 | |
| 639 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 640 | genlmsg_attrlen(gnlh, 0), NULL); |
| 641 | |
| 642 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 643 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 644 | gnlh->cmd); |
| 645 | return NL_SKIP; |
| 646 | } |
| 647 | |
| 648 | if (!tb[NL80211_ATTR_FRAME]) |
| 649 | return NL_SKIP; |
| 650 | |
| 651 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 652 | wiphy_list) { |
| 653 | os_memset(&event, 0, sizeof(event)); |
| 654 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 655 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 656 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 657 | } |
| 658 | |
| 659 | return NL_SKIP; |
| 660 | } |
| 661 | |
| 662 | |
| 663 | static struct nl80211_wiphy_data * |
| 664 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 665 | { |
| 666 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 667 | struct nl80211_wiphy_data *w; |
| 668 | int wiphy_idx, found = 0; |
| 669 | struct i802_bss *tmp_bss; |
| 670 | |
| 671 | if (bss->wiphy_data != NULL) |
| 672 | return bss->wiphy_data; |
| 673 | |
| 674 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 675 | |
| 676 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 677 | if (w->wiphy_idx == wiphy_idx) |
| 678 | goto add; |
| 679 | } |
| 680 | |
| 681 | /* alloc new one */ |
| 682 | w = os_zalloc(sizeof(*w)); |
| 683 | if (w == NULL) |
| 684 | return NULL; |
| 685 | w->wiphy_idx = wiphy_idx; |
| 686 | dl_list_init(&w->bsss); |
| 687 | dl_list_init(&w->drvs); |
| 688 | |
| 689 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 690 | if (!w->nl_cb) { |
| 691 | os_free(w); |
| 692 | return NULL; |
| 693 | } |
| 694 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); |
| 695 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, |
| 696 | w); |
| 697 | |
| 698 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 699 | "wiphy beacons"); |
| 700 | if (w->nl_beacons == NULL) { |
| 701 | os_free(w); |
| 702 | return NULL; |
| 703 | } |
| 704 | |
| 705 | if (nl80211_register_beacons(bss->drv, w)) { |
| 706 | nl_destroy_handles(&w->nl_beacons); |
| 707 | os_free(w); |
| 708 | return NULL; |
| 709 | } |
| 710 | |
| 711 | eloop_register_read_sock(nl_socket_get_fd(w->nl_beacons), |
| 712 | nl80211_recv_beacons, w, w->nl_beacons); |
| 713 | |
| 714 | dl_list_add(&nl80211_wiphys, &w->list); |
| 715 | |
| 716 | add: |
| 717 | /* drv entry for this bss already there? */ |
| 718 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 719 | if (tmp_bss->drv == bss->drv) { |
| 720 | found = 1; |
| 721 | break; |
| 722 | } |
| 723 | } |
| 724 | /* if not add it */ |
| 725 | if (!found) |
| 726 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 727 | |
| 728 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 729 | bss->wiphy_data = w; |
| 730 | return w; |
| 731 | } |
| 732 | |
| 733 | |
| 734 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 735 | { |
| 736 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 737 | struct i802_bss *tmp_bss; |
| 738 | int found = 0; |
| 739 | |
| 740 | if (w == NULL) |
| 741 | return; |
| 742 | bss->wiphy_data = NULL; |
| 743 | dl_list_del(&bss->wiphy_list); |
| 744 | |
| 745 | /* still any for this drv present? */ |
| 746 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 747 | if (tmp_bss->drv == bss->drv) { |
| 748 | found = 1; |
| 749 | break; |
| 750 | } |
| 751 | } |
| 752 | /* if not remove it */ |
| 753 | if (!found) |
| 754 | dl_list_del(&bss->drv->wiphy_list); |
| 755 | |
| 756 | if (!dl_list_empty(&w->bsss)) |
| 757 | return; |
| 758 | |
| 759 | eloop_unregister_read_sock(nl_socket_get_fd(w->nl_beacons)); |
| 760 | |
| 761 | nl_cb_put(w->nl_cb); |
| 762 | nl_destroy_handles(&w->nl_beacons); |
| 763 | dl_list_del(&w->list); |
| 764 | os_free(w); |
| 765 | } |
| 766 | |
| 767 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 768 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 769 | { |
| 770 | struct i802_bss *bss = priv; |
| 771 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 772 | if (!drv->associated) |
| 773 | return -1; |
| 774 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | |
| 779 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 780 | { |
| 781 | struct i802_bss *bss = priv; |
| 782 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 783 | if (!drv->associated) |
| 784 | return -1; |
| 785 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 786 | return drv->ssid_len; |
| 787 | } |
| 788 | |
| 789 | |
| 790 | static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data *drv, |
| 791 | char *buf, size_t len, int del) |
| 792 | { |
| 793 | union wpa_event_data event; |
| 794 | |
| 795 | os_memset(&event, 0, sizeof(event)); |
| 796 | if (len > sizeof(event.interface_status.ifname)) |
| 797 | len = sizeof(event.interface_status.ifname) - 1; |
| 798 | os_memcpy(event.interface_status.ifname, buf, len); |
| 799 | event.interface_status.ievent = del ? EVENT_INTERFACE_REMOVED : |
| 800 | EVENT_INTERFACE_ADDED; |
| 801 | |
| 802 | wpa_printf(MSG_DEBUG, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s", |
| 803 | del ? "DEL" : "NEW", |
| 804 | event.interface_status.ifname, |
| 805 | del ? "removed" : "added"); |
| 806 | |
| 807 | if (os_strcmp(drv->first_bss.ifname, event.interface_status.ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 808 | if (del) { |
| 809 | if (drv->if_removed) { |
| 810 | wpa_printf(MSG_DEBUG, "nl80211: if_removed " |
| 811 | "already set - ignore event"); |
| 812 | return; |
| 813 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 814 | drv->if_removed = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 815 | } else { |
| 816 | if (if_nametoindex(drv->first_bss.ifname) == 0) { |
| 817 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s " |
| 818 | "does not exist - ignore " |
| 819 | "RTM_NEWLINK", |
| 820 | drv->first_bss.ifname); |
| 821 | return; |
| 822 | } |
| 823 | if (!drv->if_removed) { |
| 824 | wpa_printf(MSG_DEBUG, "nl80211: if_removed " |
| 825 | "already cleared - ignore event"); |
| 826 | return; |
| 827 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 828 | drv->if_removed = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 829 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 833 | } |
| 834 | |
| 835 | |
| 836 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 837 | u8 *buf, size_t len) |
| 838 | { |
| 839 | int attrlen, rta_len; |
| 840 | struct rtattr *attr; |
| 841 | |
| 842 | attrlen = len; |
| 843 | attr = (struct rtattr *) buf; |
| 844 | |
| 845 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 846 | while (RTA_OK(attr, attrlen)) { |
| 847 | if (attr->rta_type == IFLA_IFNAME) { |
| 848 | if (os_strcmp(((char *) attr) + rta_len, drv->first_bss.ifname) |
| 849 | == 0) |
| 850 | return 1; |
| 851 | else |
| 852 | break; |
| 853 | } |
| 854 | attr = RTA_NEXT(attr, attrlen); |
| 855 | } |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | |
| 861 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 862 | int ifindex, u8 *buf, size_t len) |
| 863 | { |
| 864 | if (drv->ifindex == ifindex) |
| 865 | return 1; |
| 866 | |
| 867 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
| 868 | drv->first_bss.ifindex = if_nametoindex(drv->first_bss.ifname); |
| 869 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 870 | "interface"); |
| 871 | wpa_driver_nl80211_finish_drv_init(drv); |
| 872 | return 1; |
| 873 | } |
| 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 879 | static struct wpa_driver_nl80211_data * |
| 880 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) |
| 881 | { |
| 882 | struct wpa_driver_nl80211_data *drv; |
| 883 | dl_list_for_each(drv, &global->interfaces, |
| 884 | struct wpa_driver_nl80211_data, list) { |
| 885 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || |
| 886 | have_ifidx(drv, idx)) |
| 887 | return drv; |
| 888 | } |
| 889 | return NULL; |
| 890 | } |
| 891 | |
| 892 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 893 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 894 | struct ifinfomsg *ifi, |
| 895 | u8 *buf, size_t len) |
| 896 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 897 | struct nl80211_global *global = ctx; |
| 898 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 899 | int attrlen, rta_len; |
| 900 | struct rtattr *attr; |
| 901 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 902 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 903 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 904 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 905 | if (!drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 906 | wpa_printf(MSG_DEBUG, "nl80211: Ignore event for foreign " |
| 907 | "ifindex %d", ifi->ifi_index); |
| 908 | return; |
| 909 | } |
| 910 | |
| 911 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x " |
| 912 | "(%s%s%s%s)", |
| 913 | drv->operstate, ifi->ifi_flags, |
| 914 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 915 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 916 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 917 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 918 | |
| 919 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 920 | if (if_indextoname(ifi->ifi_index, namebuf) && |
| 921 | linux_iface_up(drv->global->ioctl_sock, |
| 922 | drv->first_bss.ifname) > 0) { |
| 923 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 924 | "event since interface %s is up", namebuf); |
| 925 | return; |
| 926 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 927 | wpa_printf(MSG_DEBUG, "nl80211: Interface down"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 928 | if (drv->ignore_if_down_event) { |
| 929 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 930 | "event generated by mode change"); |
| 931 | drv->ignore_if_down_event = 0; |
| 932 | } else { |
| 933 | drv->if_disabled = 1; |
| 934 | wpa_supplicant_event(drv->ctx, |
| 935 | EVENT_INTERFACE_DISABLED, NULL); |
| 936 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 940 | if (if_indextoname(ifi->ifi_index, namebuf) && |
| 941 | linux_iface_up(drv->global->ioctl_sock, |
| 942 | drv->first_bss.ifname) == 0) { |
| 943 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 944 | "event since interface %s is down", |
| 945 | namebuf); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 946 | } else if (if_nametoindex(drv->first_bss.ifname) == 0) { |
| 947 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 948 | "event since interface %s does not exist", |
| 949 | drv->first_bss.ifname); |
| 950 | } else if (drv->if_removed) { |
| 951 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 952 | "event since interface %s is marked " |
| 953 | "removed", drv->first_bss.ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 954 | } else { |
| 955 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
| 956 | drv->if_disabled = 0; |
| 957 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 958 | NULL); |
| 959 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /* |
| 963 | * Some drivers send the association event before the operup event--in |
| 964 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 965 | * fails. This will hit us when wpa_supplicant does not need to do |
| 966 | * IEEE 802.1X authentication |
| 967 | */ |
| 968 | if (drv->operstate == 1 && |
| 969 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
| 970 | !(ifi->ifi_flags & IFF_RUNNING)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 971 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 972 | -1, IF_OPER_UP); |
| 973 | |
| 974 | attrlen = len; |
| 975 | attr = (struct rtattr *) buf; |
| 976 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 977 | while (RTA_OK(attr, attrlen)) { |
| 978 | if (attr->rta_type == IFLA_IFNAME) { |
| 979 | wpa_driver_nl80211_event_link( |
| 980 | drv, |
| 981 | ((char *) attr) + rta_len, |
| 982 | attr->rta_len - rta_len, 0); |
| 983 | } else if (attr->rta_type == IFLA_MASTER) |
| 984 | brid = nla_get_u32((struct nlattr *) attr); |
| 985 | attr = RTA_NEXT(attr, attrlen); |
| 986 | } |
| 987 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 988 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
| 989 | /* device has been added to bridge */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 990 | if_indextoname(brid, namebuf); |
| 991 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 992 | brid, namebuf); |
| 993 | add_ifidx(drv, brid); |
| 994 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | |
| 998 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 999 | struct ifinfomsg *ifi, |
| 1000 | u8 *buf, size_t len) |
| 1001 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1002 | struct nl80211_global *global = ctx; |
| 1003 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1004 | int attrlen, rta_len; |
| 1005 | struct rtattr *attr; |
| 1006 | u32 brid = 0; |
| 1007 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1008 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 1009 | if (!drv) { |
| 1010 | wpa_printf(MSG_DEBUG, "nl80211: Ignore dellink event for " |
| 1011 | "foreign ifindex %d", ifi->ifi_index); |
| 1012 | return; |
| 1013 | } |
| 1014 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1015 | attrlen = len; |
| 1016 | attr = (struct rtattr *) buf; |
| 1017 | |
| 1018 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 1019 | while (RTA_OK(attr, attrlen)) { |
| 1020 | if (attr->rta_type == IFLA_IFNAME) { |
| 1021 | wpa_driver_nl80211_event_link( |
| 1022 | drv, |
| 1023 | ((char *) attr) + rta_len, |
| 1024 | attr->rta_len - rta_len, 1); |
| 1025 | } else if (attr->rta_type == IFLA_MASTER) |
| 1026 | brid = nla_get_u32((struct nlattr *) attr); |
| 1027 | attr = RTA_NEXT(attr, attrlen); |
| 1028 | } |
| 1029 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1030 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
| 1031 | /* device has been removed from bridge */ |
| 1032 | char namebuf[IFNAMSIZ]; |
| 1033 | if_indextoname(brid, namebuf); |
| 1034 | wpa_printf(MSG_DEBUG, "nl80211: Remove ifindex %u for bridge " |
| 1035 | "%s", brid, namebuf); |
| 1036 | del_ifidx(drv, brid); |
| 1037 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | |
| 1041 | static void mlme_event_auth(struct wpa_driver_nl80211_data *drv, |
| 1042 | const u8 *frame, size_t len) |
| 1043 | { |
| 1044 | const struct ieee80211_mgmt *mgmt; |
| 1045 | union wpa_event_data event; |
| 1046 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1047 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate event"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1048 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1049 | if (len < 24 + sizeof(mgmt->u.auth)) { |
| 1050 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " |
| 1051 | "frame"); |
| 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | os_memcpy(drv->auth_bssid, mgmt->sa, ETH_ALEN); |
| 1056 | os_memset(&event, 0, sizeof(event)); |
| 1057 | os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN); |
| 1058 | event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1059 | event.auth.auth_transaction = |
| 1060 | le_to_host16(mgmt->u.auth.auth_transaction); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1061 | event.auth.status_code = le_to_host16(mgmt->u.auth.status_code); |
| 1062 | if (len > 24 + sizeof(mgmt->u.auth)) { |
| 1063 | event.auth.ies = mgmt->u.auth.variable; |
| 1064 | event.auth.ies_len = len - 24 - sizeof(mgmt->u.auth); |
| 1065 | } |
| 1066 | |
| 1067 | wpa_supplicant_event(drv->ctx, EVENT_AUTH, &event); |
| 1068 | } |
| 1069 | |
| 1070 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1071 | static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1072 | { |
| 1073 | struct nl_msg *msg; |
| 1074 | int ret; |
| 1075 | struct nl80211_bss_info_arg arg; |
| 1076 | |
| 1077 | os_memset(&arg, 0, sizeof(arg)); |
| 1078 | msg = nlmsg_alloc(); |
| 1079 | if (!msg) |
| 1080 | goto nla_put_failure; |
| 1081 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1082 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1083 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 1084 | |
| 1085 | arg.drv = drv; |
| 1086 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
| 1087 | msg = NULL; |
| 1088 | if (ret == 0) { |
| 1089 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
| 1090 | "associated BSS from scan results: %u MHz", |
| 1091 | arg.assoc_freq); |
| 1092 | return arg.assoc_freq ? arg.assoc_freq : drv->assoc_freq; |
| 1093 | } |
| 1094 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1095 | "(%s)", ret, strerror(-ret)); |
| 1096 | nla_put_failure: |
| 1097 | nlmsg_free(msg); |
| 1098 | return drv->assoc_freq; |
| 1099 | } |
| 1100 | |
| 1101 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1102 | static void mlme_event_assoc(struct wpa_driver_nl80211_data *drv, |
| 1103 | const u8 *frame, size_t len) |
| 1104 | { |
| 1105 | const struct ieee80211_mgmt *mgmt; |
| 1106 | union wpa_event_data event; |
| 1107 | u16 status; |
| 1108 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1109 | wpa_printf(MSG_DEBUG, "nl80211: Associate event"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1110 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1111 | if (len < 24 + sizeof(mgmt->u.assoc_resp)) { |
| 1112 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " |
| 1113 | "frame"); |
| 1114 | return; |
| 1115 | } |
| 1116 | |
| 1117 | status = le_to_host16(mgmt->u.assoc_resp.status_code); |
| 1118 | if (status != WLAN_STATUS_SUCCESS) { |
| 1119 | os_memset(&event, 0, sizeof(event)); |
| 1120 | event.assoc_reject.bssid = mgmt->bssid; |
| 1121 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { |
| 1122 | event.assoc_reject.resp_ies = |
| 1123 | (u8 *) mgmt->u.assoc_resp.variable; |
| 1124 | event.assoc_reject.resp_ies_len = |
| 1125 | len - 24 - sizeof(mgmt->u.assoc_resp); |
| 1126 | } |
| 1127 | event.assoc_reject.status_code = status; |
| 1128 | |
| 1129 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); |
| 1130 | return; |
| 1131 | } |
| 1132 | |
| 1133 | drv->associated = 1; |
| 1134 | os_memcpy(drv->bssid, mgmt->sa, ETH_ALEN); |
| 1135 | |
| 1136 | os_memset(&event, 0, sizeof(event)); |
| 1137 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { |
| 1138 | event.assoc_info.resp_ies = (u8 *) mgmt->u.assoc_resp.variable; |
| 1139 | event.assoc_info.resp_ies_len = |
| 1140 | len - 24 - sizeof(mgmt->u.assoc_resp); |
| 1141 | } |
| 1142 | |
| 1143 | event.assoc_info.freq = drv->assoc_freq; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1144 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1145 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
| 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | static void mlme_event_connect(struct wpa_driver_nl80211_data *drv, |
| 1150 | enum nl80211_commands cmd, struct nlattr *status, |
| 1151 | struct nlattr *addr, struct nlattr *req_ie, |
| 1152 | struct nlattr *resp_ie) |
| 1153 | { |
| 1154 | union wpa_event_data event; |
| 1155 | |
| 1156 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 1157 | /* |
| 1158 | * Avoid reporting two association events that would confuse |
| 1159 | * the core code. |
| 1160 | */ |
| 1161 | wpa_printf(MSG_DEBUG, "nl80211: Ignore connect event (cmd=%d) " |
| 1162 | "when using userspace SME", cmd); |
| 1163 | return; |
| 1164 | } |
| 1165 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1166 | if (cmd == NL80211_CMD_CONNECT) |
| 1167 | wpa_printf(MSG_DEBUG, "nl80211: Connect event"); |
| 1168 | else if (cmd == NL80211_CMD_ROAM) |
| 1169 | wpa_printf(MSG_DEBUG, "nl80211: Roam event"); |
| 1170 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1171 | os_memset(&event, 0, sizeof(event)); |
| 1172 | if (cmd == NL80211_CMD_CONNECT && |
| 1173 | nla_get_u16(status) != WLAN_STATUS_SUCCESS) { |
| 1174 | if (addr) |
| 1175 | event.assoc_reject.bssid = nla_data(addr); |
| 1176 | if (resp_ie) { |
| 1177 | event.assoc_reject.resp_ies = nla_data(resp_ie); |
| 1178 | event.assoc_reject.resp_ies_len = nla_len(resp_ie); |
| 1179 | } |
| 1180 | event.assoc_reject.status_code = nla_get_u16(status); |
| 1181 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
| 1185 | drv->associated = 1; |
| 1186 | if (addr) |
| 1187 | os_memcpy(drv->bssid, nla_data(addr), ETH_ALEN); |
| 1188 | |
| 1189 | if (req_ie) { |
| 1190 | event.assoc_info.req_ies = nla_data(req_ie); |
| 1191 | event.assoc_info.req_ies_len = nla_len(req_ie); |
| 1192 | } |
| 1193 | if (resp_ie) { |
| 1194 | event.assoc_info.resp_ies = nla_data(resp_ie); |
| 1195 | event.assoc_info.resp_ies_len = nla_len(resp_ie); |
| 1196 | } |
| 1197 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1198 | event.assoc_info.freq = nl80211_get_assoc_freq(drv); |
| 1199 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1200 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
| 1201 | } |
| 1202 | |
| 1203 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1204 | static void mlme_event_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1205 | struct nlattr *reason, struct nlattr *addr, |
| 1206 | struct nlattr *by_ap) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1207 | { |
| 1208 | union wpa_event_data data; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1209 | unsigned int locally_generated = by_ap == NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1210 | |
| 1211 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 1212 | /* |
| 1213 | * Avoid reporting two disassociation events that could |
| 1214 | * confuse the core code. |
| 1215 | */ |
| 1216 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " |
| 1217 | "event when using userspace SME"); |
| 1218 | return; |
| 1219 | } |
| 1220 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1221 | if (drv->ignore_next_local_disconnect) { |
| 1222 | drv->ignore_next_local_disconnect = 0; |
| 1223 | if (locally_generated) { |
| 1224 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " |
| 1225 | "event triggered during reassociation"); |
| 1226 | return; |
| 1227 | } |
| 1228 | wpa_printf(MSG_WARNING, "nl80211: Was expecting local " |
| 1229 | "disconnect but got another disconnect " |
| 1230 | "event first"); |
| 1231 | } |
| 1232 | |
| 1233 | wpa_printf(MSG_DEBUG, "nl80211: Disconnect event"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1234 | drv->associated = 0; |
| 1235 | os_memset(&data, 0, sizeof(data)); |
| 1236 | if (reason) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1237 | data.deauth_info.reason_code = nla_get_u16(reason); |
| 1238 | data.deauth_info.locally_generated = by_ap == NULL; |
| 1239 | wpa_supplicant_event(drv->ctx, EVENT_DEAUTH, &data); |
| 1240 | } |
| 1241 | |
| 1242 | |
| 1243 | static void mlme_event_ch_switch(struct wpa_driver_nl80211_data *drv, |
| 1244 | struct nlattr *freq, struct nlattr *type) |
| 1245 | { |
| 1246 | union wpa_event_data data; |
| 1247 | int ht_enabled = 1; |
| 1248 | int chan_offset = 0; |
| 1249 | |
| 1250 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch event"); |
| 1251 | |
| 1252 | if (!freq || !type) |
| 1253 | return; |
| 1254 | |
| 1255 | switch (nla_get_u32(type)) { |
| 1256 | case NL80211_CHAN_NO_HT: |
| 1257 | ht_enabled = 0; |
| 1258 | break; |
| 1259 | case NL80211_CHAN_HT20: |
| 1260 | break; |
| 1261 | case NL80211_CHAN_HT40PLUS: |
| 1262 | chan_offset = 1; |
| 1263 | break; |
| 1264 | case NL80211_CHAN_HT40MINUS: |
| 1265 | chan_offset = -1; |
| 1266 | break; |
| 1267 | } |
| 1268 | |
| 1269 | data.ch_switch.freq = nla_get_u32(freq); |
| 1270 | data.ch_switch.ht_enabled = ht_enabled; |
| 1271 | data.ch_switch.ch_offset = chan_offset; |
| 1272 | |
| 1273 | wpa_supplicant_event(drv->ctx, EVENT_CH_SWITCH, &data); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1277 | static void mlme_timeout_event(struct wpa_driver_nl80211_data *drv, |
| 1278 | enum nl80211_commands cmd, struct nlattr *addr) |
| 1279 | { |
| 1280 | union wpa_event_data event; |
| 1281 | enum wpa_event_type ev; |
| 1282 | |
| 1283 | if (nla_len(addr) != ETH_ALEN) |
| 1284 | return; |
| 1285 | |
| 1286 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d; timeout with " MACSTR, |
| 1287 | cmd, MAC2STR((u8 *) nla_data(addr))); |
| 1288 | |
| 1289 | if (cmd == NL80211_CMD_AUTHENTICATE) |
| 1290 | ev = EVENT_AUTH_TIMED_OUT; |
| 1291 | else if (cmd == NL80211_CMD_ASSOCIATE) |
| 1292 | ev = EVENT_ASSOC_TIMED_OUT; |
| 1293 | else |
| 1294 | return; |
| 1295 | |
| 1296 | os_memset(&event, 0, sizeof(event)); |
| 1297 | os_memcpy(event.timeout_event.addr, nla_data(addr), ETH_ALEN); |
| 1298 | wpa_supplicant_event(drv->ctx, ev, &event); |
| 1299 | } |
| 1300 | |
| 1301 | |
| 1302 | static void mlme_event_mgmt(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1303 | struct nlattr *freq, struct nlattr *sig, |
| 1304 | const u8 *frame, size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1305 | { |
| 1306 | const struct ieee80211_mgmt *mgmt; |
| 1307 | union wpa_event_data event; |
| 1308 | u16 fc, stype; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1309 | int ssi_signal = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1310 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1311 | wpa_printf(MSG_DEBUG, "nl80211: Frame event"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1312 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1313 | if (len < 24) { |
| 1314 | wpa_printf(MSG_DEBUG, "nl80211: Too short action frame"); |
| 1315 | return; |
| 1316 | } |
| 1317 | |
| 1318 | fc = le_to_host16(mgmt->frame_control); |
| 1319 | stype = WLAN_FC_GET_STYPE(fc); |
| 1320 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1321 | if (sig) |
| 1322 | ssi_signal = (s32) nla_get_u32(sig); |
| 1323 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1324 | os_memset(&event, 0, sizeof(event)); |
| 1325 | if (freq) { |
| 1326 | event.rx_action.freq = nla_get_u32(freq); |
| 1327 | drv->last_mgmt_freq = event.rx_action.freq; |
| 1328 | } |
| 1329 | if (stype == WLAN_FC_STYPE_ACTION) { |
| 1330 | event.rx_action.da = mgmt->da; |
| 1331 | event.rx_action.sa = mgmt->sa; |
| 1332 | event.rx_action.bssid = mgmt->bssid; |
| 1333 | event.rx_action.category = mgmt->u.action.category; |
| 1334 | event.rx_action.data = &mgmt->u.action.category + 1; |
| 1335 | event.rx_action.len = frame + len - event.rx_action.data; |
| 1336 | wpa_supplicant_event(drv->ctx, EVENT_RX_ACTION, &event); |
| 1337 | } else { |
| 1338 | event.rx_mgmt.frame = frame; |
| 1339 | event.rx_mgmt.frame_len = len; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1340 | event.rx_mgmt.ssi_signal = ssi_signal; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1341 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1346 | static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data *drv, |
| 1347 | struct nlattr *cookie, const u8 *frame, |
| 1348 | size_t len, struct nlattr *ack) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1349 | { |
| 1350 | union wpa_event_data event; |
| 1351 | const struct ieee80211_hdr *hdr; |
| 1352 | u16 fc; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1353 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1354 | wpa_printf(MSG_DEBUG, "nl80211: Frame TX status event"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1355 | if (!is_ap_interface(drv->nlmode)) { |
| 1356 | u64 cookie_val; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1357 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1358 | if (!cookie) |
| 1359 | return; |
| 1360 | |
| 1361 | cookie_val = nla_get_u64(cookie); |
| 1362 | wpa_printf(MSG_DEBUG, "nl80211: Action TX status:" |
| 1363 | " cookie=0%llx%s (ack=%d)", |
| 1364 | (long long unsigned int) cookie_val, |
| 1365 | cookie_val == drv->send_action_cookie ? |
| 1366 | " (match)" : " (unknown)", ack != NULL); |
| 1367 | if (cookie_val != drv->send_action_cookie) |
| 1368 | return; |
| 1369 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1370 | |
| 1371 | hdr = (const struct ieee80211_hdr *) frame; |
| 1372 | fc = le_to_host16(hdr->frame_control); |
| 1373 | |
| 1374 | os_memset(&event, 0, sizeof(event)); |
| 1375 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); |
| 1376 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); |
| 1377 | event.tx_status.dst = hdr->addr1; |
| 1378 | event.tx_status.data = frame; |
| 1379 | event.tx_status.data_len = len; |
| 1380 | event.tx_status.ack = ack != NULL; |
| 1381 | wpa_supplicant_event(drv->ctx, EVENT_TX_STATUS, &event); |
| 1382 | } |
| 1383 | |
| 1384 | |
| 1385 | static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data *drv, |
| 1386 | enum wpa_event_type type, |
| 1387 | const u8 *frame, size_t len) |
| 1388 | { |
| 1389 | const struct ieee80211_mgmt *mgmt; |
| 1390 | union wpa_event_data event; |
| 1391 | const u8 *bssid = NULL; |
| 1392 | u16 reason_code = 0; |
| 1393 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1394 | if (type == EVENT_DEAUTH) |
| 1395 | wpa_printf(MSG_DEBUG, "nl80211: Deauthenticate event"); |
| 1396 | else |
| 1397 | wpa_printf(MSG_DEBUG, "nl80211: Disassociate event"); |
| 1398 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1399 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1400 | if (len >= 24) { |
| 1401 | bssid = mgmt->bssid; |
| 1402 | |
| 1403 | if (drv->associated != 0 && |
| 1404 | os_memcmp(bssid, drv->bssid, ETH_ALEN) != 0 && |
| 1405 | os_memcmp(bssid, drv->auth_bssid, ETH_ALEN) != 0) { |
| 1406 | /* |
| 1407 | * We have presumably received this deauth as a |
| 1408 | * response to a clear_state_mismatch() outgoing |
| 1409 | * deauth. Don't let it take us offline! |
| 1410 | */ |
| 1411 | wpa_printf(MSG_DEBUG, "nl80211: Deauth received " |
| 1412 | "from Unknown BSSID " MACSTR " -- ignoring", |
| 1413 | MAC2STR(bssid)); |
| 1414 | return; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | drv->associated = 0; |
| 1419 | os_memset(&event, 0, sizeof(event)); |
| 1420 | |
| 1421 | /* Note: Same offset for Reason Code in both frame subtypes */ |
| 1422 | if (len >= 24 + sizeof(mgmt->u.deauth)) |
| 1423 | reason_code = le_to_host16(mgmt->u.deauth.reason_code); |
| 1424 | |
| 1425 | if (type == EVENT_DISASSOC) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1426 | event.disassoc_info.locally_generated = |
| 1427 | !os_memcmp(mgmt->sa, drv->first_bss.addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1428 | event.disassoc_info.addr = bssid; |
| 1429 | event.disassoc_info.reason_code = reason_code; |
| 1430 | if (frame + len > mgmt->u.disassoc.variable) { |
| 1431 | event.disassoc_info.ie = mgmt->u.disassoc.variable; |
| 1432 | event.disassoc_info.ie_len = frame + len - |
| 1433 | mgmt->u.disassoc.variable; |
| 1434 | } |
| 1435 | } else { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1436 | event.deauth_info.locally_generated = |
| 1437 | !os_memcmp(mgmt->sa, drv->first_bss.addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1438 | event.deauth_info.addr = bssid; |
| 1439 | event.deauth_info.reason_code = reason_code; |
| 1440 | if (frame + len > mgmt->u.deauth.variable) { |
| 1441 | event.deauth_info.ie = mgmt->u.deauth.variable; |
| 1442 | event.deauth_info.ie_len = frame + len - |
| 1443 | mgmt->u.deauth.variable; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | wpa_supplicant_event(drv->ctx, type, &event); |
| 1448 | } |
| 1449 | |
| 1450 | |
| 1451 | static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data *drv, |
| 1452 | enum wpa_event_type type, |
| 1453 | const u8 *frame, size_t len) |
| 1454 | { |
| 1455 | const struct ieee80211_mgmt *mgmt; |
| 1456 | union wpa_event_data event; |
| 1457 | u16 reason_code = 0; |
| 1458 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1459 | if (type == EVENT_UNPROT_DEAUTH) |
| 1460 | wpa_printf(MSG_DEBUG, "nl80211: Unprot Deauthenticate event"); |
| 1461 | else |
| 1462 | wpa_printf(MSG_DEBUG, "nl80211: Unprot Disassociate event"); |
| 1463 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1464 | if (len < 24) |
| 1465 | return; |
| 1466 | |
| 1467 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 1468 | |
| 1469 | os_memset(&event, 0, sizeof(event)); |
| 1470 | /* Note: Same offset for Reason Code in both frame subtypes */ |
| 1471 | if (len >= 24 + sizeof(mgmt->u.deauth)) |
| 1472 | reason_code = le_to_host16(mgmt->u.deauth.reason_code); |
| 1473 | |
| 1474 | if (type == EVENT_UNPROT_DISASSOC) { |
| 1475 | event.unprot_disassoc.sa = mgmt->sa; |
| 1476 | event.unprot_disassoc.da = mgmt->da; |
| 1477 | event.unprot_disassoc.reason_code = reason_code; |
| 1478 | } else { |
| 1479 | event.unprot_deauth.sa = mgmt->sa; |
| 1480 | event.unprot_deauth.da = mgmt->da; |
| 1481 | event.unprot_deauth.reason_code = reason_code; |
| 1482 | } |
| 1483 | |
| 1484 | wpa_supplicant_event(drv->ctx, type, &event); |
| 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | static void mlme_event(struct wpa_driver_nl80211_data *drv, |
| 1489 | enum nl80211_commands cmd, struct nlattr *frame, |
| 1490 | struct nlattr *addr, struct nlattr *timed_out, |
| 1491 | struct nlattr *freq, struct nlattr *ack, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1492 | struct nlattr *cookie, struct nlattr *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1493 | { |
| 1494 | if (timed_out && addr) { |
| 1495 | mlme_timeout_event(drv, cmd, addr); |
| 1496 | return; |
| 1497 | } |
| 1498 | |
| 1499 | if (frame == NULL) { |
| 1500 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d without frame " |
| 1501 | "data", cmd); |
| 1502 | return; |
| 1503 | } |
| 1504 | |
| 1505 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d", cmd); |
| 1506 | wpa_hexdump(MSG_MSGDUMP, "nl80211: MLME event frame", |
| 1507 | nla_data(frame), nla_len(frame)); |
| 1508 | |
| 1509 | switch (cmd) { |
| 1510 | case NL80211_CMD_AUTHENTICATE: |
| 1511 | mlme_event_auth(drv, nla_data(frame), nla_len(frame)); |
| 1512 | break; |
| 1513 | case NL80211_CMD_ASSOCIATE: |
| 1514 | mlme_event_assoc(drv, nla_data(frame), nla_len(frame)); |
| 1515 | break; |
| 1516 | case NL80211_CMD_DEAUTHENTICATE: |
| 1517 | mlme_event_deauth_disassoc(drv, EVENT_DEAUTH, |
| 1518 | nla_data(frame), nla_len(frame)); |
| 1519 | break; |
| 1520 | case NL80211_CMD_DISASSOCIATE: |
| 1521 | mlme_event_deauth_disassoc(drv, EVENT_DISASSOC, |
| 1522 | nla_data(frame), nla_len(frame)); |
| 1523 | break; |
| 1524 | case NL80211_CMD_FRAME: |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1525 | mlme_event_mgmt(drv, freq, sig, nla_data(frame), |
| 1526 | nla_len(frame)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1527 | break; |
| 1528 | case NL80211_CMD_FRAME_TX_STATUS: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1529 | mlme_event_mgmt_tx_status(drv, cookie, nla_data(frame), |
| 1530 | nla_len(frame), ack); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1531 | break; |
| 1532 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
| 1533 | mlme_event_unprot_disconnect(drv, EVENT_UNPROT_DEAUTH, |
| 1534 | nla_data(frame), nla_len(frame)); |
| 1535 | break; |
| 1536 | case NL80211_CMD_UNPROT_DISASSOCIATE: |
| 1537 | mlme_event_unprot_disconnect(drv, EVENT_UNPROT_DISASSOC, |
| 1538 | nla_data(frame), nla_len(frame)); |
| 1539 | break; |
| 1540 | default: |
| 1541 | break; |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1546 | static void mlme_event_michael_mic_failure(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1547 | struct nlattr *tb[]) |
| 1548 | { |
| 1549 | union wpa_event_data data; |
| 1550 | |
| 1551 | wpa_printf(MSG_DEBUG, "nl80211: MLME event Michael MIC failure"); |
| 1552 | os_memset(&data, 0, sizeof(data)); |
| 1553 | if (tb[NL80211_ATTR_MAC]) { |
| 1554 | wpa_hexdump(MSG_DEBUG, "nl80211: Source MAC address", |
| 1555 | nla_data(tb[NL80211_ATTR_MAC]), |
| 1556 | nla_len(tb[NL80211_ATTR_MAC])); |
| 1557 | data.michael_mic_failure.src = nla_data(tb[NL80211_ATTR_MAC]); |
| 1558 | } |
| 1559 | if (tb[NL80211_ATTR_KEY_SEQ]) { |
| 1560 | wpa_hexdump(MSG_DEBUG, "nl80211: TSC", |
| 1561 | nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 1562 | nla_len(tb[NL80211_ATTR_KEY_SEQ])); |
| 1563 | } |
| 1564 | if (tb[NL80211_ATTR_KEY_TYPE]) { |
| 1565 | enum nl80211_key_type key_type = |
| 1566 | nla_get_u32(tb[NL80211_ATTR_KEY_TYPE]); |
| 1567 | wpa_printf(MSG_DEBUG, "nl80211: Key Type %d", key_type); |
| 1568 | if (key_type == NL80211_KEYTYPE_PAIRWISE) |
| 1569 | data.michael_mic_failure.unicast = 1; |
| 1570 | } else |
| 1571 | data.michael_mic_failure.unicast = 1; |
| 1572 | |
| 1573 | if (tb[NL80211_ATTR_KEY_IDX]) { |
| 1574 | u8 key_id = nla_get_u8(tb[NL80211_ATTR_KEY_IDX]); |
| 1575 | wpa_printf(MSG_DEBUG, "nl80211: Key Id %d", key_id); |
| 1576 | } |
| 1577 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1578 | wpa_supplicant_event(bss->ctx, EVENT_MICHAEL_MIC_FAILURE, &data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | |
| 1582 | static void mlme_event_join_ibss(struct wpa_driver_nl80211_data *drv, |
| 1583 | struct nlattr *tb[]) |
| 1584 | { |
| 1585 | if (tb[NL80211_ATTR_MAC] == NULL) { |
| 1586 | wpa_printf(MSG_DEBUG, "nl80211: No address in IBSS joined " |
| 1587 | "event"); |
| 1588 | return; |
| 1589 | } |
| 1590 | os_memcpy(drv->bssid, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 1591 | drv->associated = 1; |
| 1592 | wpa_printf(MSG_DEBUG, "nl80211: IBSS " MACSTR " joined", |
| 1593 | MAC2STR(drv->bssid)); |
| 1594 | |
| 1595 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL); |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data *drv, |
| 1600 | int cancel_event, struct nlattr *tb[]) |
| 1601 | { |
| 1602 | unsigned int freq, chan_type, duration; |
| 1603 | union wpa_event_data data; |
| 1604 | u64 cookie; |
| 1605 | |
| 1606 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 1607 | freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 1608 | else |
| 1609 | freq = 0; |
| 1610 | |
| 1611 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) |
| 1612 | chan_type = nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1613 | else |
| 1614 | chan_type = 0; |
| 1615 | |
| 1616 | if (tb[NL80211_ATTR_DURATION]) |
| 1617 | duration = nla_get_u32(tb[NL80211_ATTR_DURATION]); |
| 1618 | else |
| 1619 | duration = 0; |
| 1620 | |
| 1621 | if (tb[NL80211_ATTR_COOKIE]) |
| 1622 | cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 1623 | else |
| 1624 | cookie = 0; |
| 1625 | |
| 1626 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel event (cancel=%d " |
| 1627 | "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))", |
| 1628 | cancel_event, freq, chan_type, duration, |
| 1629 | (long long unsigned int) cookie, |
| 1630 | cookie == drv->remain_on_chan_cookie ? "match" : "unknown"); |
| 1631 | |
| 1632 | if (cookie != drv->remain_on_chan_cookie) |
| 1633 | return; /* not for us */ |
| 1634 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1635 | if (cancel_event) |
| 1636 | drv->pending_remain_on_chan = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1637 | |
| 1638 | os_memset(&data, 0, sizeof(data)); |
| 1639 | data.remain_on_channel.freq = freq; |
| 1640 | data.remain_on_channel.duration = duration; |
| 1641 | wpa_supplicant_event(drv->ctx, cancel_event ? |
| 1642 | EVENT_CANCEL_REMAIN_ON_CHANNEL : |
| 1643 | EVENT_REMAIN_ON_CHANNEL, &data); |
| 1644 | } |
| 1645 | |
| 1646 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 1647 | static void mlme_event_ft_event(struct wpa_driver_nl80211_data *drv, |
| 1648 | struct nlattr *tb[]) |
| 1649 | { |
| 1650 | union wpa_event_data data; |
| 1651 | |
| 1652 | os_memset(&data, 0, sizeof(data)); |
| 1653 | |
| 1654 | if (tb[NL80211_ATTR_IE]) { |
| 1655 | data.ft_ies.ies = nla_data(tb[NL80211_ATTR_IE]); |
| 1656 | data.ft_ies.ies_len = nla_len(tb[NL80211_ATTR_IE]); |
| 1657 | } |
| 1658 | |
| 1659 | if (tb[NL80211_ATTR_IE_RIC]) { |
| 1660 | data.ft_ies.ric_ies = nla_data(tb[NL80211_ATTR_IE_RIC]); |
| 1661 | data.ft_ies.ric_ies_len = nla_len(tb[NL80211_ATTR_IE_RIC]); |
| 1662 | } |
| 1663 | |
| 1664 | if (tb[NL80211_ATTR_MAC]) |
| 1665 | os_memcpy(data.ft_ies.target_ap, |
| 1666 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 1667 | |
| 1668 | wpa_printf(MSG_DEBUG, "nl80211: FT event target_ap " MACSTR, |
| 1669 | MAC2STR(data.ft_ies.target_ap)); |
| 1670 | |
| 1671 | wpa_supplicant_event(drv->ctx, EVENT_FT_RESPONSE, &data); |
| 1672 | } |
| 1673 | |
| 1674 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1675 | static void send_scan_event(struct wpa_driver_nl80211_data *drv, int aborted, |
| 1676 | struct nlattr *tb[]) |
| 1677 | { |
| 1678 | union wpa_event_data event; |
| 1679 | struct nlattr *nl; |
| 1680 | int rem; |
| 1681 | struct scan_info *info; |
| 1682 | #define MAX_REPORT_FREQS 50 |
| 1683 | int freqs[MAX_REPORT_FREQS]; |
| 1684 | int num_freqs = 0; |
| 1685 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1686 | if (drv->scan_for_auth) { |
| 1687 | drv->scan_for_auth = 0; |
| 1688 | wpa_printf(MSG_DEBUG, "nl80211: Scan results for missing " |
| 1689 | "cfg80211 BSS entry"); |
| 1690 | wpa_driver_nl80211_authenticate_retry(drv); |
| 1691 | return; |
| 1692 | } |
| 1693 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1694 | os_memset(&event, 0, sizeof(event)); |
| 1695 | info = &event.scan_info; |
| 1696 | info->aborted = aborted; |
| 1697 | |
| 1698 | if (tb[NL80211_ATTR_SCAN_SSIDS]) { |
| 1699 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_SSIDS], rem) { |
| 1700 | struct wpa_driver_scan_ssid *s = |
| 1701 | &info->ssids[info->num_ssids]; |
| 1702 | s->ssid = nla_data(nl); |
| 1703 | s->ssid_len = nla_len(nl); |
| 1704 | info->num_ssids++; |
| 1705 | if (info->num_ssids == WPAS_MAX_SCAN_SSIDS) |
| 1706 | break; |
| 1707 | } |
| 1708 | } |
| 1709 | if (tb[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 1710 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_FREQUENCIES], rem) |
| 1711 | { |
| 1712 | freqs[num_freqs] = nla_get_u32(nl); |
| 1713 | num_freqs++; |
| 1714 | if (num_freqs == MAX_REPORT_FREQS - 1) |
| 1715 | break; |
| 1716 | } |
| 1717 | info->freqs = freqs; |
| 1718 | info->num_freqs = num_freqs; |
| 1719 | } |
| 1720 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, &event); |
| 1721 | } |
| 1722 | |
| 1723 | |
| 1724 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1725 | { |
| 1726 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1727 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1728 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1729 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1730 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
| 1731 | }; |
| 1732 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1733 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1734 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1735 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1736 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1737 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1738 | }; |
| 1739 | struct wpa_signal_info *sig_change = arg; |
| 1740 | |
| 1741 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1742 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1743 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1744 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1745 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1746 | return NL_SKIP; |
| 1747 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1748 | return NL_SKIP; |
| 1749 | |
| 1750 | sig_change->current_signal = |
| 1751 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1752 | |
| 1753 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1754 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1755 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1756 | rate_policy)) { |
| 1757 | sig_change->current_txrate = 0; |
| 1758 | } else { |
| 1759 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1760 | sig_change->current_txrate = |
| 1761 | nla_get_u16(rinfo[ |
| 1762 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1763 | } |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | return NL_SKIP; |
| 1768 | } |
| 1769 | |
| 1770 | |
| 1771 | static int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1772 | struct wpa_signal_info *sig) |
| 1773 | { |
| 1774 | struct nl_msg *msg; |
| 1775 | |
| 1776 | sig->current_signal = -9999; |
| 1777 | sig->current_txrate = 0; |
| 1778 | |
| 1779 | msg = nlmsg_alloc(); |
| 1780 | if (!msg) |
| 1781 | return -ENOMEM; |
| 1782 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1783 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1784 | |
| 1785 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 1786 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
| 1787 | |
| 1788 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
| 1789 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1790 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1791 | return -ENOBUFS; |
| 1792 | } |
| 1793 | |
| 1794 | |
| 1795 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1796 | { |
| 1797 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1798 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1799 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1800 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1801 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1802 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1803 | }; |
| 1804 | struct wpa_signal_info *sig_change = arg; |
| 1805 | |
| 1806 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1807 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1808 | |
| 1809 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1810 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1811 | return NL_SKIP; |
| 1812 | } |
| 1813 | |
| 1814 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1815 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1816 | survey_policy)) { |
| 1817 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1818 | "attributes!"); |
| 1819 | return NL_SKIP; |
| 1820 | } |
| 1821 | |
| 1822 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1823 | return NL_SKIP; |
| 1824 | |
| 1825 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1826 | sig_change->frequency) |
| 1827 | return NL_SKIP; |
| 1828 | |
| 1829 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1830 | return NL_SKIP; |
| 1831 | |
| 1832 | sig_change->current_noise = |
| 1833 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1834 | |
| 1835 | return NL_SKIP; |
| 1836 | } |
| 1837 | |
| 1838 | |
| 1839 | static int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1840 | struct wpa_signal_info *sig_change) |
| 1841 | { |
| 1842 | struct nl_msg *msg; |
| 1843 | |
| 1844 | sig_change->current_noise = 9999; |
| 1845 | sig_change->frequency = drv->assoc_freq; |
| 1846 | |
| 1847 | msg = nlmsg_alloc(); |
| 1848 | if (!msg) |
| 1849 | return -ENOMEM; |
| 1850 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1851 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1852 | |
| 1853 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 1854 | |
| 1855 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
| 1856 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1857 | nlmsg_free(msg); |
| 1858 | return -ENOBUFS; |
| 1859 | } |
| 1860 | |
| 1861 | |
| 1862 | static int get_noise_for_scan_results(struct nl_msg *msg, void *arg) |
| 1863 | { |
| 1864 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1865 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1866 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1867 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1868 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1869 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1870 | }; |
| 1871 | struct wpa_scan_results *scan_results = arg; |
| 1872 | struct wpa_scan_res *scan_res; |
| 1873 | size_t i; |
| 1874 | |
| 1875 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1876 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1877 | |
| 1878 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1879 | wpa_printf(MSG_DEBUG, "nl80211: Survey data missing"); |
| 1880 | return NL_SKIP; |
| 1881 | } |
| 1882 | |
| 1883 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1884 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1885 | survey_policy)) { |
| 1886 | wpa_printf(MSG_DEBUG, "nl80211: Failed to parse nested " |
| 1887 | "attributes"); |
| 1888 | return NL_SKIP; |
| 1889 | } |
| 1890 | |
| 1891 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1892 | return NL_SKIP; |
| 1893 | |
| 1894 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1895 | return NL_SKIP; |
| 1896 | |
| 1897 | for (i = 0; i < scan_results->num; ++i) { |
| 1898 | scan_res = scan_results->res[i]; |
| 1899 | if (!scan_res) |
| 1900 | continue; |
| 1901 | if ((int) nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1902 | scan_res->freq) |
| 1903 | continue; |
| 1904 | if (!(scan_res->flags & WPA_SCAN_NOISE_INVALID)) |
| 1905 | continue; |
| 1906 | scan_res->noise = (s8) |
| 1907 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1908 | scan_res->flags &= ~WPA_SCAN_NOISE_INVALID; |
| 1909 | } |
| 1910 | |
| 1911 | return NL_SKIP; |
| 1912 | } |
| 1913 | |
| 1914 | |
| 1915 | static int nl80211_get_noise_for_scan_results( |
| 1916 | struct wpa_driver_nl80211_data *drv, |
| 1917 | struct wpa_scan_results *scan_res) |
| 1918 | { |
| 1919 | struct nl_msg *msg; |
| 1920 | |
| 1921 | msg = nlmsg_alloc(); |
| 1922 | if (!msg) |
| 1923 | return -ENOMEM; |
| 1924 | |
| 1925 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
| 1926 | |
| 1927 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 1928 | |
| 1929 | return send_and_recv_msgs(drv, msg, get_noise_for_scan_results, |
| 1930 | scan_res); |
| 1931 | nla_put_failure: |
| 1932 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1933 | return -ENOBUFS; |
| 1934 | } |
| 1935 | |
| 1936 | |
| 1937 | static void nl80211_cqm_event(struct wpa_driver_nl80211_data *drv, |
| 1938 | struct nlattr *tb[]) |
| 1939 | { |
| 1940 | static struct nla_policy cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
| 1941 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 1942 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U8 }, |
| 1943 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 1944 | [NL80211_ATTR_CQM_PKT_LOSS_EVENT] = { .type = NLA_U32 }, |
| 1945 | }; |
| 1946 | struct nlattr *cqm[NL80211_ATTR_CQM_MAX + 1]; |
| 1947 | enum nl80211_cqm_rssi_threshold_event event; |
| 1948 | union wpa_event_data ed; |
| 1949 | struct wpa_signal_info sig; |
| 1950 | int res; |
| 1951 | |
| 1952 | if (tb[NL80211_ATTR_CQM] == NULL || |
| 1953 | nla_parse_nested(cqm, NL80211_ATTR_CQM_MAX, tb[NL80211_ATTR_CQM], |
| 1954 | cqm_policy)) { |
| 1955 | wpa_printf(MSG_DEBUG, "nl80211: Ignore invalid CQM event"); |
| 1956 | return; |
| 1957 | } |
| 1958 | |
| 1959 | os_memset(&ed, 0, sizeof(ed)); |
| 1960 | |
| 1961 | if (cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT]) { |
| 1962 | if (!tb[NL80211_ATTR_MAC]) |
| 1963 | return; |
| 1964 | os_memcpy(ed.low_ack.addr, nla_data(tb[NL80211_ATTR_MAC]), |
| 1965 | ETH_ALEN); |
| 1966 | wpa_supplicant_event(drv->ctx, EVENT_STATION_LOW_ACK, &ed); |
| 1967 | return; |
| 1968 | } |
| 1969 | |
| 1970 | if (cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] == NULL) |
| 1971 | return; |
| 1972 | event = nla_get_u32(cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]); |
| 1973 | |
| 1974 | if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH) { |
| 1975 | wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor " |
| 1976 | "event: RSSI high"); |
| 1977 | ed.signal_change.above_threshold = 1; |
| 1978 | } else if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW) { |
| 1979 | wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor " |
| 1980 | "event: RSSI low"); |
| 1981 | ed.signal_change.above_threshold = 0; |
| 1982 | } else |
| 1983 | return; |
| 1984 | |
| 1985 | res = nl80211_get_link_signal(drv, &sig); |
| 1986 | if (res == 0) { |
| 1987 | ed.signal_change.current_signal = sig.current_signal; |
| 1988 | ed.signal_change.current_txrate = sig.current_txrate; |
| 1989 | wpa_printf(MSG_DEBUG, "nl80211: Signal: %d dBm txrate: %d", |
| 1990 | sig.current_signal, sig.current_txrate); |
| 1991 | } |
| 1992 | |
| 1993 | res = nl80211_get_link_noise(drv, &sig); |
| 1994 | if (res == 0) { |
| 1995 | ed.signal_change.current_noise = sig.current_noise; |
| 1996 | wpa_printf(MSG_DEBUG, "nl80211: Noise: %d dBm", |
| 1997 | sig.current_noise); |
| 1998 | } |
| 1999 | |
| 2000 | wpa_supplicant_event(drv->ctx, EVENT_SIGNAL_CHANGE, &ed); |
| 2001 | } |
| 2002 | |
| 2003 | |
| 2004 | static void nl80211_new_station_event(struct wpa_driver_nl80211_data *drv, |
| 2005 | struct nlattr **tb) |
| 2006 | { |
| 2007 | u8 *addr; |
| 2008 | union wpa_event_data data; |
| 2009 | |
| 2010 | if (tb[NL80211_ATTR_MAC] == NULL) |
| 2011 | return; |
| 2012 | addr = nla_data(tb[NL80211_ATTR_MAC]); |
| 2013 | wpa_printf(MSG_DEBUG, "nl80211: New station " MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2014 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2015 | if (is_ap_interface(drv->nlmode) && drv->device_ap_sme) { |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2016 | u8 *ies = NULL; |
| 2017 | size_t ies_len = 0; |
| 2018 | if (tb[NL80211_ATTR_IE]) { |
| 2019 | ies = nla_data(tb[NL80211_ATTR_IE]); |
| 2020 | ies_len = nla_len(tb[NL80211_ATTR_IE]); |
| 2021 | } |
| 2022 | wpa_hexdump(MSG_DEBUG, "nl80211: Assoc Req IEs", ies, ies_len); |
| 2023 | drv_event_assoc(drv->ctx, addr, ies, ies_len, 0); |
| 2024 | return; |
| 2025 | } |
| 2026 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2027 | if (drv->nlmode != NL80211_IFTYPE_ADHOC) |
| 2028 | return; |
| 2029 | |
| 2030 | os_memset(&data, 0, sizeof(data)); |
| 2031 | os_memcpy(data.ibss_rsn_start.peer, addr, ETH_ALEN); |
| 2032 | wpa_supplicant_event(drv->ctx, EVENT_IBSS_RSN_START, &data); |
| 2033 | } |
| 2034 | |
| 2035 | |
| 2036 | static void nl80211_del_station_event(struct wpa_driver_nl80211_data *drv, |
| 2037 | struct nlattr **tb) |
| 2038 | { |
| 2039 | u8 *addr; |
| 2040 | union wpa_event_data data; |
| 2041 | |
| 2042 | if (tb[NL80211_ATTR_MAC] == NULL) |
| 2043 | return; |
| 2044 | addr = nla_data(tb[NL80211_ATTR_MAC]); |
| 2045 | wpa_printf(MSG_DEBUG, "nl80211: Delete station " MACSTR, |
| 2046 | MAC2STR(addr)); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2047 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2048 | if (is_ap_interface(drv->nlmode) && drv->device_ap_sme) { |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2049 | drv_event_disassoc(drv->ctx, addr); |
| 2050 | return; |
| 2051 | } |
| 2052 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2053 | if (drv->nlmode != NL80211_IFTYPE_ADHOC) |
| 2054 | return; |
| 2055 | |
| 2056 | os_memset(&data, 0, sizeof(data)); |
| 2057 | os_memcpy(data.ibss_peer_lost.peer, addr, ETH_ALEN); |
| 2058 | wpa_supplicant_event(drv->ctx, EVENT_IBSS_PEER_LOST, &data); |
| 2059 | } |
| 2060 | |
| 2061 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2062 | static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data *drv, |
| 2063 | struct nlattr **tb) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2064 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2065 | struct nlattr *rekey_info[NUM_NL80211_REKEY_DATA]; |
| 2066 | static struct nla_policy rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 2067 | [NL80211_REKEY_DATA_KEK] = { |
| 2068 | .minlen = NL80211_KEK_LEN, |
| 2069 | .maxlen = NL80211_KEK_LEN, |
| 2070 | }, |
| 2071 | [NL80211_REKEY_DATA_KCK] = { |
| 2072 | .minlen = NL80211_KCK_LEN, |
| 2073 | .maxlen = NL80211_KCK_LEN, |
| 2074 | }, |
| 2075 | [NL80211_REKEY_DATA_REPLAY_CTR] = { |
| 2076 | .minlen = NL80211_REPLAY_CTR_LEN, |
| 2077 | .maxlen = NL80211_REPLAY_CTR_LEN, |
| 2078 | }, |
| 2079 | }; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2080 | union wpa_event_data data; |
| 2081 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2082 | if (!tb[NL80211_ATTR_MAC]) |
| 2083 | return; |
| 2084 | if (!tb[NL80211_ATTR_REKEY_DATA]) |
| 2085 | return; |
| 2086 | if (nla_parse_nested(rekey_info, MAX_NL80211_REKEY_DATA, |
| 2087 | tb[NL80211_ATTR_REKEY_DATA], rekey_policy)) |
| 2088 | return; |
| 2089 | if (!rekey_info[NL80211_REKEY_DATA_REPLAY_CTR]) |
| 2090 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2091 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2092 | os_memset(&data, 0, sizeof(data)); |
| 2093 | data.driver_gtk_rekey.bssid = nla_data(tb[NL80211_ATTR_MAC]); |
| 2094 | wpa_printf(MSG_DEBUG, "nl80211: Rekey offload event for BSSID " MACSTR, |
| 2095 | MAC2STR(data.driver_gtk_rekey.bssid)); |
| 2096 | data.driver_gtk_rekey.replay_ctr = |
| 2097 | nla_data(rekey_info[NL80211_REKEY_DATA_REPLAY_CTR]); |
| 2098 | wpa_hexdump(MSG_DEBUG, "nl80211: Rekey offload - Replay Counter", |
| 2099 | data.driver_gtk_rekey.replay_ctr, NL80211_REPLAY_CTR_LEN); |
| 2100 | wpa_supplicant_event(drv->ctx, EVENT_DRIVER_GTK_REKEY, &data); |
| 2101 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2102 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2103 | |
| 2104 | static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data *drv, |
| 2105 | struct nlattr **tb) |
| 2106 | { |
| 2107 | struct nlattr *cand[NUM_NL80211_PMKSA_CANDIDATE]; |
| 2108 | static struct nla_policy cand_policy[NUM_NL80211_PMKSA_CANDIDATE] = { |
| 2109 | [NL80211_PMKSA_CANDIDATE_INDEX] = { .type = NLA_U32 }, |
| 2110 | [NL80211_PMKSA_CANDIDATE_BSSID] = { |
| 2111 | .minlen = ETH_ALEN, |
| 2112 | .maxlen = ETH_ALEN, |
| 2113 | }, |
| 2114 | [NL80211_PMKSA_CANDIDATE_PREAUTH] = { .type = NLA_FLAG }, |
| 2115 | }; |
| 2116 | union wpa_event_data data; |
| 2117 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2118 | wpa_printf(MSG_DEBUG, "nl80211: PMKSA candidate event"); |
| 2119 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2120 | if (!tb[NL80211_ATTR_PMKSA_CANDIDATE]) |
| 2121 | return; |
| 2122 | if (nla_parse_nested(cand, MAX_NL80211_PMKSA_CANDIDATE, |
| 2123 | tb[NL80211_ATTR_PMKSA_CANDIDATE], cand_policy)) |
| 2124 | return; |
| 2125 | if (!cand[NL80211_PMKSA_CANDIDATE_INDEX] || |
| 2126 | !cand[NL80211_PMKSA_CANDIDATE_BSSID]) |
| 2127 | return; |
| 2128 | |
| 2129 | os_memset(&data, 0, sizeof(data)); |
| 2130 | os_memcpy(data.pmkid_candidate.bssid, |
| 2131 | nla_data(cand[NL80211_PMKSA_CANDIDATE_BSSID]), ETH_ALEN); |
| 2132 | data.pmkid_candidate.index = |
| 2133 | nla_get_u32(cand[NL80211_PMKSA_CANDIDATE_INDEX]); |
| 2134 | data.pmkid_candidate.preauth = |
| 2135 | cand[NL80211_PMKSA_CANDIDATE_PREAUTH] != NULL; |
| 2136 | wpa_supplicant_event(drv->ctx, EVENT_PMKID_CANDIDATE, &data); |
| 2137 | } |
| 2138 | |
| 2139 | |
| 2140 | static void nl80211_client_probe_event(struct wpa_driver_nl80211_data *drv, |
| 2141 | struct nlattr **tb) |
| 2142 | { |
| 2143 | union wpa_event_data data; |
| 2144 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2145 | wpa_printf(MSG_DEBUG, "nl80211: Probe client event"); |
| 2146 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2147 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_ACK]) |
| 2148 | return; |
| 2149 | |
| 2150 | os_memset(&data, 0, sizeof(data)); |
| 2151 | os_memcpy(data.client_poll.addr, |
| 2152 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 2153 | |
| 2154 | wpa_supplicant_event(drv->ctx, EVENT_DRIVER_CLIENT_POLL_OK, &data); |
| 2155 | } |
| 2156 | |
| 2157 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2158 | static void nl80211_tdls_oper_event(struct wpa_driver_nl80211_data *drv, |
| 2159 | struct nlattr **tb) |
| 2160 | { |
| 2161 | union wpa_event_data data; |
| 2162 | |
| 2163 | wpa_printf(MSG_DEBUG, "nl80211: TDLS operation event"); |
| 2164 | |
| 2165 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_TDLS_OPERATION]) |
| 2166 | return; |
| 2167 | |
| 2168 | os_memset(&data, 0, sizeof(data)); |
| 2169 | os_memcpy(data.tdls.peer, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 2170 | switch (nla_get_u8(tb[NL80211_ATTR_TDLS_OPERATION])) { |
| 2171 | case NL80211_TDLS_SETUP: |
| 2172 | wpa_printf(MSG_DEBUG, "nl80211: TDLS setup request for peer " |
| 2173 | MACSTR, MAC2STR(data.tdls.peer)); |
| 2174 | data.tdls.oper = TDLS_REQUEST_SETUP; |
| 2175 | break; |
| 2176 | case NL80211_TDLS_TEARDOWN: |
| 2177 | wpa_printf(MSG_DEBUG, "nl80211: TDLS teardown request for peer " |
| 2178 | MACSTR, MAC2STR(data.tdls.peer)); |
| 2179 | data.tdls.oper = TDLS_REQUEST_TEARDOWN; |
| 2180 | break; |
| 2181 | default: |
| 2182 | wpa_printf(MSG_DEBUG, "nl80211: Unsupported TDLS operatione " |
| 2183 | "event"); |
| 2184 | return; |
| 2185 | } |
| 2186 | if (tb[NL80211_ATTR_REASON_CODE]) { |
| 2187 | data.tdls.reason_code = |
| 2188 | nla_get_u16(tb[NL80211_ATTR_REASON_CODE]); |
| 2189 | } |
| 2190 | |
| 2191 | wpa_supplicant_event(drv->ctx, EVENT_TDLS, &data); |
| 2192 | } |
| 2193 | |
| 2194 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2195 | static void nl80211_connect_failed_event(struct wpa_driver_nl80211_data *drv, |
| 2196 | struct nlattr **tb) |
| 2197 | { |
| 2198 | union wpa_event_data data; |
| 2199 | u32 reason; |
| 2200 | |
| 2201 | wpa_printf(MSG_DEBUG, "nl80211: Connect failed event"); |
| 2202 | |
| 2203 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_CONN_FAILED_REASON]) |
| 2204 | return; |
| 2205 | |
| 2206 | os_memset(&data, 0, sizeof(data)); |
| 2207 | os_memcpy(data.connect_failed_reason.addr, |
| 2208 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); |
| 2209 | |
| 2210 | reason = nla_get_u32(tb[NL80211_ATTR_CONN_FAILED_REASON]); |
| 2211 | switch (reason) { |
| 2212 | case NL80211_CONN_FAIL_MAX_CLIENTS: |
| 2213 | wpa_printf(MSG_DEBUG, "nl80211: Max client reached"); |
| 2214 | data.connect_failed_reason.code = MAX_CLIENT_REACHED; |
| 2215 | break; |
| 2216 | case NL80211_CONN_FAIL_BLOCKED_CLIENT: |
| 2217 | wpa_printf(MSG_DEBUG, "nl80211: Blocked client " MACSTR |
| 2218 | " tried to connect", |
| 2219 | MAC2STR(data.connect_failed_reason.addr)); |
| 2220 | data.connect_failed_reason.code = BLOCKED_CLIENT; |
| 2221 | break; |
| 2222 | default: |
| 2223 | wpa_printf(MSG_DEBUG, "nl8021l: Unknown connect failed reason " |
| 2224 | "%u", reason); |
| 2225 | return; |
| 2226 | } |
| 2227 | |
| 2228 | wpa_supplicant_event(drv->ctx, EVENT_CONNECT_FAILED_REASON, &data); |
| 2229 | } |
| 2230 | |
| 2231 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2232 | static void nl80211_spurious_frame(struct i802_bss *bss, struct nlattr **tb, |
| 2233 | int wds) |
| 2234 | { |
| 2235 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2236 | union wpa_event_data event; |
| 2237 | |
| 2238 | if (!tb[NL80211_ATTR_MAC]) |
| 2239 | return; |
| 2240 | |
| 2241 | os_memset(&event, 0, sizeof(event)); |
| 2242 | event.rx_from_unknown.bssid = bss->addr; |
| 2243 | event.rx_from_unknown.addr = nla_data(tb[NL80211_ATTR_MAC]); |
| 2244 | event.rx_from_unknown.wds = wds; |
| 2245 | |
| 2246 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); |
| 2247 | } |
| 2248 | |
| 2249 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2250 | static void do_process_drv_event(struct i802_bss *bss, int cmd, |
| 2251 | struct nlattr **tb) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2252 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2253 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2254 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2255 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED && |
| 2256 | (cmd == NL80211_CMD_NEW_SCAN_RESULTS || |
| 2257 | cmd == NL80211_CMD_SCAN_ABORTED)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2258 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2259 | drv->ap_scan_as_station); |
| 2260 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2263 | switch (cmd) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2264 | case NL80211_CMD_TRIGGER_SCAN: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2265 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan trigger"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2266 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2267 | case NL80211_CMD_START_SCHED_SCAN: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2268 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan started"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2269 | break; |
| 2270 | case NL80211_CMD_SCHED_SCAN_STOPPED: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2271 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan stopped"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2272 | wpa_supplicant_event(drv->ctx, EVENT_SCHED_SCAN_STOPPED, NULL); |
| 2273 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2274 | case NL80211_CMD_NEW_SCAN_RESULTS: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2275 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2276 | "nl80211: New scan results available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2277 | drv->scan_complete_events = 1; |
| 2278 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, |
| 2279 | drv->ctx); |
| 2280 | send_scan_event(drv, 0, tb); |
| 2281 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2282 | case NL80211_CMD_SCHED_SCAN_RESULTS: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2283 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2284 | "nl80211: New sched scan results available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2285 | send_scan_event(drv, 0, tb); |
| 2286 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2287 | case NL80211_CMD_SCAN_ABORTED: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2288 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan aborted"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2289 | /* |
| 2290 | * Need to indicate that scan results are available in order |
| 2291 | * not to make wpa_supplicant stop its scanning. |
| 2292 | */ |
| 2293 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, |
| 2294 | drv->ctx); |
| 2295 | send_scan_event(drv, 1, tb); |
| 2296 | break; |
| 2297 | case NL80211_CMD_AUTHENTICATE: |
| 2298 | case NL80211_CMD_ASSOCIATE: |
| 2299 | case NL80211_CMD_DEAUTHENTICATE: |
| 2300 | case NL80211_CMD_DISASSOCIATE: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2301 | case NL80211_CMD_FRAME_TX_STATUS: |
| 2302 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
| 2303 | case NL80211_CMD_UNPROT_DISASSOCIATE: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2304 | mlme_event(drv, cmd, tb[NL80211_ATTR_FRAME], |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2305 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
| 2306 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2307 | tb[NL80211_ATTR_COOKIE], |
| 2308 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2309 | break; |
| 2310 | case NL80211_CMD_CONNECT: |
| 2311 | case NL80211_CMD_ROAM: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2312 | mlme_event_connect(drv, cmd, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2313 | tb[NL80211_ATTR_STATUS_CODE], |
| 2314 | tb[NL80211_ATTR_MAC], |
| 2315 | tb[NL80211_ATTR_REQ_IE], |
| 2316 | tb[NL80211_ATTR_RESP_IE]); |
| 2317 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2318 | case NL80211_CMD_CH_SWITCH_NOTIFY: |
| 2319 | mlme_event_ch_switch(drv, tb[NL80211_ATTR_WIPHY_FREQ], |
| 2320 | tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2321 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2322 | case NL80211_CMD_DISCONNECT: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2323 | mlme_event_disconnect(drv, tb[NL80211_ATTR_REASON_CODE], |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2324 | tb[NL80211_ATTR_MAC], |
| 2325 | tb[NL80211_ATTR_DISCONNECTED_BY_AP]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2326 | break; |
| 2327 | case NL80211_CMD_MICHAEL_MIC_FAILURE: |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2328 | mlme_event_michael_mic_failure(bss, tb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2329 | break; |
| 2330 | case NL80211_CMD_JOIN_IBSS: |
| 2331 | mlme_event_join_ibss(drv, tb); |
| 2332 | break; |
| 2333 | case NL80211_CMD_REMAIN_ON_CHANNEL: |
| 2334 | mlme_event_remain_on_channel(drv, 0, tb); |
| 2335 | break; |
| 2336 | case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: |
| 2337 | mlme_event_remain_on_channel(drv, 1, tb); |
| 2338 | break; |
| 2339 | case NL80211_CMD_NOTIFY_CQM: |
| 2340 | nl80211_cqm_event(drv, tb); |
| 2341 | break; |
| 2342 | case NL80211_CMD_REG_CHANGE: |
| 2343 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory domain change"); |
| 2344 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, |
| 2345 | NULL); |
| 2346 | break; |
| 2347 | case NL80211_CMD_REG_BEACON_HINT: |
| 2348 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory beacon hint"); |
| 2349 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, |
| 2350 | NULL); |
| 2351 | break; |
| 2352 | case NL80211_CMD_NEW_STATION: |
| 2353 | nl80211_new_station_event(drv, tb); |
| 2354 | break; |
| 2355 | case NL80211_CMD_DEL_STATION: |
| 2356 | nl80211_del_station_event(drv, tb); |
| 2357 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2358 | case NL80211_CMD_SET_REKEY_OFFLOAD: |
| 2359 | nl80211_rekey_offload_event(drv, tb); |
| 2360 | break; |
| 2361 | case NL80211_CMD_PMKSA_CANDIDATE: |
| 2362 | nl80211_pmksa_candidate_event(drv, tb); |
| 2363 | break; |
| 2364 | case NL80211_CMD_PROBE_CLIENT: |
| 2365 | nl80211_client_probe_event(drv, tb); |
| 2366 | break; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2367 | case NL80211_CMD_TDLS_OPER: |
| 2368 | nl80211_tdls_oper_event(drv, tb); |
| 2369 | break; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2370 | case NL80211_CMD_CONN_FAILED: |
| 2371 | nl80211_connect_failed_event(drv, tb); |
| 2372 | break; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2373 | case NL80211_CMD_FT_EVENT: |
| 2374 | mlme_event_ft_event(drv, tb); |
| 2375 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2376 | default: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2377 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Ignored unknown event " |
| 2378 | "(cmd=%d)", cmd); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2379 | break; |
| 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | |
| 2384 | static int process_drv_event(struct nl_msg *msg, void *arg) |
| 2385 | { |
| 2386 | struct wpa_driver_nl80211_data *drv = arg; |
| 2387 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2388 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2389 | struct i802_bss *bss; |
| 2390 | int ifidx = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2391 | |
| 2392 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2393 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2394 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2395 | if (tb[NL80211_ATTR_IFINDEX]) |
| 2396 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2397 | |
| 2398 | for (bss = &drv->first_bss; bss; bss = bss->next) { |
| 2399 | if (ifidx == -1 || ifidx == bss->ifindex) { |
| 2400 | do_process_drv_event(bss, gnlh->cmd, tb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2401 | return NL_SKIP; |
| 2402 | } |
| 2403 | } |
| 2404 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2405 | wpa_printf(MSG_DEBUG, "nl80211: Ignored event (cmd=%d) for foreign " |
| 2406 | "interface (ifindex %d)", gnlh->cmd, ifidx); |
| 2407 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2408 | return NL_SKIP; |
| 2409 | } |
| 2410 | |
| 2411 | |
| 2412 | static int process_global_event(struct nl_msg *msg, void *arg) |
| 2413 | { |
| 2414 | struct nl80211_global *global = arg; |
| 2415 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2416 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2417 | struct wpa_driver_nl80211_data *drv, *tmp; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2418 | int ifidx = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2419 | struct i802_bss *bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2420 | |
| 2421 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2422 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2423 | |
| 2424 | if (tb[NL80211_ATTR_IFINDEX]) |
| 2425 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2426 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2427 | dl_list_for_each_safe(drv, tmp, &global->interfaces, |
| 2428 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2429 | for (bss = &drv->first_bss; bss; bss = bss->next) { |
| 2430 | if (ifidx == -1 || ifidx == bss->ifindex) { |
| 2431 | do_process_drv_event(bss, gnlh->cmd, tb); |
| 2432 | return NL_SKIP; |
| 2433 | } |
| 2434 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | return NL_SKIP; |
| 2438 | } |
| 2439 | |
| 2440 | |
| 2441 | static int process_bss_event(struct nl_msg *msg, void *arg) |
| 2442 | { |
| 2443 | struct i802_bss *bss = arg; |
| 2444 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2445 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2446 | |
| 2447 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2448 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2449 | |
| 2450 | switch (gnlh->cmd) { |
| 2451 | case NL80211_CMD_FRAME: |
| 2452 | case NL80211_CMD_FRAME_TX_STATUS: |
| 2453 | mlme_event(bss->drv, gnlh->cmd, tb[NL80211_ATTR_FRAME], |
| 2454 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
| 2455 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2456 | tb[NL80211_ATTR_COOKIE], |
| 2457 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2458 | break; |
| 2459 | case NL80211_CMD_UNEXPECTED_FRAME: |
| 2460 | nl80211_spurious_frame(bss, tb, 0); |
| 2461 | break; |
| 2462 | case NL80211_CMD_UNEXPECTED_4ADDR_FRAME: |
| 2463 | nl80211_spurious_frame(bss, tb, 1); |
| 2464 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2465 | default: |
| 2466 | wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event " |
| 2467 | "(cmd=%d)", gnlh->cmd); |
| 2468 | break; |
| 2469 | } |
| 2470 | |
| 2471 | return NL_SKIP; |
| 2472 | } |
| 2473 | |
| 2474 | |
| 2475 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 2476 | void *handle) |
| 2477 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2478 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2479 | |
| 2480 | wpa_printf(MSG_DEBUG, "nl80211: Event message available"); |
| 2481 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2482 | nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | |
| 2486 | /** |
| 2487 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 2488 | * @priv: driver_nl80211 private data |
| 2489 | * @alpha2_arg: country to which to switch to |
| 2490 | * Returns: 0 on success, -1 on failure |
| 2491 | * |
| 2492 | * This asks nl80211 to set the regulatory domain for given |
| 2493 | * country ISO / IEC alpha2. |
| 2494 | */ |
| 2495 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 2496 | { |
| 2497 | struct i802_bss *bss = priv; |
| 2498 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2499 | char alpha2[3]; |
| 2500 | struct nl_msg *msg; |
| 2501 | |
| 2502 | msg = nlmsg_alloc(); |
| 2503 | if (!msg) |
| 2504 | return -ENOMEM; |
| 2505 | |
| 2506 | alpha2[0] = alpha2_arg[0]; |
| 2507 | alpha2[1] = alpha2_arg[1]; |
| 2508 | alpha2[2] = '\0'; |
| 2509 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2510 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2511 | |
| 2512 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); |
| 2513 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 2514 | return -EINVAL; |
| 2515 | return 0; |
| 2516 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2517 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2518 | return -EINVAL; |
| 2519 | } |
| 2520 | |
| 2521 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2522 | static int protocol_feature_handler(struct nl_msg *msg, void *arg) |
| 2523 | { |
| 2524 | u32 *feat = arg; |
| 2525 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 2526 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2527 | |
| 2528 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2529 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2530 | |
| 2531 | if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]) |
| 2532 | *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]); |
| 2533 | |
| 2534 | return NL_SKIP; |
| 2535 | } |
| 2536 | |
| 2537 | |
| 2538 | static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv) |
| 2539 | { |
| 2540 | u32 feat = 0; |
| 2541 | struct nl_msg *msg; |
| 2542 | |
| 2543 | msg = nlmsg_alloc(); |
| 2544 | if (!msg) |
| 2545 | goto nla_put_failure; |
| 2546 | |
| 2547 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 2548 | if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0) |
| 2549 | return feat; |
| 2550 | |
| 2551 | msg = NULL; |
| 2552 | nla_put_failure: |
| 2553 | nlmsg_free(msg); |
| 2554 | return 0; |
| 2555 | } |
| 2556 | |
| 2557 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2558 | struct wiphy_info_data { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 2559 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2560 | struct wpa_driver_capa *capa; |
| 2561 | |
| 2562 | unsigned int error:1; |
| 2563 | unsigned int device_ap_sme:1; |
| 2564 | unsigned int poll_command_supported:1; |
| 2565 | unsigned int data_tx_status:1; |
| 2566 | unsigned int monitor_supported:1; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2567 | unsigned int auth_supported:1; |
| 2568 | unsigned int connect_supported:1; |
| 2569 | unsigned int p2p_go_supported:1; |
| 2570 | unsigned int p2p_client_supported:1; |
| 2571 | unsigned int p2p_concurrent:1; |
| 2572 | unsigned int p2p_multichan_concurrent:1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2573 | }; |
| 2574 | |
| 2575 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2576 | static unsigned int probe_resp_offload_support(int supp_protocols) |
| 2577 | { |
| 2578 | unsigned int prot = 0; |
| 2579 | |
| 2580 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS) |
| 2581 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS; |
| 2582 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2) |
| 2583 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2; |
| 2584 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P) |
| 2585 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P; |
| 2586 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U) |
| 2587 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING; |
| 2588 | |
| 2589 | return prot; |
| 2590 | } |
| 2591 | |
| 2592 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2593 | static void wiphy_info_supported_iftypes(struct wiphy_info_data *info, |
| 2594 | struct nlattr *tb) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2595 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2596 | struct nlattr *nl_mode; |
| 2597 | int i; |
| 2598 | |
| 2599 | if (tb == NULL) |
| 2600 | return; |
| 2601 | |
| 2602 | nla_for_each_nested(nl_mode, tb, i) { |
| 2603 | switch (nla_type(nl_mode)) { |
| 2604 | case NL80211_IFTYPE_AP: |
| 2605 | info->capa->flags |= WPA_DRIVER_FLAGS_AP; |
| 2606 | break; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2607 | case NL80211_IFTYPE_ADHOC: |
| 2608 | info->capa->flags |= WPA_DRIVER_FLAGS_IBSS; |
| 2609 | break; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2610 | case NL80211_IFTYPE_P2P_GO: |
| 2611 | info->p2p_go_supported = 1; |
| 2612 | break; |
| 2613 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2614 | info->p2p_client_supported = 1; |
| 2615 | break; |
| 2616 | case NL80211_IFTYPE_MONITOR: |
| 2617 | info->monitor_supported = 1; |
| 2618 | break; |
| 2619 | } |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | |
| 2624 | static int wiphy_info_iface_comb_process(struct wiphy_info_data *info, |
| 2625 | struct nlattr *nl_combi) |
| 2626 | { |
| 2627 | struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB]; |
| 2628 | struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT]; |
| 2629 | struct nlattr *nl_limit, *nl_mode; |
| 2630 | int err, rem_limit, rem_mode; |
| 2631 | int combination_has_p2p = 0, combination_has_mgd = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2632 | static struct nla_policy |
| 2633 | iface_combination_policy[NUM_NL80211_IFACE_COMB] = { |
| 2634 | [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED }, |
| 2635 | [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 }, |
| 2636 | [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG }, |
| 2637 | [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 }, |
| 2638 | }, |
| 2639 | iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = { |
| 2640 | [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED }, |
| 2641 | [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 }, |
| 2642 | }; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2643 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2644 | err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB, |
| 2645 | nl_combi, iface_combination_policy); |
| 2646 | if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] || |
| 2647 | !tb_comb[NL80211_IFACE_COMB_MAXNUM] || |
| 2648 | !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) |
| 2649 | return 0; /* broken combination */ |
| 2650 | |
| 2651 | nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], |
| 2652 | rem_limit) { |
| 2653 | err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT, |
| 2654 | nl_limit, iface_limit_policy); |
| 2655 | if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) |
| 2656 | return 0; /* broken combination */ |
| 2657 | |
| 2658 | nla_for_each_nested(nl_mode, |
| 2659 | tb_limit[NL80211_IFACE_LIMIT_TYPES], |
| 2660 | rem_mode) { |
| 2661 | int ift = nla_type(nl_mode); |
| 2662 | if (ift == NL80211_IFTYPE_P2P_GO || |
| 2663 | ift == NL80211_IFTYPE_P2P_CLIENT) |
| 2664 | combination_has_p2p = 1; |
| 2665 | if (ift == NL80211_IFTYPE_STATION) |
| 2666 | combination_has_mgd = 1; |
| 2667 | } |
| 2668 | if (combination_has_p2p && combination_has_mgd) |
| 2669 | break; |
| 2670 | } |
| 2671 | |
| 2672 | if (combination_has_p2p && combination_has_mgd) { |
| 2673 | info->p2p_concurrent = 1; |
| 2674 | if (nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) > 1) |
| 2675 | info->p2p_multichan_concurrent = 1; |
| 2676 | return 1; |
| 2677 | } |
| 2678 | |
| 2679 | return 0; |
| 2680 | } |
| 2681 | |
| 2682 | |
| 2683 | static void wiphy_info_iface_comb(struct wiphy_info_data *info, |
| 2684 | struct nlattr *tb) |
| 2685 | { |
| 2686 | struct nlattr *nl_combi; |
| 2687 | int rem_combi; |
| 2688 | |
| 2689 | if (tb == NULL) |
| 2690 | return; |
| 2691 | |
| 2692 | nla_for_each_nested(nl_combi, tb, rem_combi) { |
| 2693 | if (wiphy_info_iface_comb_process(info, nl_combi) > 0) |
| 2694 | break; |
| 2695 | } |
| 2696 | } |
| 2697 | |
| 2698 | |
| 2699 | static void wiphy_info_supp_cmds(struct wiphy_info_data *info, |
| 2700 | struct nlattr *tb) |
| 2701 | { |
| 2702 | struct nlattr *nl_cmd; |
| 2703 | int i; |
| 2704 | |
| 2705 | if (tb == NULL) |
| 2706 | return; |
| 2707 | |
| 2708 | nla_for_each_nested(nl_cmd, tb, i) { |
| 2709 | switch (nla_get_u32(nl_cmd)) { |
| 2710 | case NL80211_CMD_AUTHENTICATE: |
| 2711 | info->auth_supported = 1; |
| 2712 | break; |
| 2713 | case NL80211_CMD_CONNECT: |
| 2714 | info->connect_supported = 1; |
| 2715 | break; |
| 2716 | case NL80211_CMD_START_SCHED_SCAN: |
| 2717 | info->capa->sched_scan_supported = 1; |
| 2718 | break; |
| 2719 | case NL80211_CMD_PROBE_CLIENT: |
| 2720 | info->poll_command_supported = 1; |
| 2721 | break; |
| 2722 | } |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | |
| 2727 | static void wiphy_info_max_roc(struct wpa_driver_capa *capa, |
| 2728 | struct nlattr *tb) |
| 2729 | { |
| 2730 | /* default to 5000 since early versions of mac80211 don't set it */ |
| 2731 | capa->max_remain_on_chan = 5000; |
| 2732 | |
| 2733 | if (tb) |
| 2734 | capa->max_remain_on_chan = nla_get_u32(tb); |
| 2735 | } |
| 2736 | |
| 2737 | |
| 2738 | static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls, |
| 2739 | struct nlattr *ext_setup) |
| 2740 | { |
| 2741 | if (tdls == NULL) |
| 2742 | return; |
| 2743 | |
| 2744 | wpa_printf(MSG_DEBUG, "nl80211: TDLS supported"); |
| 2745 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT; |
| 2746 | |
| 2747 | if (ext_setup) { |
| 2748 | wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup"); |
| 2749 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP; |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | |
| 2754 | static void wiphy_info_feature_flags(struct wiphy_info_data *info, |
| 2755 | struct nlattr *tb) |
| 2756 | { |
| 2757 | u32 flags; |
| 2758 | struct wpa_driver_capa *capa = info->capa; |
| 2759 | |
| 2760 | if (tb == NULL) |
| 2761 | return; |
| 2762 | |
| 2763 | flags = nla_get_u32(tb); |
| 2764 | |
| 2765 | if (flags & NL80211_FEATURE_SK_TX_STATUS) |
| 2766 | info->data_tx_status = 1; |
| 2767 | |
| 2768 | if (flags & NL80211_FEATURE_INACTIVITY_TIMER) |
| 2769 | capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER; |
| 2770 | |
| 2771 | if (flags & NL80211_FEATURE_SAE) |
| 2772 | capa->flags |= WPA_DRIVER_FLAGS_SAE; |
| 2773 | |
| 2774 | if (flags & NL80211_FEATURE_NEED_OBSS_SCAN) |
| 2775 | capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN; |
| 2776 | } |
| 2777 | |
| 2778 | |
| 2779 | static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa, |
| 2780 | struct nlattr *tb) |
| 2781 | { |
| 2782 | u32 protocols; |
| 2783 | |
| 2784 | if (tb == NULL) |
| 2785 | return; |
| 2786 | |
| 2787 | protocols = nla_get_u32(tb); |
| 2788 | wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP " |
| 2789 | "mode"); |
| 2790 | capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD; |
| 2791 | capa->probe_resp_offloads = probe_resp_offload_support(protocols); |
| 2792 | } |
| 2793 | |
| 2794 | |
| 2795 | static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
| 2796 | { |
| 2797 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2798 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2799 | struct wiphy_info_data *info = arg; |
| 2800 | struct wpa_driver_capa *capa = info->capa; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 2801 | struct wpa_driver_nl80211_data *drv = info->drv; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2802 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2803 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2804 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2805 | |
| 2806 | if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2807 | capa->max_scan_ssids = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2808 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]); |
| 2809 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2810 | if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]) |
| 2811 | capa->max_sched_scan_ssids = |
| 2812 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]); |
| 2813 | |
| 2814 | if (tb[NL80211_ATTR_MAX_MATCH_SETS]) |
| 2815 | capa->max_match_sets = |
| 2816 | nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]); |
| 2817 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2818 | wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]); |
| 2819 | wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]); |
| 2820 | wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2821 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2822 | if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) { |
| 2823 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based " |
| 2824 | "off-channel TX"); |
| 2825 | capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 2826 | } |
| 2827 | |
| 2828 | if (tb[NL80211_ATTR_ROAM_SUPPORT]) { |
| 2829 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming"); |
| 2830 | capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 2831 | } |
| 2832 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2833 | wiphy_info_max_roc(capa, |
| 2834 | tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2835 | |
| 2836 | if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD]) |
| 2837 | capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2838 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2839 | wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT], |
| 2840 | tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]); |
Dmitry Shmidt | ad266fb | 2012-08-24 17:03:35 -0700 | [diff] [blame] | 2841 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2842 | if (tb[NL80211_ATTR_DEVICE_AP_SME]) |
| 2843 | info->device_ap_sme = 1; |
| 2844 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2845 | wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]); |
| 2846 | wiphy_info_probe_resp_offload(capa, |
| 2847 | tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2848 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 2849 | if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] && |
| 2850 | drv->extended_capa == NULL) { |
| 2851 | drv->extended_capa = |
| 2852 | os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 2853 | if (drv->extended_capa) { |
| 2854 | os_memcpy(drv->extended_capa, |
| 2855 | nla_data(tb[NL80211_ATTR_EXT_CAPA]), |
| 2856 | nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 2857 | drv->extended_capa_len = |
| 2858 | nla_len(tb[NL80211_ATTR_EXT_CAPA]); |
| 2859 | } |
| 2860 | drv->extended_capa_mask = |
| 2861 | os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 2862 | if (drv->extended_capa_mask) { |
| 2863 | os_memcpy(drv->extended_capa_mask, |
| 2864 | nla_data(tb[NL80211_ATTR_EXT_CAPA]), |
| 2865 | nla_len(tb[NL80211_ATTR_EXT_CAPA])); |
| 2866 | } else { |
| 2867 | os_free(drv->extended_capa); |
| 2868 | drv->extended_capa = NULL; |
| 2869 | drv->extended_capa_len = 0; |
| 2870 | } |
| 2871 | } |
| 2872 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2873 | return NL_SKIP; |
| 2874 | } |
| 2875 | |
| 2876 | |
| 2877 | static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv, |
| 2878 | struct wiphy_info_data *info) |
| 2879 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2880 | u32 feat; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2881 | struct nl_msg *msg; |
| 2882 | |
| 2883 | os_memset(info, 0, sizeof(*info)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2884 | info->capa = &drv->capa; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 2885 | info->drv = drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2886 | |
| 2887 | msg = nlmsg_alloc(); |
| 2888 | if (!msg) |
| 2889 | return -1; |
| 2890 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2891 | feat = get_nl80211_protocol_features(drv); |
| 2892 | if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) |
| 2893 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY); |
| 2894 | else |
| 2895 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2896 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2897 | NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2898 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->first_bss.ifindex); |
| 2899 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2900 | if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info)) |
| 2901 | return -1; |
| 2902 | |
| 2903 | if (info->auth_supported) |
| 2904 | drv->capa.flags |= WPA_DRIVER_FLAGS_SME; |
| 2905 | else if (!info->connect_supported) { |
| 2906 | wpa_printf(MSG_INFO, "nl80211: Driver does not support " |
| 2907 | "authentication/association or connect commands"); |
| 2908 | info->error = 1; |
| 2909 | } |
| 2910 | |
| 2911 | if (info->p2p_go_supported && info->p2p_client_supported) |
| 2912 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE; |
| 2913 | if (info->p2p_concurrent) { |
| 2914 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 2915 | "interface (driver advertised support)"); |
| 2916 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 2917 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 2918 | } |
| 2919 | if (info->p2p_multichan_concurrent) { |
| 2920 | wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel " |
| 2921 | "concurrent (driver advertised support)"); |
| 2922 | drv->capa.flags |= WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT; |
| 2923 | } |
| 2924 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2925 | nla_put_failure: |
| 2926 | nlmsg_free(msg); |
| 2927 | return -1; |
| 2928 | } |
| 2929 | |
| 2930 | |
| 2931 | static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv) |
| 2932 | { |
| 2933 | struct wiphy_info_data info; |
| 2934 | if (wpa_driver_nl80211_get_info(drv, &info)) |
| 2935 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2936 | |
| 2937 | if (info.error) |
| 2938 | return -1; |
| 2939 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | drv->has_capability = 1; |
| 2941 | /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */ |
| 2942 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | |
| 2943 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | |
| 2944 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | |
| 2945 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; |
| 2946 | drv->capa.enc = WPA_DRIVER_CAPA_ENC_WEP40 | |
| 2947 | WPA_DRIVER_CAPA_ENC_WEP104 | |
| 2948 | WPA_DRIVER_CAPA_ENC_TKIP | |
| 2949 | WPA_DRIVER_CAPA_ENC_CCMP; |
| 2950 | drv->capa.auth = WPA_DRIVER_AUTH_OPEN | |
| 2951 | WPA_DRIVER_AUTH_SHARED | |
| 2952 | WPA_DRIVER_AUTH_LEAP; |
| 2953 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2954 | drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES; |
| 2955 | drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2956 | drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
Dmitry Shmidt | ad266fb | 2012-08-24 17:03:35 -0700 | [diff] [blame] | 2957 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2958 | if (!info.device_ap_sme) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2959 | drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2960 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2961 | /* |
| 2962 | * No AP SME is currently assumed to also indicate no AP MLME |
| 2963 | * in the driver/firmware. |
| 2964 | */ |
| 2965 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME; |
| 2966 | } |
| 2967 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2968 | drv->device_ap_sme = info.device_ap_sme; |
| 2969 | drv->poll_command_supported = info.poll_command_supported; |
| 2970 | drv->data_tx_status = info.data_tx_status; |
| 2971 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2972 | #ifdef ANDROID_P2P |
| 2973 | if(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) { |
| 2974 | /* Driver is new enough to support monitorless mode*/ |
| 2975 | wpa_printf(MSG_DEBUG, "nl80211: Driver is new " |
| 2976 | "enough to support monitor-less mode"); |
| 2977 | drv->use_monitor = 0; |
| 2978 | } |
| 2979 | #else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2980 | /* |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2981 | * If poll command and tx status are supported, mac80211 is new enough |
| 2982 | * to have everything we need to not need monitor interfaces. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2983 | */ |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2984 | drv->use_monitor = !info.poll_command_supported || !info.data_tx_status; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2985 | #endif |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2986 | |
| 2987 | if (drv->device_ap_sme && drv->use_monitor) { |
| 2988 | /* |
| 2989 | * Non-mac80211 drivers may not support monitor interface. |
| 2990 | * Make sure we do not get stuck with incorrect capability here |
| 2991 | * by explicitly testing this. |
| 2992 | */ |
| 2993 | if (!info.monitor_supported) { |
| 2994 | wpa_printf(MSG_DEBUG, "nl80211: Disable use_monitor " |
| 2995 | "with device_ap_sme since no monitor mode " |
| 2996 | "support detected"); |
| 2997 | drv->use_monitor = 0; |
| 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | /* |
| 3002 | * If we aren't going to use monitor interfaces, but the |
| 3003 | * driver doesn't support data TX status, we won't get TX |
| 3004 | * status for EAPOL frames. |
| 3005 | */ |
| 3006 | if (!drv->use_monitor && !info.data_tx_status) |
| 3007 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3008 | |
| 3009 | return 0; |
| 3010 | } |
| 3011 | |
| 3012 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3013 | #ifdef ANDROID |
| 3014 | static int android_genl_ctrl_resolve(struct nl_handle *handle, |
| 3015 | const char *name) |
| 3016 | { |
| 3017 | /* |
| 3018 | * Android ICS has very minimal genl_ctrl_resolve() implementation, so |
| 3019 | * need to work around that. |
| 3020 | */ |
| 3021 | struct nl_cache *cache = NULL; |
| 3022 | struct genl_family *nl80211 = NULL; |
| 3023 | int id = -1; |
| 3024 | |
| 3025 | if (genl_ctrl_alloc_cache(handle, &cache) < 0) { |
| 3026 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " |
| 3027 | "netlink cache"); |
| 3028 | goto fail; |
| 3029 | } |
| 3030 | |
| 3031 | nl80211 = genl_ctrl_search_by_name(cache, name); |
| 3032 | if (nl80211 == NULL) |
| 3033 | goto fail; |
| 3034 | |
| 3035 | id = genl_family_get_id(nl80211); |
| 3036 | |
| 3037 | fail: |
| 3038 | if (nl80211) |
| 3039 | genl_family_put(nl80211); |
| 3040 | if (cache) |
| 3041 | nl_cache_free(cache); |
| 3042 | |
| 3043 | return id; |
| 3044 | } |
| 3045 | #define genl_ctrl_resolve android_genl_ctrl_resolve |
| 3046 | #endif /* ANDROID */ |
| 3047 | |
| 3048 | |
| 3049 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3050 | { |
| 3051 | int ret; |
| 3052 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3053 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 3054 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3055 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 3056 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3057 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3060 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 3061 | if (global->nl == NULL) |
| 3062 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3063 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3064 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 3065 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3066 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 3067 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3068 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3071 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 3072 | if (global->nl_event == NULL) |
| 3073 | goto err; |
| 3074 | |
| 3075 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3076 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3077 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3078 | if (ret < 0) { |
| 3079 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 3080 | "membership for scan events: %d (%s)", |
| 3081 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3082 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3085 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3086 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3087 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3088 | if (ret < 0) { |
| 3089 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 3090 | "membership for mlme events: %d (%s)", |
| 3091 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3092 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3095 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3096 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3097 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3098 | if (ret < 0) { |
| 3099 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 3100 | "membership for regulatory events: %d (%s)", |
| 3101 | ret, strerror(-ret)); |
| 3102 | /* Continue without regulatory events */ |
| 3103 | } |
| 3104 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3105 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 3106 | no_seq_check, NULL); |
| 3107 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 3108 | process_global_event, global); |
| 3109 | |
| 3110 | eloop_register_read_sock(nl_socket_get_fd(global->nl_event), |
| 3111 | wpa_driver_nl80211_event_receive, |
| 3112 | global->nl_cb, global->nl_event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3113 | |
| 3114 | return 0; |
| 3115 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3116 | err: |
| 3117 | nl_destroy_handles(&global->nl_event); |
| 3118 | nl_destroy_handles(&global->nl); |
| 3119 | nl_cb_put(global->nl_cb); |
| 3120 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3121 | return -1; |
| 3122 | } |
| 3123 | |
| 3124 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3125 | static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data *drv) |
| 3126 | { |
| 3127 | drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 3128 | if (!drv->nl_cb) { |
| 3129 | wpa_printf(MSG_ERROR, "nl80211: Failed to alloc cb struct"); |
| 3130 | return -1; |
| 3131 | } |
| 3132 | |
| 3133 | nl_cb_set(drv->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 3134 | no_seq_check, NULL); |
| 3135 | nl_cb_set(drv->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 3136 | process_drv_event, drv); |
| 3137 | |
| 3138 | return 0; |
| 3139 | } |
| 3140 | |
| 3141 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3142 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 3143 | { |
| 3144 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
| 3145 | /* |
| 3146 | * This may be for any interface; use ifdown event to disable |
| 3147 | * interface. |
| 3148 | */ |
| 3149 | } |
| 3150 | |
| 3151 | |
| 3152 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 3153 | { |
| 3154 | struct wpa_driver_nl80211_data *drv = ctx; |
| 3155 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3156 | if (linux_set_iface_flags(drv->global->ioctl_sock, |
| 3157 | drv->first_bss.ifname, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3158 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 3159 | "after rfkill unblock"); |
| 3160 | return; |
| 3161 | } |
| 3162 | /* rtnetlink ifup handler will report interface as enabled */ |
| 3163 | } |
| 3164 | |
| 3165 | |
| 3166 | static void nl80211_get_phy_name(struct wpa_driver_nl80211_data *drv) |
| 3167 | { |
| 3168 | /* Find phy (radio) to which this interface belongs */ |
| 3169 | char buf[90], *pos; |
| 3170 | int f, rv; |
| 3171 | |
| 3172 | drv->phyname[0] = '\0'; |
| 3173 | snprintf(buf, sizeof(buf) - 1, "/sys/class/net/%s/phy80211/name", |
| 3174 | drv->first_bss.ifname); |
| 3175 | f = open(buf, O_RDONLY); |
| 3176 | if (f < 0) { |
| 3177 | wpa_printf(MSG_DEBUG, "Could not open file %s: %s", |
| 3178 | buf, strerror(errno)); |
| 3179 | return; |
| 3180 | } |
| 3181 | |
| 3182 | rv = read(f, drv->phyname, sizeof(drv->phyname) - 1); |
| 3183 | close(f); |
| 3184 | if (rv < 0) { |
| 3185 | wpa_printf(MSG_DEBUG, "Could not read file %s: %s", |
| 3186 | buf, strerror(errno)); |
| 3187 | return; |
| 3188 | } |
| 3189 | |
| 3190 | drv->phyname[rv] = '\0'; |
| 3191 | pos = os_strchr(drv->phyname, '\n'); |
| 3192 | if (pos) |
| 3193 | *pos = '\0'; |
| 3194 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 3195 | drv->first_bss.ifname, drv->phyname); |
| 3196 | } |
| 3197 | |
| 3198 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3199 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 3200 | void *eloop_ctx, |
| 3201 | void *handle) |
| 3202 | { |
| 3203 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 3204 | u8 data[2048]; |
| 3205 | struct msghdr msg; |
| 3206 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3207 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3208 | struct cmsghdr *cmsg; |
| 3209 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 3210 | union wpa_event_data event; |
| 3211 | |
| 3212 | memset(&msg, 0, sizeof(msg)); |
| 3213 | msg.msg_iov = &entry; |
| 3214 | msg.msg_iovlen = 1; |
| 3215 | entry.iov_base = data; |
| 3216 | entry.iov_len = sizeof(data); |
| 3217 | msg.msg_control = &control; |
| 3218 | msg.msg_controllen = sizeof(control); |
| 3219 | |
| 3220 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 3221 | /* if error or not fitting 802.3 header, return */ |
| 3222 | if (res < 14) |
| 3223 | return; |
| 3224 | |
| 3225 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 3226 | { |
| 3227 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 3228 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 3229 | int *ack; |
| 3230 | |
| 3231 | found_wifi = 1; |
| 3232 | ack = (void *)CMSG_DATA(cmsg); |
| 3233 | acked = *ack; |
| 3234 | } |
| 3235 | |
| 3236 | if (cmsg->cmsg_level == SOL_PACKET && |
| 3237 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 3238 | struct sock_extended_err *err = |
| 3239 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 3240 | |
| 3241 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 3242 | found_ee = 1; |
| 3243 | } |
| 3244 | } |
| 3245 | |
| 3246 | if (!found_ee || !found_wifi) |
| 3247 | return; |
| 3248 | |
| 3249 | memset(&event, 0, sizeof(event)); |
| 3250 | event.eapol_tx_status.dst = data; |
| 3251 | event.eapol_tx_status.data = data + 14; |
| 3252 | event.eapol_tx_status.data_len = res - 14; |
| 3253 | event.eapol_tx_status.ack = acked; |
| 3254 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 3255 | } |
| 3256 | |
| 3257 | |
| 3258 | static int nl80211_init_bss(struct i802_bss *bss) |
| 3259 | { |
| 3260 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 3261 | if (!bss->nl_cb) |
| 3262 | return -1; |
| 3263 | |
| 3264 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 3265 | no_seq_check, NULL); |
| 3266 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 3267 | process_bss_event, bss); |
| 3268 | |
| 3269 | return 0; |
| 3270 | } |
| 3271 | |
| 3272 | |
| 3273 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 3274 | { |
| 3275 | nl_cb_put(bss->nl_cb); |
| 3276 | bss->nl_cb = NULL; |
| 3277 | } |
| 3278 | |
| 3279 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3280 | /** |
| 3281 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 3282 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 3283 | * e.g., wpa_supplicant_event() |
| 3284 | * @ifname: interface name, e.g., wlan0 |
| 3285 | * @global_priv: private driver global data from global_init() |
| 3286 | * Returns: Pointer to private data, %NULL on failure |
| 3287 | */ |
| 3288 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 3289 | void *global_priv) |
| 3290 | { |
| 3291 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3292 | struct rfkill_config *rcfg; |
| 3293 | struct i802_bss *bss; |
| 3294 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3295 | if (global_priv == NULL) |
| 3296 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3297 | drv = os_zalloc(sizeof(*drv)); |
| 3298 | if (drv == NULL) |
| 3299 | return NULL; |
| 3300 | drv->global = global_priv; |
| 3301 | drv->ctx = ctx; |
| 3302 | bss = &drv->first_bss; |
| 3303 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3304 | bss->ctx = ctx; |
| 3305 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3306 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 3307 | drv->monitor_ifidx = -1; |
| 3308 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3309 | drv->eapol_tx_sock = -1; |
| 3310 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3311 | |
| 3312 | if (wpa_driver_nl80211_init_nl(drv)) { |
| 3313 | os_free(drv); |
| 3314 | return NULL; |
| 3315 | } |
| 3316 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3317 | if (nl80211_init_bss(bss)) |
| 3318 | goto failed; |
| 3319 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3320 | nl80211_get_phy_name(drv); |
| 3321 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3322 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 3323 | if (rcfg == NULL) |
| 3324 | goto failed; |
| 3325 | rcfg->ctx = drv; |
| 3326 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); |
| 3327 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 3328 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 3329 | drv->rfkill = rfkill_init(rcfg); |
| 3330 | if (drv->rfkill == NULL) { |
| 3331 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 3332 | os_free(rcfg); |
| 3333 | } |
| 3334 | |
| 3335 | if (wpa_driver_nl80211_finish_drv_init(drv)) |
| 3336 | goto failed; |
| 3337 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3338 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 3339 | if (drv->eapol_tx_sock < 0) |
| 3340 | goto failed; |
| 3341 | |
| 3342 | if (drv->data_tx_status) { |
| 3343 | int enabled = 1; |
| 3344 | |
| 3345 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 3346 | &enabled, sizeof(enabled)) < 0) { |
| 3347 | wpa_printf(MSG_DEBUG, |
| 3348 | "nl80211: wifi status sockopt failed\n"); |
| 3349 | drv->data_tx_status = 0; |
| 3350 | if (!drv->use_monitor) |
| 3351 | drv->capa.flags &= |
| 3352 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 3353 | } else { |
| 3354 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 3355 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 3356 | drv, NULL); |
| 3357 | } |
| 3358 | } |
| 3359 | |
| 3360 | if (drv->global) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3361 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3362 | drv->in_interface_list = 1; |
| 3363 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3364 | |
| 3365 | return bss; |
| 3366 | |
| 3367 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3368 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3369 | return NULL; |
| 3370 | } |
| 3371 | |
| 3372 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3373 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3374 | struct nl_handle *nl_handle, |
| 3375 | u16 type, const u8 *match, size_t match_len) |
| 3376 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3377 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3378 | struct nl_msg *msg; |
| 3379 | int ret = -1; |
| 3380 | |
| 3381 | msg = nlmsg_alloc(); |
| 3382 | if (!msg) |
| 3383 | return -1; |
| 3384 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3385 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x nl_handle=%p", |
| 3386 | type, nl_handle); |
| 3387 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 3388 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3389 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3390 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_ACTION); |
| 3391 | |
| 3392 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3393 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, type); |
| 3394 | NLA_PUT(msg, NL80211_ATTR_FRAME_MATCH, match_len, match); |
| 3395 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3396 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3397 | msg = NULL; |
| 3398 | if (ret) { |
| 3399 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 3400 | "failed (type=%u): ret=%d (%s)", |
| 3401 | type, ret, strerror(-ret)); |
| 3402 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 3403 | match, match_len); |
| 3404 | goto nla_put_failure; |
| 3405 | } |
| 3406 | ret = 0; |
| 3407 | nla_put_failure: |
| 3408 | nlmsg_free(msg); |
| 3409 | return ret; |
| 3410 | } |
| 3411 | |
| 3412 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3413 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 3414 | { |
| 3415 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3416 | |
| 3417 | if (bss->nl_mgmt) { |
| 3418 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 3419 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 3420 | return -1; |
| 3421 | } |
| 3422 | |
| 3423 | bss->nl_mgmt = nl_create_handle(drv->nl_cb, "mgmt"); |
| 3424 | if (bss->nl_mgmt == NULL) |
| 3425 | return -1; |
| 3426 | |
| 3427 | eloop_register_read_sock(nl_socket_get_fd(bss->nl_mgmt), |
| 3428 | wpa_driver_nl80211_event_receive, bss->nl_cb, |
| 3429 | bss->nl_mgmt); |
| 3430 | |
| 3431 | return 0; |
| 3432 | } |
| 3433 | |
| 3434 | |
| 3435 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3436 | const u8 *match, size_t match_len) |
| 3437 | { |
| 3438 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3439 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3440 | type, match, match_len); |
| 3441 | } |
| 3442 | |
| 3443 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3444 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3445 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3446 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3447 | |
| 3448 | if (nl80211_alloc_mgmt_handle(bss)) |
| 3449 | return -1; |
| 3450 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 3451 | "handle %p", bss->nl_mgmt); |
| 3452 | |
| 3453 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3454 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3455 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3456 | return -1; |
| 3457 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3458 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3459 | return -1; |
| 3460 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3461 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3462 | return -1; |
| 3463 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3464 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3465 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3466 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 3467 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3468 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3469 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3470 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 3471 | 6) < 0) |
| 3472 | return -1; |
| 3473 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3474 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3475 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 3476 | 5) < 0) |
| 3477 | return -1; |
| 3478 | #endif /* CONFIG_P2P */ |
| 3479 | #ifdef CONFIG_IEEE80211W |
| 3480 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3481 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3482 | return -1; |
| 3483 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3484 | #ifdef CONFIG_TDLS |
| 3485 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 3486 | /* TDLS Discovery Response */ |
| 3487 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 3488 | 0) |
| 3489 | return -1; |
| 3490 | } |
| 3491 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3492 | |
| 3493 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3494 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3495 | return -1; |
| 3496 | else |
| 3497 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 3498 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 3499 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3500 | /* WNM - BSS Transition Management Request */ |
| 3501 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
| 3502 | return -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3503 | /* WNM-Sleep Mode Response */ |
| 3504 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
| 3505 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3506 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3507 | return 0; |
| 3508 | } |
| 3509 | |
| 3510 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3511 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 3512 | { |
| 3513 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3514 | struct nl_msg *msg; |
| 3515 | int ret = -1; |
| 3516 | |
| 3517 | msg = nlmsg_alloc(); |
| 3518 | if (!msg) |
| 3519 | return -1; |
| 3520 | |
| 3521 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 3522 | |
| 3523 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 3524 | |
| 3525 | ret = send_and_recv(drv->global, bss->nl_mgmt, msg, NULL, NULL); |
| 3526 | msg = NULL; |
| 3527 | if (ret) { |
| 3528 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 3529 | "failed: ret=%d (%s)", |
| 3530 | ret, strerror(-ret)); |
| 3531 | goto nla_put_failure; |
| 3532 | } |
| 3533 | ret = 0; |
| 3534 | nla_put_failure: |
| 3535 | nlmsg_free(msg); |
| 3536 | return ret; |
| 3537 | } |
| 3538 | |
| 3539 | |
| 3540 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 3541 | { |
| 3542 | static const int stypes[] = { |
| 3543 | WLAN_FC_STYPE_AUTH, |
| 3544 | WLAN_FC_STYPE_ASSOC_REQ, |
| 3545 | WLAN_FC_STYPE_REASSOC_REQ, |
| 3546 | WLAN_FC_STYPE_DISASSOC, |
| 3547 | WLAN_FC_STYPE_DEAUTH, |
| 3548 | WLAN_FC_STYPE_ACTION, |
| 3549 | WLAN_FC_STYPE_PROBE_REQ, |
| 3550 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 3551 | * it, but it wouldn't really be the right thing anyway as |
| 3552 | * it isn't per interface ... maybe just dump the scan |
| 3553 | * results periodically for OLBC? |
| 3554 | */ |
| 3555 | // WLAN_FC_STYPE_BEACON, |
| 3556 | }; |
| 3557 | unsigned int i; |
| 3558 | |
| 3559 | if (nl80211_alloc_mgmt_handle(bss)) |
| 3560 | return -1; |
| 3561 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 3562 | "handle %p", bss->nl_mgmt); |
| 3563 | |
| 3564 | for (i = 0; i < sizeof(stypes) / sizeof(stypes[0]); i++) { |
| 3565 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 3566 | (WLAN_FC_TYPE_MGMT << 2) | |
| 3567 | (stypes[i] << 4), |
| 3568 | NULL, 0) < 0) { |
| 3569 | goto out_err; |
| 3570 | } |
| 3571 | } |
| 3572 | |
| 3573 | if (nl80211_register_spurious_class3(bss)) |
| 3574 | goto out_err; |
| 3575 | |
| 3576 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 3577 | goto out_err; |
| 3578 | |
| 3579 | return 0; |
| 3580 | |
| 3581 | out_err: |
| 3582 | eloop_unregister_read_sock(nl_socket_get_fd(bss->nl_mgmt)); |
| 3583 | nl_destroy_handles(&bss->nl_mgmt); |
| 3584 | return -1; |
| 3585 | } |
| 3586 | |
| 3587 | |
| 3588 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 3589 | { |
| 3590 | if (nl80211_alloc_mgmt_handle(bss)) |
| 3591 | return -1; |
| 3592 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 3593 | "handle %p (device SME)", bss->nl_mgmt); |
| 3594 | |
| 3595 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 3596 | (WLAN_FC_TYPE_MGMT << 2) | |
| 3597 | (WLAN_FC_STYPE_ACTION << 4), |
| 3598 | NULL, 0) < 0) |
| 3599 | goto out_err; |
| 3600 | |
| 3601 | return 0; |
| 3602 | |
| 3603 | out_err: |
| 3604 | eloop_unregister_read_sock(nl_socket_get_fd(bss->nl_mgmt)); |
| 3605 | nl_destroy_handles(&bss->nl_mgmt); |
| 3606 | return -1; |
| 3607 | } |
| 3608 | |
| 3609 | |
| 3610 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 3611 | { |
| 3612 | if (bss->nl_mgmt == NULL) |
| 3613 | return; |
| 3614 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 3615 | "(%s)", bss->nl_mgmt, reason); |
| 3616 | eloop_unregister_read_sock(nl_socket_get_fd(bss->nl_mgmt)); |
| 3617 | nl_destroy_handles(&bss->nl_mgmt); |
| 3618 | |
| 3619 | nl80211_put_wiphy_data_ap(bss); |
| 3620 | } |
| 3621 | |
| 3622 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3623 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 3624 | { |
| 3625 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 3626 | } |
| 3627 | |
| 3628 | |
| 3629 | static int |
| 3630 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv) |
| 3631 | { |
| 3632 | struct i802_bss *bss = &drv->first_bss; |
| 3633 | int send_rfkill_event = 0; |
| 3634 | |
| 3635 | drv->ifindex = if_nametoindex(bss->ifname); |
| 3636 | drv->first_bss.ifindex = drv->ifindex; |
| 3637 | |
| 3638 | #ifndef HOSTAPD |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3639 | /* |
| 3640 | * Make sure the interface starts up in station mode unless this is a |
| 3641 | * dynamically added interface (e.g., P2P) that was already configured |
| 3642 | * with proper iftype. |
| 3643 | */ |
| 3644 | if (drv->ifindex != drv->global->if_add_ifindex && |
| 3645 | wpa_driver_nl80211_set_mode(bss, NL80211_IFTYPE_STATION) < 0) { |
| 3646 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver to " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3647 | "use managed mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3648 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3651 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3652 | if (rfkill_is_blocked(drv->rfkill)) { |
| 3653 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 3654 | "interface '%s' due to rfkill", |
| 3655 | bss->ifname); |
| 3656 | drv->if_disabled = 1; |
| 3657 | send_rfkill_event = 1; |
| 3658 | } else { |
| 3659 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 3660 | "interface '%s' UP", bss->ifname); |
| 3661 | return -1; |
| 3662 | } |
| 3663 | } |
| 3664 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3665 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3666 | 1, IF_OPER_DORMANT); |
| 3667 | #endif /* HOSTAPD */ |
| 3668 | |
| 3669 | if (wpa_driver_nl80211_capa(drv)) |
| 3670 | return -1; |
| 3671 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3672 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 3673 | bss->addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3674 | return -1; |
| 3675 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3676 | if (send_rfkill_event) { |
| 3677 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 3678 | drv, drv->ctx); |
| 3679 | } |
| 3680 | |
| 3681 | return 0; |
| 3682 | } |
| 3683 | |
| 3684 | |
| 3685 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 3686 | { |
| 3687 | struct nl_msg *msg; |
| 3688 | |
| 3689 | msg = nlmsg_alloc(); |
| 3690 | if (!msg) |
| 3691 | return -ENOMEM; |
| 3692 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3693 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3694 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 3695 | |
| 3696 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3697 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3698 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3699 | return -ENOBUFS; |
| 3700 | } |
| 3701 | |
| 3702 | |
| 3703 | /** |
| 3704 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3705 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3706 | * |
| 3707 | * Shut down driver interface and processing of driver events. Free |
| 3708 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 3709 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3710 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3711 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3712 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3713 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3714 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3715 | if (drv->data_tx_status) |
| 3716 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 3717 | if (drv->eapol_tx_sock >= 0) |
| 3718 | close(drv->eapol_tx_sock); |
| 3719 | |
| 3720 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3721 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 3722 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3723 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 3724 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3725 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 3726 | "interface %s from bridge %s: %s", |
| 3727 | bss->ifname, bss->brname, strerror(errno)); |
| 3728 | } |
| 3729 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3730 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3731 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 3732 | "bridge %s: %s", |
| 3733 | bss->brname, strerror(errno)); |
| 3734 | } |
| 3735 | |
| 3736 | nl80211_remove_monitor_interface(drv); |
| 3737 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3738 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3739 | wpa_driver_nl80211_del_beacon(drv); |
| 3740 | |
| 3741 | #ifdef HOSTAPD |
| 3742 | if (drv->last_freq_ht) { |
| 3743 | /* Clear HT flags from the driver */ |
| 3744 | struct hostapd_freq_params freq; |
| 3745 | os_memset(&freq, 0, sizeof(freq)); |
| 3746 | freq.freq = drv->last_freq; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3747 | wpa_driver_nl80211_set_freq(bss, &freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | if (drv->eapol_sock >= 0) { |
| 3751 | eloop_unregister_read_sock(drv->eapol_sock); |
| 3752 | close(drv->eapol_sock); |
| 3753 | } |
| 3754 | |
| 3755 | if (drv->if_indices != drv->default_if_indices) |
| 3756 | os_free(drv->if_indices); |
| 3757 | #endif /* HOSTAPD */ |
| 3758 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3759 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3760 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3761 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3762 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 3763 | IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3764 | rfkill_deinit(drv->rfkill); |
| 3765 | |
| 3766 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 3767 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3768 | (void) linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0); |
| 3769 | wpa_driver_nl80211_set_mode(bss, NL80211_IFTYPE_STATION); |
| 3770 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3771 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3772 | nl_cb_put(drv->nl_cb); |
| 3773 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3774 | nl80211_destroy_bss(&drv->first_bss); |
| 3775 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3776 | os_free(drv->filter_ssids); |
| 3777 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3778 | os_free(drv->auth_ie); |
| 3779 | |
| 3780 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3781 | dl_list_del(&drv->list); |
| 3782 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3783 | os_free(drv->extended_capa); |
| 3784 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3785 | os_free(drv); |
| 3786 | } |
| 3787 | |
| 3788 | |
| 3789 | /** |
| 3790 | * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion |
| 3791 | * @eloop_ctx: Driver private data |
| 3792 | * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init() |
| 3793 | * |
| 3794 | * This function can be used as registered timeout when starting a scan to |
| 3795 | * generate a scan completed event if the driver does not report this. |
| 3796 | */ |
| 3797 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
| 3798 | { |
| 3799 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3800 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3801 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3802 | drv->ap_scan_as_station); |
| 3803 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3804 | } |
| 3805 | wpa_printf(MSG_DEBUG, "Scan timeout - try to get results"); |
| 3806 | wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL); |
| 3807 | } |
| 3808 | |
| 3809 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3810 | static struct nl_msg * |
| 3811 | nl80211_scan_common(struct wpa_driver_nl80211_data *drv, u8 cmd, |
| 3812 | struct wpa_driver_scan_params *params) |
| 3813 | { |
| 3814 | struct nl_msg *msg; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3815 | size_t i; |
| 3816 | |
| 3817 | msg = nlmsg_alloc(); |
| 3818 | if (!msg) |
| 3819 | return NULL; |
| 3820 | |
| 3821 | nl80211_cmd(drv, msg, 0, cmd); |
| 3822 | |
| 3823 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) < 0) |
| 3824 | goto fail; |
| 3825 | |
| 3826 | if (params->num_ssids) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3827 | struct nlattr *ssids; |
| 3828 | |
| 3829 | ssids = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3830 | if (ssids == NULL) |
| 3831 | goto fail; |
| 3832 | for (i = 0; i < params->num_ssids; i++) { |
| 3833 | wpa_hexdump_ascii(MSG_MSGDUMP, "nl80211: Scan SSID", |
| 3834 | params->ssids[i].ssid, |
| 3835 | params->ssids[i].ssid_len); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3836 | if (nla_put(msg, i + 1, params->ssids[i].ssid_len, |
| 3837 | params->ssids[i].ssid) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3838 | goto fail; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3839 | } |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3840 | nla_nest_end(msg, ssids); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | if (params->extra_ies) { |
| 3844 | wpa_hexdump(MSG_MSGDUMP, "nl80211: Scan extra IEs", |
| 3845 | params->extra_ies, params->extra_ies_len); |
| 3846 | if (nla_put(msg, NL80211_ATTR_IE, params->extra_ies_len, |
| 3847 | params->extra_ies) < 0) |
| 3848 | goto fail; |
| 3849 | } |
| 3850 | |
| 3851 | if (params->freqs) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3852 | struct nlattr *freqs; |
| 3853 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3854 | if (freqs == NULL) |
| 3855 | goto fail; |
| 3856 | for (i = 0; params->freqs[i]; i++) { |
| 3857 | wpa_printf(MSG_MSGDUMP, "nl80211: Scan frequency %u " |
| 3858 | "MHz", params->freqs[i]); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3859 | if (nla_put_u32(msg, i + 1, params->freqs[i]) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3860 | goto fail; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3861 | } |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3862 | nla_nest_end(msg, freqs); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | os_free(drv->filter_ssids); |
| 3866 | drv->filter_ssids = params->filter_ssids; |
| 3867 | params->filter_ssids = NULL; |
| 3868 | drv->num_filter_ssids = params->num_filter_ssids; |
| 3869 | |
| 3870 | return msg; |
| 3871 | |
| 3872 | fail: |
| 3873 | nlmsg_free(msg); |
| 3874 | return NULL; |
| 3875 | } |
| 3876 | |
| 3877 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3878 | /** |
| 3879 | * wpa_driver_nl80211_scan - Request the driver to initiate scan |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3880 | * @bss: Pointer to private driver data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3881 | * @params: Scan parameters |
| 3882 | * Returns: 0 on success, -1 on failure |
| 3883 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3884 | static int wpa_driver_nl80211_scan(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3885 | struct wpa_driver_scan_params *params) |
| 3886 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3887 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3888 | int ret = -1, timeout; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3889 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3890 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3891 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: scan request"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3892 | drv->scan_for_auth = 0; |
| 3893 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3894 | msg = nl80211_scan_common(drv, NL80211_CMD_TRIGGER_SCAN, params); |
| 3895 | if (!msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3896 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3897 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3898 | if (params->p2p_probe) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3899 | struct nlattr *rates; |
| 3900 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3901 | wpa_printf(MSG_DEBUG, "nl80211: P2P probe - mask SuppRates"); |
| 3902 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3903 | rates = nla_nest_start(msg, NL80211_ATTR_SCAN_SUPP_RATES); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3904 | if (rates == NULL) |
| 3905 | goto nla_put_failure; |
| 3906 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3907 | /* |
| 3908 | * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates |
| 3909 | * by masking out everything else apart from the OFDM rates 6, |
| 3910 | * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz |
| 3911 | * rates are left enabled. |
| 3912 | */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3913 | NLA_PUT(msg, NL80211_BAND_2GHZ, 8, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3914 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 3915 | nla_nest_end(msg, rates); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3916 | |
| 3917 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); |
| 3918 | } |
| 3919 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3920 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3921 | msg = NULL; |
| 3922 | if (ret) { |
| 3923 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger failed: ret=%d " |
| 3924 | "(%s)", ret, strerror(-ret)); |
| 3925 | #ifdef HOSTAPD |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3926 | if (is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3927 | /* |
| 3928 | * mac80211 does not allow scan requests in AP mode, so |
| 3929 | * try to do this in station mode. |
| 3930 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3931 | if (wpa_driver_nl80211_set_mode( |
| 3932 | bss, NL80211_IFTYPE_STATION)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3933 | goto nla_put_failure; |
| 3934 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3935 | if (wpa_driver_nl80211_scan(bss, params)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3936 | wpa_driver_nl80211_set_mode(bss, drv->nlmode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3937 | goto nla_put_failure; |
| 3938 | } |
| 3939 | |
| 3940 | /* Restore AP mode when processing scan results */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3941 | drv->ap_scan_as_station = drv->nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3942 | ret = 0; |
| 3943 | } else |
| 3944 | goto nla_put_failure; |
| 3945 | #else /* HOSTAPD */ |
| 3946 | goto nla_put_failure; |
| 3947 | #endif /* HOSTAPD */ |
| 3948 | } |
| 3949 | |
| 3950 | /* Not all drivers generate "scan completed" wireless event, so try to |
| 3951 | * read results after a timeout. */ |
| 3952 | timeout = 10; |
| 3953 | if (drv->scan_complete_events) { |
| 3954 | /* |
| 3955 | * The driver seems to deliver events to notify when scan is |
| 3956 | * complete, so use longer timeout to avoid race conditions |
| 3957 | * with scanning and following association request. |
| 3958 | */ |
| 3959 | timeout = 30; |
| 3960 | } |
| 3961 | wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d " |
| 3962 | "seconds", ret, timeout); |
| 3963 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 3964 | eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout, |
| 3965 | drv, drv->ctx); |
| 3966 | |
| 3967 | nla_put_failure: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3968 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3969 | return ret; |
| 3970 | } |
| 3971 | |
| 3972 | |
| 3973 | /** |
| 3974 | * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan |
| 3975 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 3976 | * @params: Scan parameters |
| 3977 | * @interval: Interval between scan cycles in milliseconds |
| 3978 | * Returns: 0 on success, -1 on failure or if not supported |
| 3979 | */ |
| 3980 | static int wpa_driver_nl80211_sched_scan(void *priv, |
| 3981 | struct wpa_driver_scan_params *params, |
| 3982 | u32 interval) |
| 3983 | { |
| 3984 | struct i802_bss *bss = priv; |
| 3985 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3986 | int ret = -1; |
| 3987 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3988 | size_t i; |
| 3989 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3990 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: sched_scan request"); |
| 3991 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3992 | #ifdef ANDROID |
| 3993 | if (!drv->capa.sched_scan_supported) |
| 3994 | return android_pno_start(bss, params); |
| 3995 | #endif /* ANDROID */ |
| 3996 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3997 | msg = nl80211_scan_common(drv, NL80211_CMD_START_SCHED_SCAN, params); |
| 3998 | if (!msg) |
| 3999 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4000 | |
| 4001 | NLA_PUT_U32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, interval); |
| 4002 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4003 | if ((drv->num_filter_ssids && |
| 4004 | (int) drv->num_filter_ssids <= drv->capa.max_match_sets) || |
| 4005 | params->filter_rssi) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4006 | struct nlattr *match_sets; |
| 4007 | match_sets = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4008 | if (match_sets == NULL) |
| 4009 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4010 | |
| 4011 | for (i = 0; i < drv->num_filter_ssids; i++) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4012 | struct nlattr *match_set_ssid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4013 | wpa_hexdump_ascii(MSG_MSGDUMP, |
| 4014 | "nl80211: Sched scan filter SSID", |
| 4015 | drv->filter_ssids[i].ssid, |
| 4016 | drv->filter_ssids[i].ssid_len); |
| 4017 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4018 | match_set_ssid = nla_nest_start(msg, i + 1); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4019 | if (match_set_ssid == NULL) |
| 4020 | goto nla_put_failure; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4021 | NLA_PUT(msg, NL80211_ATTR_SCHED_SCAN_MATCH_SSID, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4022 | drv->filter_ssids[i].ssid_len, |
| 4023 | drv->filter_ssids[i].ssid); |
| 4024 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4025 | nla_nest_end(msg, match_sets); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4026 | } |
| 4027 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4028 | if (params->filter_rssi) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4029 | struct nlattr *match_set_rssi; |
| 4030 | match_set_rssi = nla_nest_start(msg, 0); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4031 | if (match_set_rssi == NULL) |
| 4032 | goto nla_put_failure; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4033 | NLA_PUT_U32(msg, NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4034 | params->filter_rssi); |
| 4035 | wpa_printf(MSG_MSGDUMP, |
| 4036 | "nl80211: Sched scan RSSI filter %d dBm", |
| 4037 | params->filter_rssi); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4038 | nla_nest_end(msg, match_set_rssi); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4039 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4040 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4041 | nla_nest_end(msg, match_sets); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4045 | |
| 4046 | /* TODO: if we get an error here, we should fall back to normal scan */ |
| 4047 | |
| 4048 | msg = NULL; |
| 4049 | if (ret) { |
| 4050 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan start failed: " |
| 4051 | "ret=%d (%s)", ret, strerror(-ret)); |
| 4052 | goto nla_put_failure; |
| 4053 | } |
| 4054 | |
| 4055 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan requested (ret=%d) - " |
| 4056 | "scan interval %d msec", ret, interval); |
| 4057 | |
| 4058 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4059 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4060 | return ret; |
| 4061 | } |
| 4062 | |
| 4063 | |
| 4064 | /** |
| 4065 | * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan |
| 4066 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 4067 | * Returns: 0 on success, -1 on failure or if not supported |
| 4068 | */ |
| 4069 | static int wpa_driver_nl80211_stop_sched_scan(void *priv) |
| 4070 | { |
| 4071 | struct i802_bss *bss = priv; |
| 4072 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4073 | int ret = 0; |
| 4074 | struct nl_msg *msg; |
| 4075 | |
| 4076 | #ifdef ANDROID |
| 4077 | if (!drv->capa.sched_scan_supported) |
| 4078 | return android_pno_stop(bss); |
| 4079 | #endif /* ANDROID */ |
| 4080 | |
| 4081 | msg = nlmsg_alloc(); |
| 4082 | if (!msg) |
| 4083 | return -1; |
| 4084 | |
| 4085 | nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_SCHED_SCAN); |
| 4086 | |
| 4087 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 4088 | |
| 4089 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4090 | msg = NULL; |
| 4091 | if (ret) { |
| 4092 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop failed: " |
| 4093 | "ret=%d (%s)", ret, strerror(-ret)); |
| 4094 | goto nla_put_failure; |
| 4095 | } |
| 4096 | |
| 4097 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop sent (ret=%d)", ret); |
| 4098 | |
| 4099 | nla_put_failure: |
| 4100 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4101 | return ret; |
| 4102 | } |
| 4103 | |
| 4104 | |
| 4105 | static const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie) |
| 4106 | { |
| 4107 | const u8 *end, *pos; |
| 4108 | |
| 4109 | if (ies == NULL) |
| 4110 | return NULL; |
| 4111 | |
| 4112 | pos = ies; |
| 4113 | end = ies + ies_len; |
| 4114 | |
| 4115 | while (pos + 1 < end) { |
| 4116 | if (pos + 2 + pos[1] > end) |
| 4117 | break; |
| 4118 | if (pos[0] == ie) |
| 4119 | return pos; |
| 4120 | pos += 2 + pos[1]; |
| 4121 | } |
| 4122 | |
| 4123 | return NULL; |
| 4124 | } |
| 4125 | |
| 4126 | |
| 4127 | static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv, |
| 4128 | const u8 *ie, size_t ie_len) |
| 4129 | { |
| 4130 | const u8 *ssid; |
| 4131 | size_t i; |
| 4132 | |
| 4133 | if (drv->filter_ssids == NULL) |
| 4134 | return 0; |
| 4135 | |
| 4136 | ssid = nl80211_get_ie(ie, ie_len, WLAN_EID_SSID); |
| 4137 | if (ssid == NULL) |
| 4138 | return 1; |
| 4139 | |
| 4140 | for (i = 0; i < drv->num_filter_ssids; i++) { |
| 4141 | if (ssid[1] == drv->filter_ssids[i].ssid_len && |
| 4142 | os_memcmp(ssid + 2, drv->filter_ssids[i].ssid, ssid[1]) == |
| 4143 | 0) |
| 4144 | return 0; |
| 4145 | } |
| 4146 | |
| 4147 | return 1; |
| 4148 | } |
| 4149 | |
| 4150 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4151 | static int bss_info_handler(struct nl_msg *msg, void *arg) |
| 4152 | { |
| 4153 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 4154 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 4155 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 4156 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 4157 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 4158 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 4159 | [NL80211_BSS_TSF] = { .type = NLA_U64 }, |
| 4160 | [NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 }, |
| 4161 | [NL80211_BSS_CAPABILITY] = { .type = NLA_U16 }, |
| 4162 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 4163 | [NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 }, |
| 4164 | [NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 }, |
| 4165 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 4166 | [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 }, |
| 4167 | [NL80211_BSS_BEACON_IES] = { .type = NLA_UNSPEC }, |
| 4168 | }; |
| 4169 | struct nl80211_bss_info_arg *_arg = arg; |
| 4170 | struct wpa_scan_results *res = _arg->res; |
| 4171 | struct wpa_scan_res **tmp; |
| 4172 | struct wpa_scan_res *r; |
| 4173 | const u8 *ie, *beacon_ie; |
| 4174 | size_t ie_len, beacon_ie_len; |
| 4175 | u8 *pos; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 4176 | size_t i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4177 | |
| 4178 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 4179 | genlmsg_attrlen(gnlh, 0), NULL); |
| 4180 | if (!tb[NL80211_ATTR_BSS]) |
| 4181 | return NL_SKIP; |
| 4182 | if (nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 4183 | bss_policy)) |
| 4184 | return NL_SKIP; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 4185 | if (bss[NL80211_BSS_STATUS]) { |
| 4186 | enum nl80211_bss_status status; |
| 4187 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 4188 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 4189 | bss[NL80211_BSS_FREQUENCY]) { |
| 4190 | _arg->assoc_freq = |
| 4191 | nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 4192 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 4193 | _arg->assoc_freq); |
| 4194 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4195 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 4196 | bss[NL80211_BSS_BSSID]) { |
| 4197 | os_memcpy(_arg->assoc_bssid, |
| 4198 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 4199 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 4200 | MACSTR, MAC2STR(_arg->assoc_bssid)); |
| 4201 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 4202 | } |
| 4203 | if (!res) |
| 4204 | return NL_SKIP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4205 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 4206 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 4207 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 4208 | } else { |
| 4209 | ie = NULL; |
| 4210 | ie_len = 0; |
| 4211 | } |
| 4212 | if (bss[NL80211_BSS_BEACON_IES]) { |
| 4213 | beacon_ie = nla_data(bss[NL80211_BSS_BEACON_IES]); |
| 4214 | beacon_ie_len = nla_len(bss[NL80211_BSS_BEACON_IES]); |
| 4215 | } else { |
| 4216 | beacon_ie = NULL; |
| 4217 | beacon_ie_len = 0; |
| 4218 | } |
| 4219 | |
| 4220 | if (nl80211_scan_filtered(_arg->drv, ie ? ie : beacon_ie, |
| 4221 | ie ? ie_len : beacon_ie_len)) |
| 4222 | return NL_SKIP; |
| 4223 | |
| 4224 | r = os_zalloc(sizeof(*r) + ie_len + beacon_ie_len); |
| 4225 | if (r == NULL) |
| 4226 | return NL_SKIP; |
| 4227 | if (bss[NL80211_BSS_BSSID]) |
| 4228 | os_memcpy(r->bssid, nla_data(bss[NL80211_BSS_BSSID]), |
| 4229 | ETH_ALEN); |
| 4230 | if (bss[NL80211_BSS_FREQUENCY]) |
| 4231 | r->freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 4232 | if (bss[NL80211_BSS_BEACON_INTERVAL]) |
| 4233 | r->beacon_int = nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]); |
| 4234 | if (bss[NL80211_BSS_CAPABILITY]) |
| 4235 | r->caps = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); |
| 4236 | r->flags |= WPA_SCAN_NOISE_INVALID; |
| 4237 | if (bss[NL80211_BSS_SIGNAL_MBM]) { |
| 4238 | r->level = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]); |
| 4239 | r->level /= 100; /* mBm to dBm */ |
| 4240 | r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID; |
| 4241 | } else if (bss[NL80211_BSS_SIGNAL_UNSPEC]) { |
| 4242 | r->level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4243 | r->flags |= WPA_SCAN_QUAL_INVALID; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4244 | } else |
| 4245 | r->flags |= WPA_SCAN_LEVEL_INVALID | WPA_SCAN_QUAL_INVALID; |
| 4246 | if (bss[NL80211_BSS_TSF]) |
| 4247 | r->tsf = nla_get_u64(bss[NL80211_BSS_TSF]); |
| 4248 | if (bss[NL80211_BSS_SEEN_MS_AGO]) |
| 4249 | r->age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); |
| 4250 | r->ie_len = ie_len; |
| 4251 | pos = (u8 *) (r + 1); |
| 4252 | if (ie) { |
| 4253 | os_memcpy(pos, ie, ie_len); |
| 4254 | pos += ie_len; |
| 4255 | } |
| 4256 | r->beacon_ie_len = beacon_ie_len; |
| 4257 | if (beacon_ie) |
| 4258 | os_memcpy(pos, beacon_ie, beacon_ie_len); |
| 4259 | |
| 4260 | if (bss[NL80211_BSS_STATUS]) { |
| 4261 | enum nl80211_bss_status status; |
| 4262 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 4263 | switch (status) { |
| 4264 | case NL80211_BSS_STATUS_AUTHENTICATED: |
| 4265 | r->flags |= WPA_SCAN_AUTHENTICATED; |
| 4266 | break; |
| 4267 | case NL80211_BSS_STATUS_ASSOCIATED: |
| 4268 | r->flags |= WPA_SCAN_ASSOCIATED; |
| 4269 | break; |
| 4270 | default: |
| 4271 | break; |
| 4272 | } |
| 4273 | } |
| 4274 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 4275 | /* |
| 4276 | * cfg80211 maintains separate BSS table entries for APs if the same |
| 4277 | * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does |
| 4278 | * not use frequency as a separate key in the BSS table, so filter out |
| 4279 | * duplicated entries. Prefer associated BSS entry in such a case in |
| 4280 | * order to get the correct frequency into the BSS table. |
| 4281 | */ |
| 4282 | for (i = 0; i < res->num; i++) { |
| 4283 | const u8 *s1, *s2; |
| 4284 | if (os_memcmp(res->res[i]->bssid, r->bssid, ETH_ALEN) != 0) |
| 4285 | continue; |
| 4286 | |
| 4287 | s1 = nl80211_get_ie((u8 *) (res->res[i] + 1), |
| 4288 | res->res[i]->ie_len, WLAN_EID_SSID); |
| 4289 | s2 = nl80211_get_ie((u8 *) (r + 1), r->ie_len, WLAN_EID_SSID); |
| 4290 | if (s1 == NULL || s2 == NULL || s1[1] != s2[1] || |
| 4291 | os_memcmp(s1, s2, 2 + s1[1]) != 0) |
| 4292 | continue; |
| 4293 | |
| 4294 | /* Same BSSID,SSID was already included in scan results */ |
| 4295 | wpa_printf(MSG_DEBUG, "nl80211: Remove duplicated scan result " |
| 4296 | "for " MACSTR, MAC2STR(r->bssid)); |
| 4297 | |
| 4298 | if ((r->flags & WPA_SCAN_ASSOCIATED) && |
| 4299 | !(res->res[i]->flags & WPA_SCAN_ASSOCIATED)) { |
| 4300 | os_free(res->res[i]); |
| 4301 | res->res[i] = r; |
| 4302 | } else |
| 4303 | os_free(r); |
| 4304 | return NL_SKIP; |
| 4305 | } |
| 4306 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4307 | tmp = os_realloc_array(res->res, res->num + 1, |
| 4308 | sizeof(struct wpa_scan_res *)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4309 | if (tmp == NULL) { |
| 4310 | os_free(r); |
| 4311 | return NL_SKIP; |
| 4312 | } |
| 4313 | tmp[res->num++] = r; |
| 4314 | res->res = tmp; |
| 4315 | |
| 4316 | return NL_SKIP; |
| 4317 | } |
| 4318 | |
| 4319 | |
| 4320 | static void clear_state_mismatch(struct wpa_driver_nl80211_data *drv, |
| 4321 | const u8 *addr) |
| 4322 | { |
| 4323 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
| 4324 | wpa_printf(MSG_DEBUG, "nl80211: Clear possible state " |
| 4325 | "mismatch (" MACSTR ")", MAC2STR(addr)); |
| 4326 | wpa_driver_nl80211_mlme(drv, addr, |
| 4327 | NL80211_CMD_DEAUTHENTICATE, |
| 4328 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1); |
| 4329 | } |
| 4330 | } |
| 4331 | |
| 4332 | |
| 4333 | static void wpa_driver_nl80211_check_bss_status( |
| 4334 | struct wpa_driver_nl80211_data *drv, struct wpa_scan_results *res) |
| 4335 | { |
| 4336 | size_t i; |
| 4337 | |
| 4338 | for (i = 0; i < res->num; i++) { |
| 4339 | struct wpa_scan_res *r = res->res[i]; |
| 4340 | if (r->flags & WPA_SCAN_AUTHENTICATED) { |
| 4341 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " |
| 4342 | "indicates BSS status with " MACSTR |
| 4343 | " as authenticated", |
| 4344 | MAC2STR(r->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4345 | if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4346 | os_memcmp(r->bssid, drv->bssid, ETH_ALEN) != 0 && |
| 4347 | os_memcmp(r->bssid, drv->auth_bssid, ETH_ALEN) != |
| 4348 | 0) { |
| 4349 | wpa_printf(MSG_DEBUG, "nl80211: Unknown BSSID" |
| 4350 | " in local state (auth=" MACSTR |
| 4351 | " assoc=" MACSTR ")", |
| 4352 | MAC2STR(drv->auth_bssid), |
| 4353 | MAC2STR(drv->bssid)); |
| 4354 | clear_state_mismatch(drv, r->bssid); |
| 4355 | } |
| 4356 | } |
| 4357 | |
| 4358 | if (r->flags & WPA_SCAN_ASSOCIATED) { |
| 4359 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " |
| 4360 | "indicate BSS status with " MACSTR |
| 4361 | " as associated", |
| 4362 | MAC2STR(r->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4363 | if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4364 | !drv->associated) { |
| 4365 | wpa_printf(MSG_DEBUG, "nl80211: Local state " |
| 4366 | "(not associated) does not match " |
| 4367 | "with BSS state"); |
| 4368 | clear_state_mismatch(drv, r->bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4369 | } else if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4370 | os_memcmp(drv->bssid, r->bssid, ETH_ALEN) != |
| 4371 | 0) { |
| 4372 | wpa_printf(MSG_DEBUG, "nl80211: Local state " |
| 4373 | "(associated with " MACSTR ") does " |
| 4374 | "not match with BSS state", |
| 4375 | MAC2STR(drv->bssid)); |
| 4376 | clear_state_mismatch(drv, r->bssid); |
| 4377 | clear_state_mismatch(drv, drv->bssid); |
| 4378 | } |
| 4379 | } |
| 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4384 | static struct wpa_scan_results * |
| 4385 | nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv) |
| 4386 | { |
| 4387 | struct nl_msg *msg; |
| 4388 | struct wpa_scan_results *res; |
| 4389 | int ret; |
| 4390 | struct nl80211_bss_info_arg arg; |
| 4391 | |
| 4392 | res = os_zalloc(sizeof(*res)); |
| 4393 | if (res == NULL) |
| 4394 | return NULL; |
| 4395 | msg = nlmsg_alloc(); |
| 4396 | if (!msg) |
| 4397 | goto nla_put_failure; |
| 4398 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4399 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4400 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 4401 | |
| 4402 | arg.drv = drv; |
| 4403 | arg.res = res; |
| 4404 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
| 4405 | msg = NULL; |
| 4406 | if (ret == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4407 | wpa_printf(MSG_DEBUG, "nl80211: Received scan results (%lu " |
| 4408 | "BSSes)", (unsigned long) res->num); |
| 4409 | nl80211_get_noise_for_scan_results(drv, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4410 | return res; |
| 4411 | } |
| 4412 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 4413 | "(%s)", ret, strerror(-ret)); |
| 4414 | nla_put_failure: |
| 4415 | nlmsg_free(msg); |
| 4416 | wpa_scan_results_free(res); |
| 4417 | return NULL; |
| 4418 | } |
| 4419 | |
| 4420 | |
| 4421 | /** |
| 4422 | * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results |
| 4423 | * @priv: Pointer to private wext data from wpa_driver_nl80211_init() |
| 4424 | * Returns: Scan results on success, -1 on failure |
| 4425 | */ |
| 4426 | static struct wpa_scan_results * |
| 4427 | wpa_driver_nl80211_get_scan_results(void *priv) |
| 4428 | { |
| 4429 | struct i802_bss *bss = priv; |
| 4430 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4431 | struct wpa_scan_results *res; |
| 4432 | |
| 4433 | res = nl80211_get_scan_results(drv); |
| 4434 | if (res) |
| 4435 | wpa_driver_nl80211_check_bss_status(drv, res); |
| 4436 | return res; |
| 4437 | } |
| 4438 | |
| 4439 | |
| 4440 | static void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv) |
| 4441 | { |
| 4442 | struct wpa_scan_results *res; |
| 4443 | size_t i; |
| 4444 | |
| 4445 | res = nl80211_get_scan_results(drv); |
| 4446 | if (res == NULL) { |
| 4447 | wpa_printf(MSG_DEBUG, "nl80211: Failed to get scan results"); |
| 4448 | return; |
| 4449 | } |
| 4450 | |
| 4451 | wpa_printf(MSG_DEBUG, "nl80211: Scan result dump"); |
| 4452 | for (i = 0; i < res->num; i++) { |
| 4453 | struct wpa_scan_res *r = res->res[i]; |
| 4454 | wpa_printf(MSG_DEBUG, "nl80211: %d/%d " MACSTR "%s%s", |
| 4455 | (int) i, (int) res->num, MAC2STR(r->bssid), |
| 4456 | r->flags & WPA_SCAN_AUTHENTICATED ? " [auth]" : "", |
| 4457 | r->flags & WPA_SCAN_ASSOCIATED ? " [assoc]" : ""); |
| 4458 | } |
| 4459 | |
| 4460 | wpa_scan_results_free(res); |
| 4461 | } |
| 4462 | |
| 4463 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4464 | 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] | 4465 | enum wpa_alg alg, const u8 *addr, |
| 4466 | int key_idx, int set_tx, |
| 4467 | const u8 *seq, size_t seq_len, |
| 4468 | const u8 *key, size_t key_len) |
| 4469 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4470 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4471 | int ifindex = if_nametoindex(ifname); |
| 4472 | struct nl_msg *msg; |
| 4473 | int ret; |
| 4474 | |
| 4475 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d alg=%d addr=%p key_idx=%d " |
| 4476 | "set_tx=%d seq_len=%lu key_len=%lu", |
| 4477 | __func__, ifindex, alg, addr, key_idx, set_tx, |
| 4478 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4479 | #ifdef CONFIG_TDLS |
| 4480 | if (key_idx == -1) |
| 4481 | key_idx = 0; |
| 4482 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4483 | |
| 4484 | msg = nlmsg_alloc(); |
| 4485 | if (!msg) |
| 4486 | return -ENOMEM; |
| 4487 | |
| 4488 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4489 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4490 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4491 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4492 | NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key); |
| 4493 | switch (alg) { |
| 4494 | case WPA_ALG_WEP: |
| 4495 | if (key_len == 5) |
| 4496 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 4497 | WLAN_CIPHER_SUITE_WEP40); |
| 4498 | else |
| 4499 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 4500 | WLAN_CIPHER_SUITE_WEP104); |
| 4501 | break; |
| 4502 | case WPA_ALG_TKIP: |
| 4503 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 4504 | WLAN_CIPHER_SUITE_TKIP); |
| 4505 | break; |
| 4506 | case WPA_ALG_CCMP: |
| 4507 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 4508 | WLAN_CIPHER_SUITE_CCMP); |
| 4509 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4510 | case WPA_ALG_GCMP: |
| 4511 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 4512 | WLAN_CIPHER_SUITE_GCMP); |
| 4513 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4514 | case WPA_ALG_IGTK: |
| 4515 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 4516 | WLAN_CIPHER_SUITE_AES_CMAC); |
| 4517 | break; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4518 | case WPA_ALG_SMS4: |
| 4519 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 4520 | WLAN_CIPHER_SUITE_SMS4); |
| 4521 | break; |
| 4522 | case WPA_ALG_KRK: |
| 4523 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, |
| 4524 | WLAN_CIPHER_SUITE_KRK); |
| 4525 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4526 | default: |
| 4527 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " |
| 4528 | "algorithm %d", __func__, alg); |
| 4529 | nlmsg_free(msg); |
| 4530 | return -1; |
| 4531 | } |
| 4532 | } |
| 4533 | |
| 4534 | if (seq && seq_len) |
| 4535 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq); |
| 4536 | |
| 4537 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 4538 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
| 4539 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 4540 | |
| 4541 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 4542 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
| 4543 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, |
| 4544 | NL80211_KEYTYPE_GROUP); |
| 4545 | } |
| 4546 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4547 | struct nlattr *types; |
| 4548 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4549 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4550 | |
| 4551 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4552 | if (!types) |
| 4553 | goto nla_put_failure; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4554 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST); |
| 4555 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4556 | } |
| 4557 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 4558 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 4559 | |
| 4560 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4561 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 4562 | ret = 0; |
| 4563 | if (ret) |
| 4564 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 4565 | ret, strerror(-ret)); |
| 4566 | |
| 4567 | /* |
| 4568 | * If we failed or don't need to set the default TX key (below), |
| 4569 | * we're done here. |
| 4570 | */ |
| 4571 | if (ret || !set_tx || alg == WPA_ALG_NONE) |
| 4572 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4573 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4574 | !is_broadcast_ether_addr(addr)) |
| 4575 | return ret; |
| 4576 | |
| 4577 | msg = nlmsg_alloc(); |
| 4578 | if (!msg) |
| 4579 | return -ENOMEM; |
| 4580 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4581 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4582 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 4583 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 4584 | if (alg == WPA_ALG_IGTK) |
| 4585 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT); |
| 4586 | else |
| 4587 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT); |
| 4588 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4589 | struct nlattr *types; |
| 4590 | |
| 4591 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4592 | if (!types) |
| 4593 | goto nla_put_failure; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4594 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST); |
| 4595 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4596 | } else if (addr) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4597 | struct nlattr *types; |
| 4598 | |
| 4599 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4600 | if (!types) |
| 4601 | goto nla_put_failure; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 4602 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST); |
| 4603 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4607 | if (ret == -ENOENT) |
| 4608 | ret = 0; |
| 4609 | if (ret) |
| 4610 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 4611 | "err=%d %s)", ret, strerror(-ret)); |
| 4612 | return ret; |
| 4613 | |
| 4614 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4615 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4616 | return -ENOBUFS; |
| 4617 | } |
| 4618 | |
| 4619 | |
| 4620 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 4621 | int key_idx, int defkey, |
| 4622 | const u8 *seq, size_t seq_len, |
| 4623 | const u8 *key, size_t key_len) |
| 4624 | { |
| 4625 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
| 4626 | if (!key_attr) |
| 4627 | return -1; |
| 4628 | |
| 4629 | if (defkey && alg == WPA_ALG_IGTK) |
| 4630 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_MGMT); |
| 4631 | else if (defkey) |
| 4632 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); |
| 4633 | |
| 4634 | NLA_PUT_U8(msg, NL80211_KEY_IDX, key_idx); |
| 4635 | |
| 4636 | switch (alg) { |
| 4637 | case WPA_ALG_WEP: |
| 4638 | if (key_len == 5) |
| 4639 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 4640 | WLAN_CIPHER_SUITE_WEP40); |
| 4641 | else |
| 4642 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 4643 | WLAN_CIPHER_SUITE_WEP104); |
| 4644 | break; |
| 4645 | case WPA_ALG_TKIP: |
| 4646 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_TKIP); |
| 4647 | break; |
| 4648 | case WPA_ALG_CCMP: |
| 4649 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_CCMP); |
| 4650 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4651 | case WPA_ALG_GCMP: |
| 4652 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_GCMP); |
| 4653 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4654 | case WPA_ALG_IGTK: |
| 4655 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 4656 | WLAN_CIPHER_SUITE_AES_CMAC); |
| 4657 | break; |
| 4658 | default: |
| 4659 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " |
| 4660 | "algorithm %d", __func__, alg); |
| 4661 | return -1; |
| 4662 | } |
| 4663 | |
| 4664 | if (seq && seq_len) |
| 4665 | NLA_PUT(msg, NL80211_KEY_SEQ, seq_len, seq); |
| 4666 | |
| 4667 | NLA_PUT(msg, NL80211_KEY_DATA, key_len, key); |
| 4668 | |
| 4669 | nla_nest_end(msg, key_attr); |
| 4670 | |
| 4671 | return 0; |
| 4672 | nla_put_failure: |
| 4673 | return -1; |
| 4674 | } |
| 4675 | |
| 4676 | |
| 4677 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 4678 | struct nl_msg *msg) |
| 4679 | { |
| 4680 | int i, privacy = 0; |
| 4681 | struct nlattr *nl_keys, *nl_key; |
| 4682 | |
| 4683 | for (i = 0; i < 4; i++) { |
| 4684 | if (!params->wep_key[i]) |
| 4685 | continue; |
| 4686 | privacy = 1; |
| 4687 | break; |
| 4688 | } |
| 4689 | if (params->wps == WPS_MODE_PRIVACY) |
| 4690 | privacy = 1; |
| 4691 | if (params->pairwise_suite && |
| 4692 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 4693 | privacy = 1; |
| 4694 | |
| 4695 | if (!privacy) |
| 4696 | return 0; |
| 4697 | |
| 4698 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); |
| 4699 | |
| 4700 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 4701 | if (!nl_keys) |
| 4702 | goto nla_put_failure; |
| 4703 | |
| 4704 | for (i = 0; i < 4; i++) { |
| 4705 | if (!params->wep_key[i]) |
| 4706 | continue; |
| 4707 | |
| 4708 | nl_key = nla_nest_start(msg, i); |
| 4709 | if (!nl_key) |
| 4710 | goto nla_put_failure; |
| 4711 | |
| 4712 | NLA_PUT(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 4713 | params->wep_key[i]); |
| 4714 | if (params->wep_key_len[i] == 5) |
| 4715 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 4716 | WLAN_CIPHER_SUITE_WEP40); |
| 4717 | else |
| 4718 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
| 4719 | WLAN_CIPHER_SUITE_WEP104); |
| 4720 | |
| 4721 | NLA_PUT_U8(msg, NL80211_KEY_IDX, i); |
| 4722 | |
| 4723 | if (i == params->wep_tx_keyidx) |
| 4724 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); |
| 4725 | |
| 4726 | nla_nest_end(msg, nl_key); |
| 4727 | } |
| 4728 | nla_nest_end(msg, nl_keys); |
| 4729 | |
| 4730 | return 0; |
| 4731 | |
| 4732 | nla_put_failure: |
| 4733 | return -ENOBUFS; |
| 4734 | } |
| 4735 | |
| 4736 | |
| 4737 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 4738 | const u8 *addr, int cmd, u16 reason_code, |
| 4739 | int local_state_change) |
| 4740 | { |
| 4741 | int ret = -1; |
| 4742 | struct nl_msg *msg; |
| 4743 | |
| 4744 | msg = nlmsg_alloc(); |
| 4745 | if (!msg) |
| 4746 | return -1; |
| 4747 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4748 | nl80211_cmd(drv, msg, 0, cmd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4749 | |
| 4750 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 4751 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4752 | if (addr) |
| 4753 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4754 | if (local_state_change) |
| 4755 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); |
| 4756 | |
| 4757 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4758 | msg = NULL; |
| 4759 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4760 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 4761 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 4762 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4763 | goto nla_put_failure; |
| 4764 | } |
| 4765 | ret = 0; |
| 4766 | |
| 4767 | nla_put_failure: |
| 4768 | nlmsg_free(msg); |
| 4769 | return ret; |
| 4770 | } |
| 4771 | |
| 4772 | |
| 4773 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4774 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4775 | { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4776 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4777 | drv->associated = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4778 | drv->ignore_next_local_disconnect = 0; |
| 4779 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
| 4780 | return wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4781 | reason_code, 0); |
| 4782 | } |
| 4783 | |
| 4784 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4785 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 4786 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4787 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4788 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4789 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4790 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4791 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 4792 | __func__, MAC2STR(addr), reason_code); |
| 4793 | drv->associated = 0; |
| 4794 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) |
| 4795 | return nl80211_leave_ibss(drv); |
| 4796 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 4797 | reason_code, 0); |
| 4798 | } |
| 4799 | |
| 4800 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4801 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 4802 | struct wpa_driver_auth_params *params) |
| 4803 | { |
| 4804 | int i; |
| 4805 | |
| 4806 | drv->auth_freq = params->freq; |
| 4807 | drv->auth_alg = params->auth_alg; |
| 4808 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 4809 | drv->auth_local_state_change = params->local_state_change; |
| 4810 | drv->auth_p2p = params->p2p; |
| 4811 | |
| 4812 | if (params->bssid) |
| 4813 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 4814 | else |
| 4815 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 4816 | |
| 4817 | if (params->ssid) { |
| 4818 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 4819 | drv->auth_ssid_len = params->ssid_len; |
| 4820 | } else |
| 4821 | drv->auth_ssid_len = 0; |
| 4822 | |
| 4823 | |
| 4824 | os_free(drv->auth_ie); |
| 4825 | drv->auth_ie = NULL; |
| 4826 | drv->auth_ie_len = 0; |
| 4827 | if (params->ie) { |
| 4828 | drv->auth_ie = os_malloc(params->ie_len); |
| 4829 | if (drv->auth_ie) { |
| 4830 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 4831 | drv->auth_ie_len = params->ie_len; |
| 4832 | } |
| 4833 | } |
| 4834 | |
| 4835 | for (i = 0; i < 4; i++) { |
| 4836 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 4837 | params->wep_key_len[i] <= 16) { |
| 4838 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 4839 | params->wep_key_len[i]); |
| 4840 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 4841 | } else |
| 4842 | drv->auth_wep_key_len[i] = 0; |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4847 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4848 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4849 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4850 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4851 | int ret = -1, i; |
| 4852 | struct nl_msg *msg; |
| 4853 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4854 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4855 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4856 | int is_retry; |
| 4857 | |
| 4858 | is_retry = drv->retry_auth; |
| 4859 | drv->retry_auth = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4860 | |
| 4861 | drv->associated = 0; |
| 4862 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
| 4863 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4864 | nlmode = params->p2p ? |
| 4865 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 4866 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4867 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4868 | return -1; |
| 4869 | |
| 4870 | retry: |
| 4871 | msg = nlmsg_alloc(); |
| 4872 | if (!msg) |
| 4873 | return -1; |
| 4874 | |
| 4875 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 4876 | drv->ifindex); |
| 4877 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4878 | nl80211_cmd(drv, msg, 0, NL80211_CMD_AUTHENTICATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4879 | |
| 4880 | for (i = 0; i < 4; i++) { |
| 4881 | if (!params->wep_key[i]) |
| 4882 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4883 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4884 | NULL, i, |
| 4885 | i == params->wep_tx_keyidx, NULL, 0, |
| 4886 | params->wep_key[i], |
| 4887 | params->wep_key_len[i]); |
| 4888 | if (params->wep_tx_keyidx != i) |
| 4889 | continue; |
| 4890 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
| 4891 | params->wep_key[i], params->wep_key_len[i])) { |
| 4892 | nlmsg_free(msg); |
| 4893 | return -1; |
| 4894 | } |
| 4895 | } |
| 4896 | |
| 4897 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 4898 | if (params->bssid) { |
| 4899 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4900 | MAC2STR(params->bssid)); |
| 4901 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 4902 | } |
| 4903 | if (params->freq) { |
| 4904 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 4905 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
| 4906 | } |
| 4907 | if (params->ssid) { |
| 4908 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4909 | params->ssid, params->ssid_len); |
| 4910 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4911 | params->ssid); |
| 4912 | } |
| 4913 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
| 4914 | if (params->ie) |
| 4915 | NLA_PUT(msg, NL80211_ATTR_IE, params->ie_len, params->ie); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4916 | if (params->sae_data) { |
| 4917 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 4918 | params->sae_data_len); |
| 4919 | NLA_PUT(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 4920 | params->sae_data); |
| 4921 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4922 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4923 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 4924 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4925 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 4926 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4927 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 4928 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 4929 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4930 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 4931 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4932 | else |
| 4933 | goto nla_put_failure; |
| 4934 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 4935 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); |
| 4936 | if (params->local_state_change) { |
| 4937 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
| 4938 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); |
| 4939 | } |
| 4940 | |
| 4941 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4942 | msg = NULL; |
| 4943 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4944 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 4945 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 4946 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4947 | count++; |
| 4948 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 4949 | !params->local_state_change) { |
| 4950 | /* |
| 4951 | * mac80211 does not currently accept new |
| 4952 | * authentication if we are already authenticated. As a |
| 4953 | * workaround, force deauthentication and try again. |
| 4954 | */ |
| 4955 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 4956 | "after forced deauthentication"); |
| 4957 | wpa_driver_nl80211_deauthenticate( |
| 4958 | bss, params->bssid, |
| 4959 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 4960 | nlmsg_free(msg); |
| 4961 | goto retry; |
| 4962 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4963 | |
| 4964 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 4965 | /* |
| 4966 | * cfg80211 has likely expired the BSS entry even |
| 4967 | * though it was previously available in our internal |
| 4968 | * BSS table. To recover quickly, start a single |
| 4969 | * channel scan on the specified channel. |
| 4970 | */ |
| 4971 | struct wpa_driver_scan_params scan; |
| 4972 | int freqs[2]; |
| 4973 | |
| 4974 | os_memset(&scan, 0, sizeof(scan)); |
| 4975 | scan.num_ssids = 1; |
| 4976 | if (params->ssid) { |
| 4977 | scan.ssids[0].ssid = params->ssid; |
| 4978 | scan.ssids[0].ssid_len = params->ssid_len; |
| 4979 | } |
| 4980 | freqs[0] = params->freq; |
| 4981 | freqs[1] = 0; |
| 4982 | scan.freqs = freqs; |
| 4983 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 4984 | "channel scan to refresh cfg80211 BSS " |
| 4985 | "entry"); |
| 4986 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 4987 | if (ret == 0) { |
| 4988 | nl80211_copy_auth_params(drv, params); |
| 4989 | drv->scan_for_auth = 1; |
| 4990 | } |
| 4991 | } else if (is_retry) { |
| 4992 | /* |
| 4993 | * Need to indicate this with an event since the return |
| 4994 | * value from the retry is not delivered to core code. |
| 4995 | */ |
| 4996 | union wpa_event_data event; |
| 4997 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 4998 | "failed"); |
| 4999 | os_memset(&event, 0, sizeof(event)); |
| 5000 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 5001 | ETH_ALEN); |
| 5002 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 5003 | &event); |
| 5004 | } |
| 5005 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5006 | goto nla_put_failure; |
| 5007 | } |
| 5008 | ret = 0; |
| 5009 | wpa_printf(MSG_DEBUG, "nl80211: Authentication request send " |
| 5010 | "successfully"); |
| 5011 | |
| 5012 | nla_put_failure: |
| 5013 | nlmsg_free(msg); |
| 5014 | return ret; |
| 5015 | } |
| 5016 | |
| 5017 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5018 | static int wpa_driver_nl80211_authenticate_retry( |
| 5019 | struct wpa_driver_nl80211_data *drv) |
| 5020 | { |
| 5021 | struct wpa_driver_auth_params params; |
| 5022 | struct i802_bss *bss = &drv->first_bss; |
| 5023 | int i; |
| 5024 | |
| 5025 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 5026 | |
| 5027 | os_memset(¶ms, 0, sizeof(params)); |
| 5028 | params.freq = drv->auth_freq; |
| 5029 | params.auth_alg = drv->auth_alg; |
| 5030 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 5031 | params.local_state_change = drv->auth_local_state_change; |
| 5032 | params.p2p = drv->auth_p2p; |
| 5033 | |
| 5034 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 5035 | params.bssid = drv->auth_bssid_; |
| 5036 | |
| 5037 | if (drv->auth_ssid_len) { |
| 5038 | params.ssid = drv->auth_ssid; |
| 5039 | params.ssid_len = drv->auth_ssid_len; |
| 5040 | } |
| 5041 | |
| 5042 | params.ie = drv->auth_ie; |
| 5043 | params.ie_len = drv->auth_ie_len; |
| 5044 | |
| 5045 | for (i = 0; i < 4; i++) { |
| 5046 | if (drv->auth_wep_key_len[i]) { |
| 5047 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 5048 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | drv->retry_auth = 1; |
| 5053 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 5054 | } |
| 5055 | |
| 5056 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5057 | struct phy_info_arg { |
| 5058 | u16 *num_modes; |
| 5059 | struct hostapd_hw_modes *modes; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5060 | int last_mode, last_chan_idx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5061 | }; |
| 5062 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5063 | static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa, |
| 5064 | struct nlattr *ampdu_factor, |
| 5065 | struct nlattr *ampdu_density, |
| 5066 | struct nlattr *mcs_set) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5067 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5068 | if (capa) |
| 5069 | mode->ht_capab = nla_get_u16(capa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5070 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5071 | if (ampdu_factor) |
| 5072 | mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5073 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5074 | if (ampdu_density) |
| 5075 | mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2; |
| 5076 | |
| 5077 | if (mcs_set && nla_len(mcs_set) >= 16) { |
| 5078 | u8 *mcs; |
| 5079 | mcs = nla_data(mcs_set); |
| 5080 | os_memcpy(mode->mcs_set, mcs, 16); |
| 5081 | } |
| 5082 | } |
| 5083 | |
| 5084 | |
| 5085 | static void phy_info_vht_capa(struct hostapd_hw_modes *mode, |
| 5086 | struct nlattr *capa, |
| 5087 | struct nlattr *mcs_set) |
| 5088 | { |
| 5089 | if (capa) |
| 5090 | mode->vht_capab = nla_get_u32(capa); |
| 5091 | |
| 5092 | if (mcs_set && nla_len(mcs_set) >= 8) { |
| 5093 | u8 *mcs; |
| 5094 | mcs = nla_data(mcs_set); |
| 5095 | os_memcpy(mode->vht_mcs_set, mcs, 8); |
| 5096 | } |
| 5097 | } |
| 5098 | |
| 5099 | |
| 5100 | static void phy_info_freq(struct hostapd_hw_modes *mode, |
| 5101 | struct hostapd_channel_data *chan, |
| 5102 | struct nlattr *tb_freq[]) |
| 5103 | { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5104 | enum hostapd_hw_mode m; |
| 5105 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5106 | chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); |
| 5107 | chan->flag = 0; |
| 5108 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5109 | if (chan->freq < 4000) |
| 5110 | m = HOSTAPD_MODE_IEEE80211B; |
| 5111 | else if (chan->freq > 50000) |
| 5112 | m = HOSTAPD_MODE_IEEE80211AD; |
| 5113 | else |
| 5114 | m = HOSTAPD_MODE_IEEE80211A; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5115 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5116 | switch (m) { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5117 | case HOSTAPD_MODE_IEEE80211AD: |
| 5118 | chan->chan = (chan->freq - 56160) / 2160; |
| 5119 | break; |
| 5120 | case HOSTAPD_MODE_IEEE80211A: |
| 5121 | chan->chan = chan->freq / 5 - 1000; |
| 5122 | break; |
| 5123 | case HOSTAPD_MODE_IEEE80211B: |
| 5124 | case HOSTAPD_MODE_IEEE80211G: |
| 5125 | if (chan->freq == 2484) |
| 5126 | chan->chan = 14; |
| 5127 | else |
| 5128 | chan->chan = (chan->freq - 2407) / 5; |
| 5129 | break; |
| 5130 | default: |
| 5131 | break; |
| 5132 | } |
| 5133 | |
| 5134 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) |
| 5135 | chan->flag |= HOSTAPD_CHAN_DISABLED; |
| 5136 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) |
| 5137 | chan->flag |= HOSTAPD_CHAN_PASSIVE_SCAN; |
| 5138 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) |
| 5139 | chan->flag |= HOSTAPD_CHAN_NO_IBSS; |
| 5140 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) |
| 5141 | chan->flag |= HOSTAPD_CHAN_RADAR; |
| 5142 | |
| 5143 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && |
| 5144 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) |
| 5145 | chan->max_tx_power = nla_get_u32( |
| 5146 | tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100; |
| 5147 | } |
| 5148 | |
| 5149 | |
| 5150 | static int phy_info_freqs(struct phy_info_arg *phy_info, |
| 5151 | struct hostapd_hw_modes *mode, struct nlattr *tb) |
| 5152 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5153 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 5154 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, |
| 5155 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 5156 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, |
| 5157 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, |
| 5158 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, |
| 5159 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, |
| 5160 | }; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5161 | int new_channels = 0; |
| 5162 | struct hostapd_channel_data *channel; |
| 5163 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5164 | struct nlattr *nl_freq; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5165 | int rem_freq, idx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5166 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5167 | if (tb == NULL) |
| 5168 | return NL_OK; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5169 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5170 | nla_for_each_nested(nl_freq, tb, rem_freq) { |
| 5171 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, |
| 5172 | nla_data(nl_freq), nla_len(nl_freq), freq_policy); |
| 5173 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 5174 | continue; |
| 5175 | new_channels++; |
| 5176 | } |
| 5177 | |
| 5178 | channel = os_realloc_array(mode->channels, |
| 5179 | mode->num_channels + new_channels, |
| 5180 | sizeof(struct hostapd_channel_data)); |
| 5181 | if (!channel) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5182 | return NL_SKIP; |
| 5183 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5184 | mode->channels = channel; |
| 5185 | mode->num_channels += new_channels; |
| 5186 | |
| 5187 | idx = phy_info->last_chan_idx; |
| 5188 | |
| 5189 | nla_for_each_nested(nl_freq, tb, rem_freq) { |
| 5190 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, |
| 5191 | nla_data(nl_freq), nla_len(nl_freq), freq_policy); |
| 5192 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 5193 | continue; |
| 5194 | phy_info_freq(mode, &mode->channels[idx], tb_freq); |
| 5195 | idx++; |
| 5196 | } |
| 5197 | phy_info->last_chan_idx = idx; |
| 5198 | |
| 5199 | return NL_OK; |
| 5200 | } |
| 5201 | |
| 5202 | |
| 5203 | static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb) |
| 5204 | { |
| 5205 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { |
| 5206 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, |
| 5207 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = |
| 5208 | { .type = NLA_FLAG }, |
| 5209 | }; |
| 5210 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; |
| 5211 | struct nlattr *nl_rate; |
| 5212 | int rem_rate, idx; |
| 5213 | |
| 5214 | if (tb == NULL) |
| 5215 | return NL_OK; |
| 5216 | |
| 5217 | nla_for_each_nested(nl_rate, tb, rem_rate) { |
| 5218 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, |
| 5219 | nla_data(nl_rate), nla_len(nl_rate), |
| 5220 | rate_policy); |
| 5221 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 5222 | continue; |
| 5223 | mode->num_rates++; |
| 5224 | } |
| 5225 | |
| 5226 | mode->rates = os_calloc(mode->num_rates, sizeof(int)); |
| 5227 | if (!mode->rates) |
| 5228 | return NL_SKIP; |
| 5229 | |
| 5230 | idx = 0; |
| 5231 | |
| 5232 | nla_for_each_nested(nl_rate, tb, rem_rate) { |
| 5233 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, |
| 5234 | nla_data(nl_rate), nla_len(nl_rate), |
| 5235 | rate_policy); |
| 5236 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 5237 | continue; |
| 5238 | mode->rates[idx] = nla_get_u32( |
| 5239 | tb_rate[NL80211_BITRATE_ATTR_RATE]); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5240 | idx++; |
| 5241 | } |
| 5242 | |
| 5243 | return NL_OK; |
| 5244 | } |
| 5245 | |
| 5246 | |
| 5247 | static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band) |
| 5248 | { |
| 5249 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; |
| 5250 | struct hostapd_hw_modes *mode; |
| 5251 | int ret; |
| 5252 | |
| 5253 | if (phy_info->last_mode != nl_band->nla_type) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5254 | mode = os_realloc_array(phy_info->modes, |
| 5255 | *phy_info->num_modes + 1, |
| 5256 | sizeof(*mode)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5257 | if (!mode) |
| 5258 | return NL_SKIP; |
| 5259 | phy_info->modes = mode; |
| 5260 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5261 | mode = &phy_info->modes[*(phy_info->num_modes)]; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5262 | os_memset(mode, 0, sizeof(*mode)); |
| 5263 | mode->mode = NUM_HOSTAPD_MODES; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5264 | mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5265 | *(phy_info->num_modes) += 1; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5266 | phy_info->last_mode = nl_band->nla_type; |
| 5267 | phy_info->last_chan_idx = 0; |
| 5268 | } else |
| 5269 | mode = &phy_info->modes[*(phy_info->num_modes) - 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5270 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5271 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), |
| 5272 | nla_len(nl_band), NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5273 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5274 | phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA], |
| 5275 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR], |
| 5276 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY], |
| 5277 | tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); |
| 5278 | phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA], |
| 5279 | tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]); |
| 5280 | ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]); |
| 5281 | if (ret != NL_OK) |
| 5282 | return ret; |
| 5283 | ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]); |
| 5284 | if (ret != NL_OK) |
| 5285 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5286 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5287 | return NL_OK; |
| 5288 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5289 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5290 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5291 | static int phy_info_handler(struct nl_msg *msg, void *arg) |
| 5292 | { |
| 5293 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 5294 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5295 | struct phy_info_arg *phy_info = arg; |
| 5296 | struct nlattr *nl_band; |
| 5297 | int rem_band; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5298 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5299 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5300 | genlmsg_attrlen(gnlh, 0), NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5301 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5302 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) |
| 5303 | return NL_SKIP; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5304 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5305 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) |
| 5306 | { |
| 5307 | int res = phy_info_band(phy_info, nl_band); |
| 5308 | if (res != NL_OK) |
| 5309 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | return NL_SKIP; |
| 5313 | } |
| 5314 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5315 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5316 | static struct hostapd_hw_modes * |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5317 | wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes, |
| 5318 | u16 *num_modes) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5319 | { |
| 5320 | u16 m; |
| 5321 | struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; |
| 5322 | int i, mode11g_idx = -1; |
| 5323 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5324 | /* heuristic to set up modes */ |
| 5325 | for (m = 0; m < *num_modes; m++) { |
| 5326 | if (!modes[m].num_channels) |
| 5327 | continue; |
| 5328 | if (modes[m].channels[0].freq < 4000) { |
| 5329 | modes[m].mode = HOSTAPD_MODE_IEEE80211B; |
| 5330 | for (i = 0; i < modes[m].num_rates; i++) { |
| 5331 | if (modes[m].rates[i] > 200) { |
| 5332 | modes[m].mode = HOSTAPD_MODE_IEEE80211G; |
| 5333 | break; |
| 5334 | } |
| 5335 | } |
| 5336 | } else if (modes[m].channels[0].freq > 50000) |
| 5337 | modes[m].mode = HOSTAPD_MODE_IEEE80211AD; |
| 5338 | else |
| 5339 | modes[m].mode = HOSTAPD_MODE_IEEE80211A; |
| 5340 | } |
| 5341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5342 | /* If only 802.11g mode is included, use it to construct matching |
| 5343 | * 802.11b mode data. */ |
| 5344 | |
| 5345 | for (m = 0; m < *num_modes; m++) { |
| 5346 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) |
| 5347 | return modes; /* 802.11b already included */ |
| 5348 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) |
| 5349 | mode11g_idx = m; |
| 5350 | } |
| 5351 | |
| 5352 | if (mode11g_idx < 0) |
| 5353 | return modes; /* 2.4 GHz band not supported at all */ |
| 5354 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5355 | nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5356 | if (nmodes == NULL) |
| 5357 | return modes; /* Could not add 802.11b mode */ |
| 5358 | |
| 5359 | mode = &nmodes[*num_modes]; |
| 5360 | os_memset(mode, 0, sizeof(*mode)); |
| 5361 | (*num_modes)++; |
| 5362 | modes = nmodes; |
| 5363 | |
| 5364 | mode->mode = HOSTAPD_MODE_IEEE80211B; |
| 5365 | |
| 5366 | mode11g = &modes[mode11g_idx]; |
| 5367 | mode->num_channels = mode11g->num_channels; |
| 5368 | mode->channels = os_malloc(mode11g->num_channels * |
| 5369 | sizeof(struct hostapd_channel_data)); |
| 5370 | if (mode->channels == NULL) { |
| 5371 | (*num_modes)--; |
| 5372 | return modes; /* Could not add 802.11b mode */ |
| 5373 | } |
| 5374 | os_memcpy(mode->channels, mode11g->channels, |
| 5375 | mode11g->num_channels * sizeof(struct hostapd_channel_data)); |
| 5376 | |
| 5377 | mode->num_rates = 0; |
| 5378 | mode->rates = os_malloc(4 * sizeof(int)); |
| 5379 | if (mode->rates == NULL) { |
| 5380 | os_free(mode->channels); |
| 5381 | (*num_modes)--; |
| 5382 | return modes; /* Could not add 802.11b mode */ |
| 5383 | } |
| 5384 | |
| 5385 | for (i = 0; i < mode11g->num_rates; i++) { |
| 5386 | if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && |
| 5387 | mode11g->rates[i] != 55 && mode11g->rates[i] != 110) |
| 5388 | continue; |
| 5389 | mode->rates[mode->num_rates] = mode11g->rates[i]; |
| 5390 | mode->num_rates++; |
| 5391 | if (mode->num_rates == 4) |
| 5392 | break; |
| 5393 | } |
| 5394 | |
| 5395 | if (mode->num_rates == 0) { |
| 5396 | os_free(mode->channels); |
| 5397 | os_free(mode->rates); |
| 5398 | (*num_modes)--; |
| 5399 | return modes; /* No 802.11b rates */ |
| 5400 | } |
| 5401 | |
| 5402 | wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " |
| 5403 | "information"); |
| 5404 | |
| 5405 | return modes; |
| 5406 | } |
| 5407 | |
| 5408 | |
| 5409 | static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start, |
| 5410 | int end) |
| 5411 | { |
| 5412 | int c; |
| 5413 | |
| 5414 | for (c = 0; c < mode->num_channels; c++) { |
| 5415 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 5416 | if (chan->freq - 10 >= start && chan->freq + 10 <= end) |
| 5417 | chan->flag |= HOSTAPD_CHAN_HT40; |
| 5418 | } |
| 5419 | } |
| 5420 | |
| 5421 | |
| 5422 | static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start, |
| 5423 | int end) |
| 5424 | { |
| 5425 | int c; |
| 5426 | |
| 5427 | for (c = 0; c < mode->num_channels; c++) { |
| 5428 | struct hostapd_channel_data *chan = &mode->channels[c]; |
| 5429 | if (!(chan->flag & HOSTAPD_CHAN_HT40)) |
| 5430 | continue; |
| 5431 | if (chan->freq - 30 >= start && chan->freq - 10 <= end) |
| 5432 | chan->flag |= HOSTAPD_CHAN_HT40MINUS; |
| 5433 | if (chan->freq + 10 >= start && chan->freq + 30 <= end) |
| 5434 | chan->flag |= HOSTAPD_CHAN_HT40PLUS; |
| 5435 | } |
| 5436 | } |
| 5437 | |
| 5438 | |
| 5439 | static void nl80211_reg_rule_ht40(struct nlattr *tb[], |
| 5440 | struct phy_info_arg *results) |
| 5441 | { |
| 5442 | u32 start, end, max_bw; |
| 5443 | u16 m; |
| 5444 | |
| 5445 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || |
| 5446 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || |
| 5447 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) |
| 5448 | return; |
| 5449 | |
| 5450 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; |
| 5451 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; |
| 5452 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; |
| 5453 | |
| 5454 | wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz", |
| 5455 | start, end, max_bw); |
| 5456 | if (max_bw < 40) |
| 5457 | return; |
| 5458 | |
| 5459 | for (m = 0; m < *results->num_modes; m++) { |
| 5460 | if (!(results->modes[m].ht_capab & |
| 5461 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 5462 | continue; |
| 5463 | nl80211_set_ht40_mode(&results->modes[m], start, end); |
| 5464 | } |
| 5465 | } |
| 5466 | |
| 5467 | |
| 5468 | static void nl80211_reg_rule_sec(struct nlattr *tb[], |
| 5469 | struct phy_info_arg *results) |
| 5470 | { |
| 5471 | u32 start, end, max_bw; |
| 5472 | u16 m; |
| 5473 | |
| 5474 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || |
| 5475 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || |
| 5476 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) |
| 5477 | return; |
| 5478 | |
| 5479 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; |
| 5480 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; |
| 5481 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; |
| 5482 | |
| 5483 | if (max_bw < 20) |
| 5484 | return; |
| 5485 | |
| 5486 | for (m = 0; m < *results->num_modes; m++) { |
| 5487 | if (!(results->modes[m].ht_capab & |
| 5488 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 5489 | continue; |
| 5490 | nl80211_set_ht40_mode_sec(&results->modes[m], start, end); |
| 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | |
| 5495 | static int nl80211_get_reg(struct nl_msg *msg, void *arg) |
| 5496 | { |
| 5497 | struct phy_info_arg *results = arg; |
| 5498 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 5499 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5500 | struct nlattr *nl_rule; |
| 5501 | struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1]; |
| 5502 | int rem_rule; |
| 5503 | static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 5504 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 5505 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 5506 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 5507 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 5508 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 5509 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 5510 | }; |
| 5511 | |
| 5512 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5513 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5514 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2] || |
| 5515 | !tb_msg[NL80211_ATTR_REG_RULES]) { |
| 5516 | wpa_printf(MSG_DEBUG, "nl80211: No regulatory information " |
| 5517 | "available"); |
| 5518 | return NL_SKIP; |
| 5519 | } |
| 5520 | |
| 5521 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s", |
| 5522 | (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2])); |
| 5523 | |
| 5524 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) |
| 5525 | { |
| 5526 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, |
| 5527 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); |
| 5528 | nl80211_reg_rule_ht40(tb_rule, results); |
| 5529 | } |
| 5530 | |
| 5531 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) |
| 5532 | { |
| 5533 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, |
| 5534 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); |
| 5535 | nl80211_reg_rule_sec(tb_rule, results); |
| 5536 | } |
| 5537 | |
| 5538 | return NL_SKIP; |
| 5539 | } |
| 5540 | |
| 5541 | |
| 5542 | static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data *drv, |
| 5543 | struct phy_info_arg *results) |
| 5544 | { |
| 5545 | struct nl_msg *msg; |
| 5546 | |
| 5547 | msg = nlmsg_alloc(); |
| 5548 | if (!msg) |
| 5549 | return -ENOMEM; |
| 5550 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5551 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5552 | return send_and_recv_msgs(drv, msg, nl80211_get_reg, results); |
| 5553 | } |
| 5554 | |
| 5555 | |
| 5556 | static struct hostapd_hw_modes * |
| 5557 | wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags) |
| 5558 | { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5559 | u32 feat; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5560 | struct i802_bss *bss = priv; |
| 5561 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5562 | struct nl_msg *msg; |
| 5563 | struct phy_info_arg result = { |
| 5564 | .num_modes = num_modes, |
| 5565 | .modes = NULL, |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5566 | .last_mode = -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5567 | }; |
| 5568 | |
| 5569 | *num_modes = 0; |
| 5570 | *flags = 0; |
| 5571 | |
| 5572 | msg = nlmsg_alloc(); |
| 5573 | if (!msg) |
| 5574 | return NULL; |
| 5575 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5576 | feat = get_nl80211_protocol_features(drv); |
| 5577 | if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) |
| 5578 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY); |
| 5579 | else |
| 5580 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5581 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 5582 | NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5583 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 5584 | |
| 5585 | if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) { |
| 5586 | nl80211_set_ht40_flags(drv, &result); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5587 | return wpa_driver_nl80211_postprocess_modes(result.modes, |
| 5588 | num_modes); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5589 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5590 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5591 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5592 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5593 | return NULL; |
| 5594 | } |
| 5595 | |
| 5596 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5597 | static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data *drv, |
| 5598 | const void *data, size_t len, |
| 5599 | int encrypt, int noack) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5600 | { |
| 5601 | __u8 rtap_hdr[] = { |
| 5602 | 0x00, 0x00, /* radiotap version */ |
| 5603 | 0x0e, 0x00, /* radiotap length */ |
| 5604 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ |
| 5605 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ |
| 5606 | 0x00, /* padding */ |
| 5607 | 0x00, 0x00, /* RX and TX flags to indicate that */ |
| 5608 | 0x00, 0x00, /* this is the injected frame directly */ |
| 5609 | }; |
| 5610 | struct iovec iov[2] = { |
| 5611 | { |
| 5612 | .iov_base = &rtap_hdr, |
| 5613 | .iov_len = sizeof(rtap_hdr), |
| 5614 | }, |
| 5615 | { |
| 5616 | .iov_base = (void *) data, |
| 5617 | .iov_len = len, |
| 5618 | } |
| 5619 | }; |
| 5620 | struct msghdr msg = { |
| 5621 | .msg_name = NULL, |
| 5622 | .msg_namelen = 0, |
| 5623 | .msg_iov = iov, |
| 5624 | .msg_iovlen = 2, |
| 5625 | .msg_control = NULL, |
| 5626 | .msg_controllen = 0, |
| 5627 | .msg_flags = 0, |
| 5628 | }; |
| 5629 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5630 | u16 txflags = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5631 | |
| 5632 | if (encrypt) |
| 5633 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; |
| 5634 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 5635 | if (drv->monitor_sock < 0) { |
| 5636 | wpa_printf(MSG_DEBUG, "nl80211: No monitor socket available " |
| 5637 | "for %s", __func__); |
| 5638 | return -1; |
| 5639 | } |
| 5640 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5641 | if (noack) |
| 5642 | txflags |= IEEE80211_RADIOTAP_F_TX_NOACK; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5643 | WPA_PUT_LE16(&rtap_hdr[12], txflags); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5644 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5645 | res = sendmsg(drv->monitor_sock, &msg, 0); |
| 5646 | if (res < 0) { |
| 5647 | wpa_printf(MSG_INFO, "nl80211: sendmsg: %s", strerror(errno)); |
| 5648 | return -1; |
| 5649 | } |
| 5650 | return 0; |
| 5651 | } |
| 5652 | |
| 5653 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5654 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 5655 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5656 | int encrypt, int noack, |
| 5657 | unsigned int freq, int no_cck, |
| 5658 | int offchanok, unsigned int wait_time) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5659 | { |
| 5660 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5661 | u64 cookie; |
| 5662 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5663 | if (freq == 0) |
| 5664 | freq = bss->freq; |
| 5665 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5666 | if (drv->use_monitor) |
| 5667 | return wpa_driver_nl80211_send_mntr(drv, data, len, |
| 5668 | encrypt, noack); |
| 5669 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5670 | return nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
| 5671 | &cookie, no_cck, noack, offchanok); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5675 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 5676 | size_t data_len, int noack, |
| 5677 | unsigned int freq, int no_cck, |
| 5678 | int offchanok, |
| 5679 | unsigned int wait_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5680 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5681 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5682 | struct ieee80211_mgmt *mgmt; |
| 5683 | int encrypt = 1; |
| 5684 | u16 fc; |
| 5685 | |
| 5686 | mgmt = (struct ieee80211_mgmt *) data; |
| 5687 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5688 | |
| 5689 | if (is_sta_interface(drv->nlmode) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5690 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 5691 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 5692 | /* |
| 5693 | * The use of last_mgmt_freq is a bit of a hack, |
| 5694 | * but it works due to the single-threaded nature |
| 5695 | * of wpa_supplicant. |
| 5696 | */ |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5697 | if (freq == 0) |
| 5698 | freq = drv->last_mgmt_freq; |
| 5699 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5700 | data, data_len, NULL, 1, noack, |
| 5701 | 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5702 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5703 | |
| 5704 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5705 | if (freq == 0) |
| 5706 | freq = bss->freq; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5707 | return nl80211_send_frame_cmd(bss, freq, |
| 5708 | (int) freq == bss->freq ? 0 : |
| 5709 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5710 | data, data_len, |
| 5711 | &drv->send_action_cookie, |
| 5712 | no_cck, noack, offchanok); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 5713 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 5714 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5715 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 5716 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 5717 | /* |
| 5718 | * Only one of the authentication frame types is encrypted. |
| 5719 | * In order for static WEP encryption to work properly (i.e., |
| 5720 | * to not encrypt the frame), we need to tell mac80211 about |
| 5721 | * the frames that must not be encrypted. |
| 5722 | */ |
| 5723 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 5724 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 5725 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 5726 | encrypt = 0; |
| 5727 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5728 | |
| 5729 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5730 | noack, freq, no_cck, offchanok, |
| 5731 | wait_time); |
| 5732 | } |
| 5733 | |
| 5734 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5735 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 5736 | int slot, int ht_opmode, int ap_isolate, |
| 5737 | int *basic_rates) |
| 5738 | { |
| 5739 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5740 | struct nl_msg *msg; |
| 5741 | |
| 5742 | msg = nlmsg_alloc(); |
| 5743 | if (!msg) |
| 5744 | return -ENOMEM; |
| 5745 | |
| 5746 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_BSS); |
| 5747 | |
| 5748 | if (cts >= 0) |
| 5749 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts); |
| 5750 | if (preamble >= 0) |
| 5751 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble); |
| 5752 | if (slot >= 0) |
| 5753 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot); |
| 5754 | if (ht_opmode >= 0) |
| 5755 | NLA_PUT_U16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode); |
| 5756 | if (ap_isolate >= 0) |
| 5757 | NLA_PUT_U8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate); |
| 5758 | |
| 5759 | if (basic_rates) { |
| 5760 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 5761 | u8 rates_len = 0; |
| 5762 | int i; |
| 5763 | |
| 5764 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; |
| 5765 | i++) |
| 5766 | rates[rates_len++] = basic_rates[i] / 5; |
| 5767 | |
| 5768 | NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 5769 | } |
| 5770 | |
| 5771 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 5772 | |
| 5773 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5774 | nla_put_failure: |
| 5775 | nlmsg_free(msg); |
| 5776 | return -ENOBUFS; |
| 5777 | } |
| 5778 | |
| 5779 | |
| 5780 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 5781 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5782 | { |
| 5783 | struct i802_bss *bss = priv; |
| 5784 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5785 | struct nl_msg *msg; |
| 5786 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 5787 | int ret; |
| 5788 | int beacon_set; |
| 5789 | int ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5790 | int num_suites; |
| 5791 | u32 suites[10]; |
| 5792 | u32 ver; |
| 5793 | |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 5794 | beacon_set = bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5795 | |
| 5796 | msg = nlmsg_alloc(); |
| 5797 | if (!msg) |
| 5798 | return -ENOMEM; |
| 5799 | |
| 5800 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 5801 | beacon_set); |
| 5802 | if (beacon_set) |
| 5803 | cmd = NL80211_CMD_SET_BEACON; |
| 5804 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5805 | nl80211_cmd(drv, msg, 0, cmd); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5806 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 5807 | params->head, params->head_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5808 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, params->head); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5809 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 5810 | params->tail, params->tail_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5811 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, params->tail); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5812 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5813 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5814 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5815 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5816 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5817 | NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5818 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 5819 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5820 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 5821 | params->ssid); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5822 | if (params->proberesp && params->proberesp_len) { |
| 5823 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 5824 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5825 | NLA_PUT(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 5826 | params->proberesp); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5827 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5828 | switch (params->hide_ssid) { |
| 5829 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5830 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5831 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 5832 | NL80211_HIDDEN_SSID_NOT_IN_USE); |
| 5833 | break; |
| 5834 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5835 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5836 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 5837 | NL80211_HIDDEN_SSID_ZERO_LEN); |
| 5838 | break; |
| 5839 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5840 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5841 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 5842 | NL80211_HIDDEN_SSID_ZERO_CONTENTS); |
| 5843 | break; |
| 5844 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5845 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5846 | if (params->privacy) |
| 5847 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5848 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5849 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 5850 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 5851 | /* Leave out the attribute */ |
| 5852 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) |
| 5853 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, |
| 5854 | NL80211_AUTHTYPE_SHARED_KEY); |
| 5855 | else |
| 5856 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, |
| 5857 | NL80211_AUTHTYPE_OPEN_SYSTEM); |
| 5858 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5859 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5860 | ver = 0; |
| 5861 | if (params->wpa_version & WPA_PROTO_WPA) |
| 5862 | ver |= NL80211_WPA_VERSION_1; |
| 5863 | if (params->wpa_version & WPA_PROTO_RSN) |
| 5864 | ver |= NL80211_WPA_VERSION_2; |
| 5865 | if (ver) |
| 5866 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); |
| 5867 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5868 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 5869 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5870 | num_suites = 0; |
| 5871 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 5872 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 5873 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 5874 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
| 5875 | if (num_suites) { |
| 5876 | NLA_PUT(msg, NL80211_ATTR_AKM_SUITES, |
| 5877 | num_suites * sizeof(u32), suites); |
| 5878 | } |
| 5879 | |
| 5880 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X && |
| 5881 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) |
| 5882 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT); |
| 5883 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5884 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 5885 | params->pairwise_ciphers); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5886 | num_suites = 0; |
| 5887 | if (params->pairwise_ciphers & WPA_CIPHER_CCMP) |
| 5888 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5889 | if (params->pairwise_ciphers & WPA_CIPHER_GCMP) |
| 5890 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5891 | if (params->pairwise_ciphers & WPA_CIPHER_TKIP) |
| 5892 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 5893 | if (params->pairwise_ciphers & WPA_CIPHER_WEP104) |
| 5894 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 5895 | if (params->pairwise_ciphers & WPA_CIPHER_WEP40) |
| 5896 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 5897 | if (num_suites) { |
| 5898 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 5899 | num_suites * sizeof(u32), suites); |
| 5900 | } |
| 5901 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5902 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 5903 | params->group_cipher); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5904 | switch (params->group_cipher) { |
| 5905 | case WPA_CIPHER_CCMP: |
| 5906 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, |
| 5907 | WLAN_CIPHER_SUITE_CCMP); |
| 5908 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5909 | case WPA_CIPHER_GCMP: |
| 5910 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, |
| 5911 | WLAN_CIPHER_SUITE_GCMP); |
| 5912 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5913 | case WPA_CIPHER_TKIP: |
| 5914 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, |
| 5915 | WLAN_CIPHER_SUITE_TKIP); |
| 5916 | break; |
| 5917 | case WPA_CIPHER_WEP104: |
| 5918 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, |
| 5919 | WLAN_CIPHER_SUITE_WEP104); |
| 5920 | break; |
| 5921 | case WPA_CIPHER_WEP40: |
| 5922 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, |
| 5923 | WLAN_CIPHER_SUITE_WEP40); |
| 5924 | break; |
| 5925 | } |
| 5926 | |
| 5927 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5928 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 5929 | params->beacon_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5930 | NLA_PUT(msg, NL80211_ATTR_IE, wpabuf_len(params->beacon_ies), |
| 5931 | wpabuf_head(params->beacon_ies)); |
| 5932 | } |
| 5933 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5934 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 5935 | params->proberesp_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5936 | NLA_PUT(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 5937 | wpabuf_len(params->proberesp_ies), |
| 5938 | wpabuf_head(params->proberesp_ies)); |
| 5939 | } |
| 5940 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5941 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 5942 | params->assocresp_ies); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5943 | NLA_PUT(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 5944 | wpabuf_len(params->assocresp_ies), |
| 5945 | wpabuf_head(params->assocresp_ies)); |
| 5946 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5947 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5948 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 5949 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 5950 | params->ap_max_inactivity); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5951 | NLA_PUT_U16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 5952 | params->ap_max_inactivity); |
| 5953 | } |
| 5954 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5955 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5956 | if (ret) { |
| 5957 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 5958 | ret, strerror(-ret)); |
| 5959 | } else { |
| 5960 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5961 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 5962 | params->short_slot_time, params->ht_opmode, |
| 5963 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5964 | } |
| 5965 | return ret; |
| 5966 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5967 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5968 | return -ENOBUFS; |
| 5969 | } |
| 5970 | |
| 5971 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5972 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5973 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5974 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5975 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5976 | struct nl_msg *msg; |
| 5977 | int ret; |
| 5978 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5979 | wpa_printf(MSG_DEBUG, "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d," |
| 5980 | " bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 5981 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 5982 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5983 | msg = nlmsg_alloc(); |
| 5984 | if (!msg) |
| 5985 | return -1; |
| 5986 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5987 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5988 | |
| 5989 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5990 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); |
| 5991 | if (freq->vht_enabled) { |
| 5992 | switch (freq->bandwidth) { |
| 5993 | case 20: |
| 5994 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 5995 | NL80211_CHAN_WIDTH_20); |
| 5996 | break; |
| 5997 | case 40: |
| 5998 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 5999 | NL80211_CHAN_WIDTH_40); |
| 6000 | break; |
| 6001 | case 80: |
| 6002 | if (freq->center_freq2) |
| 6003 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 6004 | NL80211_CHAN_WIDTH_80P80); |
| 6005 | else |
| 6006 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 6007 | NL80211_CHAN_WIDTH_80); |
| 6008 | break; |
| 6009 | case 160: |
| 6010 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, |
| 6011 | NL80211_CHAN_WIDTH_160); |
| 6012 | break; |
| 6013 | default: |
| 6014 | return -1; |
| 6015 | } |
| 6016 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); |
| 6017 | if (freq->center_freq2) |
| 6018 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 6019 | freq->center_freq2); |
| 6020 | } else if (freq->ht_enabled) { |
| 6021 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6022 | case -1: |
| 6023 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 6024 | NL80211_CHAN_HT40MINUS); |
| 6025 | break; |
| 6026 | case 1: |
| 6027 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 6028 | NL80211_CHAN_HT40PLUS); |
| 6029 | break; |
| 6030 | default: |
| 6031 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 6032 | NL80211_CHAN_HT20); |
| 6033 | break; |
| 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6038 | msg = NULL; |
| 6039 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6040 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6041 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6042 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6043 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6044 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6045 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6046 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6047 | return -1; |
| 6048 | } |
| 6049 | |
| 6050 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6051 | static u32 sta_flags_nl80211(int flags) |
| 6052 | { |
| 6053 | u32 f = 0; |
| 6054 | |
| 6055 | if (flags & WPA_STA_AUTHORIZED) |
| 6056 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 6057 | if (flags & WPA_STA_WMM) |
| 6058 | f |= BIT(NL80211_STA_FLAG_WME); |
| 6059 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 6060 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 6061 | if (flags & WPA_STA_MFP) |
| 6062 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 6063 | if (flags & WPA_STA_TDLS_PEER) |
| 6064 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 6065 | |
| 6066 | return f; |
| 6067 | } |
| 6068 | |
| 6069 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6070 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 6071 | struct hostapd_sta_add_params *params) |
| 6072 | { |
| 6073 | struct i802_bss *bss = priv; |
| 6074 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6075 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6076 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6077 | int ret = -ENOBUFS; |
| 6078 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6079 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 6080 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 6081 | return -EOPNOTSUPP; |
| 6082 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6083 | msg = nlmsg_alloc(); |
| 6084 | if (!msg) |
| 6085 | return -ENOMEM; |
| 6086 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6087 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 6088 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6089 | nl80211_cmd(drv, msg, 0, params->set ? NL80211_CMD_SET_STATION : |
| 6090 | NL80211_CMD_NEW_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6091 | |
| 6092 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 6093 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6094 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len, |
| 6095 | params->supp_rates); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6096 | wpa_hexdump(MSG_DEBUG, " * supported rates", params->supp_rates, |
| 6097 | params->supp_rates_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6098 | if (!params->set) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6099 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6100 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6101 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 6102 | params->listen_interval); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6103 | NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 6104 | params->listen_interval); |
| 6105 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6106 | if (params->ht_capabilities) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6107 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 6108 | (u8 *) params->ht_capabilities, |
| 6109 | sizeof(*params->ht_capabilities)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6110 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, |
| 6111 | sizeof(*params->ht_capabilities), |
| 6112 | params->ht_capabilities); |
| 6113 | } |
| 6114 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6115 | if (params->vht_capabilities) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6116 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 6117 | (u8 *) params->vht_capabilities, |
| 6118 | sizeof(*params->vht_capabilities)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6119 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 6120 | sizeof(*params->vht_capabilities), |
| 6121 | params->vht_capabilities); |
| 6122 | } |
| 6123 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6124 | wpa_printf(MSG_DEBUG, " * capability=0x%x", params->capability); |
| 6125 | NLA_PUT_U16(msg, NL80211_ATTR_STA_CAPABILITY, params->capability); |
| 6126 | |
| 6127 | if (params->ext_capab) { |
| 6128 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 6129 | params->ext_capab, params->ext_capab_len); |
| 6130 | NLA_PUT(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 6131 | params->ext_capab_len, params->ext_capab); |
| 6132 | } |
| 6133 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6134 | os_memset(&upd, 0, sizeof(upd)); |
| 6135 | upd.mask = sta_flags_nl80211(params->flags); |
| 6136 | upd.set = upd.mask; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6137 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 6138 | upd.set, upd.mask); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6139 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 6140 | |
| 6141 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6142 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 6143 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6144 | if (!wme) |
| 6145 | goto nla_put_failure; |
| 6146 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6147 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6148 | NLA_PUT_U8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6149 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6150 | NLA_PUT_U8(msg, NL80211_STA_WME_MAX_SP, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6151 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6152 | WMM_QOSINFO_STA_SP_MASK); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6153 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6154 | } |
| 6155 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6156 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6157 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6158 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6159 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 6160 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 6161 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6162 | if (ret == -EEXIST) |
| 6163 | ret = 0; |
| 6164 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6165 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6166 | return ret; |
| 6167 | } |
| 6168 | |
| 6169 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6170 | 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] | 6171 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6172 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6173 | struct nl_msg *msg; |
| 6174 | int ret; |
| 6175 | |
| 6176 | msg = nlmsg_alloc(); |
| 6177 | if (!msg) |
| 6178 | return -ENOMEM; |
| 6179 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6180 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6181 | |
| 6182 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 6183 | if_nametoindex(bss->ifname)); |
| 6184 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6185 | |
| 6186 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6187 | if (ret == -ENOENT) |
| 6188 | return 0; |
| 6189 | return ret; |
| 6190 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6191 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6192 | return -ENOBUFS; |
| 6193 | } |
| 6194 | |
| 6195 | |
| 6196 | static void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, |
| 6197 | int ifidx) |
| 6198 | { |
| 6199 | struct nl_msg *msg; |
| 6200 | |
| 6201 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 6202 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6203 | /* stop listening for EAPOL on this interface */ |
| 6204 | del_ifidx(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6205 | |
| 6206 | msg = nlmsg_alloc(); |
| 6207 | if (!msg) |
| 6208 | goto nla_put_failure; |
| 6209 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6210 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6211 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); |
| 6212 | |
| 6213 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 6214 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6215 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6216 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6217 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6218 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 6219 | } |
| 6220 | |
| 6221 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6222 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 6223 | { |
| 6224 | switch (mode) { |
| 6225 | case NL80211_IFTYPE_ADHOC: |
| 6226 | return "ADHOC"; |
| 6227 | case NL80211_IFTYPE_STATION: |
| 6228 | return "STATION"; |
| 6229 | case NL80211_IFTYPE_AP: |
| 6230 | return "AP"; |
| 6231 | case NL80211_IFTYPE_MONITOR: |
| 6232 | return "MONITOR"; |
| 6233 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6234 | return "P2P_CLIENT"; |
| 6235 | case NL80211_IFTYPE_P2P_GO: |
| 6236 | return "P2P_GO"; |
| 6237 | default: |
| 6238 | return "unknown"; |
| 6239 | } |
| 6240 | } |
| 6241 | |
| 6242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6243 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 6244 | const char *ifname, |
| 6245 | enum nl80211_iftype iftype, |
| 6246 | const u8 *addr, int wds) |
| 6247 | { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6248 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6249 | int ifidx; |
| 6250 | int ret = -ENOBUFS; |
| 6251 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6252 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 6253 | iftype, nl80211_iftype_str(iftype)); |
| 6254 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6255 | msg = nlmsg_alloc(); |
| 6256 | if (!msg) |
| 6257 | return -1; |
| 6258 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6259 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6260 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 6261 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname); |
| 6262 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype); |
| 6263 | |
| 6264 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6265 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6266 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6267 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6268 | if (!flags) |
| 6269 | goto nla_put_failure; |
| 6270 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6271 | NLA_PUT_FLAG(msg, NL80211_MNTR_FLAG_COOK_FRAMES); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6272 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6273 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6274 | } else if (wds) { |
| 6275 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, wds); |
| 6276 | } |
| 6277 | |
| 6278 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6279 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6280 | if (ret) { |
| 6281 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6282 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6283 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 6284 | ifname, ret, strerror(-ret)); |
| 6285 | return ret; |
| 6286 | } |
| 6287 | |
| 6288 | ifidx = if_nametoindex(ifname); |
| 6289 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 6290 | ifname, ifidx); |
| 6291 | |
| 6292 | if (ifidx <= 0) |
| 6293 | return -1; |
| 6294 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6295 | /* start listening for EAPOL on this interface */ |
| 6296 | add_ifidx(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6297 | |
| 6298 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6299 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6300 | nl80211_remove_iface(drv, ifidx); |
| 6301 | return -1; |
| 6302 | } |
| 6303 | |
| 6304 | return ifidx; |
| 6305 | } |
| 6306 | |
| 6307 | |
| 6308 | static int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 6309 | const char *ifname, enum nl80211_iftype iftype, |
| 6310 | const u8 *addr, int wds) |
| 6311 | { |
| 6312 | int ret; |
| 6313 | |
| 6314 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds); |
| 6315 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6316 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6317 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
| 6318 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 6319 | |
| 6320 | /* Try to remove the interface that was already there. */ |
| 6321 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 6322 | |
| 6323 | /* Try to create the interface again */ |
| 6324 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
| 6325 | wds); |
| 6326 | } |
| 6327 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6328 | if (ret >= 0 && is_p2p_interface(iftype)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6329 | nl80211_disable_11b_rates(drv, ret, 1); |
| 6330 | |
| 6331 | return ret; |
| 6332 | } |
| 6333 | |
| 6334 | |
| 6335 | static void handle_tx_callback(void *ctx, u8 *buf, size_t len, int ok) |
| 6336 | { |
| 6337 | struct ieee80211_hdr *hdr; |
| 6338 | u16 fc; |
| 6339 | union wpa_event_data event; |
| 6340 | |
| 6341 | hdr = (struct ieee80211_hdr *) buf; |
| 6342 | fc = le_to_host16(hdr->frame_control); |
| 6343 | |
| 6344 | os_memset(&event, 0, sizeof(event)); |
| 6345 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); |
| 6346 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); |
| 6347 | event.tx_status.dst = hdr->addr1; |
| 6348 | event.tx_status.data = buf; |
| 6349 | event.tx_status.data_len = len; |
| 6350 | event.tx_status.ack = ok; |
| 6351 | wpa_supplicant_event(ctx, EVENT_TX_STATUS, &event); |
| 6352 | } |
| 6353 | |
| 6354 | |
| 6355 | static void from_unknown_sta(struct wpa_driver_nl80211_data *drv, |
| 6356 | u8 *buf, size_t len) |
| 6357 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6358 | struct ieee80211_hdr *hdr = (void *)buf; |
| 6359 | u16 fc; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6360 | union wpa_event_data event; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6361 | |
| 6362 | if (len < sizeof(*hdr)) |
| 6363 | return; |
| 6364 | |
| 6365 | fc = le_to_host16(hdr->frame_control); |
| 6366 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6367 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6368 | event.rx_from_unknown.bssid = get_hdr_bssid(hdr, len); |
| 6369 | event.rx_from_unknown.addr = hdr->addr2; |
| 6370 | event.rx_from_unknown.wds = (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) == |
| 6371 | (WLAN_FC_FROMDS | WLAN_FC_TODS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6372 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); |
| 6373 | } |
| 6374 | |
| 6375 | |
| 6376 | static void handle_frame(struct wpa_driver_nl80211_data *drv, |
| 6377 | u8 *buf, size_t len, int datarate, int ssi_signal) |
| 6378 | { |
| 6379 | struct ieee80211_hdr *hdr; |
| 6380 | u16 fc; |
| 6381 | union wpa_event_data event; |
| 6382 | |
| 6383 | hdr = (struct ieee80211_hdr *) buf; |
| 6384 | fc = le_to_host16(hdr->frame_control); |
| 6385 | |
| 6386 | switch (WLAN_FC_GET_TYPE(fc)) { |
| 6387 | case WLAN_FC_TYPE_MGMT: |
| 6388 | os_memset(&event, 0, sizeof(event)); |
| 6389 | event.rx_mgmt.frame = buf; |
| 6390 | event.rx_mgmt.frame_len = len; |
| 6391 | event.rx_mgmt.datarate = datarate; |
| 6392 | event.rx_mgmt.ssi_signal = ssi_signal; |
| 6393 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 6394 | break; |
| 6395 | case WLAN_FC_TYPE_CTRL: |
| 6396 | /* can only get here with PS-Poll frames */ |
| 6397 | wpa_printf(MSG_DEBUG, "CTRL"); |
| 6398 | from_unknown_sta(drv, buf, len); |
| 6399 | break; |
| 6400 | case WLAN_FC_TYPE_DATA: |
| 6401 | from_unknown_sta(drv, buf, len); |
| 6402 | break; |
| 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | |
| 6407 | static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx) |
| 6408 | { |
| 6409 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 6410 | int len; |
| 6411 | unsigned char buf[3000]; |
| 6412 | struct ieee80211_radiotap_iterator iter; |
| 6413 | int ret; |
| 6414 | int datarate = 0, ssi_signal = 0; |
| 6415 | int injected = 0, failed = 0, rxflags = 0; |
| 6416 | |
| 6417 | len = recv(sock, buf, sizeof(buf), 0); |
| 6418 | if (len < 0) { |
| 6419 | perror("recv"); |
| 6420 | return; |
| 6421 | } |
| 6422 | |
| 6423 | if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) { |
| 6424 | printf("received invalid radiotap frame\n"); |
| 6425 | return; |
| 6426 | } |
| 6427 | |
| 6428 | while (1) { |
| 6429 | ret = ieee80211_radiotap_iterator_next(&iter); |
| 6430 | if (ret == -ENOENT) |
| 6431 | break; |
| 6432 | if (ret) { |
| 6433 | printf("received invalid radiotap frame (%d)\n", ret); |
| 6434 | return; |
| 6435 | } |
| 6436 | switch (iter.this_arg_index) { |
| 6437 | case IEEE80211_RADIOTAP_FLAGS: |
| 6438 | if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS) |
| 6439 | len -= 4; |
| 6440 | break; |
| 6441 | case IEEE80211_RADIOTAP_RX_FLAGS: |
| 6442 | rxflags = 1; |
| 6443 | break; |
| 6444 | case IEEE80211_RADIOTAP_TX_FLAGS: |
| 6445 | injected = 1; |
| 6446 | failed = le_to_host16((*(uint16_t *) iter.this_arg)) & |
| 6447 | IEEE80211_RADIOTAP_F_TX_FAIL; |
| 6448 | break; |
| 6449 | case IEEE80211_RADIOTAP_DATA_RETRIES: |
| 6450 | break; |
| 6451 | case IEEE80211_RADIOTAP_CHANNEL: |
| 6452 | /* TODO: convert from freq/flags to channel number */ |
| 6453 | break; |
| 6454 | case IEEE80211_RADIOTAP_RATE: |
| 6455 | datarate = *iter.this_arg * 5; |
| 6456 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6457 | case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: |
| 6458 | ssi_signal = (s8) *iter.this_arg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6459 | break; |
| 6460 | } |
| 6461 | } |
| 6462 | |
| 6463 | if (rxflags && injected) |
| 6464 | return; |
| 6465 | |
| 6466 | if (!injected) |
| 6467 | handle_frame(drv, buf + iter.max_length, |
| 6468 | len - iter.max_length, datarate, ssi_signal); |
| 6469 | else |
| 6470 | handle_tx_callback(drv->ctx, buf + iter.max_length, |
| 6471 | len - iter.max_length, !failed); |
| 6472 | } |
| 6473 | |
| 6474 | |
| 6475 | /* |
| 6476 | * we post-process the filter code later and rewrite |
| 6477 | * this to the offset to the last instruction |
| 6478 | */ |
| 6479 | #define PASS 0xFF |
| 6480 | #define FAIL 0xFE |
| 6481 | |
| 6482 | static struct sock_filter msock_filter_insns[] = { |
| 6483 | /* |
| 6484 | * do a little-endian load of the radiotap length field |
| 6485 | */ |
| 6486 | /* load lower byte into A */ |
| 6487 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), |
| 6488 | /* put it into X (== index register) */ |
| 6489 | BPF_STMT(BPF_MISC| BPF_TAX, 0), |
| 6490 | /* load upper byte into A */ |
| 6491 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 3), |
| 6492 | /* left-shift it by 8 */ |
| 6493 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8), |
| 6494 | /* or with X */ |
| 6495 | BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0), |
| 6496 | /* put result into X */ |
| 6497 | BPF_STMT(BPF_MISC| BPF_TAX, 0), |
| 6498 | |
| 6499 | /* |
| 6500 | * Allow management frames through, this also gives us those |
| 6501 | * management frames that we sent ourselves with status |
| 6502 | */ |
| 6503 | /* load the lower byte of the IEEE 802.11 frame control field */ |
| 6504 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 6505 | /* mask off frame type and version */ |
| 6506 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF), |
| 6507 | /* accept frame if it's both 0, fall through otherwise */ |
| 6508 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0), |
| 6509 | |
| 6510 | /* |
| 6511 | * TODO: add a bit to radiotap RX flags that indicates |
| 6512 | * that the sending station is not associated, then |
| 6513 | * add a filter here that filters on our DA and that flag |
| 6514 | * to allow us to deauth frames to that bad station. |
| 6515 | * |
| 6516 | * For now allow all To DS data frames through. |
| 6517 | */ |
| 6518 | /* load the IEEE 802.11 frame control field */ |
| 6519 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 0), |
| 6520 | /* mask off frame type, version and DS status */ |
| 6521 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0F03), |
| 6522 | /* accept frame if version 0, type 2 and To DS, fall through otherwise |
| 6523 | */ |
| 6524 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0801, PASS, 0), |
| 6525 | |
| 6526 | #if 0 |
| 6527 | /* |
| 6528 | * drop non-data frames |
| 6529 | */ |
| 6530 | /* load the lower byte of the frame control field */ |
| 6531 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 6532 | /* mask off QoS bit */ |
| 6533 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0c), |
| 6534 | /* drop non-data frames */ |
| 6535 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 8, 0, FAIL), |
| 6536 | #endif |
| 6537 | /* load the upper byte of the frame control field */ |
| 6538 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), |
| 6539 | /* mask off toDS/fromDS */ |
| 6540 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x03), |
| 6541 | /* accept WDS frames */ |
| 6542 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 3, PASS, 0), |
| 6543 | |
| 6544 | /* |
| 6545 | * add header length to index |
| 6546 | */ |
| 6547 | /* load the lower byte of the frame control field */ |
| 6548 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), |
| 6549 | /* mask off QoS bit */ |
| 6550 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x80), |
| 6551 | /* right shift it by 6 to give 0 or 2 */ |
| 6552 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 6), |
| 6553 | /* add data frame header length */ |
| 6554 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 24), |
| 6555 | /* add index, was start of 802.11 header */ |
| 6556 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), |
| 6557 | /* move to index, now start of LL header */ |
| 6558 | BPF_STMT(BPF_MISC | BPF_TAX, 0), |
| 6559 | |
| 6560 | /* |
| 6561 | * Accept empty data frames, we use those for |
| 6562 | * polling activity. |
| 6563 | */ |
| 6564 | BPF_STMT(BPF_LD | BPF_W | BPF_LEN, 0), |
| 6565 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0), |
| 6566 | |
| 6567 | /* |
| 6568 | * Accept EAPOL frames |
| 6569 | */ |
| 6570 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), |
| 6571 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL), |
| 6572 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 4), |
| 6573 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL), |
| 6574 | |
| 6575 | /* keep these last two statements or change the code below */ |
| 6576 | /* return 0 == "DROP" */ |
| 6577 | BPF_STMT(BPF_RET | BPF_K, 0), |
| 6578 | /* return ~0 == "keep all" */ |
| 6579 | BPF_STMT(BPF_RET | BPF_K, ~0), |
| 6580 | }; |
| 6581 | |
| 6582 | static struct sock_fprog msock_filter = { |
| 6583 | .len = sizeof(msock_filter_insns)/sizeof(msock_filter_insns[0]), |
| 6584 | .filter = msock_filter_insns, |
| 6585 | }; |
| 6586 | |
| 6587 | |
| 6588 | static int add_monitor_filter(int s) |
| 6589 | { |
| 6590 | int idx; |
| 6591 | |
| 6592 | /* rewrite all PASS/FAIL jump offsets */ |
| 6593 | for (idx = 0; idx < msock_filter.len; idx++) { |
| 6594 | struct sock_filter *insn = &msock_filter_insns[idx]; |
| 6595 | |
| 6596 | if (BPF_CLASS(insn->code) == BPF_JMP) { |
| 6597 | if (insn->code == (BPF_JMP|BPF_JA)) { |
| 6598 | if (insn->k == PASS) |
| 6599 | insn->k = msock_filter.len - idx - 2; |
| 6600 | else if (insn->k == FAIL) |
| 6601 | insn->k = msock_filter.len - idx - 3; |
| 6602 | } |
| 6603 | |
| 6604 | if (insn->jt == PASS) |
| 6605 | insn->jt = msock_filter.len - idx - 2; |
| 6606 | else if (insn->jt == FAIL) |
| 6607 | insn->jt = msock_filter.len - idx - 3; |
| 6608 | |
| 6609 | if (insn->jf == PASS) |
| 6610 | insn->jf = msock_filter.len - idx - 2; |
| 6611 | else if (insn->jf == FAIL) |
| 6612 | insn->jf = msock_filter.len - idx - 3; |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, |
| 6617 | &msock_filter, sizeof(msock_filter))) { |
| 6618 | perror("SO_ATTACH_FILTER"); |
| 6619 | return -1; |
| 6620 | } |
| 6621 | |
| 6622 | return 0; |
| 6623 | } |
| 6624 | |
| 6625 | |
| 6626 | static void nl80211_remove_monitor_interface( |
| 6627 | struct wpa_driver_nl80211_data *drv) |
| 6628 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6629 | drv->monitor_refcount--; |
| 6630 | if (drv->monitor_refcount > 0) |
| 6631 | return; |
| 6632 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6633 | if (drv->monitor_ifidx >= 0) { |
| 6634 | nl80211_remove_iface(drv, drv->monitor_ifidx); |
| 6635 | drv->monitor_ifidx = -1; |
| 6636 | } |
| 6637 | if (drv->monitor_sock >= 0) { |
| 6638 | eloop_unregister_read_sock(drv->monitor_sock); |
| 6639 | close(drv->monitor_sock); |
| 6640 | drv->monitor_sock = -1; |
| 6641 | } |
| 6642 | } |
| 6643 | |
| 6644 | |
| 6645 | static int |
| 6646 | nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) |
| 6647 | { |
| 6648 | char buf[IFNAMSIZ]; |
| 6649 | struct sockaddr_ll ll; |
| 6650 | int optval; |
| 6651 | socklen_t optlen; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6652 | |
| 6653 | if (drv->monitor_ifidx >= 0) { |
| 6654 | drv->monitor_refcount++; |
| 6655 | return 0; |
| 6656 | } |
| 6657 | |
| 6658 | if (os_strncmp(drv->first_bss.ifname, "p2p-", 4) == 0) { |
| 6659 | /* |
| 6660 | * P2P interface name is of the format p2p-%s-%d. For monitor |
| 6661 | * interface name corresponding to P2P GO, replace "p2p-" with |
| 6662 | * "mon-" to retain the same interface name length and to |
| 6663 | * indicate that it is a monitor interface. |
| 6664 | */ |
| 6665 | snprintf(buf, IFNAMSIZ, "mon-%s", drv->first_bss.ifname + 4); |
| 6666 | } else { |
| 6667 | /* Non-P2P interface with AP functionality. */ |
| 6668 | snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss.ifname); |
| 6669 | } |
| 6670 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6671 | buf[IFNAMSIZ - 1] = '\0'; |
| 6672 | |
| 6673 | drv->monitor_ifidx = |
| 6674 | nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL, |
| 6675 | 0); |
| 6676 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 6677 | if (drv->monitor_ifidx == -EOPNOTSUPP) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6678 | /* |
| 6679 | * This is backward compatibility for a few versions of |
| 6680 | * the kernel only that didn't advertise the right |
| 6681 | * attributes for the only driver that then supported |
| 6682 | * AP mode w/o monitor -- ath6kl. |
| 6683 | */ |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 6684 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support " |
| 6685 | "monitor interface type - try to run without it"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6686 | drv->device_ap_sme = 1; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 6687 | } |
| 6688 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6689 | if (drv->monitor_ifidx < 0) |
| 6690 | return -1; |
| 6691 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6692 | if (linux_set_iface_flags(drv->global->ioctl_sock, buf, 1)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6693 | goto error; |
| 6694 | |
| 6695 | memset(&ll, 0, sizeof(ll)); |
| 6696 | ll.sll_family = AF_PACKET; |
| 6697 | ll.sll_ifindex = drv->monitor_ifidx; |
| 6698 | drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 6699 | if (drv->monitor_sock < 0) { |
| 6700 | perror("socket[PF_PACKET,SOCK_RAW]"); |
| 6701 | goto error; |
| 6702 | } |
| 6703 | |
| 6704 | if (add_monitor_filter(drv->monitor_sock)) { |
| 6705 | wpa_printf(MSG_INFO, "Failed to set socket filter for monitor " |
| 6706 | "interface; do filtering in user space"); |
| 6707 | /* This works, but will cost in performance. */ |
| 6708 | } |
| 6709 | |
| 6710 | if (bind(drv->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
| 6711 | perror("monitor socket bind"); |
| 6712 | goto error; |
| 6713 | } |
| 6714 | |
| 6715 | optlen = sizeof(optval); |
| 6716 | optval = 20; |
| 6717 | if (setsockopt |
| 6718 | (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) { |
| 6719 | perror("Failed to set socket priority"); |
| 6720 | goto error; |
| 6721 | } |
| 6722 | |
| 6723 | if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read, |
| 6724 | drv, NULL)) { |
| 6725 | printf("Could not register monitor read socket\n"); |
| 6726 | goto error; |
| 6727 | } |
| 6728 | |
| 6729 | return 0; |
| 6730 | error: |
| 6731 | nl80211_remove_monitor_interface(drv); |
| 6732 | return -1; |
| 6733 | } |
| 6734 | |
| 6735 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6736 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 6737 | { |
| 6738 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6739 | |
| 6740 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP - device_ap_sme=%d " |
| 6741 | "use_monitor=%d", drv->device_ap_sme, drv->use_monitor); |
| 6742 | |
| 6743 | /* |
| 6744 | * Disable Probe Request reporting unless we need it in this way for |
| 6745 | * devices that include the AP SME, in the other case (unless using |
| 6746 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 6747 | */ |
| 6748 | if (!drv->device_ap_sme) |
| 6749 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 6750 | |
| 6751 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 6752 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 6753 | return -1; |
| 6754 | |
| 6755 | if (drv->device_ap_sme && !drv->use_monitor) |
| 6756 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 6757 | return -1; |
| 6758 | |
| 6759 | if (!drv->device_ap_sme && drv->use_monitor && |
| 6760 | nl80211_create_monitor_interface(drv) && |
| 6761 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6762 | return -1; |
| 6763 | |
| 6764 | #ifdef ANDROID_P2P |
| 6765 | if (drv->device_ap_sme && drv->use_monitor) |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 6766 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 6767 | return -1; |
| 6768 | |
| 6769 | if (drv->use_monitor && |
| 6770 | nl80211_create_monitor_interface(drv)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6771 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6772 | #endif |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6773 | |
| 6774 | if (drv->device_ap_sme && |
| 6775 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 6776 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 6777 | "Probe Request frame reporting in AP mode"); |
| 6778 | /* Try to survive without this */ |
| 6779 | } |
| 6780 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6781 | return 0; |
| 6782 | } |
| 6783 | |
| 6784 | |
| 6785 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 6786 | { |
| 6787 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6788 | |
| 6789 | if (drv->device_ap_sme) { |
| 6790 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 6791 | if (!drv->use_monitor) |
| 6792 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 6793 | } else if (drv->use_monitor) |
| 6794 | nl80211_remove_monitor_interface(drv); |
| 6795 | else |
| 6796 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 6797 | |
| 6798 | bss->beacon_set = 0; |
| 6799 | } |
| 6800 | |
| 6801 | |
| 6802 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 6803 | const u8 *addr, const u8 *data, |
| 6804 | size_t data_len) |
| 6805 | { |
| 6806 | struct sockaddr_ll ll; |
| 6807 | int ret; |
| 6808 | |
| 6809 | if (bss->drv->eapol_tx_sock < 0) { |
| 6810 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 6811 | return -1; |
| 6812 | } |
| 6813 | |
| 6814 | os_memset(&ll, 0, sizeof(ll)); |
| 6815 | ll.sll_family = AF_PACKET; |
| 6816 | ll.sll_ifindex = bss->ifindex; |
| 6817 | ll.sll_protocol = htons(ETH_P_PAE); |
| 6818 | ll.sll_halen = ETH_ALEN; |
| 6819 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 6820 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 6821 | (struct sockaddr *) &ll, sizeof(ll)); |
| 6822 | if (ret < 0) |
| 6823 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 6824 | strerror(errno)); |
| 6825 | |
| 6826 | return ret; |
| 6827 | } |
| 6828 | |
| 6829 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6830 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 6831 | |
| 6832 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 6833 | void *priv, const u8 *addr, const u8 *data, |
| 6834 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 6835 | { |
| 6836 | struct i802_bss *bss = priv; |
| 6837 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6838 | struct ieee80211_hdr *hdr; |
| 6839 | size_t len; |
| 6840 | u8 *pos; |
| 6841 | int res; |
| 6842 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 6843 | #ifndef ANDROID_P2P |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6844 | if (drv->device_ap_sme || !drv->use_monitor) |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 6845 | #else |
| 6846 | if (drv->device_ap_sme && !drv->use_monitor) |
| 6847 | #endif |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6848 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 6849 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6850 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 6851 | data_len; |
| 6852 | hdr = os_zalloc(len); |
| 6853 | if (hdr == NULL) { |
| 6854 | printf("malloc() failed for i802_send_data(len=%lu)\n", |
| 6855 | (unsigned long) len); |
| 6856 | return -1; |
| 6857 | } |
| 6858 | |
| 6859 | hdr->frame_control = |
| 6860 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 6861 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 6862 | if (encrypt) |
| 6863 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 6864 | if (qos) { |
| 6865 | hdr->frame_control |= |
| 6866 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 6867 | } |
| 6868 | |
| 6869 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 6870 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 6871 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 6872 | pos = (u8 *) (hdr + 1); |
| 6873 | |
| 6874 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6875 | /* Set highest priority in QoS header */ |
| 6876 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6877 | pos[1] = 0; |
| 6878 | pos += 2; |
| 6879 | } |
| 6880 | |
| 6881 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 6882 | pos += sizeof(rfc1042_header); |
| 6883 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 6884 | pos += 2; |
| 6885 | memcpy(pos, data, data_len); |
| 6886 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6887 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
| 6888 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6889 | if (res < 0) { |
| 6890 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 6891 | "failed: %d (%s)", |
| 6892 | (unsigned long) len, errno, strerror(errno)); |
| 6893 | } |
| 6894 | os_free(hdr); |
| 6895 | |
| 6896 | return res; |
| 6897 | } |
| 6898 | |
| 6899 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6900 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
| 6901 | int total_flags, |
| 6902 | int flags_or, int flags_and) |
| 6903 | { |
| 6904 | struct i802_bss *bss = priv; |
| 6905 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6906 | struct nl_msg *msg; |
| 6907 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6908 | struct nl80211_sta_flag_update upd; |
| 6909 | |
| 6910 | msg = nlmsg_alloc(); |
| 6911 | if (!msg) |
| 6912 | return -ENOMEM; |
| 6913 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6914 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6915 | |
| 6916 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 6917 | if_nametoindex(bss->ifname)); |
| 6918 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6919 | |
| 6920 | /* |
| 6921 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 6922 | * can be removed eventually. |
| 6923 | */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6924 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
| 6925 | if (!flags) |
| 6926 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6927 | if (total_flags & WPA_STA_AUTHORIZED) |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6928 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6929 | |
| 6930 | if (total_flags & WPA_STA_WMM) |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6931 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_WME); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6932 | |
| 6933 | if (total_flags & WPA_STA_SHORT_PREAMBLE) |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6934 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_SHORT_PREAMBLE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6935 | |
| 6936 | if (total_flags & WPA_STA_MFP) |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6937 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_MFP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6938 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6939 | if (total_flags & WPA_STA_TDLS_PEER) |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6940 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6941 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 6942 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6943 | |
| 6944 | os_memset(&upd, 0, sizeof(upd)); |
| 6945 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 6946 | upd.set = sta_flags_nl80211(flags_or); |
| 6947 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 6948 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6949 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6950 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6951 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6952 | return -ENOBUFS; |
| 6953 | } |
| 6954 | |
| 6955 | |
| 6956 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 6957 | struct wpa_driver_associate_params *params) |
| 6958 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6959 | enum nl80211_iftype nlmode, old_mode; |
| 6960 | struct hostapd_freq_params freq = { |
| 6961 | .freq = params->freq, |
| 6962 | }; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6963 | |
| 6964 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6965 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 6966 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6967 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 6968 | } else |
| 6969 | nlmode = NL80211_IFTYPE_AP; |
| 6970 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6971 | old_mode = drv->nlmode; |
| 6972 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, nlmode)) { |
| 6973 | nl80211_remove_monitor_interface(drv); |
| 6974 | return -1; |
| 6975 | } |
| 6976 | |
| 6977 | if (wpa_driver_nl80211_set_freq(&drv->first_bss, &freq)) { |
| 6978 | if (old_mode != nlmode) |
| 6979 | wpa_driver_nl80211_set_mode(&drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6980 | nl80211_remove_monitor_interface(drv); |
| 6981 | return -1; |
| 6982 | } |
| 6983 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6984 | return 0; |
| 6985 | } |
| 6986 | |
| 6987 | |
| 6988 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv) |
| 6989 | { |
| 6990 | struct nl_msg *msg; |
| 6991 | int ret = -1; |
| 6992 | |
| 6993 | msg = nlmsg_alloc(); |
| 6994 | if (!msg) |
| 6995 | return -1; |
| 6996 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6997 | nl80211_cmd(drv, msg, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6998 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 6999 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7000 | msg = NULL; |
| 7001 | if (ret) { |
| 7002 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 7003 | "(%s)", ret, strerror(-ret)); |
| 7004 | goto nla_put_failure; |
| 7005 | } |
| 7006 | |
| 7007 | ret = 0; |
| 7008 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS request sent successfully"); |
| 7009 | |
| 7010 | nla_put_failure: |
| 7011 | nlmsg_free(msg); |
| 7012 | return ret; |
| 7013 | } |
| 7014 | |
| 7015 | |
| 7016 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 7017 | struct wpa_driver_associate_params *params) |
| 7018 | { |
| 7019 | struct nl_msg *msg; |
| 7020 | int ret = -1; |
| 7021 | int count = 0; |
| 7022 | |
| 7023 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 7024 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7025 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, |
| 7026 | NL80211_IFTYPE_ADHOC)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7027 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 7028 | "IBSS mode"); |
| 7029 | return -1; |
| 7030 | } |
| 7031 | |
| 7032 | retry: |
| 7033 | msg = nlmsg_alloc(); |
| 7034 | if (!msg) |
| 7035 | return -1; |
| 7036 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7037 | nl80211_cmd(drv, msg, 0, NL80211_CMD_JOIN_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7038 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7039 | |
| 7040 | if (params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 7041 | goto nla_put_failure; |
| 7042 | |
| 7043 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 7044 | params->ssid, params->ssid_len); |
| 7045 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 7046 | params->ssid); |
| 7047 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 7048 | drv->ssid_len = params->ssid_len; |
| 7049 | |
| 7050 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 7051 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
| 7052 | |
| 7053 | ret = nl80211_set_conn_keys(params, msg); |
| 7054 | if (ret) |
| 7055 | goto nla_put_failure; |
| 7056 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7057 | if (params->bssid && params->fixed_bssid) { |
| 7058 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 7059 | MAC2STR(params->bssid)); |
| 7060 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 7061 | } |
| 7062 | |
| 7063 | if (params->key_mgmt_suite == KEY_MGMT_802_1X || |
| 7064 | params->key_mgmt_suite == KEY_MGMT_PSK || |
| 7065 | params->key_mgmt_suite == KEY_MGMT_802_1X_SHA256 || |
| 7066 | params->key_mgmt_suite == KEY_MGMT_PSK_SHA256) { |
| 7067 | wpa_printf(MSG_DEBUG, " * control port"); |
| 7068 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
| 7069 | } |
| 7070 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7071 | if (params->wpa_ie) { |
| 7072 | wpa_hexdump(MSG_DEBUG, |
| 7073 | " * Extra IEs for Beacon/Probe Response frames", |
| 7074 | params->wpa_ie, params->wpa_ie_len); |
| 7075 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 7076 | params->wpa_ie); |
| 7077 | } |
| 7078 | |
| 7079 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7080 | msg = NULL; |
| 7081 | if (ret) { |
| 7082 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 7083 | ret, strerror(-ret)); |
| 7084 | count++; |
| 7085 | if (ret == -EALREADY && count == 1) { |
| 7086 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 7087 | "forced leave"); |
| 7088 | nl80211_leave_ibss(drv); |
| 7089 | nlmsg_free(msg); |
| 7090 | goto retry; |
| 7091 | } |
| 7092 | |
| 7093 | goto nla_put_failure; |
| 7094 | } |
| 7095 | ret = 0; |
| 7096 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS request sent successfully"); |
| 7097 | |
| 7098 | nla_put_failure: |
| 7099 | nlmsg_free(msg); |
| 7100 | return ret; |
| 7101 | } |
| 7102 | |
| 7103 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7104 | static int wpa_driver_nl80211_try_connect( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7105 | struct wpa_driver_nl80211_data *drv, |
| 7106 | struct wpa_driver_associate_params *params) |
| 7107 | { |
| 7108 | struct nl_msg *msg; |
| 7109 | enum nl80211_auth_type type; |
| 7110 | int ret = 0; |
| 7111 | int algs; |
| 7112 | |
| 7113 | msg = nlmsg_alloc(); |
| 7114 | if (!msg) |
| 7115 | return -1; |
| 7116 | |
| 7117 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7118 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7119 | |
| 7120 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7121 | if (params->bssid) { |
| 7122 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 7123 | MAC2STR(params->bssid)); |
| 7124 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 7125 | } |
| 7126 | if (params->freq) { |
| 7127 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 7128 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
| 7129 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7130 | if (params->bg_scan_period >= 0) { |
| 7131 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 7132 | params->bg_scan_period); |
| 7133 | NLA_PUT_U16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 7134 | params->bg_scan_period); |
| 7135 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7136 | if (params->ssid) { |
| 7137 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 7138 | params->ssid, params->ssid_len); |
| 7139 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 7140 | params->ssid); |
| 7141 | if (params->ssid_len > sizeof(drv->ssid)) |
| 7142 | goto nla_put_failure; |
| 7143 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 7144 | drv->ssid_len = params->ssid_len; |
| 7145 | } |
| 7146 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
| 7147 | if (params->wpa_ie) |
| 7148 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 7149 | params->wpa_ie); |
| 7150 | |
| 7151 | algs = 0; |
| 7152 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 7153 | algs++; |
| 7154 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 7155 | algs++; |
| 7156 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 7157 | algs++; |
| 7158 | if (algs > 1) { |
| 7159 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 7160 | "selection"); |
| 7161 | goto skip_auth_type; |
| 7162 | } |
| 7163 | |
| 7164 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 7165 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 7166 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 7167 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 7168 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 7169 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 7170 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 7171 | type = NL80211_AUTHTYPE_FT; |
| 7172 | else |
| 7173 | goto nla_put_failure; |
| 7174 | |
| 7175 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 7176 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); |
| 7177 | |
| 7178 | skip_auth_type: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7179 | if (params->wpa_proto) { |
| 7180 | enum nl80211_wpa_versions ver = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7181 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7182 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 7183 | ver |= NL80211_WPA_VERSION_1; |
| 7184 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 7185 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7186 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7187 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7188 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); |
| 7189 | } |
| 7190 | |
| 7191 | if (params->pairwise_suite != CIPHER_NONE) { |
| 7192 | int cipher; |
| 7193 | |
| 7194 | switch (params->pairwise_suite) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7195 | case CIPHER_SMS4: |
| 7196 | cipher = WLAN_CIPHER_SUITE_SMS4; |
| 7197 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7198 | case CIPHER_WEP40: |
| 7199 | cipher = WLAN_CIPHER_SUITE_WEP40; |
| 7200 | break; |
| 7201 | case CIPHER_WEP104: |
| 7202 | cipher = WLAN_CIPHER_SUITE_WEP104; |
| 7203 | break; |
| 7204 | case CIPHER_CCMP: |
| 7205 | cipher = WLAN_CIPHER_SUITE_CCMP; |
| 7206 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7207 | case CIPHER_GCMP: |
| 7208 | cipher = WLAN_CIPHER_SUITE_GCMP; |
| 7209 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7210 | case CIPHER_TKIP: |
| 7211 | default: |
| 7212 | cipher = WLAN_CIPHER_SUITE_TKIP; |
| 7213 | break; |
| 7214 | } |
| 7215 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); |
| 7216 | } |
| 7217 | |
| 7218 | if (params->group_suite != CIPHER_NONE) { |
| 7219 | int cipher; |
| 7220 | |
| 7221 | switch (params->group_suite) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7222 | case CIPHER_SMS4: |
| 7223 | cipher = WLAN_CIPHER_SUITE_SMS4; |
| 7224 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7225 | case CIPHER_WEP40: |
| 7226 | cipher = WLAN_CIPHER_SUITE_WEP40; |
| 7227 | break; |
| 7228 | case CIPHER_WEP104: |
| 7229 | cipher = WLAN_CIPHER_SUITE_WEP104; |
| 7230 | break; |
| 7231 | case CIPHER_CCMP: |
| 7232 | cipher = WLAN_CIPHER_SUITE_CCMP; |
| 7233 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7234 | case CIPHER_GCMP: |
| 7235 | cipher = WLAN_CIPHER_SUITE_GCMP; |
| 7236 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7237 | case CIPHER_TKIP: |
| 7238 | default: |
| 7239 | cipher = WLAN_CIPHER_SUITE_TKIP; |
| 7240 | break; |
| 7241 | } |
| 7242 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); |
| 7243 | } |
| 7244 | |
| 7245 | if (params->key_mgmt_suite == KEY_MGMT_802_1X || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7246 | params->key_mgmt_suite == KEY_MGMT_PSK || |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7247 | params->key_mgmt_suite == KEY_MGMT_FT_802_1X || |
| 7248 | params->key_mgmt_suite == KEY_MGMT_FT_PSK || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7249 | params->key_mgmt_suite == KEY_MGMT_CCKM) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7250 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 7251 | |
| 7252 | switch (params->key_mgmt_suite) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7253 | case KEY_MGMT_CCKM: |
| 7254 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 7255 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7256 | case KEY_MGMT_802_1X: |
| 7257 | mgmt = WLAN_AKM_SUITE_8021X; |
| 7258 | break; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7259 | case KEY_MGMT_FT_802_1X: |
| 7260 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 7261 | break; |
| 7262 | case KEY_MGMT_FT_PSK: |
| 7263 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 7264 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7265 | case KEY_MGMT_PSK: |
| 7266 | default: |
| 7267 | mgmt = WLAN_AKM_SUITE_PSK; |
| 7268 | break; |
| 7269 | } |
| 7270 | NLA_PUT_U32(msg, NL80211_ATTR_AKM_SUITES, mgmt); |
| 7271 | } |
| 7272 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7273 | #ifdef CONFIG_IEEE80211W |
| 7274 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) |
| 7275 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); |
| 7276 | #endif /* CONFIG_IEEE80211W */ |
| 7277 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7278 | if (params->disable_ht) |
| 7279 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT); |
| 7280 | |
| 7281 | if (params->htcaps && params->htcaps_mask) { |
| 7282 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 7283 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps); |
| 7284 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 7285 | params->htcaps_mask); |
| 7286 | } |
| 7287 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 7288 | #ifdef CONFIG_VHT_OVERRIDES |
| 7289 | if (params->disable_vht) { |
| 7290 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 7291 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_VHT); |
| 7292 | } |
| 7293 | |
| 7294 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 7295 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 7296 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, sz, params->vhtcaps); |
| 7297 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 7298 | params->vhtcaps_mask); |
| 7299 | } |
| 7300 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 7301 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7302 | ret = nl80211_set_conn_keys(params, msg); |
| 7303 | if (ret) |
| 7304 | goto nla_put_failure; |
| 7305 | |
| 7306 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7307 | msg = NULL; |
| 7308 | if (ret) { |
| 7309 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 7310 | "(%s)", ret, strerror(-ret)); |
| 7311 | goto nla_put_failure; |
| 7312 | } |
| 7313 | ret = 0; |
| 7314 | wpa_printf(MSG_DEBUG, "nl80211: Connect request send successfully"); |
| 7315 | |
| 7316 | nla_put_failure: |
| 7317 | nlmsg_free(msg); |
| 7318 | return ret; |
| 7319 | |
| 7320 | } |
| 7321 | |
| 7322 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7323 | static int wpa_driver_nl80211_connect( |
| 7324 | struct wpa_driver_nl80211_data *drv, |
| 7325 | struct wpa_driver_associate_params *params) |
| 7326 | { |
| 7327 | int ret = wpa_driver_nl80211_try_connect(drv, params); |
| 7328 | if (ret == -EALREADY) { |
| 7329 | /* |
| 7330 | * cfg80211 does not currently accept new connections if |
| 7331 | * we are already connected. As a workaround, force |
| 7332 | * disconnection and try again. |
| 7333 | */ |
| 7334 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 7335 | "disconnecting before reassociation " |
| 7336 | "attempt"); |
| 7337 | if (wpa_driver_nl80211_disconnect( |
| 7338 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 7339 | return -1; |
| 7340 | /* Ignore the next local disconnect message. */ |
| 7341 | drv->ignore_next_local_disconnect = 1; |
| 7342 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 7343 | } |
| 7344 | return ret; |
| 7345 | } |
| 7346 | |
| 7347 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7348 | static int wpa_driver_nl80211_associate( |
| 7349 | void *priv, struct wpa_driver_associate_params *params) |
| 7350 | { |
| 7351 | struct i802_bss *bss = priv; |
| 7352 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7353 | int ret = -1; |
| 7354 | struct nl_msg *msg; |
| 7355 | |
| 7356 | if (params->mode == IEEE80211_MODE_AP) |
| 7357 | return wpa_driver_nl80211_ap(drv, params); |
| 7358 | |
| 7359 | if (params->mode == IEEE80211_MODE_IBSS) |
| 7360 | return wpa_driver_nl80211_ibss(drv, params); |
| 7361 | |
| 7362 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7363 | enum nl80211_iftype nlmode = params->p2p ? |
| 7364 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 7365 | |
| 7366 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7367 | return -1; |
| 7368 | return wpa_driver_nl80211_connect(drv, params); |
| 7369 | } |
| 7370 | |
| 7371 | drv->associated = 0; |
| 7372 | |
| 7373 | msg = nlmsg_alloc(); |
| 7374 | if (!msg) |
| 7375 | return -1; |
| 7376 | |
| 7377 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 7378 | drv->ifindex); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7379 | nl80211_cmd(drv, msg, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7380 | |
| 7381 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7382 | if (params->bssid) { |
| 7383 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 7384 | MAC2STR(params->bssid)); |
| 7385 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); |
| 7386 | } |
| 7387 | if (params->freq) { |
| 7388 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 7389 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); |
| 7390 | drv->assoc_freq = params->freq; |
| 7391 | } else |
| 7392 | drv->assoc_freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7393 | if (params->bg_scan_period >= 0) { |
| 7394 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 7395 | params->bg_scan_period); |
| 7396 | NLA_PUT_U16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 7397 | params->bg_scan_period); |
| 7398 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7399 | if (params->ssid) { |
| 7400 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 7401 | params->ssid, params->ssid_len); |
| 7402 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 7403 | params->ssid); |
| 7404 | if (params->ssid_len > sizeof(drv->ssid)) |
| 7405 | goto nla_put_failure; |
| 7406 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 7407 | drv->ssid_len = params->ssid_len; |
| 7408 | } |
| 7409 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
| 7410 | if (params->wpa_ie) |
| 7411 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 7412 | params->wpa_ie); |
| 7413 | |
| 7414 | if (params->pairwise_suite != CIPHER_NONE) { |
| 7415 | int cipher; |
| 7416 | |
| 7417 | switch (params->pairwise_suite) { |
| 7418 | case CIPHER_WEP40: |
| 7419 | cipher = WLAN_CIPHER_SUITE_WEP40; |
| 7420 | break; |
| 7421 | case CIPHER_WEP104: |
| 7422 | cipher = WLAN_CIPHER_SUITE_WEP104; |
| 7423 | break; |
| 7424 | case CIPHER_CCMP: |
| 7425 | cipher = WLAN_CIPHER_SUITE_CCMP; |
| 7426 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7427 | case CIPHER_GCMP: |
| 7428 | cipher = WLAN_CIPHER_SUITE_GCMP; |
| 7429 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7430 | case CIPHER_TKIP: |
| 7431 | default: |
| 7432 | cipher = WLAN_CIPHER_SUITE_TKIP; |
| 7433 | break; |
| 7434 | } |
| 7435 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
| 7436 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); |
| 7437 | } |
| 7438 | |
| 7439 | if (params->group_suite != CIPHER_NONE) { |
| 7440 | int cipher; |
| 7441 | |
| 7442 | switch (params->group_suite) { |
| 7443 | case CIPHER_WEP40: |
| 7444 | cipher = WLAN_CIPHER_SUITE_WEP40; |
| 7445 | break; |
| 7446 | case CIPHER_WEP104: |
| 7447 | cipher = WLAN_CIPHER_SUITE_WEP104; |
| 7448 | break; |
| 7449 | case CIPHER_CCMP: |
| 7450 | cipher = WLAN_CIPHER_SUITE_CCMP; |
| 7451 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7452 | case CIPHER_GCMP: |
| 7453 | cipher = WLAN_CIPHER_SUITE_GCMP; |
| 7454 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7455 | case CIPHER_TKIP: |
| 7456 | default: |
| 7457 | cipher = WLAN_CIPHER_SUITE_TKIP; |
| 7458 | break; |
| 7459 | } |
| 7460 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
| 7461 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); |
| 7462 | } |
| 7463 | |
| 7464 | #ifdef CONFIG_IEEE80211W |
| 7465 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) |
| 7466 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); |
| 7467 | #endif /* CONFIG_IEEE80211W */ |
| 7468 | |
| 7469 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
| 7470 | |
| 7471 | if (params->prev_bssid) { |
| 7472 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 7473 | MAC2STR(params->prev_bssid)); |
| 7474 | NLA_PUT(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 7475 | params->prev_bssid); |
| 7476 | } |
| 7477 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7478 | if (params->disable_ht) |
| 7479 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT); |
| 7480 | |
| 7481 | if (params->htcaps && params->htcaps_mask) { |
| 7482 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 7483 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps); |
| 7484 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 7485 | params->htcaps_mask); |
| 7486 | } |
| 7487 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 7488 | #ifdef CONFIG_VHT_OVERRIDES |
| 7489 | if (params->disable_vht) { |
| 7490 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 7491 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_VHT); |
| 7492 | } |
| 7493 | |
| 7494 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 7495 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 7496 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, sz, params->vhtcaps); |
| 7497 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 7498 | params->vhtcaps_mask); |
| 7499 | } |
| 7500 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 7501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7502 | if (params->p2p) |
| 7503 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 7504 | |
| 7505 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7506 | msg = NULL; |
| 7507 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7508 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 7509 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 7510 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7511 | nl80211_dump_scan(drv); |
| 7512 | goto nla_put_failure; |
| 7513 | } |
| 7514 | ret = 0; |
| 7515 | wpa_printf(MSG_DEBUG, "nl80211: Association request send " |
| 7516 | "successfully"); |
| 7517 | |
| 7518 | nla_put_failure: |
| 7519 | nlmsg_free(msg); |
| 7520 | return ret; |
| 7521 | } |
| 7522 | |
| 7523 | |
| 7524 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7525 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7526 | { |
| 7527 | struct nl_msg *msg; |
| 7528 | int ret = -ENOBUFS; |
| 7529 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7530 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 7531 | ifindex, mode, nl80211_iftype_str(mode)); |
| 7532 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7533 | msg = nlmsg_alloc(); |
| 7534 | if (!msg) |
| 7535 | return -ENOMEM; |
| 7536 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7537 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7538 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 7539 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, mode); |
| 7540 | |
| 7541 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7542 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7543 | if (!ret) |
| 7544 | return 0; |
| 7545 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7546 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7547 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 7548 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 7549 | return ret; |
| 7550 | } |
| 7551 | |
| 7552 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7553 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 7554 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7555 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7556 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7557 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7558 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7559 | int was_ap = is_ap_interface(drv->nlmode); |
| 7560 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7561 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7562 | res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 7563 | if (res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7564 | drv->nlmode = nlmode; |
| 7565 | ret = 0; |
| 7566 | goto done; |
| 7567 | } |
| 7568 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7569 | if (res == -ENODEV) |
| 7570 | return -1; |
| 7571 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7572 | if (nlmode == drv->nlmode) { |
| 7573 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 7574 | "requested mode - ignore error"); |
| 7575 | ret = 0; |
| 7576 | goto done; /* Already in the requested mode */ |
| 7577 | } |
| 7578 | |
| 7579 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 7580 | * take the device down, try to set the mode again, and bring the |
| 7581 | * device back up. |
| 7582 | */ |
| 7583 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 7584 | "interface down"); |
| 7585 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7586 | res = linux_set_iface_flags(drv->global->ioctl_sock, |
| 7587 | bss->ifname, 0); |
| 7588 | if (res == -EACCES || res == -ENODEV) |
| 7589 | break; |
| 7590 | if (res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7591 | /* Try to set the mode again while the interface is |
| 7592 | * down */ |
| 7593 | ret = nl80211_set_mode(drv, drv->ifindex, nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7594 | if (ret == -EACCES) |
| 7595 | break; |
| 7596 | res = linux_set_iface_flags(drv->global->ioctl_sock, |
| 7597 | bss->ifname, 1); |
| 7598 | if (res && !ret) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7599 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7600 | else if (ret != -EBUSY) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7601 | break; |
| 7602 | } else |
| 7603 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 7604 | "interface down"); |
| 7605 | os_sleep(0, 100000); |
| 7606 | } |
| 7607 | |
| 7608 | if (!ret) { |
| 7609 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 7610 | "interface is down"); |
| 7611 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7612 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7613 | } |
| 7614 | |
| 7615 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7616 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7617 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 7618 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7619 | return ret; |
| 7620 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7621 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7622 | if (is_p2p_interface(nlmode)) |
| 7623 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 7624 | else if (drv->disabled_11b_rates) |
| 7625 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 7626 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7627 | if (is_ap_interface(nlmode)) { |
| 7628 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 7629 | /* Setup additional AP mode functionality if needed */ |
| 7630 | if (nl80211_setup_ap(bss)) |
| 7631 | return -1; |
| 7632 | } else if (was_ap) { |
| 7633 | /* Remove additional AP mode functionality */ |
| 7634 | nl80211_teardown_ap(bss); |
| 7635 | } else { |
| 7636 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 7637 | } |
| 7638 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7639 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7640 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 7641 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 7642 | "frame processing - ignore for now"); |
| 7643 | |
| 7644 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7645 | } |
| 7646 | |
| 7647 | |
| 7648 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 7649 | struct wpa_driver_capa *capa) |
| 7650 | { |
| 7651 | struct i802_bss *bss = priv; |
| 7652 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7653 | if (!drv->has_capability) |
| 7654 | return -1; |
| 7655 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 7656 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 7657 | capa->extended_capa = drv->extended_capa; |
| 7658 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 7659 | capa->extended_capa_len = drv->extended_capa_len; |
| 7660 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7661 | return 0; |
| 7662 | } |
| 7663 | |
| 7664 | |
| 7665 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 7666 | { |
| 7667 | struct i802_bss *bss = priv; |
| 7668 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7669 | |
| 7670 | wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)", |
| 7671 | __func__, drv->operstate, state, state ? "UP" : "DORMANT"); |
| 7672 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7673 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7674 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 7675 | } |
| 7676 | |
| 7677 | |
| 7678 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 7679 | { |
| 7680 | struct i802_bss *bss = priv; |
| 7681 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7682 | struct nl_msg *msg; |
| 7683 | struct nl80211_sta_flag_update upd; |
| 7684 | |
| 7685 | msg = nlmsg_alloc(); |
| 7686 | if (!msg) |
| 7687 | return -ENOMEM; |
| 7688 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7689 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7690 | |
| 7691 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 7692 | if_nametoindex(bss->ifname)); |
| 7693 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
| 7694 | |
| 7695 | os_memset(&upd, 0, sizeof(upd)); |
| 7696 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 7697 | if (authorized) |
| 7698 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 7699 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
| 7700 | |
| 7701 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7702 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7703 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7704 | return -ENOBUFS; |
| 7705 | } |
| 7706 | |
| 7707 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7708 | /* Set kernel driver on given frequency (MHz) */ |
| 7709 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7710 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7711 | struct i802_bss *bss = priv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7712 | return wpa_driver_nl80211_set_freq(bss, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7713 | } |
| 7714 | |
| 7715 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7716 | #if defined(HOSTAPD) || defined(CONFIG_AP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7717 | |
| 7718 | static inline int min_int(int a, int b) |
| 7719 | { |
| 7720 | if (a < b) |
| 7721 | return a; |
| 7722 | return b; |
| 7723 | } |
| 7724 | |
| 7725 | |
| 7726 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 7727 | { |
| 7728 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7729 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7730 | |
| 7731 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7732 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7733 | |
| 7734 | /* |
| 7735 | * TODO: validate the key index and mac address! |
| 7736 | * Otherwise, there's a race condition as soon as |
| 7737 | * the kernel starts sending key notifications. |
| 7738 | */ |
| 7739 | |
| 7740 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 7741 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 7742 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 7743 | return NL_SKIP; |
| 7744 | } |
| 7745 | |
| 7746 | |
| 7747 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 7748 | int idx, u8 *seq) |
| 7749 | { |
| 7750 | struct i802_bss *bss = priv; |
| 7751 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7752 | struct nl_msg *msg; |
| 7753 | |
| 7754 | msg = nlmsg_alloc(); |
| 7755 | if (!msg) |
| 7756 | return -ENOMEM; |
| 7757 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7758 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_KEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7759 | |
| 7760 | if (addr) |
| 7761 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7762 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx); |
| 7763 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface)); |
| 7764 | |
| 7765 | memset(seq, 0, 6); |
| 7766 | |
| 7767 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
| 7768 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7769 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7770 | return -ENOBUFS; |
| 7771 | } |
| 7772 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7773 | |
| 7774 | static int i802_set_rts(void *priv, int rts) |
| 7775 | { |
| 7776 | struct i802_bss *bss = priv; |
| 7777 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7778 | struct nl_msg *msg; |
| 7779 | int ret = -ENOBUFS; |
| 7780 | u32 val; |
| 7781 | |
| 7782 | msg = nlmsg_alloc(); |
| 7783 | if (!msg) |
| 7784 | return -ENOMEM; |
| 7785 | |
| 7786 | if (rts >= 2347) |
| 7787 | val = (u32) -1; |
| 7788 | else |
| 7789 | val = rts; |
| 7790 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7791 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7792 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7793 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val); |
| 7794 | |
| 7795 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7796 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7797 | if (!ret) |
| 7798 | return 0; |
| 7799 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7800 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7801 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 7802 | "%d (%s)", rts, ret, strerror(-ret)); |
| 7803 | return ret; |
| 7804 | } |
| 7805 | |
| 7806 | |
| 7807 | static int i802_set_frag(void *priv, int frag) |
| 7808 | { |
| 7809 | struct i802_bss *bss = priv; |
| 7810 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7811 | struct nl_msg *msg; |
| 7812 | int ret = -ENOBUFS; |
| 7813 | u32 val; |
| 7814 | |
| 7815 | msg = nlmsg_alloc(); |
| 7816 | if (!msg) |
| 7817 | return -ENOMEM; |
| 7818 | |
| 7819 | if (frag >= 2346) |
| 7820 | val = (u32) -1; |
| 7821 | else |
| 7822 | val = frag; |
| 7823 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7824 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7825 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 7826 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val); |
| 7827 | |
| 7828 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7829 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7830 | if (!ret) |
| 7831 | return 0; |
| 7832 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7833 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7834 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 7835 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 7836 | return ret; |
| 7837 | } |
| 7838 | |
| 7839 | |
| 7840 | static int i802_flush(void *priv) |
| 7841 | { |
| 7842 | struct i802_bss *bss = priv; |
| 7843 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7844 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7845 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7846 | |
| 7847 | msg = nlmsg_alloc(); |
| 7848 | if (!msg) |
| 7849 | return -1; |
| 7850 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7851 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7852 | |
| 7853 | /* |
| 7854 | * XXX: FIX! this needs to flush all VLANs too |
| 7855 | */ |
| 7856 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 7857 | if_nametoindex(bss->ifname)); |
| 7858 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7859 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7860 | if (res) { |
| 7861 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 7862 | "(%s)", res, strerror(-res)); |
| 7863 | } |
| 7864 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7865 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7866 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7867 | return -ENOBUFS; |
| 7868 | } |
| 7869 | |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7870 | #endif /* HOSTAPD || CONFIG_AP */ |
| 7871 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7872 | |
| 7873 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 7874 | { |
| 7875 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7876 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7877 | struct hostap_sta_driver_data *data = arg; |
| 7878 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 7879 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 7880 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 7881 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 7882 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 7883 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 7884 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7885 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7886 | }; |
| 7887 | |
| 7888 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7889 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7890 | |
| 7891 | /* |
| 7892 | * TODO: validate the interface and mac address! |
| 7893 | * Otherwise, there's a race condition as soon as |
| 7894 | * the kernel starts sending station notifications. |
| 7895 | */ |
| 7896 | |
| 7897 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 7898 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 7899 | return NL_SKIP; |
| 7900 | } |
| 7901 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 7902 | tb[NL80211_ATTR_STA_INFO], |
| 7903 | stats_policy)) { |
| 7904 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 7905 | return NL_SKIP; |
| 7906 | } |
| 7907 | |
| 7908 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 7909 | data->inactive_msec = |
| 7910 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
| 7911 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 7912 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 7913 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 7914 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
| 7915 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 7916 | data->rx_packets = |
| 7917 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 7918 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 7919 | data->tx_packets = |
| 7920 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7921 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 7922 | data->tx_retry_failed = |
| 7923 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7924 | |
| 7925 | return NL_SKIP; |
| 7926 | } |
| 7927 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7928 | static int i802_read_sta_data(struct i802_bss *bss, |
| 7929 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7930 | const u8 *addr) |
| 7931 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7932 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7933 | struct nl_msg *msg; |
| 7934 | |
| 7935 | os_memset(data, 0, sizeof(*data)); |
| 7936 | msg = nlmsg_alloc(); |
| 7937 | if (!msg) |
| 7938 | return -ENOMEM; |
| 7939 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7940 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7941 | |
| 7942 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7943 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 7944 | |
| 7945 | return send_and_recv_msgs(drv, msg, get_sta_handler, data); |
| 7946 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7947 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7948 | return -ENOBUFS; |
| 7949 | } |
| 7950 | |
| 7951 | |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7952 | #if defined(HOSTAPD) || defined(CONFIG_AP) |
| 7953 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7954 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 7955 | int cw_min, int cw_max, int burst_time) |
| 7956 | { |
| 7957 | struct i802_bss *bss = priv; |
| 7958 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7959 | struct nl_msg *msg; |
| 7960 | struct nlattr *txq, *params; |
| 7961 | |
| 7962 | msg = nlmsg_alloc(); |
| 7963 | if (!msg) |
| 7964 | return -1; |
| 7965 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7966 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7967 | |
| 7968 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 7969 | |
| 7970 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 7971 | if (!txq) |
| 7972 | goto nla_put_failure; |
| 7973 | |
| 7974 | /* We are only sending parameters for a single TXQ at a time */ |
| 7975 | params = nla_nest_start(msg, 1); |
| 7976 | if (!params) |
| 7977 | goto nla_put_failure; |
| 7978 | |
| 7979 | switch (queue) { |
| 7980 | case 0: |
| 7981 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO); |
| 7982 | break; |
| 7983 | case 1: |
| 7984 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI); |
| 7985 | break; |
| 7986 | case 2: |
| 7987 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE); |
| 7988 | break; |
| 7989 | case 3: |
| 7990 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK); |
| 7991 | break; |
| 7992 | } |
| 7993 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 7994 | * 32 usec, so need to convert the value here. */ |
| 7995 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32); |
| 7996 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min); |
| 7997 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max); |
| 7998 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs); |
| 7999 | |
| 8000 | nla_nest_end(msg, params); |
| 8001 | |
| 8002 | nla_nest_end(msg, txq); |
| 8003 | |
| 8004 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 8005 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8006 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8007 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8008 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8009 | return -1; |
| 8010 | } |
| 8011 | |
| 8012 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8013 | 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] | 8014 | const char *ifname, int vlan_id) |
| 8015 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8016 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8017 | struct nl_msg *msg; |
| 8018 | int ret = -ENOBUFS; |
| 8019 | |
| 8020 | msg = nlmsg_alloc(); |
| 8021 | if (!msg) |
| 8022 | return -ENOMEM; |
| 8023 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8024 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8025 | |
| 8026 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, |
| 8027 | if_nametoindex(bss->ifname)); |
| 8028 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 8029 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, |
| 8030 | if_nametoindex(ifname)); |
| 8031 | |
| 8032 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8033 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8034 | if (ret < 0) { |
| 8035 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 8036 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 8037 | MAC2STR(addr), ifname, vlan_id, ret, |
| 8038 | strerror(-ret)); |
| 8039 | } |
| 8040 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8041 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8042 | return ret; |
| 8043 | } |
| 8044 | |
| 8045 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8046 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 8047 | { |
| 8048 | struct hostap_sta_driver_data data; |
| 8049 | int ret; |
| 8050 | |
| 8051 | data.inactive_msec = (unsigned long) -1; |
| 8052 | ret = i802_read_sta_data(priv, &data, addr); |
| 8053 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 8054 | return -1; |
| 8055 | return data.inactive_msec / 1000; |
| 8056 | } |
| 8057 | |
| 8058 | |
| 8059 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 8060 | { |
| 8061 | #if 0 |
| 8062 | /* TODO */ |
| 8063 | #endif |
| 8064 | return 0; |
| 8065 | } |
| 8066 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8067 | |
| 8068 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 8069 | int reason) |
| 8070 | { |
| 8071 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8072 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8073 | struct ieee80211_mgmt mgmt; |
| 8074 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8075 | if (drv->device_ap_sme) |
| 8076 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 8077 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8078 | memset(&mgmt, 0, sizeof(mgmt)); |
| 8079 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 8080 | WLAN_FC_STYPE_DEAUTH); |
| 8081 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 8082 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 8083 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 8084 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 8085 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 8086 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8087 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
| 8088 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8089 | } |
| 8090 | |
| 8091 | |
| 8092 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 8093 | int reason) |
| 8094 | { |
| 8095 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8096 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8097 | struct ieee80211_mgmt mgmt; |
| 8098 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8099 | if (drv->device_ap_sme) |
| 8100 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 8101 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8102 | memset(&mgmt, 0, sizeof(mgmt)); |
| 8103 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 8104 | WLAN_FC_STYPE_DISASSOC); |
| 8105 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 8106 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 8107 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 8108 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 8109 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 8110 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8111 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
| 8112 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8113 | } |
| 8114 | |
| 8115 | #endif /* HOSTAPD || CONFIG_AP */ |
| 8116 | |
| 8117 | #ifdef HOSTAPD |
| 8118 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8119 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 8120 | { |
| 8121 | int i; |
| 8122 | int *old; |
| 8123 | |
| 8124 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", |
| 8125 | ifidx); |
| 8126 | for (i = 0; i < drv->num_if_indices; i++) { |
| 8127 | if (drv->if_indices[i] == 0) { |
| 8128 | drv->if_indices[i] = ifidx; |
| 8129 | return; |
| 8130 | } |
| 8131 | } |
| 8132 | |
| 8133 | if (drv->if_indices != drv->default_if_indices) |
| 8134 | old = drv->if_indices; |
| 8135 | else |
| 8136 | old = NULL; |
| 8137 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8138 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 8139 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8140 | if (!drv->if_indices) { |
| 8141 | if (!old) |
| 8142 | drv->if_indices = drv->default_if_indices; |
| 8143 | else |
| 8144 | drv->if_indices = old; |
| 8145 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 8146 | "interfaces"); |
| 8147 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 8148 | return; |
| 8149 | } else if (!old) |
| 8150 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 8151 | sizeof(drv->default_if_indices)); |
| 8152 | drv->if_indices[drv->num_if_indices] = ifidx; |
| 8153 | drv->num_if_indices++; |
| 8154 | } |
| 8155 | |
| 8156 | |
| 8157 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 8158 | { |
| 8159 | int i; |
| 8160 | |
| 8161 | for (i = 0; i < drv->num_if_indices; i++) { |
| 8162 | if (drv->if_indices[i] == ifidx) { |
| 8163 | drv->if_indices[i] = 0; |
| 8164 | break; |
| 8165 | } |
| 8166 | } |
| 8167 | } |
| 8168 | |
| 8169 | |
| 8170 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 8171 | { |
| 8172 | int i; |
| 8173 | |
| 8174 | for (i = 0; i < drv->num_if_indices; i++) |
| 8175 | if (drv->if_indices[i] == ifidx) |
| 8176 | return 1; |
| 8177 | |
| 8178 | return 0; |
| 8179 | } |
| 8180 | |
| 8181 | |
| 8182 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, |
| 8183 | const char *bridge_ifname) |
| 8184 | { |
| 8185 | struct i802_bss *bss = priv; |
| 8186 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8187 | char name[IFNAMSIZ + 1]; |
| 8188 | |
| 8189 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 8190 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 8191 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 8192 | if (val) { |
| 8193 | if (!if_nametoindex(name)) { |
| 8194 | if (nl80211_create_iface(drv, name, |
| 8195 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 8196 | bss->addr, 1) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8197 | return -1; |
| 8198 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8199 | linux_br_add_if(drv->global->ioctl_sock, |
| 8200 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8201 | return -1; |
| 8202 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8203 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 8204 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 8205 | "interface %s up", name); |
| 8206 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8207 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 8208 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8209 | if (bridge_ifname) |
| 8210 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 8211 | name); |
| 8212 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8213 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
| 8214 | return wpa_driver_nl80211_if_remove(priv, WPA_IF_AP_VLAN, |
| 8215 | name); |
| 8216 | } |
| 8217 | } |
| 8218 | |
| 8219 | |
| 8220 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 8221 | { |
| 8222 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 8223 | struct sockaddr_ll lladdr; |
| 8224 | unsigned char buf[3000]; |
| 8225 | int len; |
| 8226 | socklen_t fromlen = sizeof(lladdr); |
| 8227 | |
| 8228 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 8229 | (struct sockaddr *)&lladdr, &fromlen); |
| 8230 | if (len < 0) { |
| 8231 | perror("recv"); |
| 8232 | return; |
| 8233 | } |
| 8234 | |
| 8235 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
| 8236 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 8237 | } |
| 8238 | |
| 8239 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8240 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 8241 | struct i802_bss *bss, |
| 8242 | const char *brname, const char *ifname) |
| 8243 | { |
| 8244 | int ifindex; |
| 8245 | char in_br[IFNAMSIZ]; |
| 8246 | |
| 8247 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
| 8248 | ifindex = if_nametoindex(brname); |
| 8249 | if (ifindex == 0) { |
| 8250 | /* |
| 8251 | * Bridge was configured, but the bridge device does |
| 8252 | * not exist. Try to add it now. |
| 8253 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8254 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8255 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 8256 | "bridge interface %s: %s", |
| 8257 | brname, strerror(errno)); |
| 8258 | return -1; |
| 8259 | } |
| 8260 | bss->added_bridge = 1; |
| 8261 | add_ifidx(drv, if_nametoindex(brname)); |
| 8262 | } |
| 8263 | |
| 8264 | if (linux_br_get(in_br, ifname) == 0) { |
| 8265 | if (os_strcmp(in_br, brname) == 0) |
| 8266 | return 0; /* already in the bridge */ |
| 8267 | |
| 8268 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 8269 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8270 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 8271 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8272 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 8273 | "remove interface %s from bridge " |
| 8274 | "%s: %s", |
| 8275 | ifname, brname, strerror(errno)); |
| 8276 | return -1; |
| 8277 | } |
| 8278 | } |
| 8279 | |
| 8280 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 8281 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8282 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8283 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 8284 | "into bridge %s: %s", |
| 8285 | ifname, brname, strerror(errno)); |
| 8286 | return -1; |
| 8287 | } |
| 8288 | bss->added_if_into_bridge = 1; |
| 8289 | |
| 8290 | return 0; |
| 8291 | } |
| 8292 | |
| 8293 | |
| 8294 | static void *i802_init(struct hostapd_data *hapd, |
| 8295 | struct wpa_init_params *params) |
| 8296 | { |
| 8297 | struct wpa_driver_nl80211_data *drv; |
| 8298 | struct i802_bss *bss; |
| 8299 | size_t i; |
| 8300 | char brname[IFNAMSIZ]; |
| 8301 | int ifindex, br_ifindex; |
| 8302 | int br_added = 0; |
| 8303 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8304 | bss = wpa_driver_nl80211_init(hapd, params->ifname, |
| 8305 | params->global_priv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8306 | if (bss == NULL) |
| 8307 | return NULL; |
| 8308 | |
| 8309 | drv = bss->drv; |
| 8310 | drv->nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8311 | drv->eapol_sock = -1; |
| 8312 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8313 | if (linux_br_get(brname, params->ifname) == 0) { |
| 8314 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
| 8315 | params->ifname, brname); |
| 8316 | br_ifindex = if_nametoindex(brname); |
| 8317 | } else { |
| 8318 | brname[0] = '\0'; |
| 8319 | br_ifindex = 0; |
| 8320 | } |
| 8321 | |
| 8322 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 8323 | drv->if_indices = drv->default_if_indices; |
| 8324 | for (i = 0; i < params->num_bridge; i++) { |
| 8325 | if (params->bridge[i]) { |
| 8326 | ifindex = if_nametoindex(params->bridge[i]); |
| 8327 | if (ifindex) |
| 8328 | add_ifidx(drv, ifindex); |
| 8329 | if (ifindex == br_ifindex) |
| 8330 | br_added = 1; |
| 8331 | } |
| 8332 | } |
| 8333 | if (!br_added && br_ifindex && |
| 8334 | (params->num_bridge == 0 || !params->bridge[0])) |
| 8335 | add_ifidx(drv, br_ifindex); |
| 8336 | |
| 8337 | /* start listening for EAPOL on the default AP interface */ |
| 8338 | add_ifidx(drv, drv->ifindex); |
| 8339 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8340 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8341 | goto failed; |
| 8342 | |
| 8343 | if (params->bssid) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8344 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8345 | params->bssid)) |
| 8346 | goto failed; |
| 8347 | } |
| 8348 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8349 | if (wpa_driver_nl80211_set_mode(bss, drv->nlmode)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8350 | wpa_printf(MSG_ERROR, "nl80211: Failed to set interface %s " |
| 8351 | "into AP mode", bss->ifname); |
| 8352 | goto failed; |
| 8353 | } |
| 8354 | |
| 8355 | if (params->num_bridge && params->bridge[0] && |
| 8356 | i802_check_bridge(drv, bss, params->bridge[0], params->ifname) < 0) |
| 8357 | goto failed; |
| 8358 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8359 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8360 | goto failed; |
| 8361 | |
| 8362 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 8363 | if (drv->eapol_sock < 0) { |
| 8364 | perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)"); |
| 8365 | goto failed; |
| 8366 | } |
| 8367 | |
| 8368 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 8369 | { |
| 8370 | printf("Could not register read socket for eapol\n"); |
| 8371 | goto failed; |
| 8372 | } |
| 8373 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8374 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 8375 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8376 | goto failed; |
| 8377 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8378 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 8379 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8380 | return bss; |
| 8381 | |
| 8382 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8383 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8384 | return NULL; |
| 8385 | } |
| 8386 | |
| 8387 | |
| 8388 | static void i802_deinit(void *priv) |
| 8389 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8390 | struct i802_bss *bss = priv; |
| 8391 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8392 | } |
| 8393 | |
| 8394 | #endif /* HOSTAPD */ |
| 8395 | |
| 8396 | |
| 8397 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 8398 | enum wpa_driver_if_type type) |
| 8399 | { |
| 8400 | switch (type) { |
| 8401 | case WPA_IF_STATION: |
| 8402 | return NL80211_IFTYPE_STATION; |
| 8403 | case WPA_IF_P2P_CLIENT: |
| 8404 | case WPA_IF_P2P_GROUP: |
| 8405 | return NL80211_IFTYPE_P2P_CLIENT; |
| 8406 | case WPA_IF_AP_VLAN: |
| 8407 | return NL80211_IFTYPE_AP_VLAN; |
| 8408 | case WPA_IF_AP_BSS: |
| 8409 | return NL80211_IFTYPE_AP; |
| 8410 | case WPA_IF_P2P_GO: |
| 8411 | return NL80211_IFTYPE_P2P_GO; |
| 8412 | } |
| 8413 | return -1; |
| 8414 | } |
| 8415 | |
| 8416 | |
| 8417 | #ifdef CONFIG_P2P |
| 8418 | |
| 8419 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 8420 | { |
| 8421 | struct wpa_driver_nl80211_data *drv; |
| 8422 | dl_list_for_each(drv, &global->interfaces, |
| 8423 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8424 | if (os_memcmp(addr, drv->first_bss.addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8425 | return 1; |
| 8426 | } |
| 8427 | return 0; |
| 8428 | } |
| 8429 | |
| 8430 | |
| 8431 | static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data *drv, |
| 8432 | u8 *new_addr) |
| 8433 | { |
| 8434 | unsigned int idx; |
| 8435 | |
| 8436 | if (!drv->global) |
| 8437 | return -1; |
| 8438 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8439 | os_memcpy(new_addr, drv->first_bss.addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8440 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8441 | new_addr[0] = drv->first_bss.addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8442 | new_addr[0] ^= idx << 2; |
| 8443 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 8444 | break; |
| 8445 | } |
| 8446 | if (idx == 64) |
| 8447 | return -1; |
| 8448 | |
| 8449 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new P2P Interface Address " |
| 8450 | MACSTR, MAC2STR(new_addr)); |
| 8451 | |
| 8452 | return 0; |
| 8453 | } |
| 8454 | |
| 8455 | #endif /* CONFIG_P2P */ |
| 8456 | |
| 8457 | |
| 8458 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 8459 | const char *ifname, const u8 *addr, |
| 8460 | void *bss_ctx, void **drv_priv, |
| 8461 | char *force_ifname, u8 *if_addr, |
| 8462 | const char *bridge) |
| 8463 | { |
| 8464 | struct i802_bss *bss = priv; |
| 8465 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8466 | int ifidx; |
| 8467 | #ifdef HOSTAPD |
| 8468 | struct i802_bss *new_bss = NULL; |
| 8469 | |
| 8470 | if (type == WPA_IF_AP_BSS) { |
| 8471 | new_bss = os_zalloc(sizeof(*new_bss)); |
| 8472 | if (new_bss == NULL) |
| 8473 | return -1; |
| 8474 | } |
| 8475 | #endif /* HOSTAPD */ |
| 8476 | |
| 8477 | if (addr) |
| 8478 | os_memcpy(if_addr, addr, ETH_ALEN); |
| 8479 | ifidx = nl80211_create_iface(drv, ifname, |
| 8480 | wpa_driver_nl80211_if_type(type), addr, |
| 8481 | 0); |
| 8482 | if (ifidx < 0) { |
| 8483 | #ifdef HOSTAPD |
| 8484 | os_free(new_bss); |
| 8485 | #endif /* HOSTAPD */ |
| 8486 | return -1; |
| 8487 | } |
| 8488 | |
| 8489 | if (!addr && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8490 | linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 8491 | if_addr) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8492 | nl80211_remove_iface(drv, ifidx); |
| 8493 | return -1; |
| 8494 | } |
| 8495 | |
| 8496 | #ifdef CONFIG_P2P |
| 8497 | if (!addr && |
| 8498 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
| 8499 | type == WPA_IF_P2P_GO)) { |
| 8500 | /* Enforce unique P2P Interface Address */ |
| 8501 | u8 new_addr[ETH_ALEN], own_addr[ETH_ALEN]; |
| 8502 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8503 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 8504 | own_addr) < 0 || |
| 8505 | linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 8506 | new_addr) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8507 | nl80211_remove_iface(drv, ifidx); |
| 8508 | return -1; |
| 8509 | } |
| 8510 | if (os_memcmp(own_addr, new_addr, ETH_ALEN) == 0) { |
| 8511 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
| 8512 | "for P2P group interface"); |
| 8513 | if (nl80211_p2p_interface_addr(drv, new_addr) < 0) { |
| 8514 | nl80211_remove_iface(drv, ifidx); |
| 8515 | return -1; |
| 8516 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8517 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8518 | new_addr) < 0) { |
| 8519 | nl80211_remove_iface(drv, ifidx); |
| 8520 | return -1; |
| 8521 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8522 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8523 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8524 | } |
| 8525 | #endif /* CONFIG_P2P */ |
| 8526 | |
| 8527 | #ifdef HOSTAPD |
| 8528 | if (bridge && |
| 8529 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 8530 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 8531 | "interface %s to a bridge %s", ifname, bridge); |
| 8532 | nl80211_remove_iface(drv, ifidx); |
| 8533 | os_free(new_bss); |
| 8534 | return -1; |
| 8535 | } |
| 8536 | |
| 8537 | if (type == WPA_IF_AP_BSS) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8538 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 8539 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8540 | nl80211_remove_iface(drv, ifidx); |
| 8541 | os_free(new_bss); |
| 8542 | return -1; |
| 8543 | } |
| 8544 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8545 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8546 | new_bss->ifindex = ifidx; |
| 8547 | new_bss->drv = drv; |
| 8548 | new_bss->next = drv->first_bss.next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8549 | new_bss->freq = drv->first_bss.freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8550 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8551 | drv->first_bss.next = new_bss; |
| 8552 | if (drv_priv) |
| 8553 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8554 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8555 | |
| 8556 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 8557 | if (nl80211_setup_ap(new_bss)) |
| 8558 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8559 | } |
| 8560 | #endif /* HOSTAPD */ |
| 8561 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8562 | if (drv->global) |
| 8563 | drv->global->if_add_ifindex = ifidx; |
| 8564 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8565 | return 0; |
| 8566 | } |
| 8567 | |
| 8568 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8569 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8570 | enum wpa_driver_if_type type, |
| 8571 | const char *ifname) |
| 8572 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8573 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8574 | int ifindex = if_nametoindex(ifname); |
| 8575 | |
| 8576 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d", |
| 8577 | __func__, type, ifname, ifindex); |
| 8578 | if (ifindex <= 0) |
| 8579 | return -1; |
| 8580 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8581 | nl80211_remove_iface(drv, ifindex); |
| 8582 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8583 | #ifdef HOSTAPD |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8584 | if (type != WPA_IF_AP_BSS) |
| 8585 | return 0; |
| 8586 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8587 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8588 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 8589 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8590 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 8591 | "interface %s from bridge %s: %s", |
| 8592 | bss->ifname, bss->brname, strerror(errno)); |
| 8593 | } |
| 8594 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8595 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8596 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 8597 | "bridge %s: %s", |
| 8598 | bss->brname, strerror(errno)); |
| 8599 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8600 | |
| 8601 | if (bss != &drv->first_bss) { |
| 8602 | struct i802_bss *tbss; |
| 8603 | |
| 8604 | for (tbss = &drv->first_bss; tbss; tbss = tbss->next) { |
| 8605 | if (tbss->next == bss) { |
| 8606 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8607 | /* Unsubscribe management frames */ |
| 8608 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8609 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8610 | os_free(bss); |
| 8611 | bss = NULL; |
| 8612 | break; |
| 8613 | } |
| 8614 | } |
| 8615 | if (bss) |
| 8616 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 8617 | "BSS %p in the list", __func__, bss); |
| 8618 | } |
| 8619 | #endif /* HOSTAPD */ |
| 8620 | |
| 8621 | return 0; |
| 8622 | } |
| 8623 | |
| 8624 | |
| 8625 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 8626 | { |
| 8627 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8628 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8629 | u64 *cookie = arg; |
| 8630 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8631 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8632 | if (tb[NL80211_ATTR_COOKIE]) |
| 8633 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 8634 | return NL_SKIP; |
| 8635 | } |
| 8636 | |
| 8637 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8638 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8639 | unsigned int freq, unsigned int wait, |
| 8640 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8641 | u64 *cookie_out, int no_cck, int no_ack, |
| 8642 | int offchanok) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8643 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8644 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8645 | struct nl_msg *msg; |
| 8646 | u64 cookie; |
| 8647 | int ret = -1; |
| 8648 | |
| 8649 | msg = nlmsg_alloc(); |
| 8650 | if (!msg) |
| 8651 | return -1; |
| 8652 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8653 | wpa_printf(MSG_DEBUG, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
| 8654 | "no_ack=%d offchanok=%d", |
| 8655 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8656 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8657 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8658 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8659 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8660 | if (wait) |
| 8661 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, wait); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8662 | if (offchanok && (drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8663 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 8664 | if (no_cck) |
| 8665 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); |
| 8666 | if (no_ack) |
| 8667 | NLA_PUT_FLAG(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK); |
| 8668 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8669 | NLA_PUT(msg, NL80211_ATTR_FRAME, buf_len, buf); |
| 8670 | |
| 8671 | cookie = 0; |
| 8672 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 8673 | msg = NULL; |
| 8674 | if (ret) { |
| 8675 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8676 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 8677 | freq, wait); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8678 | goto nla_put_failure; |
| 8679 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8680 | wpa_printf(MSG_DEBUG, "nl80211: Frame TX command accepted%s; " |
| 8681 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 8682 | (long long unsigned int) cookie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8683 | |
| 8684 | if (cookie_out) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8685 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8686 | |
| 8687 | nla_put_failure: |
| 8688 | nlmsg_free(msg); |
| 8689 | return ret; |
| 8690 | } |
| 8691 | |
| 8692 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8693 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 8694 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8695 | unsigned int wait_time, |
| 8696 | const u8 *dst, const u8 *src, |
| 8697 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8698 | const u8 *data, size_t data_len, |
| 8699 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8700 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8701 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8702 | int ret = -1; |
| 8703 | u8 *buf; |
| 8704 | struct ieee80211_hdr *hdr; |
| 8705 | |
| 8706 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8707 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 8708 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8709 | |
| 8710 | buf = os_zalloc(24 + data_len); |
| 8711 | if (buf == NULL) |
| 8712 | return ret; |
| 8713 | os_memcpy(buf + 24, data, data_len); |
| 8714 | hdr = (struct ieee80211_hdr *) buf; |
| 8715 | hdr->frame_control = |
| 8716 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 8717 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 8718 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 8719 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 8720 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8721 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8722 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 8723 | 0, freq, no_cck, 1, |
| 8724 | wait_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8725 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8726 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8727 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8728 | &drv->send_action_cookie, |
| 8729 | no_cck, 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8730 | |
| 8731 | os_free(buf); |
| 8732 | return ret; |
| 8733 | } |
| 8734 | |
| 8735 | |
| 8736 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 8737 | { |
| 8738 | struct i802_bss *bss = priv; |
| 8739 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8740 | struct nl_msg *msg; |
| 8741 | int ret; |
| 8742 | |
| 8743 | msg = nlmsg_alloc(); |
| 8744 | if (!msg) |
| 8745 | return; |
| 8746 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 8747 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
| 8748 | (long long unsigned int) drv->send_action_cookie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8749 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME_WAIT_CANCEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8750 | |
| 8751 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 8752 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie); |
| 8753 | |
| 8754 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8755 | msg = NULL; |
| 8756 | if (ret) |
| 8757 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 8758 | "(%s)", ret, strerror(-ret)); |
| 8759 | |
| 8760 | nla_put_failure: |
| 8761 | nlmsg_free(msg); |
| 8762 | } |
| 8763 | |
| 8764 | |
| 8765 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 8766 | unsigned int duration) |
| 8767 | { |
| 8768 | struct i802_bss *bss = priv; |
| 8769 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8770 | struct nl_msg *msg; |
| 8771 | int ret; |
| 8772 | u64 cookie; |
| 8773 | |
| 8774 | msg = nlmsg_alloc(); |
| 8775 | if (!msg) |
| 8776 | return -1; |
| 8777 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8778 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REMAIN_ON_CHANNEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8779 | |
| 8780 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 8781 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 8782 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 8783 | |
| 8784 | cookie = 0; |
| 8785 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8786 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8787 | if (ret == 0) { |
| 8788 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 8789 | "0x%llx for freq=%u MHz duration=%u", |
| 8790 | (long long unsigned int) cookie, freq, duration); |
| 8791 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8792 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8793 | return 0; |
| 8794 | } |
| 8795 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 8796 | "(freq=%d duration=%u): %d (%s)", |
| 8797 | freq, duration, ret, strerror(-ret)); |
| 8798 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8799 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8800 | return -1; |
| 8801 | } |
| 8802 | |
| 8803 | |
| 8804 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 8805 | { |
| 8806 | struct i802_bss *bss = priv; |
| 8807 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8808 | struct nl_msg *msg; |
| 8809 | int ret; |
| 8810 | |
| 8811 | if (!drv->pending_remain_on_chan) { |
| 8812 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 8813 | "to cancel"); |
| 8814 | return -1; |
| 8815 | } |
| 8816 | |
| 8817 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 8818 | "0x%llx", |
| 8819 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 8820 | |
| 8821 | msg = nlmsg_alloc(); |
| 8822 | if (!msg) |
| 8823 | return -1; |
| 8824 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8825 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8826 | |
| 8827 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 8828 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie); |
| 8829 | |
| 8830 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8831 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8832 | if (ret == 0) |
| 8833 | return 0; |
| 8834 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 8835 | "%d (%s)", ret, strerror(-ret)); |
| 8836 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8837 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8838 | return -1; |
| 8839 | } |
| 8840 | |
| 8841 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8842 | 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] | 8843 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8844 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8845 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8846 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8847 | if (bss->nl_preq && drv->device_ap_sme && |
| 8848 | is_ap_interface(drv->nlmode)) { |
| 8849 | /* |
| 8850 | * Do not disable Probe Request reporting that was |
| 8851 | * enabled in nl80211_setup_ap(). |
| 8852 | */ |
| 8853 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 8854 | "Probe Request reporting nl_preq=%p while " |
| 8855 | "in AP mode", bss->nl_preq); |
| 8856 | } else if (bss->nl_preq) { |
| 8857 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 8858 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8859 | eloop_unregister_read_sock( |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8860 | nl_socket_get_fd(bss->nl_preq)); |
| 8861 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8862 | } |
| 8863 | return 0; |
| 8864 | } |
| 8865 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8866 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8867 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8868 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8869 | return 0; |
| 8870 | } |
| 8871 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8872 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 8873 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8874 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8875 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 8876 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8877 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8878 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8879 | (WLAN_FC_TYPE_MGMT << 2) | |
| 8880 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8881 | NULL, 0) < 0) |
| 8882 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 8883 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8884 | eloop_register_read_sock(nl_socket_get_fd(bss->nl_preq), |
| 8885 | wpa_driver_nl80211_event_receive, bss->nl_cb, |
| 8886 | bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8887 | |
| 8888 | return 0; |
| 8889 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8890 | out_err: |
| 8891 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8892 | return -1; |
| 8893 | } |
| 8894 | |
| 8895 | |
| 8896 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 8897 | int ifindex, int disabled) |
| 8898 | { |
| 8899 | struct nl_msg *msg; |
| 8900 | struct nlattr *bands, *band; |
| 8901 | int ret; |
| 8902 | |
| 8903 | msg = nlmsg_alloc(); |
| 8904 | if (!msg) |
| 8905 | return -1; |
| 8906 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8907 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8908 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
| 8909 | |
| 8910 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 8911 | if (!bands) |
| 8912 | goto nla_put_failure; |
| 8913 | |
| 8914 | /* |
| 8915 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 8916 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 8917 | * rates. All 5 GHz rates are left enabled. |
| 8918 | */ |
| 8919 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 8920 | if (!band) |
| 8921 | goto nla_put_failure; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8922 | if (disabled) { |
| 8923 | NLA_PUT(msg, NL80211_TXRATE_LEGACY, 8, |
| 8924 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); |
| 8925 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8926 | nla_nest_end(msg, band); |
| 8927 | |
| 8928 | nla_nest_end(msg, bands); |
| 8929 | |
| 8930 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8931 | msg = NULL; |
| 8932 | if (ret) { |
| 8933 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 8934 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8935 | } else |
| 8936 | drv->disabled_11b_rates = disabled; |
| 8937 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8938 | return ret; |
| 8939 | |
| 8940 | nla_put_failure: |
| 8941 | nlmsg_free(msg); |
| 8942 | return -1; |
| 8943 | } |
| 8944 | |
| 8945 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8946 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 8947 | { |
| 8948 | struct i802_bss *bss = priv; |
| 8949 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8950 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8951 | return -1; |
| 8952 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8953 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8954 | } |
| 8955 | |
| 8956 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8957 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 8958 | { |
| 8959 | struct i802_bss *bss = priv; |
| 8960 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8961 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 8962 | return -1; |
| 8963 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 8964 | } |
| 8965 | |
| 8966 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8967 | static void wpa_driver_nl80211_resume(void *priv) |
| 8968 | { |
| 8969 | struct i802_bss *bss = priv; |
| 8970 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8971 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8972 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on " |
| 8973 | "resume event"); |
| 8974 | } |
| 8975 | } |
| 8976 | |
| 8977 | |
| 8978 | static int nl80211_send_ft_action(void *priv, u8 action, const u8 *target_ap, |
| 8979 | const u8 *ies, size_t ies_len) |
| 8980 | { |
| 8981 | struct i802_bss *bss = priv; |
| 8982 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8983 | int ret; |
| 8984 | u8 *data, *pos; |
| 8985 | size_t data_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8986 | const u8 *own_addr = bss->addr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8987 | |
| 8988 | if (action != 1) { |
| 8989 | wpa_printf(MSG_ERROR, "nl80211: Unsupported send_ft_action " |
| 8990 | "action %d", action); |
| 8991 | return -1; |
| 8992 | } |
| 8993 | |
| 8994 | /* |
| 8995 | * Action frame payload: |
| 8996 | * Category[1] = 6 (Fast BSS Transition) |
| 8997 | * Action[1] = 1 (Fast BSS Transition Request) |
| 8998 | * STA Address |
| 8999 | * Target AP Address |
| 9000 | * FT IEs |
| 9001 | */ |
| 9002 | |
| 9003 | data_len = 2 + 2 * ETH_ALEN + ies_len; |
| 9004 | data = os_malloc(data_len); |
| 9005 | if (data == NULL) |
| 9006 | return -1; |
| 9007 | pos = data; |
| 9008 | *pos++ = 0x06; /* FT Action category */ |
| 9009 | *pos++ = action; |
| 9010 | os_memcpy(pos, own_addr, ETH_ALEN); |
| 9011 | pos += ETH_ALEN; |
| 9012 | os_memcpy(pos, target_ap, ETH_ALEN); |
| 9013 | pos += ETH_ALEN; |
| 9014 | os_memcpy(pos, ies, ies_len); |
| 9015 | |
| 9016 | ret = wpa_driver_nl80211_send_action(bss, drv->assoc_freq, 0, |
| 9017 | drv->bssid, own_addr, drv->bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9018 | data, data_len, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9019 | os_free(data); |
| 9020 | |
| 9021 | return ret; |
| 9022 | } |
| 9023 | |
| 9024 | |
| 9025 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 9026 | { |
| 9027 | struct i802_bss *bss = priv; |
| 9028 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 9029 | struct nl_msg *msg; |
| 9030 | struct nlattr *cqm; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9031 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9032 | |
| 9033 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 9034 | "hysteresis=%d", threshold, hysteresis); |
| 9035 | |
| 9036 | msg = nlmsg_alloc(); |
| 9037 | if (!msg) |
| 9038 | return -1; |
| 9039 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9040 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_CQM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9041 | |
| 9042 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 9043 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 9044 | cqm = nla_nest_start(msg, NL80211_ATTR_CQM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9045 | if (cqm == NULL) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9046 | goto nla_put_failure; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9047 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame^] | 9048 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold); |
| 9049 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis); |
| 9050 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9051 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9052 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9053 | msg = NULL; |
| 9054 | |
| 9055 | nla_put_failure: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9056 | nlmsg_free(msg); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9057 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9058 | } |
| 9059 | |
| 9060 | |
| 9061 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 9062 | { |
| 9063 | struct i802_bss *bss = priv; |
| 9064 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9065 | int res; |
| 9066 | |
| 9067 | os_memset(si, 0, sizeof(*si)); |
| 9068 | res = nl80211_get_link_signal(drv, si); |
| 9069 | if (res != 0) |
| 9070 | return res; |
| 9071 | |
| 9072 | return nl80211_get_link_noise(drv, si); |
| 9073 | } |
| 9074 | |
| 9075 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9076 | static int wpa_driver_nl80211_shared_freq(void *priv) |
| 9077 | { |
| 9078 | struct i802_bss *bss = priv; |
| 9079 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9080 | struct wpa_driver_nl80211_data *driver; |
| 9081 | int freq = 0; |
| 9082 | |
| 9083 | /* |
| 9084 | * If the same PHY is in connected state with some other interface, |
| 9085 | * then retrieve the assoc freq. |
| 9086 | */ |
| 9087 | wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s", |
| 9088 | drv->phyname); |
| 9089 | |
| 9090 | dl_list_for_each(driver, &drv->global->interfaces, |
| 9091 | struct wpa_driver_nl80211_data, list) { |
| 9092 | if (drv == driver || |
| 9093 | os_strcmp(drv->phyname, driver->phyname) != 0 || |
| 9094 | #ifdef ANDROID_P2P |
| 9095 | (!driver->associated && !is_ap_interface(driver->nlmode))) |
| 9096 | #else |
| 9097 | !driver->associated) |
| 9098 | #endif |
| 9099 | continue; |
| 9100 | |
| 9101 | wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s " |
| 9102 | MACSTR, |
| 9103 | driver->phyname, driver->first_bss.ifname, |
| 9104 | MAC2STR(driver->first_bss.addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9105 | if (is_ap_interface(driver->nlmode)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9106 | freq = driver->first_bss.freq; |
| 9107 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9108 | freq = nl80211_get_assoc_freq(driver); |
| 9109 | wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d", |
| 9110 | drv->phyname, freq); |
| 9111 | } |
| 9112 | |
| 9113 | if (!freq) |
| 9114 | wpa_printf(MSG_DEBUG, "nl80211: No shared interface for " |
| 9115 | "PHY (%s) in associated state", drv->phyname); |
| 9116 | |
| 9117 | return freq; |
| 9118 | } |
| 9119 | |
| 9120 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9121 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 9122 | int encrypt) |
| 9123 | { |
| 9124 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9125 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
| 9126 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9127 | } |
| 9128 | |
| 9129 | |
| 9130 | static int nl80211_set_param(void *priv, const char *param) |
| 9131 | { |
| 9132 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
| 9133 | if (param == NULL) |
| 9134 | return 0; |
| 9135 | |
| 9136 | #ifdef CONFIG_P2P |
| 9137 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 9138 | struct i802_bss *bss = priv; |
| 9139 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9140 | |
| 9141 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 9142 | "interface"); |
| 9143 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 9144 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 9145 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9146 | #ifdef ANDROID_P2P |
| 9147 | if(os_strstr(param, "use_multi_chan_concurrent=1")) { |
| 9148 | struct i802_bss *bss = priv; |
| 9149 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9150 | wpa_printf(MSG_DEBUG, "nl80211: Use Multi channel " |
| 9151 | "concurrency"); |
| 9152 | drv->capa.flags |= WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT; |
| 9153 | } |
| 9154 | #endif |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9155 | #endif /* CONFIG_P2P */ |
| 9156 | |
| 9157 | return 0; |
| 9158 | } |
| 9159 | |
| 9160 | |
| 9161 | static void * nl80211_global_init(void) |
| 9162 | { |
| 9163 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9164 | struct netlink_config *cfg; |
| 9165 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9166 | global = os_zalloc(sizeof(*global)); |
| 9167 | if (global == NULL) |
| 9168 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9169 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9170 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9171 | global->if_add_ifindex = -1; |
| 9172 | |
| 9173 | cfg = os_zalloc(sizeof(*cfg)); |
| 9174 | if (cfg == NULL) |
| 9175 | goto err; |
| 9176 | |
| 9177 | cfg->ctx = global; |
| 9178 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 9179 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 9180 | global->netlink = netlink_init(cfg); |
| 9181 | if (global->netlink == NULL) { |
| 9182 | os_free(cfg); |
| 9183 | goto err; |
| 9184 | } |
| 9185 | |
| 9186 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 9187 | goto err; |
| 9188 | |
| 9189 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 9190 | if (global->ioctl_sock < 0) { |
| 9191 | perror("socket(PF_INET,SOCK_DGRAM)"); |
| 9192 | goto err; |
| 9193 | } |
| 9194 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9195 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9196 | |
| 9197 | err: |
| 9198 | nl80211_global_deinit(global); |
| 9199 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9200 | } |
| 9201 | |
| 9202 | |
| 9203 | static void nl80211_global_deinit(void *priv) |
| 9204 | { |
| 9205 | struct nl80211_global *global = priv; |
| 9206 | if (global == NULL) |
| 9207 | return; |
| 9208 | if (!dl_list_empty(&global->interfaces)) { |
| 9209 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 9210 | "nl80211_global_deinit", |
| 9211 | dl_list_len(&global->interfaces)); |
| 9212 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9213 | |
| 9214 | if (global->netlink) |
| 9215 | netlink_deinit(global->netlink); |
| 9216 | |
| 9217 | nl_destroy_handles(&global->nl); |
| 9218 | |
| 9219 | if (global->nl_event) { |
| 9220 | eloop_unregister_read_sock( |
| 9221 | nl_socket_get_fd(global->nl_event)); |
| 9222 | nl_destroy_handles(&global->nl_event); |
| 9223 | } |
| 9224 | |
| 9225 | nl_cb_put(global->nl_cb); |
| 9226 | |
| 9227 | if (global->ioctl_sock >= 0) |
| 9228 | close(global->ioctl_sock); |
| 9229 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9230 | os_free(global); |
| 9231 | } |
| 9232 | |
| 9233 | |
| 9234 | static const char * nl80211_get_radio_name(void *priv) |
| 9235 | { |
| 9236 | struct i802_bss *bss = priv; |
| 9237 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9238 | return drv->phyname; |
| 9239 | } |
| 9240 | |
| 9241 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9242 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 9243 | const u8 *pmkid) |
| 9244 | { |
| 9245 | struct nl_msg *msg; |
| 9246 | |
| 9247 | msg = nlmsg_alloc(); |
| 9248 | if (!msg) |
| 9249 | return -ENOMEM; |
| 9250 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9251 | nl80211_cmd(bss->drv, msg, 0, cmd); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9252 | |
| 9253 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
| 9254 | if (pmkid) |
| 9255 | NLA_PUT(msg, NL80211_ATTR_PMKID, 16, pmkid); |
| 9256 | if (bssid) |
| 9257 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 9258 | |
| 9259 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 9260 | nla_put_failure: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9261 | nlmsg_free(msg); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9262 | return -ENOBUFS; |
| 9263 | } |
| 9264 | |
| 9265 | |
| 9266 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 9267 | { |
| 9268 | struct i802_bss *bss = priv; |
| 9269 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 9270 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 9271 | } |
| 9272 | |
| 9273 | |
| 9274 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 9275 | { |
| 9276 | struct i802_bss *bss = priv; |
| 9277 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 9278 | MAC2STR(bssid)); |
| 9279 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 9280 | } |
| 9281 | |
| 9282 | |
| 9283 | static int nl80211_flush_pmkid(void *priv) |
| 9284 | { |
| 9285 | struct i802_bss *bss = priv; |
| 9286 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 9287 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 9288 | } |
| 9289 | |
| 9290 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9291 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, const u8 *kck, |
| 9292 | const u8 *replay_ctr) |
| 9293 | { |
| 9294 | struct i802_bss *bss = priv; |
| 9295 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9296 | struct nlattr *replay_nested; |
| 9297 | struct nl_msg *msg; |
| 9298 | |
| 9299 | msg = nlmsg_alloc(); |
| 9300 | if (!msg) |
| 9301 | return; |
| 9302 | |
| 9303 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9304 | |
| 9305 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 9306 | |
| 9307 | replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9308 | if (!replay_nested) |
| 9309 | goto nla_put_failure; |
| 9310 | |
| 9311 | NLA_PUT(msg, NL80211_REKEY_DATA_KEK, NL80211_KEK_LEN, kek); |
| 9312 | NLA_PUT(msg, NL80211_REKEY_DATA_KCK, NL80211_KCK_LEN, kck); |
| 9313 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 9314 | replay_ctr); |
| 9315 | |
| 9316 | nla_nest_end(msg, replay_nested); |
| 9317 | |
| 9318 | send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9319 | return; |
| 9320 | nla_put_failure: |
| 9321 | nlmsg_free(msg); |
| 9322 | } |
| 9323 | |
| 9324 | |
| 9325 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 9326 | const u8 *addr, int qos) |
| 9327 | { |
| 9328 | /* send data frame to poll STA and check whether |
| 9329 | * this frame is ACKed */ |
| 9330 | struct { |
| 9331 | struct ieee80211_hdr hdr; |
| 9332 | u16 qos_ctl; |
| 9333 | } STRUCT_PACKED nulldata; |
| 9334 | size_t size; |
| 9335 | |
| 9336 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 9337 | |
| 9338 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 9339 | |
| 9340 | if (qos) { |
| 9341 | nulldata.hdr.frame_control = |
| 9342 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 9343 | WLAN_FC_STYPE_QOS_NULL); |
| 9344 | size = sizeof(nulldata); |
| 9345 | } else { |
| 9346 | nulldata.hdr.frame_control = |
| 9347 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 9348 | WLAN_FC_STYPE_NULLFUNC); |
| 9349 | size = sizeof(struct ieee80211_hdr); |
| 9350 | } |
| 9351 | |
| 9352 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 9353 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 9354 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 9355 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 9356 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9357 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
| 9358 | 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9359 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 9360 | "send poll frame"); |
| 9361 | } |
| 9362 | |
| 9363 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 9364 | int qos) |
| 9365 | { |
| 9366 | struct i802_bss *bss = priv; |
| 9367 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9368 | struct nl_msg *msg; |
| 9369 | |
| 9370 | if (!drv->poll_command_supported) { |
| 9371 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 9372 | return; |
| 9373 | } |
| 9374 | |
| 9375 | msg = nlmsg_alloc(); |
| 9376 | if (!msg) |
| 9377 | return; |
| 9378 | |
| 9379 | nl80211_cmd(drv, msg, 0, NL80211_CMD_PROBE_CLIENT); |
| 9380 | |
| 9381 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 9382 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 9383 | |
| 9384 | send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9385 | return; |
| 9386 | nla_put_failure: |
| 9387 | nlmsg_free(msg); |
| 9388 | } |
| 9389 | |
| 9390 | |
| 9391 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 9392 | { |
| 9393 | struct nl_msg *msg; |
| 9394 | |
| 9395 | msg = nlmsg_alloc(); |
| 9396 | if (!msg) |
| 9397 | return -ENOMEM; |
| 9398 | |
| 9399 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_SET_POWER_SAVE); |
| 9400 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 9401 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, |
| 9402 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED); |
| 9403 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 9404 | nla_put_failure: |
| 9405 | nlmsg_free(msg); |
| 9406 | return -ENOBUFS; |
| 9407 | } |
| 9408 | |
| 9409 | |
| 9410 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 9411 | int ctwindow) |
| 9412 | { |
| 9413 | struct i802_bss *bss = priv; |
| 9414 | |
| 9415 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 9416 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 9417 | |
| 9418 | if (opp_ps != -1 || ctwindow != -1) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9419 | #ifdef ANDROID_P2P |
| 9420 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
| 9421 | #else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9422 | return -1; /* Not yet supported */ |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9423 | #endif |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9424 | |
| 9425 | if (legacy_ps == -1) |
| 9426 | return 0; |
| 9427 | if (legacy_ps != 0 && legacy_ps != 1) |
| 9428 | return -1; /* Not yet supported */ |
| 9429 | |
| 9430 | return nl80211_set_power_save(bss, legacy_ps); |
| 9431 | } |
| 9432 | |
| 9433 | |
| 9434 | #ifdef CONFIG_TDLS |
| 9435 | |
| 9436 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 9437 | u8 dialog_token, u16 status_code, |
| 9438 | const u8 *buf, size_t len) |
| 9439 | { |
| 9440 | struct i802_bss *bss = priv; |
| 9441 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9442 | struct nl_msg *msg; |
| 9443 | |
| 9444 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9445 | return -EOPNOTSUPP; |
| 9446 | |
| 9447 | if (!dst) |
| 9448 | return -EINVAL; |
| 9449 | |
| 9450 | msg = nlmsg_alloc(); |
| 9451 | if (!msg) |
| 9452 | return -ENOMEM; |
| 9453 | |
| 9454 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_MGMT); |
| 9455 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 9456 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 9457 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_ACTION, action_code); |
| 9458 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token); |
| 9459 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status_code); |
| 9460 | NLA_PUT(msg, NL80211_ATTR_IE, len, buf); |
| 9461 | |
| 9462 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9463 | |
| 9464 | nla_put_failure: |
| 9465 | nlmsg_free(msg); |
| 9466 | return -ENOBUFS; |
| 9467 | } |
| 9468 | |
| 9469 | |
| 9470 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 9471 | { |
| 9472 | struct i802_bss *bss = priv; |
| 9473 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9474 | struct nl_msg *msg; |
| 9475 | enum nl80211_tdls_operation nl80211_oper; |
| 9476 | |
| 9477 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9478 | return -EOPNOTSUPP; |
| 9479 | |
| 9480 | switch (oper) { |
| 9481 | case TDLS_DISCOVERY_REQ: |
| 9482 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 9483 | break; |
| 9484 | case TDLS_SETUP: |
| 9485 | nl80211_oper = NL80211_TDLS_SETUP; |
| 9486 | break; |
| 9487 | case TDLS_TEARDOWN: |
| 9488 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 9489 | break; |
| 9490 | case TDLS_ENABLE_LINK: |
| 9491 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 9492 | break; |
| 9493 | case TDLS_DISABLE_LINK: |
| 9494 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 9495 | break; |
| 9496 | case TDLS_ENABLE: |
| 9497 | return 0; |
| 9498 | case TDLS_DISABLE: |
| 9499 | return 0; |
| 9500 | default: |
| 9501 | return -EINVAL; |
| 9502 | } |
| 9503 | |
| 9504 | msg = nlmsg_alloc(); |
| 9505 | if (!msg) |
| 9506 | return -ENOMEM; |
| 9507 | |
| 9508 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_OPER); |
| 9509 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper); |
| 9510 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 9511 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 9512 | |
| 9513 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9514 | |
| 9515 | nla_put_failure: |
| 9516 | nlmsg_free(msg); |
| 9517 | return -ENOBUFS; |
| 9518 | } |
| 9519 | |
| 9520 | #endif /* CONFIG TDLS */ |
| 9521 | |
| 9522 | |
| 9523 | #ifdef ANDROID |
| 9524 | |
| 9525 | typedef struct android_wifi_priv_cmd { |
| 9526 | char *buf; |
| 9527 | int used_len; |
| 9528 | int total_len; |
| 9529 | } android_wifi_priv_cmd; |
| 9530 | |
| 9531 | static int drv_errors = 0; |
| 9532 | |
| 9533 | static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data *drv) |
| 9534 | { |
| 9535 | drv_errors++; |
| 9536 | if (drv_errors > DRV_NUMBER_SEQUENTIAL_ERRORS) { |
| 9537 | drv_errors = 0; |
| 9538 | wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); |
| 9539 | } |
| 9540 | } |
| 9541 | |
| 9542 | |
| 9543 | static int android_priv_cmd(struct i802_bss *bss, const char *cmd) |
| 9544 | { |
| 9545 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9546 | struct ifreq ifr; |
| 9547 | android_wifi_priv_cmd priv_cmd; |
| 9548 | char buf[MAX_DRV_CMD_SIZE]; |
| 9549 | int ret; |
| 9550 | |
| 9551 | os_memset(&ifr, 0, sizeof(ifr)); |
| 9552 | os_memset(&priv_cmd, 0, sizeof(priv_cmd)); |
| 9553 | os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); |
| 9554 | |
| 9555 | os_memset(buf, 0, sizeof(buf)); |
| 9556 | os_strlcpy(buf, cmd, sizeof(buf)); |
| 9557 | |
| 9558 | priv_cmd.buf = buf; |
| 9559 | priv_cmd.used_len = sizeof(buf); |
| 9560 | priv_cmd.total_len = sizeof(buf); |
| 9561 | ifr.ifr_data = &priv_cmd; |
| 9562 | |
| 9563 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); |
| 9564 | if (ret < 0) { |
| 9565 | wpa_printf(MSG_ERROR, "%s: failed to issue private commands", |
| 9566 | __func__); |
| 9567 | wpa_driver_send_hang_msg(drv); |
| 9568 | return ret; |
| 9569 | } |
| 9570 | |
| 9571 | drv_errors = 0; |
| 9572 | return 0; |
| 9573 | } |
| 9574 | |
| 9575 | |
| 9576 | static int android_pno_start(struct i802_bss *bss, |
| 9577 | struct wpa_driver_scan_params *params) |
| 9578 | { |
| 9579 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9580 | struct ifreq ifr; |
| 9581 | android_wifi_priv_cmd priv_cmd; |
| 9582 | int ret = 0, i = 0, bp; |
| 9583 | char buf[WEXT_PNO_MAX_COMMAND_SIZE]; |
| 9584 | |
| 9585 | bp = WEXT_PNOSETUP_HEADER_SIZE; |
| 9586 | os_memcpy(buf, WEXT_PNOSETUP_HEADER, bp); |
| 9587 | buf[bp++] = WEXT_PNO_TLV_PREFIX; |
| 9588 | buf[bp++] = WEXT_PNO_TLV_VERSION; |
| 9589 | buf[bp++] = WEXT_PNO_TLV_SUBVERSION; |
| 9590 | buf[bp++] = WEXT_PNO_TLV_RESERVED; |
| 9591 | |
| 9592 | while (i < WEXT_PNO_AMOUNT && (size_t) i < params->num_ssids) { |
| 9593 | /* Check that there is enough space needed for 1 more SSID, the |
| 9594 | * other sections and null termination */ |
| 9595 | if ((bp + WEXT_PNO_SSID_HEADER_SIZE + MAX_SSID_LEN + |
| 9596 | WEXT_PNO_NONSSID_SECTIONS_SIZE + 1) >= (int) sizeof(buf)) |
| 9597 | break; |
| 9598 | wpa_hexdump_ascii(MSG_DEBUG, "For PNO Scan", |
| 9599 | params->ssids[i].ssid, |
| 9600 | params->ssids[i].ssid_len); |
| 9601 | buf[bp++] = WEXT_PNO_SSID_SECTION; |
| 9602 | buf[bp++] = params->ssids[i].ssid_len; |
| 9603 | os_memcpy(&buf[bp], params->ssids[i].ssid, |
| 9604 | params->ssids[i].ssid_len); |
| 9605 | bp += params->ssids[i].ssid_len; |
| 9606 | i++; |
| 9607 | } |
| 9608 | |
| 9609 | buf[bp++] = WEXT_PNO_SCAN_INTERVAL_SECTION; |
| 9610 | os_snprintf(&buf[bp], WEXT_PNO_SCAN_INTERVAL_LENGTH + 1, "%x", |
| 9611 | WEXT_PNO_SCAN_INTERVAL); |
| 9612 | bp += WEXT_PNO_SCAN_INTERVAL_LENGTH; |
| 9613 | |
| 9614 | buf[bp++] = WEXT_PNO_REPEAT_SECTION; |
| 9615 | os_snprintf(&buf[bp], WEXT_PNO_REPEAT_LENGTH + 1, "%x", |
| 9616 | WEXT_PNO_REPEAT); |
| 9617 | bp += WEXT_PNO_REPEAT_LENGTH; |
| 9618 | |
| 9619 | buf[bp++] = WEXT_PNO_MAX_REPEAT_SECTION; |
| 9620 | os_snprintf(&buf[bp], WEXT_PNO_MAX_REPEAT_LENGTH + 1, "%x", |
| 9621 | WEXT_PNO_MAX_REPEAT); |
| 9622 | bp += WEXT_PNO_MAX_REPEAT_LENGTH + 1; |
| 9623 | |
| 9624 | memset(&ifr, 0, sizeof(ifr)); |
| 9625 | memset(&priv_cmd, 0, sizeof(priv_cmd)); |
| 9626 | os_strncpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); |
| 9627 | |
| 9628 | priv_cmd.buf = buf; |
| 9629 | priv_cmd.used_len = bp; |
| 9630 | priv_cmd.total_len = bp; |
| 9631 | ifr.ifr_data = &priv_cmd; |
| 9632 | |
| 9633 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); |
| 9634 | |
| 9635 | if (ret < 0) { |
| 9636 | wpa_printf(MSG_ERROR, "ioctl[SIOCSIWPRIV] (pnosetup): %d", |
| 9637 | ret); |
| 9638 | wpa_driver_send_hang_msg(drv); |
| 9639 | return ret; |
| 9640 | } |
| 9641 | |
| 9642 | drv_errors = 0; |
| 9643 | |
| 9644 | return android_priv_cmd(bss, "PNOFORCE 1"); |
| 9645 | } |
| 9646 | |
| 9647 | |
| 9648 | static int android_pno_stop(struct i802_bss *bss) |
| 9649 | { |
| 9650 | return android_priv_cmd(bss, "PNOFORCE 0"); |
| 9651 | } |
| 9652 | |
| 9653 | #endif /* ANDROID */ |
| 9654 | |
| 9655 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9656 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 9657 | enum wpa_alg alg, const u8 *addr, |
| 9658 | int key_idx, int set_tx, |
| 9659 | const u8 *seq, size_t seq_len, |
| 9660 | const u8 *key, size_t key_len) |
| 9661 | { |
| 9662 | struct i802_bss *bss = priv; |
| 9663 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 9664 | set_tx, seq, seq_len, key, key_len); |
| 9665 | } |
| 9666 | |
| 9667 | |
| 9668 | static int driver_nl80211_scan2(void *priv, |
| 9669 | struct wpa_driver_scan_params *params) |
| 9670 | { |
| 9671 | struct i802_bss *bss = priv; |
| 9672 | return wpa_driver_nl80211_scan(bss, params); |
| 9673 | } |
| 9674 | |
| 9675 | |
| 9676 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 9677 | int reason_code) |
| 9678 | { |
| 9679 | struct i802_bss *bss = priv; |
| 9680 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 9681 | } |
| 9682 | |
| 9683 | |
| 9684 | static int driver_nl80211_authenticate(void *priv, |
| 9685 | struct wpa_driver_auth_params *params) |
| 9686 | { |
| 9687 | struct i802_bss *bss = priv; |
| 9688 | return wpa_driver_nl80211_authenticate(bss, params); |
| 9689 | } |
| 9690 | |
| 9691 | |
| 9692 | static void driver_nl80211_deinit(void *priv) |
| 9693 | { |
| 9694 | struct i802_bss *bss = priv; |
| 9695 | wpa_driver_nl80211_deinit(bss); |
| 9696 | } |
| 9697 | |
| 9698 | |
| 9699 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 9700 | const char *ifname) |
| 9701 | { |
| 9702 | struct i802_bss *bss = priv; |
| 9703 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 9704 | } |
| 9705 | |
| 9706 | |
| 9707 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
| 9708 | size_t data_len, int noack) |
| 9709 | { |
| 9710 | struct i802_bss *bss = priv; |
| 9711 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
| 9712 | 0, 0, 0, 0); |
| 9713 | } |
| 9714 | |
| 9715 | |
| 9716 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 9717 | { |
| 9718 | struct i802_bss *bss = priv; |
| 9719 | return wpa_driver_nl80211_sta_remove(bss, addr); |
| 9720 | } |
| 9721 | |
| 9722 | |
| 9723 | #if defined(HOSTAPD) || defined(CONFIG_AP) |
| 9724 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 9725 | const char *ifname, int vlan_id) |
| 9726 | { |
| 9727 | struct i802_bss *bss = priv; |
| 9728 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 9729 | } |
| 9730 | #endif /* HOSTAPD || CONFIG_AP */ |
| 9731 | |
| 9732 | |
| 9733 | static int driver_nl80211_read_sta_data(void *priv, |
| 9734 | struct hostap_sta_driver_data *data, |
| 9735 | const u8 *addr) |
| 9736 | { |
| 9737 | struct i802_bss *bss = priv; |
| 9738 | return i802_read_sta_data(bss, data, addr); |
| 9739 | } |
| 9740 | |
| 9741 | |
| 9742 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 9743 | unsigned int wait_time, |
| 9744 | const u8 *dst, const u8 *src, |
| 9745 | const u8 *bssid, |
| 9746 | const u8 *data, size_t data_len, |
| 9747 | int no_cck) |
| 9748 | { |
| 9749 | struct i802_bss *bss = priv; |
| 9750 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 9751 | bssid, data, data_len, no_cck); |
| 9752 | } |
| 9753 | |
| 9754 | |
| 9755 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 9756 | { |
| 9757 | struct i802_bss *bss = priv; |
| 9758 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 9759 | } |
| 9760 | |
| 9761 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9762 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 9763 | const u8 *ies, size_t ies_len) |
| 9764 | { |
| 9765 | int ret; |
| 9766 | struct nl_msg *msg; |
| 9767 | struct i802_bss *bss = priv; |
| 9768 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9769 | u16 mdid = WPA_GET_LE16(md); |
| 9770 | |
| 9771 | msg = nlmsg_alloc(); |
| 9772 | if (!msg) |
| 9773 | return -ENOMEM; |
| 9774 | |
| 9775 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
| 9776 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UPDATE_FT_IES); |
| 9777 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
| 9778 | NLA_PUT(msg, NL80211_ATTR_IE, ies_len, ies); |
| 9779 | NLA_PUT_U16(msg, NL80211_ATTR_MDID, mdid); |
| 9780 | |
| 9781 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9782 | if (ret) { |
| 9783 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 9784 | "err=%d (%s)", ret, strerror(-ret)); |
| 9785 | } |
| 9786 | |
| 9787 | return ret; |
| 9788 | |
| 9789 | nla_put_failure: |
| 9790 | nlmsg_free(msg); |
| 9791 | return -ENOBUFS; |
| 9792 | } |
| 9793 | |
| 9794 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9795 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 9796 | .name = "nl80211", |
| 9797 | .desc = "Linux nl80211/cfg80211", |
| 9798 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 9799 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9800 | .set_key = driver_nl80211_set_key, |
| 9801 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9802 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 9803 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9804 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9805 | .deauthenticate = driver_nl80211_deauthenticate, |
| 9806 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9807 | .associate = wpa_driver_nl80211_associate, |
| 9808 | .global_init = nl80211_global_init, |
| 9809 | .global_deinit = nl80211_global_deinit, |
| 9810 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9811 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9812 | .get_capa = wpa_driver_nl80211_get_capa, |
| 9813 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 9814 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 9815 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9816 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9817 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9818 | .if_remove = driver_nl80211_if_remove, |
| 9819 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9820 | .get_hw_feature_data = wpa_driver_nl80211_get_hw_feature_data, |
| 9821 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9822 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9823 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 9824 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
| 9825 | #ifdef HOSTAPD |
| 9826 | .hapd_init = i802_init, |
| 9827 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9828 | .set_wds_sta = i802_set_wds_sta, |
| 9829 | #endif /* HOSTAPD */ |
| 9830 | #if defined(HOSTAPD) || defined(CONFIG_AP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9831 | .get_seqnum = i802_get_seqnum, |
| 9832 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9833 | .get_inact_sec = i802_get_inact_sec, |
| 9834 | .sta_clear_stats = i802_sta_clear_stats, |
| 9835 | .set_rts = i802_set_rts, |
| 9836 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9837 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9838 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9839 | .sta_deauth = i802_sta_deauth, |
| 9840 | .sta_disassoc = i802_sta_disassoc, |
| 9841 | #endif /* HOSTAPD || CONFIG_AP */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9842 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9843 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9844 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9845 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 9846 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 9847 | .cancel_remain_on_channel = |
| 9848 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9849 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9850 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9851 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9852 | .resume = wpa_driver_nl80211_resume, |
| 9853 | .send_ft_action = nl80211_send_ft_action, |
| 9854 | .signal_monitor = nl80211_signal_monitor, |
| 9855 | .signal_poll = nl80211_signal_poll, |
| 9856 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9857 | .shared_freq = wpa_driver_nl80211_shared_freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9858 | .set_param = nl80211_set_param, |
| 9859 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9860 | .add_pmkid = nl80211_add_pmkid, |
| 9861 | .remove_pmkid = nl80211_remove_pmkid, |
| 9862 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9863 | .set_rekey_info = nl80211_set_rekey_info, |
| 9864 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9865 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9866 | #ifdef CONFIG_TDLS |
| 9867 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 9868 | .tdls_oper = nl80211_tdls_oper, |
| 9869 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9870 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9871 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9872 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9873 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9874 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
| 9875 | #endif |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9876 | #ifdef ANDROID |
| 9877 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
| 9878 | #endif |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9879 | }; |