2 * Driver interaction with Linux nl80211/cfg80211
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
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
9 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
14 #include <sys/ioctl.h>
15 #include <sys/types.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>
25 #include <linux/errqueue.h>
26 #include "nl80211_copy.h"
30 #include "utils/list.h"
31 #include "common/ieee802_11_defs.h"
32 #include "common/ieee802_11_common.h"
33 #include "l2_packet/l2_packet.h"
35 #include "linux_ioctl.h"
37 #include "radiotap_iter.h"
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
47 # define SO_WIFI_STATUS 41
50 # define SCM_WIFI_STATUS SO_WIFI_STATUS
53 #ifndef SO_EE_ORIGIN_TXSTATUS
54 #define SO_EE_ORIGIN_TXSTATUS 4
57 #ifndef PACKET_TX_TIMESTAMP
58 #define PACKET_TX_TIMESTAMP 16
62 #include "android_drv.h"
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
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
77 static uint32_t port_bitmap
[32] = { 0 };
79 static struct nl_handle
*nl80211_handle_alloc(void *cb
)
81 struct nl_handle
*handle
;
82 uint32_t pid
= getpid() & 0x3FFFFF;
85 handle
= nl_handle_alloc_cb(cb
);
87 for (i
= 0; i
< 1024; i
++) {
88 if (port_bitmap
[i
/ 32] & (1 << (i
% 32)))
90 port_bitmap
[i
/ 32] |= 1 << (i
% 32);
95 nl_socket_set_local_port(handle
, pid
);
100 static void nl80211_handle_destroy(struct nl_handle
*handle
)
102 uint32_t port
= nl_socket_get_local_port(handle
);
105 port_bitmap
[port
/ 32] &= ~(1 << (port
% 32));
107 nl_handle_destroy(handle
);
109 #endif /* CONFIG_LIBNL20 */
113 /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
114 static int android_nl_socket_set_nonblocking(struct nl_handle
*handle
)
116 return fcntl(nl_socket_get_fd(handle
), F_SETFL
, O_NONBLOCK
);
118 #undef nl_socket_set_nonblocking
119 #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
123 static struct nl_handle
* nl_create_handle(struct nl_cb
*cb
, const char *dbg
)
125 struct nl_handle
*handle
;
127 handle
= nl80211_handle_alloc(cb
);
128 if (handle
== NULL
) {
129 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
130 "callbacks (%s)", dbg
);
134 if (genl_connect(handle
)) {
135 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect to generic "
136 "netlink (%s)", dbg
);
137 nl80211_handle_destroy(handle
);
145 static void nl_destroy_handles(struct nl_handle
**handle
)
149 nl80211_handle_destroy(*handle
);
155 #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
157 #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
160 static void nl80211_register_eloop_read(struct nl_handle
**handle
,
161 eloop_sock_handler handler
,
164 nl_socket_set_nonblocking(*handle
);
165 eloop_register_read_sock(nl_socket_get_fd(*handle
), handler
,
166 eloop_data
, *handle
);
167 *handle
= (void *) (((intptr_t) *handle
) ^ ELOOP_SOCKET_INVALID
);
171 static void nl80211_destroy_eloop_handle(struct nl_handle
**handle
)
173 *handle
= (void *) (((intptr_t) *handle
) ^ ELOOP_SOCKET_INVALID
);
174 eloop_unregister_read_sock(nl_socket_get_fd(*handle
));
175 nl_destroy_handles(handle
);
180 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
183 #define IFF_DORMANT 0x20000 /* driver signals dormant */
186 #ifndef IF_OPER_DORMANT
187 #define IF_OPER_DORMANT 5
193 struct nl80211_global
{
194 struct dl_list interfaces
;
197 int if_add_wdevid_set
;
198 struct netlink_data
*netlink
;
200 struct nl_handle
*nl
;
202 int ioctl_sock
; /* socket for ioctl() use */
204 struct nl_handle
*nl_event
;
207 struct nl80211_wiphy_data
{
212 struct nl_handle
*nl_beacons
;
218 static void nl80211_global_deinit(void *priv
);
221 struct wpa_driver_nl80211_data
*drv
;
222 struct i802_bss
*next
;
225 char ifname
[IFNAMSIZ
+ 1];
226 char brname
[IFNAMSIZ
];
227 unsigned int beacon_set
:1;
228 unsigned int added_if_into_bridge
:1;
229 unsigned int added_bridge
:1;
230 unsigned int in_deinit
:1;
231 unsigned int wdev_id_set
:1;
232 unsigned int added_if
:1;
240 struct nl_handle
*nl_preq
, *nl_mgmt
;
243 struct nl80211_wiphy_data
*wiphy_data
;
244 struct dl_list wiphy_list
;
247 struct wpa_driver_nl80211_data
{
248 struct nl80211_global
*global
;
250 struct dl_list wiphy_list
;
256 int ignore_if_down_event
;
257 struct rfkill_data
*rfkill
;
258 struct wpa_driver_capa capa
;
259 u8
*extended_capa
, *extended_capa_mask
;
260 unsigned int extended_capa_len
;
265 int scan_complete_events
;
267 NO_SCAN
, SCAN_REQUESTED
, SCAN_STARTED
, SCAN_COMPLETED
,
268 SCAN_ABORTED
, SCHED_SCAN_STARTED
, SCHED_SCAN_STOPPED
,
274 u8 auth_bssid
[ETH_ALEN
];
275 u8 auth_attempt_bssid
[ETH_ALEN
];
277 u8 prev_bssid
[ETH_ALEN
];
281 enum nl80211_iftype nlmode
;
282 enum nl80211_iftype ap_scan_as_station
;
283 unsigned int assoc_freq
;
287 int monitor_refcount
;
289 unsigned int disabled_11b_rates
:1;
290 unsigned int pending_remain_on_chan
:1;
291 unsigned int in_interface_list
:1;
292 unsigned int device_ap_sme
:1;
293 unsigned int poll_command_supported
:1;
294 unsigned int data_tx_status
:1;
295 unsigned int scan_for_auth
:1;
296 unsigned int retry_auth
:1;
297 unsigned int use_monitor
:1;
298 unsigned int ignore_next_local_disconnect
:1;
299 unsigned int allow_p2p_device
:1;
301 u64 remain_on_chan_cookie
;
302 u64 send_action_cookie
;
304 unsigned int last_mgmt_freq
;
306 struct wpa_driver_scan_filter
*filter_ssids
;
307 size_t num_filter_ssids
;
309 struct i802_bss
*first_bss
;
314 int eapol_sock
; /* socket for EAPOL frames */
316 int default_if_indices
[16];
324 /* From failed authentication command */
326 u8 auth_bssid_
[ETH_ALEN
];
328 size_t auth_ssid_len
;
332 u8 auth_wep_key
[4][16];
333 size_t auth_wep_key_len
[4];
334 int auth_wep_tx_keyidx
;
335 int auth_local_state_change
;
340 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
);
341 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
,
343 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
344 enum nl80211_iftype nlmode
);
346 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
);
347 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
348 const u8
*addr
, int cmd
, u16 reason_code
,
349 int local_state_change
);
350 static void nl80211_remove_monitor_interface(
351 struct wpa_driver_nl80211_data
*drv
);
352 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
353 unsigned int freq
, unsigned int wait
,
354 const u8
*buf
, size_t buf_len
, u64
*cookie
,
355 int no_cck
, int no_ack
, int offchanok
);
356 static int nl80211_register_frame(struct i802_bss
*bss
,
357 struct nl_handle
*hl_handle
,
358 u16 type
, const u8
*match
, size_t match_len
);
359 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
,
362 static int android_pno_start(struct i802_bss
*bss
,
363 struct wpa_driver_scan_params
*params
);
364 static int android_pno_stop(struct i802_bss
*bss
);
368 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
369 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
370 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
371 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
372 enum wpa_driver_if_type type
,
375 static inline void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
379 static inline void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
383 static inline int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
389 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
390 struct hostapd_freq_params
*freq
);
391 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
392 int ifindex
, int disabled
);
394 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
);
395 static int wpa_driver_nl80211_authenticate_retry(
396 struct wpa_driver_nl80211_data
*drv
);
398 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
);
401 static const char * nl80211_command_to_string(enum nl80211_commands cmd
)
403 #define C2S(x) case x: return #x;
405 C2S(NL80211_CMD_UNSPEC
)
406 C2S(NL80211_CMD_GET_WIPHY
)
407 C2S(NL80211_CMD_SET_WIPHY
)
408 C2S(NL80211_CMD_NEW_WIPHY
)
409 C2S(NL80211_CMD_DEL_WIPHY
)
410 C2S(NL80211_CMD_GET_INTERFACE
)
411 C2S(NL80211_CMD_SET_INTERFACE
)
412 C2S(NL80211_CMD_NEW_INTERFACE
)
413 C2S(NL80211_CMD_DEL_INTERFACE
)
414 C2S(NL80211_CMD_GET_KEY
)
415 C2S(NL80211_CMD_SET_KEY
)
416 C2S(NL80211_CMD_NEW_KEY
)
417 C2S(NL80211_CMD_DEL_KEY
)
418 C2S(NL80211_CMD_GET_BEACON
)
419 C2S(NL80211_CMD_SET_BEACON
)
420 C2S(NL80211_CMD_START_AP
)
421 C2S(NL80211_CMD_STOP_AP
)
422 C2S(NL80211_CMD_GET_STATION
)
423 C2S(NL80211_CMD_SET_STATION
)
424 C2S(NL80211_CMD_NEW_STATION
)
425 C2S(NL80211_CMD_DEL_STATION
)
426 C2S(NL80211_CMD_GET_MPATH
)
427 C2S(NL80211_CMD_SET_MPATH
)
428 C2S(NL80211_CMD_NEW_MPATH
)
429 C2S(NL80211_CMD_DEL_MPATH
)
430 C2S(NL80211_CMD_SET_BSS
)
431 C2S(NL80211_CMD_SET_REG
)
432 C2S(NL80211_CMD_REQ_SET_REG
)
433 C2S(NL80211_CMD_GET_MESH_CONFIG
)
434 C2S(NL80211_CMD_SET_MESH_CONFIG
)
435 C2S(NL80211_CMD_SET_MGMT_EXTRA_IE
)
436 C2S(NL80211_CMD_GET_REG
)
437 C2S(NL80211_CMD_GET_SCAN
)
438 C2S(NL80211_CMD_TRIGGER_SCAN
)
439 C2S(NL80211_CMD_NEW_SCAN_RESULTS
)
440 C2S(NL80211_CMD_SCAN_ABORTED
)
441 C2S(NL80211_CMD_REG_CHANGE
)
442 C2S(NL80211_CMD_AUTHENTICATE
)
443 C2S(NL80211_CMD_ASSOCIATE
)
444 C2S(NL80211_CMD_DEAUTHENTICATE
)
445 C2S(NL80211_CMD_DISASSOCIATE
)
446 C2S(NL80211_CMD_MICHAEL_MIC_FAILURE
)
447 C2S(NL80211_CMD_REG_BEACON_HINT
)
448 C2S(NL80211_CMD_JOIN_IBSS
)
449 C2S(NL80211_CMD_LEAVE_IBSS
)
450 C2S(NL80211_CMD_TESTMODE
)
451 C2S(NL80211_CMD_CONNECT
)
452 C2S(NL80211_CMD_ROAM
)
453 C2S(NL80211_CMD_DISCONNECT
)
454 C2S(NL80211_CMD_SET_WIPHY_NETNS
)
455 C2S(NL80211_CMD_GET_SURVEY
)
456 C2S(NL80211_CMD_NEW_SURVEY_RESULTS
)
457 C2S(NL80211_CMD_SET_PMKSA
)
458 C2S(NL80211_CMD_DEL_PMKSA
)
459 C2S(NL80211_CMD_FLUSH_PMKSA
)
460 C2S(NL80211_CMD_REMAIN_ON_CHANNEL
)
461 C2S(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
)
462 C2S(NL80211_CMD_SET_TX_BITRATE_MASK
)
463 C2S(NL80211_CMD_REGISTER_FRAME
)
464 C2S(NL80211_CMD_FRAME
)
465 C2S(NL80211_CMD_FRAME_TX_STATUS
)
466 C2S(NL80211_CMD_SET_POWER_SAVE
)
467 C2S(NL80211_CMD_GET_POWER_SAVE
)
468 C2S(NL80211_CMD_SET_CQM
)
469 C2S(NL80211_CMD_NOTIFY_CQM
)
470 C2S(NL80211_CMD_SET_CHANNEL
)
471 C2S(NL80211_CMD_SET_WDS_PEER
)
472 C2S(NL80211_CMD_FRAME_WAIT_CANCEL
)
473 C2S(NL80211_CMD_JOIN_MESH
)
474 C2S(NL80211_CMD_LEAVE_MESH
)
475 C2S(NL80211_CMD_UNPROT_DEAUTHENTICATE
)
476 C2S(NL80211_CMD_UNPROT_DISASSOCIATE
)
477 C2S(NL80211_CMD_NEW_PEER_CANDIDATE
)
478 C2S(NL80211_CMD_GET_WOWLAN
)
479 C2S(NL80211_CMD_SET_WOWLAN
)
480 C2S(NL80211_CMD_START_SCHED_SCAN
)
481 C2S(NL80211_CMD_STOP_SCHED_SCAN
)
482 C2S(NL80211_CMD_SCHED_SCAN_RESULTS
)
483 C2S(NL80211_CMD_SCHED_SCAN_STOPPED
)
484 C2S(NL80211_CMD_SET_REKEY_OFFLOAD
)
485 C2S(NL80211_CMD_PMKSA_CANDIDATE
)
486 C2S(NL80211_CMD_TDLS_OPER
)
487 C2S(NL80211_CMD_TDLS_MGMT
)
488 C2S(NL80211_CMD_UNEXPECTED_FRAME
)
489 C2S(NL80211_CMD_PROBE_CLIENT
)
490 C2S(NL80211_CMD_REGISTER_BEACONS
)
491 C2S(NL80211_CMD_UNEXPECTED_4ADDR_FRAME
)
492 C2S(NL80211_CMD_SET_NOACK_MAP
)
493 C2S(NL80211_CMD_CH_SWITCH_NOTIFY
)
494 C2S(NL80211_CMD_START_P2P_DEVICE
)
495 C2S(NL80211_CMD_STOP_P2P_DEVICE
)
496 C2S(NL80211_CMD_CONN_FAILED
)
497 C2S(NL80211_CMD_SET_MCAST_RATE
)
498 C2S(NL80211_CMD_SET_MAC_ACL
)
499 C2S(NL80211_CMD_RADAR_DETECT
)
500 C2S(NL80211_CMD_GET_PROTOCOL_FEATURES
)
501 C2S(NL80211_CMD_UPDATE_FT_IES
)
502 C2S(NL80211_CMD_FT_EVENT
)
503 C2S(NL80211_CMD_CRIT_PROTOCOL_START
)
504 C2S(NL80211_CMD_CRIT_PROTOCOL_STOP
)
506 return "NL80211_CMD_UNKNOWN";
512 static int is_ap_interface(enum nl80211_iftype nlmode
)
514 return (nlmode
== NL80211_IFTYPE_AP
||
515 nlmode
== NL80211_IFTYPE_P2P_GO
);
519 static int is_sta_interface(enum nl80211_iftype nlmode
)
521 return (nlmode
== NL80211_IFTYPE_STATION
||
522 nlmode
== NL80211_IFTYPE_P2P_CLIENT
);
526 static int is_p2p_net_interface(enum nl80211_iftype nlmode
)
528 return (nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
529 nlmode
== NL80211_IFTYPE_P2P_GO
);
533 static void nl80211_mark_disconnected(struct wpa_driver_nl80211_data
*drv
)
536 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
538 os_memset(drv
->bssid
, 0, ETH_ALEN
);
542 struct nl80211_bss_info_arg
{
543 struct wpa_driver_nl80211_data
*drv
;
544 struct wpa_scan_results
*res
;
545 unsigned int assoc_freq
;
546 u8 assoc_bssid
[ETH_ALEN
];
549 static int bss_info_handler(struct nl_msg
*msg
, void *arg
);
553 static int ack_handler(struct nl_msg
*msg
, void *arg
)
560 static int finish_handler(struct nl_msg
*msg
, void *arg
)
567 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
576 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
582 static int send_and_recv(struct nl80211_global
*global
,
583 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
584 int (*valid_handler
)(struct nl_msg
*, void *),
590 cb
= nl_cb_clone(global
->nl_cb
);
594 err
= nl_send_auto_complete(nl_handle
, msg
);
600 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
601 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
602 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
605 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
606 valid_handler
, valid_data
);
609 int res
= nl_recvmsgs(nl_handle
, cb
);
612 "nl80211: %s->nl_recvmsgs failed: %d",
623 static int send_and_recv_msgs_global(struct nl80211_global
*global
,
625 int (*valid_handler
)(struct nl_msg
*, void *),
628 return send_and_recv(global
, global
->nl
, msg
, valid_handler
,
633 static int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
635 int (*valid_handler
)(struct nl_msg
*, void *),
638 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
639 valid_handler
, valid_data
);
649 static int nl80211_set_iface_id(struct nl_msg
*msg
, struct i802_bss
*bss
)
651 if (bss
->wdev_id_set
)
652 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
654 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
662 static int family_handler(struct nl_msg
*msg
, void *arg
)
664 struct family_data
*res
= arg
;
665 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
666 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
667 struct nlattr
*mcgrp
;
670 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
671 genlmsg_attrlen(gnlh
, 0), NULL
);
672 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
675 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
676 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
677 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
678 nla_len(mcgrp
), NULL
);
679 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
680 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
681 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
683 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
685 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
693 static int nl_get_multicast_id(struct nl80211_global
*global
,
694 const char *family
, const char *group
)
698 struct family_data res
= { group
, -ENOENT
};
703 genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
704 0, 0, CTRL_CMD_GETFAMILY
, 0);
705 NLA_PUT_STRING(msg
, CTRL_ATTR_FAMILY_NAME
, family
);
707 ret
= send_and_recv_msgs_global(global
, msg
, family_handler
, &res
);
718 static void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
719 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
721 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
726 struct wiphy_idx_data
{
728 enum nl80211_iftype nlmode
;
733 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
735 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
736 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
737 struct wiphy_idx_data
*info
= arg
;
739 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
740 genlmsg_attrlen(gnlh
, 0), NULL
);
742 if (tb
[NL80211_ATTR_WIPHY
])
743 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
745 if (tb
[NL80211_ATTR_IFTYPE
])
746 info
->nlmode
= nla_get_u32(tb
[NL80211_ATTR_IFTYPE
]);
748 if (tb
[NL80211_ATTR_MAC
] && info
->macaddr
)
749 os_memcpy(info
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
756 static int nl80211_get_wiphy_index(struct i802_bss
*bss
)
759 struct wiphy_idx_data data
= {
766 return NL80211_IFTYPE_UNSPECIFIED
;
768 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
770 if (nl80211_set_iface_id(msg
, bss
) < 0)
771 goto nla_put_failure
;
773 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
774 return data
.wiphy_idx
;
782 static enum nl80211_iftype
nl80211_get_ifmode(struct i802_bss
*bss
)
785 struct wiphy_idx_data data
= {
786 .nlmode
= NL80211_IFTYPE_UNSPECIFIED
,
794 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
796 if (nl80211_set_iface_id(msg
, bss
) < 0)
797 goto nla_put_failure
;
799 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
804 return NL80211_IFTYPE_UNSPECIFIED
;
809 static int nl80211_get_macaddr(struct i802_bss
*bss
)
812 struct wiphy_idx_data data
= {
813 .macaddr
= bss
->addr
,
818 return NL80211_IFTYPE_UNSPECIFIED
;
820 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
821 if (nl80211_set_iface_id(msg
, bss
) < 0)
822 goto nla_put_failure
;
824 return send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
);
828 return NL80211_IFTYPE_UNSPECIFIED
;
833 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
834 struct nl80211_wiphy_data
*w
)
843 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
);
845 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
);
847 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
850 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
851 "failed: ret=%d (%s)",
852 ret
, strerror(-ret
));
853 goto nla_put_failure
;
862 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
864 struct nl80211_wiphy_data
*w
= eloop_ctx
;
867 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
869 res
= nl_recvmsgs(handle
, w
->nl_cb
);
871 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
877 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
879 struct nl80211_wiphy_data
*w
= arg
;
880 struct wpa_driver_nl80211_data
*drv
;
881 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
882 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
883 union wpa_event_data event
;
885 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
886 genlmsg_attrlen(gnlh
, 0), NULL
);
888 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
889 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
894 if (!tb
[NL80211_ATTR_FRAME
])
897 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
899 os_memset(&event
, 0, sizeof(event
));
900 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
901 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
902 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
909 static struct nl80211_wiphy_data
*
910 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
912 static DEFINE_DL_LIST(nl80211_wiphys
);
913 struct nl80211_wiphy_data
*w
;
914 int wiphy_idx
, found
= 0;
915 struct i802_bss
*tmp_bss
;
917 if (bss
->wiphy_data
!= NULL
)
918 return bss
->wiphy_data
;
920 wiphy_idx
= nl80211_get_wiphy_index(bss
);
922 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
923 if (w
->wiphy_idx
== wiphy_idx
)
928 w
= os_zalloc(sizeof(*w
));
931 w
->wiphy_idx
= wiphy_idx
;
932 dl_list_init(&w
->bsss
);
933 dl_list_init(&w
->drvs
);
935 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
940 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
941 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
944 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
946 if (w
->nl_beacons
== NULL
) {
951 if (nl80211_register_beacons(bss
->drv
, w
)) {
952 nl_destroy_handles(&w
->nl_beacons
);
957 nl80211_register_eloop_read(&w
->nl_beacons
, nl80211_recv_beacons
, w
);
959 dl_list_add(&nl80211_wiphys
, &w
->list
);
962 /* drv entry for this bss already there? */
963 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
964 if (tmp_bss
->drv
== bss
->drv
) {
971 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
973 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
979 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
981 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
982 struct i802_bss
*tmp_bss
;
987 bss
->wiphy_data
= NULL
;
988 dl_list_del(&bss
->wiphy_list
);
990 /* still any for this drv present? */
991 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
992 if (tmp_bss
->drv
== bss
->drv
) {
997 /* if not remove it */
999 dl_list_del(&bss
->drv
->wiphy_list
);
1001 if (!dl_list_empty(&w
->bsss
))
1004 nl80211_destroy_eloop_handle(&w
->nl_beacons
);
1006 nl_cb_put(w
->nl_cb
);
1007 dl_list_del(&w
->list
);
1012 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
1014 struct i802_bss
*bss
= priv
;
1015 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1016 if (!drv
->associated
)
1018 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
1023 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
1025 struct i802_bss
*bss
= priv
;
1026 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1027 if (!drv
->associated
)
1029 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
1030 return drv
->ssid_len
;
1034 static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data
*drv
,
1035 char *buf
, size_t len
, int del
)
1037 union wpa_event_data event
;
1039 os_memset(&event
, 0, sizeof(event
));
1040 if (len
> sizeof(event
.interface_status
.ifname
))
1041 len
= sizeof(event
.interface_status
.ifname
) - 1;
1042 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
1043 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
1044 EVENT_INTERFACE_ADDED
;
1046 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
1047 del
? "DEL" : "NEW",
1048 event
.interface_status
.ifname
,
1049 del
? "removed" : "added");
1051 if (os_strcmp(drv
->first_bss
->ifname
, event
.interface_status
.ifname
) ==
1054 if (drv
->if_removed
) {
1055 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
1056 "already set - ignore event");
1059 drv
->if_removed
= 1;
1061 if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
1062 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s "
1063 "does not exist - ignore "
1065 drv
->first_bss
->ifname
);
1068 if (!drv
->if_removed
) {
1069 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
1070 "already cleared - ignore event");
1073 drv
->if_removed
= 0;
1077 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
1081 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
1082 u8
*buf
, size_t len
)
1084 int attrlen
, rta_len
;
1085 struct rtattr
*attr
;
1088 attr
= (struct rtattr
*) buf
;
1090 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1091 while (RTA_OK(attr
, attrlen
)) {
1092 if (attr
->rta_type
== IFLA_IFNAME
) {
1093 if (os_strcmp(((char *) attr
) + rta_len
,
1094 drv
->first_bss
->ifname
) == 0)
1099 attr
= RTA_NEXT(attr
, attrlen
);
1106 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
1107 int ifindex
, u8
*buf
, size_t len
)
1109 if (drv
->ifindex
== ifindex
)
1112 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
1113 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
1115 wpa_driver_nl80211_finish_drv_init(drv
);
1123 static struct wpa_driver_nl80211_data
*
1124 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
1126 struct wpa_driver_nl80211_data
*drv
;
1127 dl_list_for_each(drv
, &global
->interfaces
,
1128 struct wpa_driver_nl80211_data
, list
) {
1129 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
1130 have_ifidx(drv
, idx
))
1137 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
1138 struct ifinfomsg
*ifi
,
1139 u8
*buf
, size_t len
)
1141 struct nl80211_global
*global
= ctx
;
1142 struct wpa_driver_nl80211_data
*drv
;
1143 int attrlen
, rta_len
;
1144 struct rtattr
*attr
;
1146 char namebuf
[IFNAMSIZ
];
1148 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1150 wpa_printf(MSG_DEBUG
, "nl80211: Ignore event for foreign "
1151 "ifindex %d", ifi
->ifi_index
);
1155 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
1157 drv
->operstate
, ifi
->ifi_flags
,
1158 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1159 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1160 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1161 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1163 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
1164 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1165 linux_iface_up(drv
->global
->ioctl_sock
,
1166 drv
->first_bss
->ifname
) > 0) {
1167 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1168 "event since interface %s is up", namebuf
);
1171 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
1172 if (drv
->ignore_if_down_event
) {
1173 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1174 "event generated by mode change");
1175 drv
->ignore_if_down_event
= 0;
1177 drv
->if_disabled
= 1;
1178 wpa_supplicant_event(drv
->ctx
,
1179 EVENT_INTERFACE_DISABLED
, NULL
);
1183 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
1184 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1185 linux_iface_up(drv
->global
->ioctl_sock
,
1186 drv
->first_bss
->ifname
) == 0) {
1187 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1188 "event since interface %s is down",
1190 } else if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
1191 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1192 "event since interface %s does not exist",
1193 drv
->first_bss
->ifname
);
1194 } else if (drv
->if_removed
) {
1195 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1196 "event since interface %s is marked "
1197 "removed", drv
->first_bss
->ifname
);
1199 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
1200 drv
->if_disabled
= 0;
1201 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
1207 * Some drivers send the association event before the operup event--in
1208 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1209 * fails. This will hit us when wpa_supplicant does not need to do
1210 * IEEE 802.1X authentication
1212 if (drv
->operstate
== 1 &&
1213 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
1214 !(ifi
->ifi_flags
& IFF_RUNNING
))
1215 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
1219 attr
= (struct rtattr
*) buf
;
1220 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1221 while (RTA_OK(attr
, attrlen
)) {
1222 if (attr
->rta_type
== IFLA_IFNAME
) {
1223 wpa_driver_nl80211_event_link(
1225 ((char *) attr
) + rta_len
,
1226 attr
->rta_len
- rta_len
, 0);
1227 } else if (attr
->rta_type
== IFLA_MASTER
)
1228 brid
= nla_get_u32((struct nlattr
*) attr
);
1229 attr
= RTA_NEXT(attr
, attrlen
);
1232 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1233 /* device has been added to bridge */
1234 if_indextoname(brid
, namebuf
);
1235 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
1237 add_ifidx(drv
, brid
);
1242 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
1243 struct ifinfomsg
*ifi
,
1244 u8
*buf
, size_t len
)
1246 struct nl80211_global
*global
= ctx
;
1247 struct wpa_driver_nl80211_data
*drv
;
1248 int attrlen
, rta_len
;
1249 struct rtattr
*attr
;
1252 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1254 wpa_printf(MSG_DEBUG
, "nl80211: Ignore dellink event for "
1255 "foreign ifindex %d", ifi
->ifi_index
);
1260 attr
= (struct rtattr
*) buf
;
1262 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1263 while (RTA_OK(attr
, attrlen
)) {
1264 if (attr
->rta_type
== IFLA_IFNAME
) {
1265 wpa_driver_nl80211_event_link(
1267 ((char *) attr
) + rta_len
,
1268 attr
->rta_len
- rta_len
, 1);
1269 } else if (attr
->rta_type
== IFLA_MASTER
)
1270 brid
= nla_get_u32((struct nlattr
*) attr
);
1271 attr
= RTA_NEXT(attr
, attrlen
);
1274 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1275 /* device has been removed from bridge */
1276 char namebuf
[IFNAMSIZ
];
1277 if_indextoname(brid
, namebuf
);
1278 wpa_printf(MSG_DEBUG
, "nl80211: Remove ifindex %u for bridge "
1279 "%s", brid
, namebuf
);
1280 del_ifidx(drv
, brid
);
1285 static void mlme_event_auth(struct wpa_driver_nl80211_data
*drv
,
1286 const u8
*frame
, size_t len
)
1288 const struct ieee80211_mgmt
*mgmt
;
1289 union wpa_event_data event
;
1291 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate event");
1292 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1293 if (len
< 24 + sizeof(mgmt
->u
.auth
)) {
1294 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1299 os_memcpy(drv
->auth_bssid
, mgmt
->sa
, ETH_ALEN
);
1300 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
1301 os_memset(&event
, 0, sizeof(event
));
1302 os_memcpy(event
.auth
.peer
, mgmt
->sa
, ETH_ALEN
);
1303 event
.auth
.auth_type
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
1304 event
.auth
.auth_transaction
=
1305 le_to_host16(mgmt
->u
.auth
.auth_transaction
);
1306 event
.auth
.status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
1307 if (len
> 24 + sizeof(mgmt
->u
.auth
)) {
1308 event
.auth
.ies
= mgmt
->u
.auth
.variable
;
1309 event
.auth
.ies_len
= len
- 24 - sizeof(mgmt
->u
.auth
);
1312 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH
, &event
);
1316 static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1320 struct nl80211_bss_info_arg arg
;
1322 os_memset(&arg
, 0, sizeof(arg
));
1323 msg
= nlmsg_alloc();
1325 goto nla_put_failure
;
1327 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1328 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1331 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
1334 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1335 "associated BSS from scan results: %u MHz",
1338 drv
->assoc_freq
= arg
.assoc_freq
;
1339 return drv
->assoc_freq
;
1341 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1342 "(%s)", ret
, strerror(-ret
));
1345 return drv
->assoc_freq
;
1349 static void mlme_event_assoc(struct wpa_driver_nl80211_data
*drv
,
1350 const u8
*frame
, size_t len
)
1352 const struct ieee80211_mgmt
*mgmt
;
1353 union wpa_event_data event
;
1356 wpa_printf(MSG_DEBUG
, "nl80211: Associate event");
1357 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1358 if (len
< 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1359 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1364 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
1365 if (status
!= WLAN_STATUS_SUCCESS
) {
1366 os_memset(&event
, 0, sizeof(event
));
1367 event
.assoc_reject
.bssid
= mgmt
->bssid
;
1368 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1369 event
.assoc_reject
.resp_ies
=
1370 (u8
*) mgmt
->u
.assoc_resp
.variable
;
1371 event
.assoc_reject
.resp_ies_len
=
1372 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1374 event
.assoc_reject
.status_code
= status
;
1376 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1380 drv
->associated
= 1;
1381 os_memcpy(drv
->bssid
, mgmt
->sa
, ETH_ALEN
);
1382 os_memcpy(drv
->prev_bssid
, mgmt
->sa
, ETH_ALEN
);
1384 os_memset(&event
, 0, sizeof(event
));
1385 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1386 event
.assoc_info
.resp_ies
= (u8
*) mgmt
->u
.assoc_resp
.variable
;
1387 event
.assoc_info
.resp_ies_len
=
1388 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1391 event
.assoc_info
.freq
= drv
->assoc_freq
;
1393 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1397 static void mlme_event_connect(struct wpa_driver_nl80211_data
*drv
,
1398 enum nl80211_commands cmd
, struct nlattr
*status
,
1399 struct nlattr
*addr
, struct nlattr
*req_ie
,
1400 struct nlattr
*resp_ie
)
1402 union wpa_event_data event
;
1404 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1406 * Avoid reporting two association events that would confuse
1409 wpa_printf(MSG_DEBUG
, "nl80211: Ignore connect event (cmd=%d) "
1410 "when using userspace SME", cmd
);
1414 if (cmd
== NL80211_CMD_CONNECT
)
1415 wpa_printf(MSG_DEBUG
, "nl80211: Connect event");
1416 else if (cmd
== NL80211_CMD_ROAM
)
1417 wpa_printf(MSG_DEBUG
, "nl80211: Roam event");
1419 os_memset(&event
, 0, sizeof(event
));
1420 if (cmd
== NL80211_CMD_CONNECT
&&
1421 nla_get_u16(status
) != WLAN_STATUS_SUCCESS
) {
1423 event
.assoc_reject
.bssid
= nla_data(addr
);
1425 event
.assoc_reject
.resp_ies
= nla_data(resp_ie
);
1426 event
.assoc_reject
.resp_ies_len
= nla_len(resp_ie
);
1428 event
.assoc_reject
.status_code
= nla_get_u16(status
);
1429 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1433 drv
->associated
= 1;
1435 os_memcpy(drv
->bssid
, nla_data(addr
), ETH_ALEN
);
1436 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
1440 event
.assoc_info
.req_ies
= nla_data(req_ie
);
1441 event
.assoc_info
.req_ies_len
= nla_len(req_ie
);
1444 event
.assoc_info
.resp_ies
= nla_data(resp_ie
);
1445 event
.assoc_info
.resp_ies_len
= nla_len(resp_ie
);
1448 event
.assoc_info
.freq
= nl80211_get_assoc_freq(drv
);
1450 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1454 static void mlme_event_disconnect(struct wpa_driver_nl80211_data
*drv
,
1455 struct nlattr
*reason
, struct nlattr
*addr
,
1456 struct nlattr
*by_ap
)
1458 union wpa_event_data data
;
1459 unsigned int locally_generated
= by_ap
== NULL
;
1461 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1463 * Avoid reporting two disassociation events that could
1464 * confuse the core code.
1466 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1467 "event when using userspace SME");
1471 if (drv
->ignore_next_local_disconnect
) {
1472 drv
->ignore_next_local_disconnect
= 0;
1473 if (locally_generated
) {
1474 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1475 "event triggered during reassociation");
1478 wpa_printf(MSG_WARNING
, "nl80211: Was expecting local "
1479 "disconnect but got another disconnect "
1483 wpa_printf(MSG_DEBUG
, "nl80211: Disconnect event");
1484 nl80211_mark_disconnected(drv
);
1485 os_memset(&data
, 0, sizeof(data
));
1487 data
.deauth_info
.reason_code
= nla_get_u16(reason
);
1488 data
.deauth_info
.locally_generated
= by_ap
== NULL
;
1489 wpa_supplicant_event(drv
->ctx
, EVENT_DEAUTH
, &data
);
1493 static void mlme_event_ch_switch(struct wpa_driver_nl80211_data
*drv
,
1494 struct nlattr
*freq
, struct nlattr
*type
)
1496 union wpa_event_data data
;
1498 int chan_offset
= 0;
1500 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch event");
1505 switch (nla_get_u32(type
)) {
1506 case NL80211_CHAN_NO_HT
:
1509 case NL80211_CHAN_HT20
:
1511 case NL80211_CHAN_HT40PLUS
:
1514 case NL80211_CHAN_HT40MINUS
:
1519 data
.ch_switch
.freq
= nla_get_u32(freq
);
1520 data
.ch_switch
.ht_enabled
= ht_enabled
;
1521 data
.ch_switch
.ch_offset
= chan_offset
;
1523 wpa_supplicant_event(drv
->ctx
, EVENT_CH_SWITCH
, &data
);
1527 static void mlme_timeout_event(struct wpa_driver_nl80211_data
*drv
,
1528 enum nl80211_commands cmd
, struct nlattr
*addr
)
1530 union wpa_event_data event
;
1531 enum wpa_event_type ev
;
1533 if (nla_len(addr
) != ETH_ALEN
)
1536 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d; timeout with " MACSTR
,
1537 cmd
, MAC2STR((u8
*) nla_data(addr
)));
1539 if (cmd
== NL80211_CMD_AUTHENTICATE
)
1540 ev
= EVENT_AUTH_TIMED_OUT
;
1541 else if (cmd
== NL80211_CMD_ASSOCIATE
)
1542 ev
= EVENT_ASSOC_TIMED_OUT
;
1546 os_memset(&event
, 0, sizeof(event
));
1547 os_memcpy(event
.timeout_event
.addr
, nla_data(addr
), ETH_ALEN
);
1548 wpa_supplicant_event(drv
->ctx
, ev
, &event
);
1552 static void mlme_event_mgmt(struct wpa_driver_nl80211_data
*drv
,
1553 struct nlattr
*freq
, struct nlattr
*sig
,
1554 const u8
*frame
, size_t len
)
1556 const struct ieee80211_mgmt
*mgmt
;
1557 union wpa_event_data event
;
1562 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame event");
1563 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1565 wpa_printf(MSG_DEBUG
, "nl80211: Too short action frame");
1569 fc
= le_to_host16(mgmt
->frame_control
);
1570 stype
= WLAN_FC_GET_STYPE(fc
);
1573 ssi_signal
= (s32
) nla_get_u32(sig
);
1575 os_memset(&event
, 0, sizeof(event
));
1577 event
.rx_action
.freq
= nla_get_u32(freq
);
1578 rx_freq
= drv
->last_mgmt_freq
= event
.rx_action
.freq
;
1580 wpa_printf(MSG_DEBUG
,
1581 "nl80211: RX frame freq=%d ssi_signal=%d stype=%u len=%u",
1582 rx_freq
, ssi_signal
, stype
, (unsigned int) len
);
1583 if (stype
== WLAN_FC_STYPE_ACTION
) {
1584 event
.rx_action
.da
= mgmt
->da
;
1585 event
.rx_action
.sa
= mgmt
->sa
;
1586 event
.rx_action
.bssid
= mgmt
->bssid
;
1587 event
.rx_action
.category
= mgmt
->u
.action
.category
;
1588 event
.rx_action
.data
= &mgmt
->u
.action
.category
+ 1;
1589 event
.rx_action
.len
= frame
+ len
- event
.rx_action
.data
;
1590 wpa_supplicant_event(drv
->ctx
, EVENT_RX_ACTION
, &event
);
1592 event
.rx_mgmt
.frame
= frame
;
1593 event
.rx_mgmt
.frame_len
= len
;
1594 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1595 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
1600 static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data
*drv
,
1601 struct nlattr
*cookie
, const u8
*frame
,
1602 size_t len
, struct nlattr
*ack
)
1604 union wpa_event_data event
;
1605 const struct ieee80211_hdr
*hdr
;
1608 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX status event");
1609 if (!is_ap_interface(drv
->nlmode
)) {
1615 cookie_val
= nla_get_u64(cookie
);
1616 wpa_printf(MSG_DEBUG
, "nl80211: Action TX status:"
1617 " cookie=0%llx%s (ack=%d)",
1618 (long long unsigned int) cookie_val
,
1619 cookie_val
== drv
->send_action_cookie
?
1620 " (match)" : " (unknown)", ack
!= NULL
);
1621 if (cookie_val
!= drv
->send_action_cookie
)
1625 hdr
= (const struct ieee80211_hdr
*) frame
;
1626 fc
= le_to_host16(hdr
->frame_control
);
1628 os_memset(&event
, 0, sizeof(event
));
1629 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
1630 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
1631 event
.tx_status
.dst
= hdr
->addr1
;
1632 event
.tx_status
.data
= frame
;
1633 event
.tx_status
.data_len
= len
;
1634 event
.tx_status
.ack
= ack
!= NULL
;
1635 wpa_supplicant_event(drv
->ctx
, EVENT_TX_STATUS
, &event
);
1639 static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data
*drv
,
1640 enum wpa_event_type type
,
1641 const u8
*frame
, size_t len
)
1643 const struct ieee80211_mgmt
*mgmt
;
1644 union wpa_event_data event
;
1645 const u8
*bssid
= NULL
;
1646 u16 reason_code
= 0;
1648 if (type
== EVENT_DEAUTH
)
1649 wpa_printf(MSG_DEBUG
, "nl80211: Deauthenticate event");
1651 wpa_printf(MSG_DEBUG
, "nl80211: Disassociate event");
1653 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1655 bssid
= mgmt
->bssid
;
1657 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) &&
1659 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0 &&
1660 os_memcmp(bssid
, drv
->auth_attempt_bssid
, ETH_ALEN
) != 0 &&
1661 os_memcmp(bssid
, drv
->prev_bssid
, ETH_ALEN
) == 0) {
1663 * Avoid issues with some roaming cases where
1664 * disconnection event for the old AP may show up after
1665 * we have started connection with the new AP.
1667 wpa_printf(MSG_DEBUG
, "nl80211: Ignore deauth/disassoc event from old AP " MACSTR
" when already authenticating with " MACSTR
,
1669 MAC2STR(drv
->auth_attempt_bssid
));
1673 if (drv
->associated
!= 0 &&
1674 os_memcmp(bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
1675 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0) {
1677 * We have presumably received this deauth as a
1678 * response to a clear_state_mismatch() outgoing
1679 * deauth. Don't let it take us offline!
1681 wpa_printf(MSG_DEBUG
, "nl80211: Deauth received "
1682 "from Unknown BSSID " MACSTR
" -- ignoring",
1688 nl80211_mark_disconnected(drv
);
1689 os_memset(&event
, 0, sizeof(event
));
1691 /* Note: Same offset for Reason Code in both frame subtypes */
1692 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1693 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1695 if (type
== EVENT_DISASSOC
) {
1696 event
.disassoc_info
.locally_generated
=
1697 !os_memcmp(mgmt
->sa
, drv
->first_bss
->addr
, ETH_ALEN
);
1698 event
.disassoc_info
.addr
= bssid
;
1699 event
.disassoc_info
.reason_code
= reason_code
;
1700 if (frame
+ len
> mgmt
->u
.disassoc
.variable
) {
1701 event
.disassoc_info
.ie
= mgmt
->u
.disassoc
.variable
;
1702 event
.disassoc_info
.ie_len
= frame
+ len
-
1703 mgmt
->u
.disassoc
.variable
;
1706 event
.deauth_info
.locally_generated
=
1707 !os_memcmp(mgmt
->sa
, drv
->first_bss
->addr
, ETH_ALEN
);
1708 event
.deauth_info
.addr
= bssid
;
1709 event
.deauth_info
.reason_code
= reason_code
;
1710 if (frame
+ len
> mgmt
->u
.deauth
.variable
) {
1711 event
.deauth_info
.ie
= mgmt
->u
.deauth
.variable
;
1712 event
.deauth_info
.ie_len
= frame
+ len
-
1713 mgmt
->u
.deauth
.variable
;
1717 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1721 static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data
*drv
,
1722 enum wpa_event_type type
,
1723 const u8
*frame
, size_t len
)
1725 const struct ieee80211_mgmt
*mgmt
;
1726 union wpa_event_data event
;
1727 u16 reason_code
= 0;
1729 if (type
== EVENT_UNPROT_DEAUTH
)
1730 wpa_printf(MSG_DEBUG
, "nl80211: Unprot Deauthenticate event");
1732 wpa_printf(MSG_DEBUG
, "nl80211: Unprot Disassociate event");
1737 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1739 os_memset(&event
, 0, sizeof(event
));
1740 /* Note: Same offset for Reason Code in both frame subtypes */
1741 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1742 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1744 if (type
== EVENT_UNPROT_DISASSOC
) {
1745 event
.unprot_disassoc
.sa
= mgmt
->sa
;
1746 event
.unprot_disassoc
.da
= mgmt
->da
;
1747 event
.unprot_disassoc
.reason_code
= reason_code
;
1749 event
.unprot_deauth
.sa
= mgmt
->sa
;
1750 event
.unprot_deauth
.da
= mgmt
->da
;
1751 event
.unprot_deauth
.reason_code
= reason_code
;
1754 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1758 static void mlme_event(struct i802_bss
*bss
,
1759 enum nl80211_commands cmd
, struct nlattr
*frame
,
1760 struct nlattr
*addr
, struct nlattr
*timed_out
,
1761 struct nlattr
*freq
, struct nlattr
*ack
,
1762 struct nlattr
*cookie
, struct nlattr
*sig
)
1764 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1768 if (timed_out
&& addr
) {
1769 mlme_timeout_event(drv
, cmd
, addr
);
1773 if (frame
== NULL
) {
1774 wpa_printf(MSG_DEBUG
,
1775 "nl80211: MLME event %d (%s) without frame data",
1776 cmd
, nl80211_command_to_string(cmd
));
1780 data
= nla_data(frame
);
1781 len
= nla_len(frame
);
1782 if (len
< 4 + 2 * ETH_ALEN
) {
1783 wpa_printf(MSG_MSGDUMP
, "nl80211: MLME event %d (%s) on %s("
1784 MACSTR
") - too short",
1785 cmd
, nl80211_command_to_string(cmd
), bss
->ifname
,
1786 MAC2STR(bss
->addr
));
1789 wpa_printf(MSG_MSGDUMP
, "nl80211: MLME event %d (%s) on %s(" MACSTR
1790 ") A1=" MACSTR
" A2=" MACSTR
, cmd
,
1791 nl80211_command_to_string(cmd
), bss
->ifname
,
1792 MAC2STR(bss
->addr
), MAC2STR(data
+ 4),
1793 MAC2STR(data
+ 4 + ETH_ALEN
));
1794 if (cmd
!= NL80211_CMD_FRAME_TX_STATUS
&& !(data
[4] & 0x01) &&
1795 os_memcmp(bss
->addr
, data
+ 4, ETH_ALEN
) != 0 &&
1796 os_memcmp(bss
->addr
, data
+ 4 + ETH_ALEN
, ETH_ALEN
) != 0) {
1797 wpa_printf(MSG_MSGDUMP
, "nl80211: %s: Ignore MLME frame event "
1798 "for foreign address", bss
->ifname
);
1801 wpa_hexdump(MSG_MSGDUMP
, "nl80211: MLME event frame",
1802 nla_data(frame
), nla_len(frame
));
1805 case NL80211_CMD_AUTHENTICATE
:
1806 mlme_event_auth(drv
, nla_data(frame
), nla_len(frame
));
1808 case NL80211_CMD_ASSOCIATE
:
1809 mlme_event_assoc(drv
, nla_data(frame
), nla_len(frame
));
1811 case NL80211_CMD_DEAUTHENTICATE
:
1812 mlme_event_deauth_disassoc(drv
, EVENT_DEAUTH
,
1813 nla_data(frame
), nla_len(frame
));
1815 case NL80211_CMD_DISASSOCIATE
:
1816 mlme_event_deauth_disassoc(drv
, EVENT_DISASSOC
,
1817 nla_data(frame
), nla_len(frame
));
1819 case NL80211_CMD_FRAME
:
1820 mlme_event_mgmt(drv
, freq
, sig
, nla_data(frame
),
1823 case NL80211_CMD_FRAME_TX_STATUS
:
1824 mlme_event_mgmt_tx_status(drv
, cookie
, nla_data(frame
),
1825 nla_len(frame
), ack
);
1827 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1828 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DEAUTH
,
1829 nla_data(frame
), nla_len(frame
));
1831 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1832 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DISASSOC
,
1833 nla_data(frame
), nla_len(frame
));
1841 static void mlme_event_michael_mic_failure(struct i802_bss
*bss
,
1842 struct nlattr
*tb
[])
1844 union wpa_event_data data
;
1846 wpa_printf(MSG_DEBUG
, "nl80211: MLME event Michael MIC failure");
1847 os_memset(&data
, 0, sizeof(data
));
1848 if (tb
[NL80211_ATTR_MAC
]) {
1849 wpa_hexdump(MSG_DEBUG
, "nl80211: Source MAC address",
1850 nla_data(tb
[NL80211_ATTR_MAC
]),
1851 nla_len(tb
[NL80211_ATTR_MAC
]));
1852 data
.michael_mic_failure
.src
= nla_data(tb
[NL80211_ATTR_MAC
]);
1854 if (tb
[NL80211_ATTR_KEY_SEQ
]) {
1855 wpa_hexdump(MSG_DEBUG
, "nl80211: TSC",
1856 nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
1857 nla_len(tb
[NL80211_ATTR_KEY_SEQ
]));
1859 if (tb
[NL80211_ATTR_KEY_TYPE
]) {
1860 enum nl80211_key_type key_type
=
1861 nla_get_u32(tb
[NL80211_ATTR_KEY_TYPE
]);
1862 wpa_printf(MSG_DEBUG
, "nl80211: Key Type %d", key_type
);
1863 if (key_type
== NL80211_KEYTYPE_PAIRWISE
)
1864 data
.michael_mic_failure
.unicast
= 1;
1866 data
.michael_mic_failure
.unicast
= 1;
1868 if (tb
[NL80211_ATTR_KEY_IDX
]) {
1869 u8 key_id
= nla_get_u8(tb
[NL80211_ATTR_KEY_IDX
]);
1870 wpa_printf(MSG_DEBUG
, "nl80211: Key Id %d", key_id
);
1873 wpa_supplicant_event(bss
->ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
1877 static void mlme_event_join_ibss(struct wpa_driver_nl80211_data
*drv
,
1878 struct nlattr
*tb
[])
1880 if (tb
[NL80211_ATTR_MAC
] == NULL
) {
1881 wpa_printf(MSG_DEBUG
, "nl80211: No address in IBSS joined "
1885 os_memcpy(drv
->bssid
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1887 drv
->associated
= 1;
1888 wpa_printf(MSG_DEBUG
, "nl80211: IBSS " MACSTR
" joined",
1889 MAC2STR(drv
->bssid
));
1891 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1895 static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data
*drv
,
1896 int cancel_event
, struct nlattr
*tb
[])
1898 unsigned int freq
, chan_type
, duration
;
1899 union wpa_event_data data
;
1902 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1903 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1907 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1908 chan_type
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1912 if (tb
[NL80211_ATTR_DURATION
])
1913 duration
= nla_get_u32(tb
[NL80211_ATTR_DURATION
]);
1917 if (tb
[NL80211_ATTR_COOKIE
])
1918 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
1922 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel event (cancel=%d "
1923 "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
1924 cancel_event
, freq
, chan_type
, duration
,
1925 (long long unsigned int) cookie
,
1926 cookie
== drv
->remain_on_chan_cookie
? "match" : "unknown");
1928 if (cookie
!= drv
->remain_on_chan_cookie
)
1929 return; /* not for us */
1932 drv
->pending_remain_on_chan
= 0;
1934 os_memset(&data
, 0, sizeof(data
));
1935 data
.remain_on_channel
.freq
= freq
;
1936 data
.remain_on_channel
.duration
= duration
;
1937 wpa_supplicant_event(drv
->ctx
, cancel_event
?
1938 EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1939 EVENT_REMAIN_ON_CHANNEL
, &data
);
1943 static void mlme_event_ft_event(struct wpa_driver_nl80211_data
*drv
,
1944 struct nlattr
*tb
[])
1946 union wpa_event_data data
;
1948 os_memset(&data
, 0, sizeof(data
));
1950 if (tb
[NL80211_ATTR_IE
]) {
1951 data
.ft_ies
.ies
= nla_data(tb
[NL80211_ATTR_IE
]);
1952 data
.ft_ies
.ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
1955 if (tb
[NL80211_ATTR_IE_RIC
]) {
1956 data
.ft_ies
.ric_ies
= nla_data(tb
[NL80211_ATTR_IE_RIC
]);
1957 data
.ft_ies
.ric_ies_len
= nla_len(tb
[NL80211_ATTR_IE_RIC
]);
1960 if (tb
[NL80211_ATTR_MAC
])
1961 os_memcpy(data
.ft_ies
.target_ap
,
1962 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1964 wpa_printf(MSG_DEBUG
, "nl80211: FT event target_ap " MACSTR
,
1965 MAC2STR(data
.ft_ies
.target_ap
));
1967 wpa_supplicant_event(drv
->ctx
, EVENT_FT_RESPONSE
, &data
);
1971 static void send_scan_event(struct wpa_driver_nl80211_data
*drv
, int aborted
,
1972 struct nlattr
*tb
[])
1974 union wpa_event_data event
;
1977 struct scan_info
*info
;
1978 #define MAX_REPORT_FREQS 50
1979 int freqs
[MAX_REPORT_FREQS
];
1982 if (drv
->scan_for_auth
) {
1983 drv
->scan_for_auth
= 0;
1984 wpa_printf(MSG_DEBUG
, "nl80211: Scan results for missing "
1985 "cfg80211 BSS entry");
1986 wpa_driver_nl80211_authenticate_retry(drv
);
1990 os_memset(&event
, 0, sizeof(event
));
1991 info
= &event
.scan_info
;
1992 info
->aborted
= aborted
;
1994 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
1995 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem
) {
1996 struct wpa_driver_scan_ssid
*s
=
1997 &info
->ssids
[info
->num_ssids
];
1998 s
->ssid
= nla_data(nl
);
1999 s
->ssid_len
= nla_len(nl
);
2001 if (info
->num_ssids
== WPAS_MAX_SCAN_SSIDS
)
2005 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2006 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem
)
2008 freqs
[num_freqs
] = nla_get_u32(nl
);
2010 if (num_freqs
== MAX_REPORT_FREQS
- 1)
2013 info
->freqs
= freqs
;
2014 info
->num_freqs
= num_freqs
;
2016 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
, &event
);
2020 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
2022 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2023 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2024 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
2025 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
2026 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
2027 [NL80211_STA_INFO_SIGNAL_AVG
] = { .type
= NLA_U8
},
2029 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
2030 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
2031 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
2032 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
2033 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
2034 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
2036 struct wpa_signal_info
*sig_change
= arg
;
2038 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2039 genlmsg_attrlen(gnlh
, 0), NULL
);
2040 if (!tb
[NL80211_ATTR_STA_INFO
] ||
2041 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
2042 tb
[NL80211_ATTR_STA_INFO
], policy
))
2044 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
2047 sig_change
->current_signal
=
2048 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
2050 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
2051 sig_change
->avg_signal
=
2052 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]);
2054 sig_change
->avg_signal
= 0;
2056 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
2057 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
2058 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
2060 sig_change
->current_txrate
= 0;
2062 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
2063 sig_change
->current_txrate
=
2065 NL80211_RATE_INFO_BITRATE
]) * 100;
2074 static int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
2075 struct wpa_signal_info
*sig
)
2079 sig
->current_signal
= -9999;
2080 sig
->current_txrate
= 0;
2082 msg
= nlmsg_alloc();
2086 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
2088 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2089 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
2091 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
2098 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
2100 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2101 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2102 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
2103 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
2104 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
2105 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
2107 struct wpa_signal_info
*sig_change
= arg
;
2109 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2110 genlmsg_attrlen(gnlh
, 0), NULL
);
2112 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
2113 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
2117 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
2118 tb
[NL80211_ATTR_SURVEY_INFO
],
2120 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
2125 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
2128 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
2129 sig_change
->frequency
)
2132 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
2135 sig_change
->current_noise
=
2136 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
2142 static int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
2143 struct wpa_signal_info
*sig_change
)
2147 sig_change
->current_noise
= 9999;
2148 sig_change
->frequency
= drv
->assoc_freq
;
2150 msg
= nlmsg_alloc();
2154 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
2156 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2158 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
2165 static int get_noise_for_scan_results(struct nl_msg
*msg
, void *arg
)
2167 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2168 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2169 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
2170 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
2171 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
2172 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
2174 struct wpa_scan_results
*scan_results
= arg
;
2175 struct wpa_scan_res
*scan_res
;
2178 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2179 genlmsg_attrlen(gnlh
, 0), NULL
);
2181 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
2182 wpa_printf(MSG_DEBUG
, "nl80211: Survey data missing");
2186 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
2187 tb
[NL80211_ATTR_SURVEY_INFO
],
2189 wpa_printf(MSG_DEBUG
, "nl80211: Failed to parse nested "
2194 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
2197 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
2200 for (i
= 0; i
< scan_results
->num
; ++i
) {
2201 scan_res
= scan_results
->res
[i
];
2204 if ((int) nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
2207 if (!(scan_res
->flags
& WPA_SCAN_NOISE_INVALID
))
2209 scan_res
->noise
= (s8
)
2210 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
2211 scan_res
->flags
&= ~WPA_SCAN_NOISE_INVALID
;
2218 static int nl80211_get_noise_for_scan_results(
2219 struct wpa_driver_nl80211_data
*drv
,
2220 struct wpa_scan_results
*scan_res
)
2224 msg
= nlmsg_alloc();
2228 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
2230 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2232 return send_and_recv_msgs(drv
, msg
, get_noise_for_scan_results
,
2240 static void nl80211_cqm_event(struct wpa_driver_nl80211_data
*drv
,
2241 struct nlattr
*tb
[])
2243 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
2244 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
2245 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U8
},
2246 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
2247 [NL80211_ATTR_CQM_PKT_LOSS_EVENT
] = { .type
= NLA_U32
},
2249 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
2250 enum nl80211_cqm_rssi_threshold_event event
;
2251 union wpa_event_data ed
;
2252 struct wpa_signal_info sig
;
2255 if (tb
[NL80211_ATTR_CQM
] == NULL
||
2256 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, tb
[NL80211_ATTR_CQM
],
2258 wpa_printf(MSG_DEBUG
, "nl80211: Ignore invalid CQM event");
2262 os_memset(&ed
, 0, sizeof(ed
));
2264 if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
2265 if (!tb
[NL80211_ATTR_MAC
])
2267 os_memcpy(ed
.low_ack
.addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
2269 wpa_supplicant_event(drv
->ctx
, EVENT_STATION_LOW_ACK
, &ed
);
2273 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] == NULL
)
2275 event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
2277 if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
) {
2278 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
2279 "event: RSSI high");
2280 ed
.signal_change
.above_threshold
= 1;
2281 } else if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
) {
2282 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
2284 ed
.signal_change
.above_threshold
= 0;
2288 res
= nl80211_get_link_signal(drv
, &sig
);
2290 ed
.signal_change
.current_signal
= sig
.current_signal
;
2291 ed
.signal_change
.current_txrate
= sig
.current_txrate
;
2292 wpa_printf(MSG_DEBUG
, "nl80211: Signal: %d dBm txrate: %d",
2293 sig
.current_signal
, sig
.current_txrate
);
2296 res
= nl80211_get_link_noise(drv
, &sig
);
2298 ed
.signal_change
.current_noise
= sig
.current_noise
;
2299 wpa_printf(MSG_DEBUG
, "nl80211: Noise: %d dBm",
2303 wpa_supplicant_event(drv
->ctx
, EVENT_SIGNAL_CHANGE
, &ed
);
2307 static void nl80211_new_station_event(struct wpa_driver_nl80211_data
*drv
,
2311 union wpa_event_data data
;
2313 if (tb
[NL80211_ATTR_MAC
] == NULL
)
2315 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2316 wpa_printf(MSG_DEBUG
, "nl80211: New station " MACSTR
, MAC2STR(addr
));
2318 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
2321 if (tb
[NL80211_ATTR_IE
]) {
2322 ies
= nla_data(tb
[NL80211_ATTR_IE
]);
2323 ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
2325 wpa_hexdump(MSG_DEBUG
, "nl80211: Assoc Req IEs", ies
, ies_len
);
2326 drv_event_assoc(drv
->ctx
, addr
, ies
, ies_len
, 0);
2330 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
2333 os_memset(&data
, 0, sizeof(data
));
2334 os_memcpy(data
.ibss_rsn_start
.peer
, addr
, ETH_ALEN
);
2335 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_RSN_START
, &data
);
2339 static void nl80211_del_station_event(struct wpa_driver_nl80211_data
*drv
,
2343 union wpa_event_data data
;
2345 if (tb
[NL80211_ATTR_MAC
] == NULL
)
2347 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2348 wpa_printf(MSG_DEBUG
, "nl80211: Delete station " MACSTR
,
2351 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
2352 drv_event_disassoc(drv
->ctx
, addr
);
2356 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
2359 os_memset(&data
, 0, sizeof(data
));
2360 os_memcpy(data
.ibss_peer_lost
.peer
, addr
, ETH_ALEN
);
2361 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_PEER_LOST
, &data
);
2365 static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data
*drv
,
2368 struct nlattr
*rekey_info
[NUM_NL80211_REKEY_DATA
];
2369 static struct nla_policy rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
2370 [NL80211_REKEY_DATA_KEK
] = {
2371 .minlen
= NL80211_KEK_LEN
,
2372 .maxlen
= NL80211_KEK_LEN
,
2374 [NL80211_REKEY_DATA_KCK
] = {
2375 .minlen
= NL80211_KCK_LEN
,
2376 .maxlen
= NL80211_KCK_LEN
,
2378 [NL80211_REKEY_DATA_REPLAY_CTR
] = {
2379 .minlen
= NL80211_REPLAY_CTR_LEN
,
2380 .maxlen
= NL80211_REPLAY_CTR_LEN
,
2383 union wpa_event_data data
;
2385 if (!tb
[NL80211_ATTR_MAC
])
2387 if (!tb
[NL80211_ATTR_REKEY_DATA
])
2389 if (nla_parse_nested(rekey_info
, MAX_NL80211_REKEY_DATA
,
2390 tb
[NL80211_ATTR_REKEY_DATA
], rekey_policy
))
2392 if (!rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
])
2395 os_memset(&data
, 0, sizeof(data
));
2396 data
.driver_gtk_rekey
.bssid
= nla_data(tb
[NL80211_ATTR_MAC
]);
2397 wpa_printf(MSG_DEBUG
, "nl80211: Rekey offload event for BSSID " MACSTR
,
2398 MAC2STR(data
.driver_gtk_rekey
.bssid
));
2399 data
.driver_gtk_rekey
.replay_ctr
=
2400 nla_data(rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
]);
2401 wpa_hexdump(MSG_DEBUG
, "nl80211: Rekey offload - Replay Counter",
2402 data
.driver_gtk_rekey
.replay_ctr
, NL80211_REPLAY_CTR_LEN
);
2403 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_GTK_REKEY
, &data
);
2407 static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data
*drv
,
2410 struct nlattr
*cand
[NUM_NL80211_PMKSA_CANDIDATE
];
2411 static struct nla_policy cand_policy
[NUM_NL80211_PMKSA_CANDIDATE
] = {
2412 [NL80211_PMKSA_CANDIDATE_INDEX
] = { .type
= NLA_U32
},
2413 [NL80211_PMKSA_CANDIDATE_BSSID
] = {
2417 [NL80211_PMKSA_CANDIDATE_PREAUTH
] = { .type
= NLA_FLAG
},
2419 union wpa_event_data data
;
2421 wpa_printf(MSG_DEBUG
, "nl80211: PMKSA candidate event");
2423 if (!tb
[NL80211_ATTR_PMKSA_CANDIDATE
])
2425 if (nla_parse_nested(cand
, MAX_NL80211_PMKSA_CANDIDATE
,
2426 tb
[NL80211_ATTR_PMKSA_CANDIDATE
], cand_policy
))
2428 if (!cand
[NL80211_PMKSA_CANDIDATE_INDEX
] ||
2429 !cand
[NL80211_PMKSA_CANDIDATE_BSSID
])
2432 os_memset(&data
, 0, sizeof(data
));
2433 os_memcpy(data
.pmkid_candidate
.bssid
,
2434 nla_data(cand
[NL80211_PMKSA_CANDIDATE_BSSID
]), ETH_ALEN
);
2435 data
.pmkid_candidate
.index
=
2436 nla_get_u32(cand
[NL80211_PMKSA_CANDIDATE_INDEX
]);
2437 data
.pmkid_candidate
.preauth
=
2438 cand
[NL80211_PMKSA_CANDIDATE_PREAUTH
] != NULL
;
2439 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
2443 static void nl80211_client_probe_event(struct wpa_driver_nl80211_data
*drv
,
2446 union wpa_event_data data
;
2448 wpa_printf(MSG_DEBUG
, "nl80211: Probe client event");
2450 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_ACK
])
2453 os_memset(&data
, 0, sizeof(data
));
2454 os_memcpy(data
.client_poll
.addr
,
2455 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2457 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_CLIENT_POLL_OK
, &data
);
2461 static void nl80211_tdls_oper_event(struct wpa_driver_nl80211_data
*drv
,
2464 union wpa_event_data data
;
2466 wpa_printf(MSG_DEBUG
, "nl80211: TDLS operation event");
2468 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_TDLS_OPERATION
])
2471 os_memset(&data
, 0, sizeof(data
));
2472 os_memcpy(data
.tdls
.peer
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2473 switch (nla_get_u8(tb
[NL80211_ATTR_TDLS_OPERATION
])) {
2474 case NL80211_TDLS_SETUP
:
2475 wpa_printf(MSG_DEBUG
, "nl80211: TDLS setup request for peer "
2476 MACSTR
, MAC2STR(data
.tdls
.peer
));
2477 data
.tdls
.oper
= TDLS_REQUEST_SETUP
;
2479 case NL80211_TDLS_TEARDOWN
:
2480 wpa_printf(MSG_DEBUG
, "nl80211: TDLS teardown request for peer "
2481 MACSTR
, MAC2STR(data
.tdls
.peer
));
2482 data
.tdls
.oper
= TDLS_REQUEST_TEARDOWN
;
2485 wpa_printf(MSG_DEBUG
, "nl80211: Unsupported TDLS operatione "
2489 if (tb
[NL80211_ATTR_REASON_CODE
]) {
2490 data
.tdls
.reason_code
=
2491 nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
]);
2494 wpa_supplicant_event(drv
->ctx
, EVENT_TDLS
, &data
);
2498 static void nl80211_stop_ap(struct wpa_driver_nl80211_data
*drv
,
2501 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_UNAVAILABLE
, NULL
);
2505 static void nl80211_connect_failed_event(struct wpa_driver_nl80211_data
*drv
,
2508 union wpa_event_data data
;
2511 wpa_printf(MSG_DEBUG
, "nl80211: Connect failed event");
2513 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_CONN_FAILED_REASON
])
2516 os_memset(&data
, 0, sizeof(data
));
2517 os_memcpy(data
.connect_failed_reason
.addr
,
2518 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2520 reason
= nla_get_u32(tb
[NL80211_ATTR_CONN_FAILED_REASON
]);
2522 case NL80211_CONN_FAIL_MAX_CLIENTS
:
2523 wpa_printf(MSG_DEBUG
, "nl80211: Max client reached");
2524 data
.connect_failed_reason
.code
= MAX_CLIENT_REACHED
;
2526 case NL80211_CONN_FAIL_BLOCKED_CLIENT
:
2527 wpa_printf(MSG_DEBUG
, "nl80211: Blocked client " MACSTR
2528 " tried to connect",
2529 MAC2STR(data
.connect_failed_reason
.addr
));
2530 data
.connect_failed_reason
.code
= BLOCKED_CLIENT
;
2533 wpa_printf(MSG_DEBUG
, "nl8021l: Unknown connect failed reason "
2538 wpa_supplicant_event(drv
->ctx
, EVENT_CONNECT_FAILED_REASON
, &data
);
2542 static enum chan_width
convert2width(int width
);
2544 static void nl80211_radar_event(struct wpa_driver_nl80211_data
*drv
,
2547 union wpa_event_data data
;
2548 enum nl80211_radar_event event_type
;
2550 if (!tb
[NL80211_ATTR_WIPHY_FREQ
] || !tb
[NL80211_ATTR_RADAR_EVENT
])
2553 os_memset(&data
, 0, sizeof(data
));
2554 data
.dfs_event
.freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
2555 event_type
= nla_get_u32(tb
[NL80211_ATTR_RADAR_EVENT
]);
2557 /* Check HT params */
2558 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2559 data
.dfs_event
.ht_enabled
= 1;
2560 data
.dfs_event
.chan_offset
= 0;
2562 switch (nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])) {
2563 case NL80211_CHAN_NO_HT
:
2564 data
.dfs_event
.ht_enabled
= 0;
2566 case NL80211_CHAN_HT20
:
2568 case NL80211_CHAN_HT40PLUS
:
2569 data
.dfs_event
.chan_offset
= 1;
2571 case NL80211_CHAN_HT40MINUS
:
2572 data
.dfs_event
.chan_offset
= -1;
2577 /* Get VHT params */
2578 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
])
2579 data
.dfs_event
.chan_width
=
2580 convert2width(nla_get_u32(
2581 tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
2582 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
2583 data
.dfs_event
.cf1
= nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
2584 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
2585 data
.dfs_event
.cf2
= nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
2587 wpa_printf(MSG_DEBUG
, "nl80211: DFS event on freq %d MHz, ht: %d, offset: %d, width: %d, cf1: %dMHz, cf2: %dMHz",
2588 data
.dfs_event
.freq
, data
.dfs_event
.ht_enabled
,
2589 data
.dfs_event
.chan_offset
, data
.dfs_event
.chan_width
,
2590 data
.dfs_event
.cf1
, data
.dfs_event
.cf2
);
2592 switch (event_type
) {
2593 case NL80211_RADAR_DETECTED
:
2594 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_RADAR_DETECTED
, &data
);
2596 case NL80211_RADAR_CAC_FINISHED
:
2597 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_CAC_FINISHED
, &data
);
2599 case NL80211_RADAR_CAC_ABORTED
:
2600 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_CAC_ABORTED
, &data
);
2602 case NL80211_RADAR_NOP_FINISHED
:
2603 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_NOP_FINISHED
, &data
);
2606 wpa_printf(MSG_DEBUG
, "nl80211: Unknown radar event %d "
2607 "received", event_type
);
2613 static void nl80211_spurious_frame(struct i802_bss
*bss
, struct nlattr
**tb
,
2616 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2617 union wpa_event_data event
;
2619 if (!tb
[NL80211_ATTR_MAC
])
2622 os_memset(&event
, 0, sizeof(event
));
2623 event
.rx_from_unknown
.bssid
= bss
->addr
;
2624 event
.rx_from_unknown
.addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2625 event
.rx_from_unknown
.wds
= wds
;
2627 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
2631 static void do_process_drv_event(struct i802_bss
*bss
, int cmd
,
2634 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2636 wpa_printf(MSG_DEBUG
, "nl80211: Drv Event %d (%s) received for %s",
2637 cmd
, nl80211_command_to_string(cmd
), bss
->ifname
);
2639 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
&&
2640 (cmd
== NL80211_CMD_NEW_SCAN_RESULTS
||
2641 cmd
== NL80211_CMD_SCAN_ABORTED
)) {
2642 wpa_driver_nl80211_set_mode(drv
->first_bss
,
2643 drv
->ap_scan_as_station
);
2644 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2648 case NL80211_CMD_TRIGGER_SCAN
:
2649 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Scan trigger");
2650 drv
->scan_state
= SCAN_STARTED
;
2652 case NL80211_CMD_START_SCHED_SCAN
:
2653 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Sched scan started");
2654 drv
->scan_state
= SCHED_SCAN_STARTED
;
2656 case NL80211_CMD_SCHED_SCAN_STOPPED
:
2657 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Sched scan stopped");
2658 drv
->scan_state
= SCHED_SCAN_STOPPED
;
2659 wpa_supplicant_event(drv
->ctx
, EVENT_SCHED_SCAN_STOPPED
, NULL
);
2661 case NL80211_CMD_NEW_SCAN_RESULTS
:
2662 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2663 "nl80211: New scan results available");
2664 drv
->scan_state
= SCAN_COMPLETED
;
2665 drv
->scan_complete_events
= 1;
2666 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2668 send_scan_event(drv
, 0, tb
);
2670 case NL80211_CMD_SCHED_SCAN_RESULTS
:
2671 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2672 "nl80211: New sched scan results available");
2673 drv
->scan_state
= SCHED_SCAN_RESULTS
;
2674 send_scan_event(drv
, 0, tb
);
2676 case NL80211_CMD_SCAN_ABORTED
:
2677 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Scan aborted");
2678 drv
->scan_state
= SCAN_ABORTED
;
2680 * Need to indicate that scan results are available in order
2681 * not to make wpa_supplicant stop its scanning.
2683 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2685 send_scan_event(drv
, 1, tb
);
2687 case NL80211_CMD_AUTHENTICATE
:
2688 case NL80211_CMD_ASSOCIATE
:
2689 case NL80211_CMD_DEAUTHENTICATE
:
2690 case NL80211_CMD_DISASSOCIATE
:
2691 case NL80211_CMD_FRAME_TX_STATUS
:
2692 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
2693 case NL80211_CMD_UNPROT_DISASSOCIATE
:
2694 mlme_event(bss
, cmd
, tb
[NL80211_ATTR_FRAME
],
2695 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2696 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2697 tb
[NL80211_ATTR_COOKIE
],
2698 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2700 case NL80211_CMD_CONNECT
:
2701 case NL80211_CMD_ROAM
:
2702 mlme_event_connect(drv
, cmd
,
2703 tb
[NL80211_ATTR_STATUS_CODE
],
2704 tb
[NL80211_ATTR_MAC
],
2705 tb
[NL80211_ATTR_REQ_IE
],
2706 tb
[NL80211_ATTR_RESP_IE
]);
2708 case NL80211_CMD_CH_SWITCH_NOTIFY
:
2709 mlme_event_ch_switch(drv
, tb
[NL80211_ATTR_WIPHY_FREQ
],
2710 tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2712 case NL80211_CMD_DISCONNECT
:
2713 mlme_event_disconnect(drv
, tb
[NL80211_ATTR_REASON_CODE
],
2714 tb
[NL80211_ATTR_MAC
],
2715 tb
[NL80211_ATTR_DISCONNECTED_BY_AP
]);
2717 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
2718 mlme_event_michael_mic_failure(bss
, tb
);
2720 case NL80211_CMD_JOIN_IBSS
:
2721 mlme_event_join_ibss(drv
, tb
);
2723 case NL80211_CMD_REMAIN_ON_CHANNEL
:
2724 mlme_event_remain_on_channel(drv
, 0, tb
);
2726 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
2727 mlme_event_remain_on_channel(drv
, 1, tb
);
2729 case NL80211_CMD_NOTIFY_CQM
:
2730 nl80211_cqm_event(drv
, tb
);
2732 case NL80211_CMD_REG_CHANGE
:
2733 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory domain change");
2734 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2737 case NL80211_CMD_REG_BEACON_HINT
:
2738 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory beacon hint");
2739 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2742 case NL80211_CMD_NEW_STATION
:
2743 nl80211_new_station_event(drv
, tb
);
2745 case NL80211_CMD_DEL_STATION
:
2746 nl80211_del_station_event(drv
, tb
);
2748 case NL80211_CMD_SET_REKEY_OFFLOAD
:
2749 nl80211_rekey_offload_event(drv
, tb
);
2751 case NL80211_CMD_PMKSA_CANDIDATE
:
2752 nl80211_pmksa_candidate_event(drv
, tb
);
2754 case NL80211_CMD_PROBE_CLIENT
:
2755 nl80211_client_probe_event(drv
, tb
);
2757 case NL80211_CMD_TDLS_OPER
:
2758 nl80211_tdls_oper_event(drv
, tb
);
2760 case NL80211_CMD_CONN_FAILED
:
2761 nl80211_connect_failed_event(drv
, tb
);
2763 case NL80211_CMD_FT_EVENT
:
2764 mlme_event_ft_event(drv
, tb
);
2766 case NL80211_CMD_RADAR_DETECT
:
2767 nl80211_radar_event(drv
, tb
);
2769 case NL80211_CMD_STOP_AP
:
2770 nl80211_stop_ap(drv
, tb
);
2773 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Ignored unknown event "
2780 static int process_drv_event(struct nl_msg
*msg
, void *arg
)
2782 struct wpa_driver_nl80211_data
*drv
= arg
;
2783 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2784 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2785 struct i802_bss
*bss
;
2788 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2789 genlmsg_attrlen(gnlh
, 0), NULL
);
2791 if (tb
[NL80211_ATTR_IFINDEX
]) {
2792 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2794 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
)
2795 if (ifidx
== -1 || ifidx
== bss
->ifindex
) {
2796 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2799 wpa_printf(MSG_DEBUG
,
2800 "nl80211: Ignored event (cmd=%d) for foreign interface (ifindex %d)",
2802 } else if (tb
[NL80211_ATTR_WDEV
]) {
2803 u64 wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
2804 wpa_printf(MSG_DEBUG
, "nl80211: Process event on P2P device");
2805 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
2806 if (bss
->wdev_id_set
&& wdev_id
== bss
->wdev_id
) {
2807 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2811 wpa_printf(MSG_DEBUG
,
2812 "nl80211: Ignored event (cmd=%d) for foreign interface (wdev 0x%llx)",
2813 gnlh
->cmd
, (long long unsigned int) wdev_id
);
2820 static int process_global_event(struct nl_msg
*msg
, void *arg
)
2822 struct nl80211_global
*global
= arg
;
2823 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2824 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2825 struct wpa_driver_nl80211_data
*drv
, *tmp
;
2827 struct i802_bss
*bss
;
2829 int wdev_id_set
= 0;
2831 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2832 genlmsg_attrlen(gnlh
, 0), NULL
);
2834 if (tb
[NL80211_ATTR_IFINDEX
])
2835 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2836 else if (tb
[NL80211_ATTR_WDEV
]) {
2837 wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
2841 dl_list_for_each_safe(drv
, tmp
, &global
->interfaces
,
2842 struct wpa_driver_nl80211_data
, list
) {
2843 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
2844 if ((ifidx
== -1 && !wdev_id_set
) ||
2845 ifidx
== bss
->ifindex
||
2846 (wdev_id_set
&& bss
->wdev_id_set
&&
2847 wdev_id
== bss
->wdev_id
)) {
2848 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2858 static int process_bss_event(struct nl_msg
*msg
, void *arg
)
2860 struct i802_bss
*bss
= arg
;
2861 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2862 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2864 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2865 genlmsg_attrlen(gnlh
, 0), NULL
);
2867 wpa_printf(MSG_DEBUG
, "nl80211: BSS Event %d (%s) received for %s",
2868 gnlh
->cmd
, nl80211_command_to_string(gnlh
->cmd
),
2871 switch (gnlh
->cmd
) {
2872 case NL80211_CMD_FRAME
:
2873 case NL80211_CMD_FRAME_TX_STATUS
:
2874 mlme_event(bss
, gnlh
->cmd
, tb
[NL80211_ATTR_FRAME
],
2875 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2876 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2877 tb
[NL80211_ATTR_COOKIE
],
2878 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2880 case NL80211_CMD_UNEXPECTED_FRAME
:
2881 nl80211_spurious_frame(bss
, tb
, 0);
2883 case NL80211_CMD_UNEXPECTED_4ADDR_FRAME
:
2884 nl80211_spurious_frame(bss
, tb
, 1);
2887 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2888 "(cmd=%d)", gnlh
->cmd
);
2896 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
2899 struct nl_cb
*cb
= eloop_ctx
;
2902 wpa_printf(MSG_MSGDUMP
, "nl80211: Event message available");
2904 res
= nl_recvmsgs(handle
, cb
);
2906 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
2913 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
2914 * @priv: driver_nl80211 private data
2915 * @alpha2_arg: country to which to switch to
2916 * Returns: 0 on success, -1 on failure
2918 * This asks nl80211 to set the regulatory domain for given
2919 * country ISO / IEC alpha2.
2921 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
2923 struct i802_bss
*bss
= priv
;
2924 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2928 msg
= nlmsg_alloc();
2932 alpha2
[0] = alpha2_arg
[0];
2933 alpha2
[1] = alpha2_arg
[1];
2936 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
);
2938 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
);
2939 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
2948 static int nl80211_get_country(struct nl_msg
*msg
, void *arg
)
2951 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
2952 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2954 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2955 genlmsg_attrlen(gnlh
, 0), NULL
);
2956 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
]) {
2957 wpa_printf(MSG_DEBUG
, "nl80211: No country information available");
2960 os_strlcpy(alpha2
, nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]), 3);
2965 static int wpa_driver_nl80211_get_country(void *priv
, char *alpha2
)
2967 struct i802_bss
*bss
= priv
;
2968 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2972 msg
= nlmsg_alloc();
2976 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
2978 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_country
, alpha2
);
2986 static int protocol_feature_handler(struct nl_msg
*msg
, void *arg
)
2989 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
2990 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2992 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2993 genlmsg_attrlen(gnlh
, 0), NULL
);
2995 if (tb_msg
[NL80211_ATTR_PROTOCOL_FEATURES
])
2996 *feat
= nla_get_u32(tb_msg
[NL80211_ATTR_PROTOCOL_FEATURES
]);
3002 static u32
get_nl80211_protocol_features(struct wpa_driver_nl80211_data
*drv
)
3007 msg
= nlmsg_alloc();
3009 goto nla_put_failure
;
3011 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_PROTOCOL_FEATURES
);
3012 if (send_and_recv_msgs(drv
, msg
, protocol_feature_handler
, &feat
) == 0)
3022 struct wiphy_info_data
{
3023 struct wpa_driver_nl80211_data
*drv
;
3024 struct wpa_driver_capa
*capa
;
3026 unsigned int num_multichan_concurrent
;
3028 unsigned int error
:1;
3029 unsigned int device_ap_sme
:1;
3030 unsigned int poll_command_supported
:1;
3031 unsigned int data_tx_status
:1;
3032 unsigned int monitor_supported
:1;
3033 unsigned int auth_supported
:1;
3034 unsigned int connect_supported
:1;
3035 unsigned int p2p_go_supported
:1;
3036 unsigned int p2p_client_supported
:1;
3037 unsigned int p2p_concurrent
:1;
3041 static unsigned int probe_resp_offload_support(int supp_protocols
)
3043 unsigned int prot
= 0;
3045 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
)
3046 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
;
3047 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
)
3048 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
;
3049 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
)
3050 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
;
3051 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
)
3052 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
;
3058 static void wiphy_info_supported_iftypes(struct wiphy_info_data
*info
,
3061 struct nlattr
*nl_mode
;
3067 nla_for_each_nested(nl_mode
, tb
, i
) {
3068 switch (nla_type(nl_mode
)) {
3069 case NL80211_IFTYPE_AP
:
3070 info
->capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
3072 case NL80211_IFTYPE_ADHOC
:
3073 info
->capa
->flags
|= WPA_DRIVER_FLAGS_IBSS
;
3075 case NL80211_IFTYPE_P2P_DEVICE
:
3076 info
->capa
->flags
|=
3077 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
;
3079 case NL80211_IFTYPE_P2P_GO
:
3080 info
->p2p_go_supported
= 1;
3082 case NL80211_IFTYPE_P2P_CLIENT
:
3083 info
->p2p_client_supported
= 1;
3085 case NL80211_IFTYPE_MONITOR
:
3086 info
->monitor_supported
= 1;
3093 static int wiphy_info_iface_comb_process(struct wiphy_info_data
*info
,
3094 struct nlattr
*nl_combi
)
3096 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
3097 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
3098 struct nlattr
*nl_limit
, *nl_mode
;
3099 int err
, rem_limit
, rem_mode
;
3100 int combination_has_p2p
= 0, combination_has_mgd
= 0;
3101 static struct nla_policy
3102 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
3103 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
3104 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
3105 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
3106 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
3107 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
] = { .type
= NLA_U32
},
3109 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
3110 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
3111 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
3114 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
3115 nl_combi
, iface_combination_policy
);
3116 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
3117 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
3118 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
3119 return 0; /* broken combination */
3121 if (tb_comb
[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
])
3122 info
->capa
->flags
|= WPA_DRIVER_FLAGS_RADAR
;
3124 nla_for_each_nested(nl_limit
, tb_comb
[NL80211_IFACE_COMB_LIMITS
],
3126 err
= nla_parse_nested(tb_limit
, MAX_NL80211_IFACE_LIMIT
,
3127 nl_limit
, iface_limit_policy
);
3128 if (err
|| !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
3129 return 0; /* broken combination */
3131 nla_for_each_nested(nl_mode
,
3132 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
3134 int ift
= nla_type(nl_mode
);
3135 if (ift
== NL80211_IFTYPE_P2P_GO
||
3136 ift
== NL80211_IFTYPE_P2P_CLIENT
)
3137 combination_has_p2p
= 1;
3138 if (ift
== NL80211_IFTYPE_STATION
)
3139 combination_has_mgd
= 1;
3141 if (combination_has_p2p
&& combination_has_mgd
)
3145 if (combination_has_p2p
&& combination_has_mgd
) {
3146 info
->p2p_concurrent
= 1;
3147 info
->num_multichan_concurrent
=
3148 nla_get_u32(tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]);
3156 static void wiphy_info_iface_comb(struct wiphy_info_data
*info
,
3159 struct nlattr
*nl_combi
;
3165 nla_for_each_nested(nl_combi
, tb
, rem_combi
) {
3166 if (wiphy_info_iface_comb_process(info
, nl_combi
) > 0)
3172 static void wiphy_info_supp_cmds(struct wiphy_info_data
*info
,
3175 struct nlattr
*nl_cmd
;
3181 nla_for_each_nested(nl_cmd
, tb
, i
) {
3182 switch (nla_get_u32(nl_cmd
)) {
3183 case NL80211_CMD_AUTHENTICATE
:
3184 info
->auth_supported
= 1;
3186 case NL80211_CMD_CONNECT
:
3187 info
->connect_supported
= 1;
3189 case NL80211_CMD_START_SCHED_SCAN
:
3190 info
->capa
->sched_scan_supported
= 1;
3192 case NL80211_CMD_PROBE_CLIENT
:
3193 info
->poll_command_supported
= 1;
3200 static void wiphy_info_max_roc(struct wpa_driver_capa
*capa
,
3204 capa
->max_remain_on_chan
= nla_get_u32(tb
);
3208 static void wiphy_info_tdls(struct wpa_driver_capa
*capa
, struct nlattr
*tdls
,
3209 struct nlattr
*ext_setup
)
3214 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
3215 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
3218 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
3219 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
3224 static void wiphy_info_feature_flags(struct wiphy_info_data
*info
,
3228 struct wpa_driver_capa
*capa
= info
->capa
;
3233 flags
= nla_get_u32(tb
);
3235 if (flags
& NL80211_FEATURE_SK_TX_STATUS
)
3236 info
->data_tx_status
= 1;
3238 if (flags
& NL80211_FEATURE_INACTIVITY_TIMER
)
3239 capa
->flags
|= WPA_DRIVER_FLAGS_INACTIVITY_TIMER
;
3241 if (flags
& NL80211_FEATURE_SAE
)
3242 capa
->flags
|= WPA_DRIVER_FLAGS_SAE
;
3244 if (flags
& NL80211_FEATURE_NEED_OBSS_SCAN
)
3245 capa
->flags
|= WPA_DRIVER_FLAGS_OBSS_SCAN
;
3249 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa
*capa
,
3257 protocols
= nla_get_u32(tb
);
3258 wpa_printf(MSG_DEBUG
, "nl80211: Supports Probe Response offload in AP "
3260 capa
->flags
|= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
;
3261 capa
->probe_resp_offloads
= probe_resp_offload_support(protocols
);
3265 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
3267 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
3268 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3269 struct wiphy_info_data
*info
= arg
;
3270 struct wpa_driver_capa
*capa
= info
->capa
;
3271 struct wpa_driver_nl80211_data
*drv
= info
->drv
;
3273 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3274 genlmsg_attrlen(gnlh
, 0), NULL
);
3276 if (tb
[NL80211_ATTR_WIPHY_NAME
])
3277 os_strlcpy(drv
->phyname
,
3278 nla_get_string(tb
[NL80211_ATTR_WIPHY_NAME
]),
3279 sizeof(drv
->phyname
));
3280 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
3281 capa
->max_scan_ssids
=
3282 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
3284 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
3285 capa
->max_sched_scan_ssids
=
3286 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
3288 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
3289 capa
->max_match_sets
=
3290 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
3292 if (tb
[NL80211_ATTR_MAC_ACL_MAX
])
3293 capa
->max_acl_mac_addrs
=
3294 nla_get_u8(tb
[NL80211_ATTR_MAC_ACL_MAX
]);
3296 wiphy_info_supported_iftypes(info
, tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]);
3297 wiphy_info_iface_comb(info
, tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]);
3298 wiphy_info_supp_cmds(info
, tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]);
3300 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
3301 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
3303 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
3306 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
3307 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
3308 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
3311 wiphy_info_max_roc(capa
,
3312 tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
3314 if (tb
[NL80211_ATTR_SUPPORT_AP_UAPSD
])
3315 capa
->flags
|= WPA_DRIVER_FLAGS_AP_UAPSD
;
3317 wiphy_info_tdls(capa
, tb
[NL80211_ATTR_TDLS_SUPPORT
],
3318 tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]);
3320 if (tb
[NL80211_ATTR_DEVICE_AP_SME
])
3321 info
->device_ap_sme
= 1;
3323 wiphy_info_feature_flags(info
, tb
[NL80211_ATTR_FEATURE_FLAGS
]);
3324 wiphy_info_probe_resp_offload(capa
,
3325 tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]);
3327 if (tb
[NL80211_ATTR_EXT_CAPA
] && tb
[NL80211_ATTR_EXT_CAPA_MASK
] &&
3328 drv
->extended_capa
== NULL
) {
3329 drv
->extended_capa
=
3330 os_malloc(nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3331 if (drv
->extended_capa
) {
3332 os_memcpy(drv
->extended_capa
,
3333 nla_data(tb
[NL80211_ATTR_EXT_CAPA
]),
3334 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3335 drv
->extended_capa_len
=
3336 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]);
3338 drv
->extended_capa_mask
=
3339 os_malloc(nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3340 if (drv
->extended_capa_mask
) {
3341 os_memcpy(drv
->extended_capa_mask
,
3342 nla_data(tb
[NL80211_ATTR_EXT_CAPA
]),
3343 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3345 os_free(drv
->extended_capa
);
3346 drv
->extended_capa
= NULL
;
3347 drv
->extended_capa_len
= 0;
3355 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
3356 struct wiphy_info_data
*info
)
3361 os_memset(info
, 0, sizeof(*info
));
3362 info
->capa
= &drv
->capa
;
3365 msg
= nlmsg_alloc();
3369 feat
= get_nl80211_protocol_features(drv
);
3370 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
3371 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_WIPHY
);
3373 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
3375 NLA_PUT_FLAG(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
);
3376 if (nl80211_set_iface_id(msg
, drv
->first_bss
) < 0)
3377 goto nla_put_failure
;
3379 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
))
3382 if (info
->auth_supported
)
3383 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SME
;
3384 else if (!info
->connect_supported
) {
3385 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
3386 "authentication/association or connect commands");
3390 if (info
->p2p_go_supported
&& info
->p2p_client_supported
)
3391 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
3392 if (info
->p2p_concurrent
) {
3393 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
3394 "interface (driver advertised support)");
3395 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
3396 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
3398 if (info
->num_multichan_concurrent
> 1) {
3399 wpa_printf(MSG_DEBUG
, "nl80211: Enable multi-channel "
3400 "concurrent (driver advertised support)");
3401 drv
->capa
.num_multichan_concurrent
=
3402 info
->num_multichan_concurrent
;
3405 /* default to 5000 since early versions of mac80211 don't set it */
3406 if (!drv
->capa
.max_remain_on_chan
)
3407 drv
->capa
.max_remain_on_chan
= 5000;
3416 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
3418 struct wiphy_info_data info
;
3419 if (wpa_driver_nl80211_get_info(drv
, &info
))
3425 drv
->has_capability
= 1;
3426 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
3427 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3428 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3429 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3430 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
3431 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
3432 WPA_DRIVER_CAPA_ENC_WEP104
|
3433 WPA_DRIVER_CAPA_ENC_TKIP
|
3434 WPA_DRIVER_CAPA_ENC_CCMP
;
3435 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
3436 WPA_DRIVER_AUTH_SHARED
|
3437 WPA_DRIVER_AUTH_LEAP
;
3439 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
3440 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
3441 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3443 if (!info
.device_ap_sme
) {
3444 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
3447 * No AP SME is currently assumed to also indicate no AP MLME
3448 * in the driver/firmware.
3450 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP_MLME
;
3453 drv
->device_ap_sme
= info
.device_ap_sme
;
3454 drv
->poll_command_supported
= info
.poll_command_supported
;
3455 drv
->data_tx_status
= info
.data_tx_status
;
3458 * If poll command and tx status are supported, mac80211 is new enough
3459 * to have everything we need to not need monitor interfaces.
3461 drv
->use_monitor
= !info
.poll_command_supported
|| !info
.data_tx_status
;
3463 if (drv
->device_ap_sme
&& drv
->use_monitor
) {
3465 * Non-mac80211 drivers may not support monitor interface.
3466 * Make sure we do not get stuck with incorrect capability here
3467 * by explicitly testing this.
3469 if (!info
.monitor_supported
) {
3470 wpa_printf(MSG_DEBUG
, "nl80211: Disable use_monitor "
3471 "with device_ap_sme since no monitor mode "
3472 "support detected");
3473 drv
->use_monitor
= 0;
3478 * If we aren't going to use monitor interfaces, but the
3479 * driver doesn't support data TX status, we won't get TX
3480 * status for EAPOL frames.
3482 if (!drv
->use_monitor
&& !info
.data_tx_status
)
3483 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3490 static int android_genl_ctrl_resolve(struct nl_handle
*handle
,
3494 * Android ICS has very minimal genl_ctrl_resolve() implementation, so
3495 * need to work around that.
3497 struct nl_cache
*cache
= NULL
;
3498 struct genl_family
*nl80211
= NULL
;
3501 if (genl_ctrl_alloc_cache(handle
, &cache
) < 0) {
3502 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate generic "
3507 nl80211
= genl_ctrl_search_by_name(cache
, name
);
3508 if (nl80211
== NULL
)
3511 id
= genl_family_get_id(nl80211
);
3515 genl_family_put(nl80211
);
3517 nl_cache_free(cache
);
3521 #define genl_ctrl_resolve android_genl_ctrl_resolve
3522 #endif /* ANDROID */
3525 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
3529 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3530 if (global
->nl_cb
== NULL
) {
3531 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
3536 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
3537 if (global
->nl
== NULL
)
3540 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
3541 if (global
->nl80211_id
< 0) {
3542 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
3547 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
3548 if (global
->nl_event
== NULL
)
3551 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
3553 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3555 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
3556 "membership for scan events: %d (%s)",
3557 ret
, strerror(-ret
));
3561 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
3563 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3565 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
3566 "membership for mlme events: %d (%s)",
3567 ret
, strerror(-ret
));
3571 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
3573 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3575 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
3576 "membership for regulatory events: %d (%s)",
3577 ret
, strerror(-ret
));
3578 /* Continue without regulatory events */
3581 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3582 no_seq_check
, NULL
);
3583 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3584 process_global_event
, global
);
3586 nl80211_register_eloop_read(&global
->nl_event
,
3587 wpa_driver_nl80211_event_receive
,
3593 nl_destroy_handles(&global
->nl_event
);
3594 nl_destroy_handles(&global
->nl
);
3595 nl_cb_put(global
->nl_cb
);
3596 global
->nl_cb
= NULL
;
3601 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
3603 drv
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3605 wpa_printf(MSG_ERROR
, "nl80211: Failed to alloc cb struct");
3609 nl_cb_set(drv
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3610 no_seq_check
, NULL
);
3611 nl_cb_set(drv
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3612 process_drv_event
, drv
);
3618 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
3620 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
3622 * This may be for any interface; use ifdown event to disable
3628 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
3630 struct wpa_driver_nl80211_data
*drv
= ctx
;
3631 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
3632 if (i802_set_iface_flags(drv
->first_bss
, 1)) {
3633 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
3634 "after rfkill unblock");
3637 /* rtnetlink ifup handler will report interface as enabled */
3641 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
3645 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
3650 struct cmsghdr
*cmsg
;
3651 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
3652 union wpa_event_data event
;
3654 memset(&msg
, 0, sizeof(msg
));
3655 msg
.msg_iov
= &entry
;
3657 entry
.iov_base
= data
;
3658 entry
.iov_len
= sizeof(data
);
3659 msg
.msg_control
= &control
;
3660 msg
.msg_controllen
= sizeof(control
);
3662 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
3663 /* if error or not fitting 802.3 header, return */
3667 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
3669 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
3670 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
3674 ack
= (void *)CMSG_DATA(cmsg
);
3678 if (cmsg
->cmsg_level
== SOL_PACKET
&&
3679 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
3680 struct sock_extended_err
*err
=
3681 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
3683 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
3688 if (!found_ee
|| !found_wifi
)
3691 memset(&event
, 0, sizeof(event
));
3692 event
.eapol_tx_status
.dst
= data
;
3693 event
.eapol_tx_status
.data
= data
+ 14;
3694 event
.eapol_tx_status
.data_len
= res
- 14;
3695 event
.eapol_tx_status
.ack
= acked
;
3696 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
3700 static int nl80211_init_bss(struct i802_bss
*bss
)
3702 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3706 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3707 no_seq_check
, NULL
);
3708 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3709 process_bss_event
, bss
);
3715 static void nl80211_destroy_bss(struct i802_bss
*bss
)
3717 nl_cb_put(bss
->nl_cb
);
3723 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
3724 * @ctx: context to be used when calling wpa_supplicant functions,
3725 * e.g., wpa_supplicant_event()
3726 * @ifname: interface name, e.g., wlan0
3727 * @global_priv: private driver global data from global_init()
3728 * Returns: Pointer to private data, %NULL on failure
3730 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
3733 struct wpa_driver_nl80211_data
*drv
;
3734 struct rfkill_config
*rcfg
;
3735 struct i802_bss
*bss
;
3737 if (global_priv
== NULL
)
3739 drv
= os_zalloc(sizeof(*drv
));
3742 drv
->global
= global_priv
;
3745 drv
->first_bss
= os_zalloc(sizeof(*drv
->first_bss
));
3746 if (!drv
->first_bss
) {
3750 bss
= drv
->first_bss
;
3754 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
3755 drv
->monitor_ifidx
= -1;
3756 drv
->monitor_sock
= -1;
3757 drv
->eapol_tx_sock
= -1;
3758 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
3760 if (wpa_driver_nl80211_init_nl(drv
)) {
3765 if (nl80211_init_bss(bss
))
3768 rcfg
= os_zalloc(sizeof(*rcfg
));
3772 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
3773 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
3774 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
3775 drv
->rfkill
= rfkill_init(rcfg
);
3776 if (drv
->rfkill
== NULL
) {
3777 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
3781 if (wpa_driver_nl80211_finish_drv_init(drv
))
3784 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
3785 if (drv
->eapol_tx_sock
< 0)
3788 if (drv
->data_tx_status
) {
3791 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
3792 &enabled
, sizeof(enabled
)) < 0) {
3793 wpa_printf(MSG_DEBUG
,
3794 "nl80211: wifi status sockopt failed\n");
3795 drv
->data_tx_status
= 0;
3796 if (!drv
->use_monitor
)
3798 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3800 eloop_register_read_sock(drv
->eapol_tx_sock
,
3801 wpa_driver_nl80211_handle_eapol_tx_status
,
3807 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
3808 drv
->in_interface_list
= 1;
3814 wpa_driver_nl80211_deinit(bss
);
3819 static int nl80211_register_frame(struct i802_bss
*bss
,
3820 struct nl_handle
*nl_handle
,
3821 u16 type
, const u8
*match
, size_t match_len
)
3823 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3827 msg
= nlmsg_alloc();
3831 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x nl_handle=%p",
3833 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3836 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
3838 if (nl80211_set_iface_id(msg
, bss
) < 0)
3839 goto nla_put_failure
;
3841 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
3842 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
3844 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
3847 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
3848 "failed (type=%u): ret=%d (%s)",
3849 type
, ret
, strerror(-ret
));
3850 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3852 goto nla_put_failure
;
3861 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
3863 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3866 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
3867 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
3871 bss
->nl_mgmt
= nl_create_handle(drv
->nl_cb
, "mgmt");
3872 if (bss
->nl_mgmt
== NULL
)
3879 static void nl80211_mgmt_handle_register_eloop(struct i802_bss
*bss
)
3881 nl80211_register_eloop_read(&bss
->nl_mgmt
,
3882 wpa_driver_nl80211_event_receive
,
3887 static int nl80211_register_action_frame(struct i802_bss
*bss
,
3888 const u8
*match
, size_t match_len
)
3890 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
3891 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
3892 type
, match
, match_len
);
3896 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
3898 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3900 if (nl80211_alloc_mgmt_handle(bss
))
3902 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
3903 "handle %p", bss
->nl_mgmt
);
3905 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3906 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_AUTH
<< 4);
3908 /* register for any AUTH message */
3909 nl80211_register_frame(bss
, bss
->nl_mgmt
, type
, NULL
, 0);
3912 #ifdef CONFIG_INTERWORKING
3913 /* QoS Map Configure */
3914 if (nl80211_register_action_frame(bss
, (u8
*) "\x01\x04", 2) < 0)
3916 #endif /* CONFIG_INTERWORKING */
3917 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
3918 /* GAS Initial Request */
3919 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
3921 /* GAS Initial Response */
3922 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
3924 /* GAS Comeback Request */
3925 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
3927 /* GAS Comeback Response */
3928 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
3930 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
3932 /* P2P Public Action */
3933 if (nl80211_register_action_frame(bss
,
3934 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
3938 if (nl80211_register_action_frame(bss
,
3939 (u8
*) "\x7f\x50\x6f\x9a\x09",
3942 #endif /* CONFIG_P2P */
3943 #ifdef CONFIG_IEEE80211W
3944 /* SA Query Response */
3945 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
3947 #endif /* CONFIG_IEEE80211W */
3949 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
3950 /* TDLS Discovery Response */
3951 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
3955 #endif /* CONFIG_TDLS */
3957 /* FT Action frames */
3958 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
3961 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
3962 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
3964 /* WNM - BSS Transition Management Request */
3965 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
3967 /* WNM-Sleep Mode Response */
3968 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
3971 nl80211_mgmt_handle_register_eloop(bss
);
3977 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
3979 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3983 msg
= nlmsg_alloc();
3987 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
3989 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3991 ret
= send_and_recv(drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
3994 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
3995 "failed: ret=%d (%s)",
3996 ret
, strerror(-ret
));
3997 goto nla_put_failure
;
4006 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
4008 static const int stypes
[] = {
4010 WLAN_FC_STYPE_ASSOC_REQ
,
4011 WLAN_FC_STYPE_REASSOC_REQ
,
4012 WLAN_FC_STYPE_DISASSOC
,
4013 WLAN_FC_STYPE_DEAUTH
,
4014 WLAN_FC_STYPE_ACTION
,
4015 WLAN_FC_STYPE_PROBE_REQ
,
4016 /* Beacon doesn't work as mac80211 doesn't currently allow
4017 * it, but it wouldn't really be the right thing anyway as
4018 * it isn't per interface ... maybe just dump the scan
4019 * results periodically for OLBC?
4021 // WLAN_FC_STYPE_BEACON,
4025 if (nl80211_alloc_mgmt_handle(bss
))
4027 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
4028 "handle %p", bss
->nl_mgmt
);
4030 for (i
= 0; i
< ARRAY_SIZE(stypes
); i
++) {
4031 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
4032 (WLAN_FC_TYPE_MGMT
<< 2) |
4039 if (nl80211_register_spurious_class3(bss
))
4042 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
4045 nl80211_mgmt_handle_register_eloop(bss
);
4049 nl_destroy_handles(&bss
->nl_mgmt
);
4054 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
4056 if (nl80211_alloc_mgmt_handle(bss
))
4058 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
4059 "handle %p (device SME)", bss
->nl_mgmt
);
4061 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
4062 (WLAN_FC_TYPE_MGMT
<< 2) |
4063 (WLAN_FC_STYPE_ACTION
<< 4),
4067 nl80211_mgmt_handle_register_eloop(bss
);
4071 nl_destroy_handles(&bss
->nl_mgmt
);
4076 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
4078 if (bss
->nl_mgmt
== NULL
)
4080 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
4081 "(%s)", bss
->nl_mgmt
, reason
);
4082 nl80211_destroy_eloop_handle(&bss
->nl_mgmt
);
4084 nl80211_put_wiphy_data_ap(bss
);
4088 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
4090 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
4094 static void nl80211_del_p2pdev(struct i802_bss
*bss
)
4096 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4100 msg
= nlmsg_alloc();
4104 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
4105 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
4107 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4110 wpa_printf(MSG_DEBUG
, "nl80211: Delete P2P Device %s (0x%llx): %s",
4111 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
4119 static int nl80211_set_p2pdev(struct i802_bss
*bss
, int start
)
4121 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4125 msg
= nlmsg_alloc();
4130 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_START_P2P_DEVICE
);
4132 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_P2P_DEVICE
);
4134 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
4136 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4139 wpa_printf(MSG_DEBUG
, "nl80211: %s P2P Device %s (0x%llx): %s",
4140 start
? "Start" : "Stop",
4141 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
4150 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
)
4152 enum nl80211_iftype nlmode
;
4154 nlmode
= nl80211_get_ifmode(bss
);
4155 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
4156 return linux_set_iface_flags(bss
->drv
->global
->ioctl_sock
,
4160 /* P2P Device has start/stop which is equivalent */
4161 return nl80211_set_p2pdev(bss
, up
);
4166 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
4169 enum nl80211_iftype nlmode
= NL80211_IFTYPE_STATION
;
4170 #endif /* HOSTAPD */
4171 struct i802_bss
*bss
= drv
->first_bss
;
4172 int send_rfkill_event
= 0;
4174 drv
->ifindex
= if_nametoindex(bss
->ifname
);
4175 bss
->ifindex
= drv
->ifindex
;
4176 bss
->wdev_id
= drv
->global
->if_add_wdevid
;
4177 bss
->wdev_id_set
= drv
->global
->if_add_wdevid_set
;
4179 bss
->if_dynamic
= drv
->ifindex
== drv
->global
->if_add_ifindex
;
4180 bss
->if_dynamic
= bss
->if_dynamic
|| drv
->global
->if_add_wdevid_set
;
4181 drv
->global
->if_add_wdevid_set
= 0;
4183 if (wpa_driver_nl80211_capa(drv
))
4186 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
4187 bss
->ifname
, drv
->phyname
);
4190 if (bss
->if_dynamic
)
4191 nlmode
= nl80211_get_ifmode(bss
);
4194 * Make sure the interface starts up in station mode unless this is a
4195 * dynamically added interface (e.g., P2P) that was already configured
4196 * with proper iftype.
4198 if (wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0) {
4199 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to use managed mode");
4202 drv
->nlmode
= nlmode
;
4204 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
4205 int ret
= nl80211_set_p2pdev(bss
, 1);
4207 wpa_printf(MSG_ERROR
, "nl80211: Could not start P2P device");
4208 nl80211_get_macaddr(bss
);
4212 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
4213 if (rfkill_is_blocked(drv
->rfkill
)) {
4214 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
4215 "interface '%s' due to rfkill",
4217 drv
->if_disabled
= 1;
4218 send_rfkill_event
= 1;
4220 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
4221 "interface '%s' UP", bss
->ifname
);
4226 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
4227 1, IF_OPER_DORMANT
);
4228 #endif /* HOSTAPD */
4230 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
4234 if (send_rfkill_event
) {
4235 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
4243 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
4247 msg
= nlmsg_alloc();
4251 wpa_printf(MSG_DEBUG
, "nl80211: Remove beacon (ifindex=%d)",
4253 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
4254 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4256 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4264 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
4265 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
4267 * Shut down driver interface and processing of driver events. Free
4268 * private data buffer if one was allocated in wpa_driver_nl80211_init().
4270 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
4272 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4275 if (drv
->data_tx_status
)
4276 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
4277 if (drv
->eapol_tx_sock
>= 0)
4278 close(drv
->eapol_tx_sock
);
4281 wpa_driver_nl80211_probe_req_report(bss
, 0);
4282 if (bss
->added_if_into_bridge
) {
4283 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
4285 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
4286 "interface %s from bridge %s: %s",
4287 bss
->ifname
, bss
->brname
, strerror(errno
));
4289 if (bss
->added_bridge
) {
4290 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
4291 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
4293 bss
->brname
, strerror(errno
));
4296 nl80211_remove_monitor_interface(drv
);
4298 if (is_ap_interface(drv
->nlmode
))
4299 wpa_driver_nl80211_del_beacon(drv
);
4302 if (drv
->last_freq_ht
) {
4303 /* Clear HT flags from the driver */
4304 struct hostapd_freq_params freq
;
4305 os_memset(&freq
, 0, sizeof(freq
));
4306 freq
.freq
= drv
->last_freq
;
4307 wpa_driver_nl80211_set_freq(bss
, &freq
);
4310 if (drv
->eapol_sock
>= 0) {
4311 eloop_unregister_read_sock(drv
->eapol_sock
);
4312 close(drv
->eapol_sock
);
4315 if (drv
->if_indices
!= drv
->default_if_indices
)
4316 os_free(drv
->if_indices
);
4317 #endif /* HOSTAPD */
4319 if (drv
->disabled_11b_rates
)
4320 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
4322 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
4324 rfkill_deinit(drv
->rfkill
);
4326 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
4328 (void) i802_set_iface_flags(bss
, 0);
4329 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
4330 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
4331 nl80211_mgmt_unsubscribe(bss
, "deinit");
4333 nl80211_mgmt_unsubscribe(bss
, "deinit");
4334 nl80211_del_p2pdev(bss
);
4336 nl_cb_put(drv
->nl_cb
);
4338 nl80211_destroy_bss(drv
->first_bss
);
4340 os_free(drv
->filter_ssids
);
4342 os_free(drv
->auth_ie
);
4344 if (drv
->in_interface_list
)
4345 dl_list_del(&drv
->list
);
4347 os_free(drv
->extended_capa
);
4348 os_free(drv
->extended_capa_mask
);
4349 os_free(drv
->first_bss
);
4355 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
4356 * @eloop_ctx: Driver private data
4357 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
4359 * This function can be used as registered timeout when starting a scan to
4360 * generate a scan completed event if the driver does not report this.
4362 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
4364 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
4365 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
4366 wpa_driver_nl80211_set_mode(drv
->first_bss
,
4367 drv
->ap_scan_as_station
);
4368 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
4370 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
4371 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
4375 static struct nl_msg
*
4376 nl80211_scan_common(struct wpa_driver_nl80211_data
*drv
, u8 cmd
,
4377 struct wpa_driver_scan_params
*params
, u64
*wdev_id
)
4382 msg
= nlmsg_alloc();
4386 nl80211_cmd(drv
, msg
, 0, cmd
);
4389 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4391 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, *wdev_id
);
4393 if (params
->num_ssids
) {
4394 struct nlattr
*ssids
;
4396 ssids
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
4399 for (i
= 0; i
< params
->num_ssids
; i
++) {
4400 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
4401 params
->ssids
[i
].ssid
,
4402 params
->ssids
[i
].ssid_len
);
4403 if (nla_put(msg
, i
+ 1, params
->ssids
[i
].ssid_len
,
4404 params
->ssids
[i
].ssid
) < 0)
4407 nla_nest_end(msg
, ssids
);
4410 if (params
->extra_ies
) {
4411 wpa_hexdump(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
4412 params
->extra_ies
, params
->extra_ies_len
);
4413 if (nla_put(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
4414 params
->extra_ies
) < 0)
4418 if (params
->freqs
) {
4419 struct nlattr
*freqs
;
4420 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
4423 for (i
= 0; params
->freqs
[i
]; i
++) {
4424 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
4425 "MHz", params
->freqs
[i
]);
4426 if (nla_put_u32(msg
, i
+ 1, params
->freqs
[i
]) < 0)
4429 nla_nest_end(msg
, freqs
);
4432 os_free(drv
->filter_ssids
);
4433 drv
->filter_ssids
= params
->filter_ssids
;
4434 params
->filter_ssids
= NULL
;
4435 drv
->num_filter_ssids
= params
->num_filter_ssids
;
4447 * wpa_driver_nl80211_scan - Request the driver to initiate scan
4448 * @bss: Pointer to private driver data from wpa_driver_nl80211_init()
4449 * @params: Scan parameters
4450 * Returns: 0 on success, -1 on failure
4452 static int wpa_driver_nl80211_scan(struct i802_bss
*bss
,
4453 struct wpa_driver_scan_params
*params
)
4455 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4456 int ret
= -1, timeout
;
4457 struct nl_msg
*msg
= NULL
;
4459 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: scan request");
4460 drv
->scan_for_auth
= 0;
4462 msg
= nl80211_scan_common(drv
, NL80211_CMD_TRIGGER_SCAN
, params
,
4463 bss
->wdev_id_set
? &bss
->wdev_id
: NULL
);
4467 if (params
->p2p_probe
) {
4468 struct nlattr
*rates
;
4470 wpa_printf(MSG_DEBUG
, "nl80211: P2P probe - mask SuppRates");
4472 rates
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SUPP_RATES
);
4474 goto nla_put_failure
;
4477 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
4478 * by masking out everything else apart from the OFDM rates 6,
4479 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
4480 * rates are left enabled.
4482 NLA_PUT(msg
, NL80211_BAND_2GHZ
, 8,
4483 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
4484 nla_nest_end(msg
, rates
);
4486 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
4489 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4492 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
4493 "(%s)", ret
, strerror(-ret
));
4495 if (is_ap_interface(drv
->nlmode
)) {
4497 * mac80211 does not allow scan requests in AP mode, so
4498 * try to do this in station mode.
4500 if (wpa_driver_nl80211_set_mode(
4501 bss
, NL80211_IFTYPE_STATION
))
4502 goto nla_put_failure
;
4504 if (wpa_driver_nl80211_scan(bss
, params
)) {
4505 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
4506 goto nla_put_failure
;
4509 /* Restore AP mode when processing scan results */
4510 drv
->ap_scan_as_station
= drv
->nlmode
;
4513 goto nla_put_failure
;
4515 goto nla_put_failure
;
4516 #endif /* HOSTAPD */
4519 drv
->scan_state
= SCAN_REQUESTED
;
4520 /* Not all drivers generate "scan completed" wireless event, so try to
4521 * read results after a timeout. */
4523 if (drv
->scan_complete_events
) {
4525 * The driver seems to deliver events to notify when scan is
4526 * complete, so use longer timeout to avoid race conditions
4527 * with scanning and following association request.
4531 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
4532 "seconds", ret
, timeout
);
4533 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
4534 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
4544 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
4545 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
4546 * @params: Scan parameters
4547 * @interval: Interval between scan cycles in milliseconds
4548 * Returns: 0 on success, -1 on failure or if not supported
4550 static int wpa_driver_nl80211_sched_scan(void *priv
,
4551 struct wpa_driver_scan_params
*params
,
4554 struct i802_bss
*bss
= priv
;
4555 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4560 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: sched_scan request");
4563 if (!drv
->capa
.sched_scan_supported
)
4564 return android_pno_start(bss
, params
);
4565 #endif /* ANDROID */
4567 msg
= nl80211_scan_common(drv
, NL80211_CMD_START_SCHED_SCAN
, params
,
4568 bss
->wdev_id_set
? &bss
->wdev_id
: NULL
);
4570 goto nla_put_failure
;
4572 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
4574 if ((drv
->num_filter_ssids
&&
4575 (int) drv
->num_filter_ssids
<= drv
->capa
.max_match_sets
) ||
4576 params
->filter_rssi
) {
4577 struct nlattr
*match_sets
;
4578 match_sets
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
4579 if (match_sets
== NULL
)
4580 goto nla_put_failure
;
4582 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
4583 struct nlattr
*match_set_ssid
;
4584 wpa_hexdump_ascii(MSG_MSGDUMP
,
4585 "nl80211: Sched scan filter SSID",
4586 drv
->filter_ssids
[i
].ssid
,
4587 drv
->filter_ssids
[i
].ssid_len
);
4589 match_set_ssid
= nla_nest_start(msg
, i
+ 1);
4590 if (match_set_ssid
== NULL
)
4591 goto nla_put_failure
;
4592 NLA_PUT(msg
, NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
4593 drv
->filter_ssids
[i
].ssid_len
,
4594 drv
->filter_ssids
[i
].ssid
);
4596 nla_nest_end(msg
, match_set_ssid
);
4599 if (params
->filter_rssi
) {
4600 struct nlattr
*match_set_rssi
;
4601 match_set_rssi
= nla_nest_start(msg
, 0);
4602 if (match_set_rssi
== NULL
)
4603 goto nla_put_failure
;
4604 NLA_PUT_U32(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
,
4605 params
->filter_rssi
);
4606 wpa_printf(MSG_MSGDUMP
,
4607 "nl80211: Sched scan RSSI filter %d dBm",
4608 params
->filter_rssi
);
4609 nla_nest_end(msg
, match_set_rssi
);
4612 nla_nest_end(msg
, match_sets
);
4615 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4617 /* TODO: if we get an error here, we should fall back to normal scan */
4621 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
4622 "ret=%d (%s)", ret
, strerror(-ret
));
4623 goto nla_put_failure
;
4626 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
4627 "scan interval %d msec", ret
, interval
);
4636 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
4637 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
4638 * Returns: 0 on success, -1 on failure or if not supported
4640 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
4642 struct i802_bss
*bss
= priv
;
4643 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4648 if (!drv
->capa
.sched_scan_supported
)
4649 return android_pno_stop(bss
);
4650 #endif /* ANDROID */
4652 msg
= nlmsg_alloc();
4656 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
4658 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4660 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4663 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
4664 "ret=%d (%s)", ret
, strerror(-ret
));
4665 goto nla_put_failure
;
4668 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
4676 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
4678 const u8
*end
, *pos
;
4684 end
= ies
+ ies_len
;
4686 while (pos
+ 1 < end
) {
4687 if (pos
+ 2 + pos
[1] > end
)
4698 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
4699 const u8
*ie
, size_t ie_len
)
4704 if (drv
->filter_ssids
== NULL
)
4707 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
4711 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
4712 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
4713 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
4722 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
4724 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
4725 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4726 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
4727 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
4728 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
4729 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
4730 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
4731 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
4732 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
4733 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
4734 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
4735 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
4736 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
4737 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
4738 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
4740 struct nl80211_bss_info_arg
*_arg
= arg
;
4741 struct wpa_scan_results
*res
= _arg
->res
;
4742 struct wpa_scan_res
**tmp
;
4743 struct wpa_scan_res
*r
;
4744 const u8
*ie
, *beacon_ie
;
4745 size_t ie_len
, beacon_ie_len
;
4749 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4750 genlmsg_attrlen(gnlh
, 0), NULL
);
4751 if (!tb
[NL80211_ATTR_BSS
])
4753 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
4756 if (bss
[NL80211_BSS_STATUS
]) {
4757 enum nl80211_bss_status status
;
4758 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
4759 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
4760 bss
[NL80211_BSS_FREQUENCY
]) {
4762 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
4763 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
4766 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
4767 bss
[NL80211_BSS_BSSID
]) {
4768 os_memcpy(_arg
->assoc_bssid
,
4769 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
4770 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
4771 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
4776 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
4777 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
4778 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
4783 if (bss
[NL80211_BSS_BEACON_IES
]) {
4784 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
4785 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
4791 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
4792 ie
? ie_len
: beacon_ie_len
))
4795 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
4798 if (bss
[NL80211_BSS_BSSID
])
4799 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
4801 if (bss
[NL80211_BSS_FREQUENCY
])
4802 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
4803 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
4804 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
4805 if (bss
[NL80211_BSS_CAPABILITY
])
4806 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
4807 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
4808 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
4809 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
4810 r
->level
/= 100; /* mBm to dBm */
4811 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
4812 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
4813 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
4814 r
->flags
|= WPA_SCAN_QUAL_INVALID
;
4816 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
4817 if (bss
[NL80211_BSS_TSF
])
4818 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
4819 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
4820 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
4822 pos
= (u8
*) (r
+ 1);
4824 os_memcpy(pos
, ie
, ie_len
);
4827 r
->beacon_ie_len
= beacon_ie_len
;
4829 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
4831 if (bss
[NL80211_BSS_STATUS
]) {
4832 enum nl80211_bss_status status
;
4833 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
4835 case NL80211_BSS_STATUS_AUTHENTICATED
:
4836 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
4838 case NL80211_BSS_STATUS_ASSOCIATED
:
4839 r
->flags
|= WPA_SCAN_ASSOCIATED
;
4847 * cfg80211 maintains separate BSS table entries for APs if the same
4848 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
4849 * not use frequency as a separate key in the BSS table, so filter out
4850 * duplicated entries. Prefer associated BSS entry in such a case in
4851 * order to get the correct frequency into the BSS table.
4853 for (i
= 0; i
< res
->num
; i
++) {
4855 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
4858 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
4859 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
4860 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
4861 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
4862 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
4865 /* Same BSSID,SSID was already included in scan results */
4866 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
4867 "for " MACSTR
, MAC2STR(r
->bssid
));
4869 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
4870 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
4871 os_free(res
->res
[i
]);
4878 tmp
= os_realloc_array(res
->res
, res
->num
+ 1,
4879 sizeof(struct wpa_scan_res
*));
4884 tmp
[res
->num
++] = r
;
4891 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
4894 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
4895 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
4896 "mismatch (" MACSTR
")", MAC2STR(addr
));
4897 wpa_driver_nl80211_mlme(drv
, addr
,
4898 NL80211_CMD_DEAUTHENTICATE
,
4899 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
4904 static void wpa_driver_nl80211_check_bss_status(
4905 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
4909 for (i
= 0; i
< res
->num
; i
++) {
4910 struct wpa_scan_res
*r
= res
->res
[i
];
4911 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
4912 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4913 "indicates BSS status with " MACSTR
4914 " as authenticated",
4916 if (is_sta_interface(drv
->nlmode
) &&
4917 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
4918 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
4920 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
4921 " in local state (auth=" MACSTR
4922 " assoc=" MACSTR
")",
4923 MAC2STR(drv
->auth_bssid
),
4924 MAC2STR(drv
->bssid
));
4925 clear_state_mismatch(drv
, r
->bssid
);
4929 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
4930 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4931 "indicate BSS status with " MACSTR
4934 if (is_sta_interface(drv
->nlmode
) &&
4936 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4937 "(not associated) does not match "
4939 clear_state_mismatch(drv
, r
->bssid
);
4940 } else if (is_sta_interface(drv
->nlmode
) &&
4941 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
4943 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4944 "(associated with " MACSTR
") does "
4945 "not match with BSS state",
4946 MAC2STR(drv
->bssid
));
4947 clear_state_mismatch(drv
, r
->bssid
);
4948 clear_state_mismatch(drv
, drv
->bssid
);
4955 static struct wpa_scan_results
*
4956 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
4959 struct wpa_scan_results
*res
;
4961 struct nl80211_bss_info_arg arg
;
4963 res
= os_zalloc(sizeof(*res
));
4966 msg
= nlmsg_alloc();
4968 goto nla_put_failure
;
4970 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
4971 if (nl80211_set_iface_id(msg
, drv
->first_bss
) < 0)
4972 goto nla_put_failure
;
4976 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
4979 wpa_printf(MSG_DEBUG
, "nl80211: Received scan results (%lu "
4980 "BSSes)", (unsigned long) res
->num
);
4981 nl80211_get_noise_for_scan_results(drv
, res
);
4984 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
4985 "(%s)", ret
, strerror(-ret
));
4988 wpa_scan_results_free(res
);
4994 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
4995 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
4996 * Returns: Scan results on success, -1 on failure
4998 static struct wpa_scan_results
*
4999 wpa_driver_nl80211_get_scan_results(void *priv
)
5001 struct i802_bss
*bss
= priv
;
5002 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5003 struct wpa_scan_results
*res
;
5005 res
= nl80211_get_scan_results(drv
);
5007 wpa_driver_nl80211_check_bss_status(drv
, res
);
5012 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
5014 struct wpa_scan_results
*res
;
5017 res
= nl80211_get_scan_results(drv
);
5019 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
5023 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
5024 for (i
= 0; i
< res
->num
; i
++) {
5025 struct wpa_scan_res
*r
= res
->res
[i
];
5026 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
5027 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
5028 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
5029 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
5032 wpa_scan_results_free(res
);
5036 static int wpa_driver_nl80211_set_key(const char *ifname
, struct i802_bss
*bss
,
5037 enum wpa_alg alg
, const u8
*addr
,
5038 int key_idx
, int set_tx
,
5039 const u8
*seq
, size_t seq_len
,
5040 const u8
*key
, size_t key_len
)
5042 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5048 /* Ignore for P2P Device */
5049 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
5052 ifindex
= if_nametoindex(ifname
);
5053 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
5054 "set_tx=%d seq_len=%lu key_len=%lu",
5055 __func__
, ifindex
, ifname
, alg
, addr
, key_idx
, set_tx
,
5056 (unsigned long) seq_len
, (unsigned long) key_len
);
5058 if (key_idx
== -1) {
5062 #endif /* CONFIG_TDLS */
5064 msg
= nlmsg_alloc();
5068 if (alg
== WPA_ALG_NONE
) {
5069 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
5071 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
5072 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
5076 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5077 WLAN_CIPHER_SUITE_WEP40
);
5079 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5080 WLAN_CIPHER_SUITE_WEP104
);
5083 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5084 WLAN_CIPHER_SUITE_TKIP
);
5087 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5088 WLAN_CIPHER_SUITE_CCMP
);
5091 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5092 WLAN_CIPHER_SUITE_GCMP
);
5095 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5096 WLAN_CIPHER_SUITE_AES_CMAC
);
5099 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5100 WLAN_CIPHER_SUITE_SMS4
);
5103 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5104 WLAN_CIPHER_SUITE_KRK
);
5107 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
5108 "algorithm %d", __func__
, alg
);
5115 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
5117 if (addr
&& !is_broadcast_ether_addr(addr
)) {
5118 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
5119 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5121 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
5122 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
5123 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
5124 NL80211_KEYTYPE_GROUP
);
5126 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
5127 struct nlattr
*types
;
5129 wpa_printf(MSG_DEBUG
, " broadcast key");
5131 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
5133 goto nla_put_failure
;
5134 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
5135 nla_nest_end(msg
, types
);
5137 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
5138 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5140 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5141 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
5144 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
5145 ret
, strerror(-ret
));
5148 * If we failed or don't need to set the default TX key (below),
5151 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
|| tdls
)
5153 if (is_ap_interface(drv
->nlmode
) && addr
&&
5154 !is_broadcast_ether_addr(addr
))
5157 msg
= nlmsg_alloc();
5161 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
5162 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
5163 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5164 if (alg
== WPA_ALG_IGTK
)
5165 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
5167 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
5168 if (addr
&& is_broadcast_ether_addr(addr
)) {
5169 struct nlattr
*types
;
5171 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
5173 goto nla_put_failure
;
5174 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
5175 nla_nest_end(msg
, types
);
5177 struct nlattr
*types
;
5179 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
5181 goto nla_put_failure
;
5182 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
5183 nla_nest_end(msg
, types
);
5186 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5190 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
5191 "err=%d %s)", ret
, strerror(-ret
));
5200 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
5201 int key_idx
, int defkey
,
5202 const u8
*seq
, size_t seq_len
,
5203 const u8
*key
, size_t key_len
)
5205 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
5209 if (defkey
&& alg
== WPA_ALG_IGTK
)
5210 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
5212 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
5214 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
5219 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5220 WLAN_CIPHER_SUITE_WEP40
);
5222 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5223 WLAN_CIPHER_SUITE_WEP104
);
5226 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
5229 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
5232 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_GCMP
);
5235 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5236 WLAN_CIPHER_SUITE_AES_CMAC
);
5239 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
5240 "algorithm %d", __func__
, alg
);
5245 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
5247 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
5249 nla_nest_end(msg
, key_attr
);
5257 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
5261 struct nlattr
*nl_keys
, *nl_key
;
5263 for (i
= 0; i
< 4; i
++) {
5264 if (!params
->wep_key
[i
])
5269 if (params
->wps
== WPS_MODE_PRIVACY
)
5271 if (params
->pairwise_suite
&&
5272 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
5278 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
5280 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
5282 goto nla_put_failure
;
5284 for (i
= 0; i
< 4; i
++) {
5285 if (!params
->wep_key
[i
])
5288 nl_key
= nla_nest_start(msg
, i
);
5290 goto nla_put_failure
;
5292 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
5293 params
->wep_key
[i
]);
5294 if (params
->wep_key_len
[i
] == 5)
5295 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5296 WLAN_CIPHER_SUITE_WEP40
);
5298 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5299 WLAN_CIPHER_SUITE_WEP104
);
5301 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
5303 if (i
== params
->wep_tx_keyidx
)
5304 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
5306 nla_nest_end(msg
, nl_key
);
5308 nla_nest_end(msg
, nl_keys
);
5317 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
5318 const u8
*addr
, int cmd
, u16 reason_code
,
5319 int local_state_change
)
5324 msg
= nlmsg_alloc();
5328 nl80211_cmd(drv
, msg
, 0, cmd
);
5330 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5331 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
5333 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5334 if (local_state_change
)
5335 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
5337 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5340 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
5341 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
5342 reason_code
, ret
, strerror(-ret
));
5343 goto nla_put_failure
;
5353 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
5358 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
5359 nl80211_mark_disconnected(drv
);
5360 /* Disconnect command doesn't need BSSID - it uses cached value */
5361 ret
= wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
5364 * For locally generated disconnect, supplicant already generates a
5365 * DEAUTH event, so ignore the event from NL80211.
5367 drv
->ignore_next_local_disconnect
= ret
== 0;
5373 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
5374 const u8
*addr
, int reason_code
)
5376 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5377 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
5378 return wpa_driver_nl80211_disconnect(drv
, reason_code
);
5379 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
5380 __func__
, MAC2STR(addr
), reason_code
);
5381 nl80211_mark_disconnected(drv
);
5382 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
5383 return nl80211_leave_ibss(drv
);
5384 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
5389 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
5390 struct wpa_driver_auth_params
*params
)
5394 drv
->auth_freq
= params
->freq
;
5395 drv
->auth_alg
= params
->auth_alg
;
5396 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
5397 drv
->auth_local_state_change
= params
->local_state_change
;
5398 drv
->auth_p2p
= params
->p2p
;
5401 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
5403 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
5406 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
5407 drv
->auth_ssid_len
= params
->ssid_len
;
5409 drv
->auth_ssid_len
= 0;
5412 os_free(drv
->auth_ie
);
5413 drv
->auth_ie
= NULL
;
5414 drv
->auth_ie_len
= 0;
5416 drv
->auth_ie
= os_malloc(params
->ie_len
);
5418 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
5419 drv
->auth_ie_len
= params
->ie_len
;
5423 for (i
= 0; i
< 4; i
++) {
5424 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
5425 params
->wep_key_len
[i
] <= 16) {
5426 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
5427 params
->wep_key_len
[i
]);
5428 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
5430 drv
->auth_wep_key_len
[i
] = 0;
5435 static int wpa_driver_nl80211_authenticate(
5436 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
5438 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5441 enum nl80211_auth_type type
;
5442 enum nl80211_iftype nlmode
;
5446 is_retry
= drv
->retry_auth
;
5447 drv
->retry_auth
= 0;
5449 nl80211_mark_disconnected(drv
);
5450 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
5452 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
5454 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
5455 /* FIX: IBSS mode */
5456 nlmode
= params
->p2p
?
5457 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
5458 if (drv
->nlmode
!= nlmode
&&
5459 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
5463 msg
= nlmsg_alloc();
5467 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
5470 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
5472 for (i
= 0; i
< 4; i
++) {
5473 if (!params
->wep_key
[i
])
5475 wpa_driver_nl80211_set_key(bss
->ifname
, bss
, WPA_ALG_WEP
,
5477 i
== params
->wep_tx_keyidx
, NULL
, 0,
5479 params
->wep_key_len
[i
]);
5480 if (params
->wep_tx_keyidx
!= i
)
5482 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
5483 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
5489 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5490 if (params
->bssid
) {
5491 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5492 MAC2STR(params
->bssid
));
5493 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
5496 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5497 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5500 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5501 params
->ssid
, params
->ssid_len
);
5502 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5505 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
5507 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
5508 if (params
->sae_data
) {
5509 wpa_hexdump(MSG_DEBUG
, " * SAE data", params
->sae_data
,
5510 params
->sae_data_len
);
5511 NLA_PUT(msg
, NL80211_ATTR_SAE_DATA
, params
->sae_data_len
,
5514 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5515 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
5516 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5517 type
= NL80211_AUTHTYPE_SHARED_KEY
;
5518 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5519 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
5520 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
5521 type
= NL80211_AUTHTYPE_FT
;
5522 else if (params
->auth_alg
& WPA_AUTH_ALG_SAE
)
5523 type
= NL80211_AUTHTYPE_SAE
;
5525 goto nla_put_failure
;
5526 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
5527 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
5528 if (params
->local_state_change
) {
5529 wpa_printf(MSG_DEBUG
, " * Local state change only");
5530 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
5533 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5536 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
5537 "nl80211: MLME command failed (auth): ret=%d (%s)",
5538 ret
, strerror(-ret
));
5540 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
5541 !params
->local_state_change
) {
5543 * mac80211 does not currently accept new
5544 * authentication if we are already authenticated. As a
5545 * workaround, force deauthentication and try again.
5547 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
5548 "after forced deauthentication");
5549 wpa_driver_nl80211_deauthenticate(
5551 WLAN_REASON_PREV_AUTH_NOT_VALID
);
5556 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
5558 * cfg80211 has likely expired the BSS entry even
5559 * though it was previously available in our internal
5560 * BSS table. To recover quickly, start a single
5561 * channel scan on the specified channel.
5563 struct wpa_driver_scan_params scan
;
5566 os_memset(&scan
, 0, sizeof(scan
));
5569 scan
.ssids
[0].ssid
= params
->ssid
;
5570 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
5572 freqs
[0] = params
->freq
;
5575 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
5576 "channel scan to refresh cfg80211 BSS "
5578 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
5580 nl80211_copy_auth_params(drv
, params
);
5581 drv
->scan_for_auth
= 1;
5583 } else if (is_retry
) {
5585 * Need to indicate this with an event since the return
5586 * value from the retry is not delivered to core code.
5588 union wpa_event_data event
;
5589 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
5591 os_memset(&event
, 0, sizeof(event
));
5592 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
5594 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
5598 goto nla_put_failure
;
5601 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
5610 static int wpa_driver_nl80211_authenticate_retry(
5611 struct wpa_driver_nl80211_data
*drv
)
5613 struct wpa_driver_auth_params params
;
5614 struct i802_bss
*bss
= drv
->first_bss
;
5617 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
5619 os_memset(¶ms
, 0, sizeof(params
));
5620 params
.freq
= drv
->auth_freq
;
5621 params
.auth_alg
= drv
->auth_alg
;
5622 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
5623 params
.local_state_change
= drv
->auth_local_state_change
;
5624 params
.p2p
= drv
->auth_p2p
;
5626 if (!is_zero_ether_addr(drv
->auth_bssid_
))
5627 params
.bssid
= drv
->auth_bssid_
;
5629 if (drv
->auth_ssid_len
) {
5630 params
.ssid
= drv
->auth_ssid
;
5631 params
.ssid_len
= drv
->auth_ssid_len
;
5634 params
.ie
= drv
->auth_ie
;
5635 params
.ie_len
= drv
->auth_ie_len
;
5637 for (i
= 0; i
< 4; i
++) {
5638 if (drv
->auth_wep_key_len
[i
]) {
5639 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
5640 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
5644 drv
->retry_auth
= 1;
5645 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
5649 struct phy_info_arg
{
5651 struct hostapd_hw_modes
*modes
;
5652 int last_mode
, last_chan_idx
;
5655 static void phy_info_ht_capa(struct hostapd_hw_modes
*mode
, struct nlattr
*capa
,
5656 struct nlattr
*ampdu_factor
,
5657 struct nlattr
*ampdu_density
,
5658 struct nlattr
*mcs_set
)
5661 mode
->ht_capab
= nla_get_u16(capa
);
5664 mode
->a_mpdu_params
|= nla_get_u8(ampdu_factor
) & 0x03;
5667 mode
->a_mpdu_params
|= nla_get_u8(ampdu_density
) << 2;
5669 if (mcs_set
&& nla_len(mcs_set
) >= 16) {
5671 mcs
= nla_data(mcs_set
);
5672 os_memcpy(mode
->mcs_set
, mcs
, 16);
5677 static void phy_info_vht_capa(struct hostapd_hw_modes
*mode
,
5678 struct nlattr
*capa
,
5679 struct nlattr
*mcs_set
)
5682 mode
->vht_capab
= nla_get_u32(capa
);
5684 if (mcs_set
&& nla_len(mcs_set
) >= 8) {
5686 mcs
= nla_data(mcs_set
);
5687 os_memcpy(mode
->vht_mcs_set
, mcs
, 8);
5692 static void phy_info_freq(struct hostapd_hw_modes
*mode
,
5693 struct hostapd_channel_data
*chan
,
5694 struct nlattr
*tb_freq
[])
5697 chan
->freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
5699 if (ieee80211_freq_to_chan(chan
->freq
, &channel
) != NUM_HOSTAPD_MODES
)
5700 chan
->chan
= channel
;
5702 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
5703 chan
->flag
|= HOSTAPD_CHAN_DISABLED
;
5704 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
5705 chan
->flag
|= HOSTAPD_CHAN_PASSIVE_SCAN
;
5706 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
5707 chan
->flag
|= HOSTAPD_CHAN_NO_IBSS
;
5708 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
5709 chan
->flag
|= HOSTAPD_CHAN_RADAR
;
5711 if (tb_freq
[NL80211_FREQUENCY_ATTR_DFS_STATE
]) {
5712 enum nl80211_dfs_state state
=
5713 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_DFS_STATE
]);
5716 case NL80211_DFS_USABLE
:
5717 chan
->flag
|= HOSTAPD_CHAN_DFS_USABLE
;
5719 case NL80211_DFS_AVAILABLE
:
5720 chan
->flag
|= HOSTAPD_CHAN_DFS_AVAILABLE
;
5722 case NL80211_DFS_UNAVAILABLE
:
5723 chan
->flag
|= HOSTAPD_CHAN_DFS_UNAVAILABLE
;
5730 static int phy_info_freqs(struct phy_info_arg
*phy_info
,
5731 struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
5733 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
5734 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
5735 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
5736 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
5737 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
5738 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
5739 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
5740 [NL80211_FREQUENCY_ATTR_DFS_STATE
] = { .type
= NLA_U32
},
5742 int new_channels
= 0;
5743 struct hostapd_channel_data
*channel
;
5744 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
5745 struct nlattr
*nl_freq
;
5751 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
5752 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
5753 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
5754 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
5759 channel
= os_realloc_array(mode
->channels
,
5760 mode
->num_channels
+ new_channels
,
5761 sizeof(struct hostapd_channel_data
));
5765 mode
->channels
= channel
;
5766 mode
->num_channels
+= new_channels
;
5768 idx
= phy_info
->last_chan_idx
;
5770 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
5771 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
5772 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
5773 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
5775 phy_info_freq(mode
, &mode
->channels
[idx
], tb_freq
);
5778 phy_info
->last_chan_idx
= idx
;
5784 static int phy_info_rates(struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
5786 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
5787 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
5788 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] =
5789 { .type
= NLA_FLAG
},
5791 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
5792 struct nlattr
*nl_rate
;
5798 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
5799 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
5800 nla_data(nl_rate
), nla_len(nl_rate
),
5802 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
5807 mode
->rates
= os_calloc(mode
->num_rates
, sizeof(int));
5813 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
5814 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
5815 nla_data(nl_rate
), nla_len(nl_rate
),
5817 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
5819 mode
->rates
[idx
] = nla_get_u32(
5820 tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
5828 static int phy_info_band(struct phy_info_arg
*phy_info
, struct nlattr
*nl_band
)
5830 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
5831 struct hostapd_hw_modes
*mode
;
5834 if (phy_info
->last_mode
!= nl_band
->nla_type
) {
5835 mode
= os_realloc_array(phy_info
->modes
,
5836 *phy_info
->num_modes
+ 1,
5840 phy_info
->modes
= mode
;
5842 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
5843 os_memset(mode
, 0, sizeof(*mode
));
5844 mode
->mode
= NUM_HOSTAPD_MODES
;
5845 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
|
5846 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN
;
5849 * Unsupported VHT MCS stream is defined as value 3, so the VHT
5850 * MCS RX/TX map must be initialized with 0xffff to mark all 8
5851 * possible streams as unsupported. This will be overridden if
5852 * driver advertises VHT support.
5854 mode
->vht_mcs_set
[0] = 0xff;
5855 mode
->vht_mcs_set
[1] = 0xff;
5856 mode
->vht_mcs_set
[4] = 0xff;
5857 mode
->vht_mcs_set
[5] = 0xff;
5859 *(phy_info
->num_modes
) += 1;
5860 phy_info
->last_mode
= nl_band
->nla_type
;
5861 phy_info
->last_chan_idx
= 0;
5863 mode
= &phy_info
->modes
[*(phy_info
->num_modes
) - 1];
5865 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
5866 nla_len(nl_band
), NULL
);
5868 phy_info_ht_capa(mode
, tb_band
[NL80211_BAND_ATTR_HT_CAPA
],
5869 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
],
5870 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
],
5871 tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
5872 phy_info_vht_capa(mode
, tb_band
[NL80211_BAND_ATTR_VHT_CAPA
],
5873 tb_band
[NL80211_BAND_ATTR_VHT_MCS_SET
]);
5874 ret
= phy_info_freqs(phy_info
, mode
, tb_band
[NL80211_BAND_ATTR_FREQS
]);
5877 ret
= phy_info_rates(mode
, tb_band
[NL80211_BAND_ATTR_RATES
]);
5885 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
5887 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
5888 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5889 struct phy_info_arg
*phy_info
= arg
;
5890 struct nlattr
*nl_band
;
5893 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5894 genlmsg_attrlen(gnlh
, 0), NULL
);
5896 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
5899 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
)
5901 int res
= phy_info_band(phy_info
, nl_band
);
5910 static struct hostapd_hw_modes
*
5911 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes
*modes
,
5915 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
5916 int i
, mode11g_idx
= -1;
5918 /* heuristic to set up modes */
5919 for (m
= 0; m
< *num_modes
; m
++) {
5920 if (!modes
[m
].num_channels
)
5922 if (modes
[m
].channels
[0].freq
< 4000) {
5923 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211B
;
5924 for (i
= 0; i
< modes
[m
].num_rates
; i
++) {
5925 if (modes
[m
].rates
[i
] > 200) {
5926 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211G
;
5930 } else if (modes
[m
].channels
[0].freq
> 50000)
5931 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211AD
;
5933 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211A
;
5936 /* If only 802.11g mode is included, use it to construct matching
5937 * 802.11b mode data. */
5939 for (m
= 0; m
< *num_modes
; m
++) {
5940 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
5941 return modes
; /* 802.11b already included */
5942 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
5946 if (mode11g_idx
< 0)
5947 return modes
; /* 2.4 GHz band not supported at all */
5949 nmodes
= os_realloc_array(modes
, *num_modes
+ 1, sizeof(*nmodes
));
5951 return modes
; /* Could not add 802.11b mode */
5953 mode
= &nmodes
[*num_modes
];
5954 os_memset(mode
, 0, sizeof(*mode
));
5958 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
5960 mode11g
= &modes
[mode11g_idx
];
5961 mode
->num_channels
= mode11g
->num_channels
;
5962 mode
->channels
= os_malloc(mode11g
->num_channels
*
5963 sizeof(struct hostapd_channel_data
));
5964 if (mode
->channels
== NULL
) {
5966 return modes
; /* Could not add 802.11b mode */
5968 os_memcpy(mode
->channels
, mode11g
->channels
,
5969 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
5971 mode
->num_rates
= 0;
5972 mode
->rates
= os_malloc(4 * sizeof(int));
5973 if (mode
->rates
== NULL
) {
5974 os_free(mode
->channels
);
5976 return modes
; /* Could not add 802.11b mode */
5979 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
5980 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
5981 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
5983 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
5985 if (mode
->num_rates
== 4)
5989 if (mode
->num_rates
== 0) {
5990 os_free(mode
->channels
);
5991 os_free(mode
->rates
);
5993 return modes
; /* No 802.11b rates */
5996 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
6003 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
6008 for (c
= 0; c
< mode
->num_channels
; c
++) {
6009 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
6010 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
6011 chan
->flag
|= HOSTAPD_CHAN_HT40
;
6016 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
6021 for (c
= 0; c
< mode
->num_channels
; c
++) {
6022 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
6023 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
6025 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
6026 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
6027 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
6028 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
6033 static void nl80211_reg_rule_max_eirp(struct nlattr
*tb
[],
6034 struct phy_info_arg
*results
)
6036 u32 start
, end
, max_eirp
;
6039 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
6040 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
6041 tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
] == NULL
)
6044 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
6045 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
6046 max_eirp
= nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]) / 100;
6048 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u mBm",
6049 start
, end
, max_eirp
);
6051 for (m
= 0; m
< *results
->num_modes
; m
++) {
6053 struct hostapd_hw_modes
*mode
= &results
->modes
[m
];
6055 for (c
= 0; c
< mode
->num_channels
; c
++) {
6056 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
6057 if ((u32
) chan
->freq
- 10 >= start
&&
6058 (u32
) chan
->freq
+ 10 <= end
)
6059 chan
->max_tx_power
= max_eirp
;
6065 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
6066 struct phy_info_arg
*results
)
6068 u32 start
, end
, max_bw
;
6071 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
6072 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
6073 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
6076 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
6077 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
6078 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
6080 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
6081 start
, end
, max_bw
);
6085 for (m
= 0; m
< *results
->num_modes
; m
++) {
6086 if (!(results
->modes
[m
].ht_capab
&
6087 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
6089 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
6094 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
6095 struct phy_info_arg
*results
)
6097 u32 start
, end
, max_bw
;
6100 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
6101 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
6102 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
6105 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
6106 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
6107 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
6112 for (m
= 0; m
< *results
->num_modes
; m
++) {
6113 if (!(results
->modes
[m
].ht_capab
&
6114 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
6116 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
6121 static void nl80211_set_vht_mode(struct hostapd_hw_modes
*mode
, int start
,
6126 for (c
= 0; c
< mode
->num_channels
; c
++) {
6127 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
6128 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 70 <= end
)
6129 chan
->flag
|= HOSTAPD_CHAN_VHT_10_70
;
6131 if (chan
->freq
- 30 >= start
&& chan
->freq
+ 50 <= end
)
6132 chan
->flag
|= HOSTAPD_CHAN_VHT_30_50
;
6134 if (chan
->freq
- 50 >= start
&& chan
->freq
+ 30 <= end
)
6135 chan
->flag
|= HOSTAPD_CHAN_VHT_50_30
;
6137 if (chan
->freq
- 70 >= start
&& chan
->freq
+ 10 <= end
)
6138 chan
->flag
|= HOSTAPD_CHAN_VHT_70_10
;
6143 static void nl80211_reg_rule_vht(struct nlattr
*tb
[],
6144 struct phy_info_arg
*results
)
6146 u32 start
, end
, max_bw
;
6149 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
6150 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
6151 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
6154 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
6155 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
6156 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
6161 for (m
= 0; m
< *results
->num_modes
; m
++) {
6162 if (!(results
->modes
[m
].ht_capab
&
6163 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
6165 /* TODO: use a real VHT support indication */
6166 if (!results
->modes
[m
].vht_capab
)
6169 nl80211_set_vht_mode(&results
->modes
[m
], start
, end
);
6174 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
6176 struct phy_info_arg
*results
= arg
;
6177 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
6178 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6179 struct nlattr
*nl_rule
;
6180 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
6182 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
6183 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
6184 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
6185 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
6186 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
6187 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
6188 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
6191 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6192 genlmsg_attrlen(gnlh
, 0), NULL
);
6193 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
6194 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
6195 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
6200 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
6201 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
6203 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
6205 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
6206 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
6207 nl80211_reg_rule_ht40(tb_rule
, results
);
6208 nl80211_reg_rule_max_eirp(tb_rule
, results
);
6211 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
6213 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
6214 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
6215 nl80211_reg_rule_sec(tb_rule
, results
);
6218 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
6220 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
6221 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
6222 nl80211_reg_rule_vht(tb_rule
, results
);
6229 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data
*drv
,
6230 struct phy_info_arg
*results
)
6234 msg
= nlmsg_alloc();
6238 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
6239 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
6243 static struct hostapd_hw_modes
*
6244 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
6247 struct i802_bss
*bss
= priv
;
6248 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6250 struct phy_info_arg result
= {
6251 .num_modes
= num_modes
,
6259 msg
= nlmsg_alloc();
6263 feat
= get_nl80211_protocol_features(drv
);
6264 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
6265 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_WIPHY
);
6267 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
6269 NLA_PUT_FLAG(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
);
6270 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6272 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
6273 nl80211_set_regulatory_flags(drv
, &result
);
6274 return wpa_driver_nl80211_postprocess_modes(result
.modes
,
6284 static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data
*drv
,
6285 const void *data
, size_t len
,
6286 int encrypt
, int noack
)
6289 0x00, 0x00, /* radiotap version */
6290 0x0e, 0x00, /* radiotap length */
6291 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
6292 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
6294 0x00, 0x00, /* RX and TX flags to indicate that */
6295 0x00, 0x00, /* this is the injected frame directly */
6297 struct iovec iov
[2] = {
6299 .iov_base
= &rtap_hdr
,
6300 .iov_len
= sizeof(rtap_hdr
),
6303 .iov_base
= (void *) data
,
6307 struct msghdr msg
= {
6312 .msg_control
= NULL
,
6313 .msg_controllen
= 0,
6320 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
6322 if (drv
->monitor_sock
< 0) {
6323 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
6324 "for %s", __func__
);
6329 txflags
|= IEEE80211_RADIOTAP_F_TX_NOACK
;
6330 WPA_PUT_LE16(&rtap_hdr
[12], txflags
);
6332 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
6334 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
6341 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
6342 const void *data
, size_t len
,
6343 int encrypt
, int noack
,
6344 unsigned int freq
, int no_cck
,
6345 int offchanok
, unsigned int wait_time
)
6347 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6352 wpa_printf(MSG_DEBUG
, "nl80211: send_frame - Use bss->freq=%u",
6357 if (drv
->use_monitor
) {
6358 wpa_printf(MSG_DEBUG
, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_mntr",
6360 return wpa_driver_nl80211_send_mntr(drv
, data
, len
,
6364 wpa_printf(MSG_DEBUG
, "nl80211: send_frame -> send_frame_cmd");
6365 res
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
6366 &cookie
, no_cck
, noack
, offchanok
);
6367 if (res
== 0 && !noack
) {
6368 const struct ieee80211_mgmt
*mgmt
;
6371 mgmt
= (const struct ieee80211_mgmt
*) data
;
6372 fc
= le_to_host16(mgmt
->frame_control
);
6373 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
6374 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_ACTION
) {
6375 wpa_printf(MSG_MSGDUMP
,
6376 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
6377 (long long unsigned int)
6378 drv
->send_action_cookie
,
6379 (long long unsigned int) cookie
);
6380 drv
->send_action_cookie
= cookie
;
6388 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
6389 size_t data_len
, int noack
,
6390 unsigned int freq
, int no_cck
,
6392 unsigned int wait_time
)
6394 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6395 struct ieee80211_mgmt
*mgmt
;
6399 mgmt
= (struct ieee80211_mgmt
*) data
;
6400 fc
= le_to_host16(mgmt
->frame_control
);
6401 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme - noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x nlmode=%d",
6402 noack
, freq
, no_cck
, offchanok
, wait_time
, fc
, drv
->nlmode
);
6404 if ((is_sta_interface(drv
->nlmode
) ||
6405 drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) &&
6406 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
6407 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
6409 * The use of last_mgmt_freq is a bit of a hack,
6410 * but it works due to the single-threaded nature
6411 * of wpa_supplicant.
6414 wpa_printf(MSG_DEBUG
, "nl80211: Use last_mgmt_freq=%d",
6415 drv
->last_mgmt_freq
);
6416 freq
= drv
->last_mgmt_freq
;
6418 return nl80211_send_frame_cmd(bss
, freq
, 0,
6419 data
, data_len
, NULL
, 1, noack
,
6423 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
6425 wpa_printf(MSG_DEBUG
, "nl80211: Use bss->freq=%d",
6429 return nl80211_send_frame_cmd(bss
, freq
,
6430 (int) freq
== bss
->freq
? 0 :
6433 &drv
->send_action_cookie
,
6434 no_cck
, noack
, offchanok
);
6437 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
6438 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
6440 * Only one of the authentication frame types is encrypted.
6441 * In order for static WEP encryption to work properly (i.e.,
6442 * to not encrypt the frame), we need to tell mac80211 about
6443 * the frames that must not be encrypted.
6445 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
6446 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
6447 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
6451 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme -> send_frame");
6452 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
6453 noack
, freq
, no_cck
, offchanok
,
6458 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
6459 int slot
, int ht_opmode
, int ap_isolate
,
6462 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6465 msg
= nlmsg_alloc();
6469 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
6472 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
6474 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
6476 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
6478 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
6479 if (ap_isolate
>= 0)
6480 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
);
6483 u8 rates
[NL80211_MAX_SUPP_RATES
];
6487 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0;
6489 rates
[rates_len
++] = basic_rates
[i
] / 5;
6491 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
6494 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6496 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6503 static int wpa_driver_nl80211_set_acl(void *priv
,
6504 struct hostapd_acl_params
*params
)
6506 struct i802_bss
*bss
= priv
;
6507 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6513 if (!(drv
->capa
.max_acl_mac_addrs
))
6516 if (params
->num_mac_acl
> drv
->capa
.max_acl_mac_addrs
)
6519 msg
= nlmsg_alloc();
6523 wpa_printf(MSG_DEBUG
, "nl80211: Set %s ACL (num_mac_acl=%u)",
6524 params
->acl_policy
? "Accept" : "Deny", params
->num_mac_acl
);
6526 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_MAC_ACL
);
6528 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6530 NLA_PUT_U32(msg
, NL80211_ATTR_ACL_POLICY
, params
->acl_policy
?
6531 NL80211_ACL_POLICY_DENY_UNLESS_LISTED
:
6532 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
);
6534 acl
= nla_nest_start(msg
, NL80211_ATTR_MAC_ADDRS
);
6536 goto nla_put_failure
;
6538 for (i
= 0; i
< params
->num_mac_acl
; i
++)
6539 NLA_PUT(msg
, i
+ 1, ETH_ALEN
, params
->mac_acl
[i
].addr
);
6541 nla_nest_end(msg
, acl
);
6543 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6546 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set MAC ACL: %d (%s)",
6547 ret
, strerror(-ret
));
6557 static int wpa_driver_nl80211_set_ap(void *priv
,
6558 struct wpa_driver_ap_params
*params
)
6560 struct i802_bss
*bss
= priv
;
6561 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6563 u8 cmd
= NL80211_CMD_NEW_BEACON
;
6566 int ifindex
= if_nametoindex(bss
->ifname
);
6571 beacon_set
= bss
->beacon_set
;
6573 msg
= nlmsg_alloc();
6577 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
6580 cmd
= NL80211_CMD_SET_BEACON
;
6582 nl80211_cmd(drv
, msg
, 0, cmd
);
6583 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon head",
6584 params
->head
, params
->head_len
);
6585 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
6586 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon tail",
6587 params
->tail
, params
->tail_len
);
6588 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
6589 wpa_printf(MSG_DEBUG
, "nl80211: ifindex=%d", ifindex
);
6590 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
6591 wpa_printf(MSG_DEBUG
, "nl80211: beacon_int=%d", params
->beacon_int
);
6592 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
6593 wpa_printf(MSG_DEBUG
, "nl80211: dtim_period=%d", params
->dtim_period
);
6594 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
6595 wpa_hexdump_ascii(MSG_DEBUG
, "nl80211: ssid",
6596 params
->ssid
, params
->ssid_len
);
6597 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6599 if (params
->proberesp
&& params
->proberesp_len
) {
6600 wpa_hexdump(MSG_DEBUG
, "nl80211: proberesp (offload)",
6601 params
->proberesp
, params
->proberesp_len
);
6602 NLA_PUT(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
6605 switch (params
->hide_ssid
) {
6606 case NO_SSID_HIDING
:
6607 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID not in use");
6608 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6609 NL80211_HIDDEN_SSID_NOT_IN_USE
);
6611 case HIDDEN_SSID_ZERO_LEN
:
6612 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero len");
6613 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6614 NL80211_HIDDEN_SSID_ZERO_LEN
);
6616 case HIDDEN_SSID_ZERO_CONTENTS
:
6617 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero contents");
6618 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6619 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
6622 wpa_printf(MSG_DEBUG
, "nl80211: privacy=%d", params
->privacy
);
6623 if (params
->privacy
)
6624 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
6625 wpa_printf(MSG_DEBUG
, "nl80211: auth_algs=0x%x", params
->auth_algs
);
6626 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
6627 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
6628 /* Leave out the attribute */
6629 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
6630 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
6631 NL80211_AUTHTYPE_SHARED_KEY
);
6633 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
6634 NL80211_AUTHTYPE_OPEN_SYSTEM
);
6636 wpa_printf(MSG_DEBUG
, "nl80211: wpa_version=0x%x", params
->wpa_version
);
6638 if (params
->wpa_version
& WPA_PROTO_WPA
)
6639 ver
|= NL80211_WPA_VERSION_1
;
6640 if (params
->wpa_version
& WPA_PROTO_RSN
)
6641 ver
|= NL80211_WPA_VERSION_2
;
6643 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
6645 wpa_printf(MSG_DEBUG
, "nl80211: key_mgmt_suites=0x%x",
6646 params
->key_mgmt_suites
);
6648 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
6649 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
6650 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
6651 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
6653 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
6654 num_suites
* sizeof(u32
), suites
);
6657 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
&&
6658 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
))
6659 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
);
6661 wpa_printf(MSG_DEBUG
, "nl80211: pairwise_ciphers=0x%x",
6662 params
->pairwise_ciphers
);
6664 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
6665 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
6666 if (params
->pairwise_ciphers
& WPA_CIPHER_GCMP
)
6667 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP
;
6668 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
6669 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
6670 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
6671 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
6672 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
6673 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
6675 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
6676 num_suites
* sizeof(u32
), suites
);
6679 wpa_printf(MSG_DEBUG
, "nl80211: group_cipher=0x%x",
6680 params
->group_cipher
);
6681 switch (params
->group_cipher
) {
6682 case WPA_CIPHER_CCMP
:
6683 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6684 WLAN_CIPHER_SUITE_CCMP
);
6686 case WPA_CIPHER_GCMP
:
6687 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6688 WLAN_CIPHER_SUITE_GCMP
);
6690 case WPA_CIPHER_TKIP
:
6691 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6692 WLAN_CIPHER_SUITE_TKIP
);
6694 case WPA_CIPHER_WEP104
:
6695 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6696 WLAN_CIPHER_SUITE_WEP104
);
6698 case WPA_CIPHER_WEP40
:
6699 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6700 WLAN_CIPHER_SUITE_WEP40
);
6704 if (params
->beacon_ies
) {
6705 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: beacon_ies",
6706 params
->beacon_ies
);
6707 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
6708 wpabuf_head(params
->beacon_ies
));
6710 if (params
->proberesp_ies
) {
6711 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: proberesp_ies",
6712 params
->proberesp_ies
);
6713 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
6714 wpabuf_len(params
->proberesp_ies
),
6715 wpabuf_head(params
->proberesp_ies
));
6717 if (params
->assocresp_ies
) {
6718 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: assocresp_ies",
6719 params
->assocresp_ies
);
6720 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
6721 wpabuf_len(params
->assocresp_ies
),
6722 wpabuf_head(params
->assocresp_ies
));
6725 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
6726 wpa_printf(MSG_DEBUG
, "nl80211: ap_max_inactivity=%d",
6727 params
->ap_max_inactivity
);
6728 NLA_PUT_U16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
6729 params
->ap_max_inactivity
);
6732 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6734 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
6735 ret
, strerror(-ret
));
6737 bss
->beacon_set
= 1;
6738 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
6739 params
->short_slot_time
, params
->ht_opmode
,
6740 params
->isolate
, params
->basic_rates
);
6749 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
6750 struct hostapd_freq_params
*freq
)
6752 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6756 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d,"
6757 " bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
6758 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
6759 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
6760 msg
= nlmsg_alloc();
6764 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
6766 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6767 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
);
6768 if (freq
->vht_enabled
) {
6769 switch (freq
->bandwidth
) {
6771 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6772 NL80211_CHAN_WIDTH_20
);
6775 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6776 NL80211_CHAN_WIDTH_40
);
6779 if (freq
->center_freq2
)
6780 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6781 NL80211_CHAN_WIDTH_80P80
);
6783 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6784 NL80211_CHAN_WIDTH_80
);
6787 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6788 NL80211_CHAN_WIDTH_160
);
6793 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ1
, freq
->center_freq1
);
6794 if (freq
->center_freq2
)
6795 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ2
,
6796 freq
->center_freq2
);
6797 } else if (freq
->ht_enabled
) {
6798 switch (freq
->sec_channel_offset
) {
6800 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6801 NL80211_CHAN_HT40MINUS
);
6804 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6805 NL80211_CHAN_HT40PLUS
);
6808 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6814 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6817 bss
->freq
= freq
->freq
;
6820 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
6821 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
6828 static u32
sta_flags_nl80211(int flags
)
6832 if (flags
& WPA_STA_AUTHORIZED
)
6833 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6834 if (flags
& WPA_STA_WMM
)
6835 f
|= BIT(NL80211_STA_FLAG_WME
);
6836 if (flags
& WPA_STA_SHORT_PREAMBLE
)
6837 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
6838 if (flags
& WPA_STA_MFP
)
6839 f
|= BIT(NL80211_STA_FLAG_MFP
);
6840 if (flags
& WPA_STA_TDLS_PEER
)
6841 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
6847 static int wpa_driver_nl80211_sta_add(void *priv
,
6848 struct hostapd_sta_add_params
*params
)
6850 struct i802_bss
*bss
= priv
;
6851 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6853 struct nl80211_sta_flag_update upd
;
6856 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
6857 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
6860 msg
= nlmsg_alloc();
6864 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
6865 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
6866 nl80211_cmd(drv
, msg
, 0, params
->set
? NL80211_CMD_SET_STATION
:
6867 NL80211_CMD_NEW_STATION
);
6869 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6870 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
6871 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
6872 params
->supp_rates
);
6873 wpa_hexdump(MSG_DEBUG
, " * supported rates", params
->supp_rates
,
6874 params
->supp_rates_len
);
6877 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
6878 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
6881 * cfg80211 validates that AID is non-zero, so we have
6882 * to make this a non-zero value for the TDLS case where
6883 * a dummy STA entry is used for now.
6885 wpa_printf(MSG_DEBUG
, " * aid=1 (TDLS workaround)");
6886 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, 1);
6888 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
6889 params
->listen_interval
);
6890 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
6891 params
->listen_interval
);
6892 } else if (params
->aid
&& (params
->flags
& WPA_STA_TDLS_PEER
)) {
6893 wpa_printf(MSG_DEBUG
, " * peer_aid=%u", params
->aid
);
6894 NLA_PUT_U16(msg
, NL80211_ATTR_PEER_AID
, params
->aid
);
6896 if (params
->ht_capabilities
) {
6897 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
6898 (u8
*) params
->ht_capabilities
,
6899 sizeof(*params
->ht_capabilities
));
6900 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
6901 sizeof(*params
->ht_capabilities
),
6902 params
->ht_capabilities
);
6905 if (params
->vht_capabilities
) {
6906 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
6907 (u8
*) params
->vht_capabilities
,
6908 sizeof(*params
->vht_capabilities
));
6909 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
,
6910 sizeof(*params
->vht_capabilities
),
6911 params
->vht_capabilities
);
6914 wpa_printf(MSG_DEBUG
, " * capability=0x%x", params
->capability
);
6915 NLA_PUT_U16(msg
, NL80211_ATTR_STA_CAPABILITY
, params
->capability
);
6917 if (params
->ext_capab
) {
6918 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
6919 params
->ext_capab
, params
->ext_capab_len
);
6920 NLA_PUT(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
6921 params
->ext_capab_len
, params
->ext_capab
);
6924 os_memset(&upd
, 0, sizeof(upd
));
6925 upd
.mask
= sta_flags_nl80211(params
->flags
);
6927 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
6929 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6931 if (params
->flags
& WPA_STA_WMM
) {
6932 struct nlattr
*wme
= nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
6935 goto nla_put_failure
;
6937 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
6938 NLA_PUT_U8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
6939 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
);
6940 NLA_PUT_U8(msg
, NL80211_STA_WME_MAX_SP
,
6941 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
6942 WMM_QOSINFO_STA_SP_MASK
);
6943 nla_nest_end(msg
, wme
);
6946 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6949 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
6950 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
6960 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
)
6962 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6966 msg
= nlmsg_alloc();
6970 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
6972 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6973 if_nametoindex(bss
->ifname
));
6974 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6976 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6977 wpa_printf(MSG_DEBUG
, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
6979 bss
->ifname
, MAC2STR(addr
), ret
, strerror(-ret
));
6989 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
6994 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
6996 /* stop listening for EAPOL on this interface */
6997 del_ifidx(drv
, ifidx
);
6999 msg
= nlmsg_alloc();
7001 goto nla_put_failure
;
7003 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
7004 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
7006 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
7011 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
7015 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
7018 case NL80211_IFTYPE_ADHOC
:
7020 case NL80211_IFTYPE_STATION
:
7022 case NL80211_IFTYPE_AP
:
7024 case NL80211_IFTYPE_AP_VLAN
:
7026 case NL80211_IFTYPE_WDS
:
7028 case NL80211_IFTYPE_MONITOR
:
7030 case NL80211_IFTYPE_MESH_POINT
:
7031 return "MESH_POINT";
7032 case NL80211_IFTYPE_P2P_CLIENT
:
7033 return "P2P_CLIENT";
7034 case NL80211_IFTYPE_P2P_GO
:
7036 case NL80211_IFTYPE_P2P_DEVICE
:
7037 return "P2P_DEVICE";
7044 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
7046 enum nl80211_iftype iftype
,
7047 const u8
*addr
, int wds
,
7048 int (*handler
)(struct nl_msg
*, void *),
7055 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
7056 iftype
, nl80211_iftype_str(iftype
));
7058 msg
= nlmsg_alloc();
7062 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
7063 if (nl80211_set_iface_id(msg
, drv
->first_bss
) < 0)
7064 goto nla_put_failure
;
7065 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
7066 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
7068 if (iftype
== NL80211_IFTYPE_MONITOR
) {
7069 struct nlattr
*flags
;
7071 flags
= nla_nest_start(msg
, NL80211_ATTR_MNTR_FLAGS
);
7073 goto nla_put_failure
;
7075 NLA_PUT_FLAG(msg
, NL80211_MNTR_FLAG_COOK_FRAMES
);
7077 nla_nest_end(msg
, flags
);
7079 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
7082 ret
= send_and_recv_msgs(drv
, msg
, handler
, arg
);
7087 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
7088 ifname
, ret
, strerror(-ret
));
7092 if (iftype
== NL80211_IFTYPE_P2P_DEVICE
)
7095 ifidx
= if_nametoindex(ifname
);
7096 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
7102 /* start listening for EAPOL on this interface */
7103 add_ifidx(drv
, ifidx
);
7105 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
7106 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
7107 nl80211_remove_iface(drv
, ifidx
);
7115 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
7116 const char *ifname
, enum nl80211_iftype iftype
,
7117 const u8
*addr
, int wds
,
7118 int (*handler
)(struct nl_msg
*, void *),
7119 void *arg
, int use_existing
)
7123 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
, handler
,
7126 /* if error occurred and interface exists already */
7127 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
7129 wpa_printf(MSG_DEBUG
, "nl80211: Continue using existing interface %s",
7133 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
7135 /* Try to remove the interface that was already there. */
7136 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
7138 /* Try to create the interface again */
7139 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
7143 if (ret
>= 0 && is_p2p_net_interface(iftype
))
7144 nl80211_disable_11b_rates(drv
, ret
, 1);
7150 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
7152 struct ieee80211_hdr
*hdr
;
7154 union wpa_event_data event
;
7156 hdr
= (struct ieee80211_hdr
*) buf
;
7157 fc
= le_to_host16(hdr
->frame_control
);
7159 os_memset(&event
, 0, sizeof(event
));
7160 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
7161 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
7162 event
.tx_status
.dst
= hdr
->addr1
;
7163 event
.tx_status
.data
= buf
;
7164 event
.tx_status
.data_len
= len
;
7165 event
.tx_status
.ack
= ok
;
7166 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
7170 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
7171 u8
*buf
, size_t len
)
7173 struct ieee80211_hdr
*hdr
= (void *)buf
;
7175 union wpa_event_data event
;
7177 if (len
< sizeof(*hdr
))
7180 fc
= le_to_host16(hdr
->frame_control
);
7182 os_memset(&event
, 0, sizeof(event
));
7183 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
7184 event
.rx_from_unknown
.addr
= hdr
->addr2
;
7185 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
7186 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
7187 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
7191 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
7192 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
7194 struct ieee80211_hdr
*hdr
;
7196 union wpa_event_data event
;
7198 hdr
= (struct ieee80211_hdr
*) buf
;
7199 fc
= le_to_host16(hdr
->frame_control
);
7201 switch (WLAN_FC_GET_TYPE(fc
)) {
7202 case WLAN_FC_TYPE_MGMT
:
7203 os_memset(&event
, 0, sizeof(event
));
7204 event
.rx_mgmt
.frame
= buf
;
7205 event
.rx_mgmt
.frame_len
= len
;
7206 event
.rx_mgmt
.datarate
= datarate
;
7207 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
7208 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
7210 case WLAN_FC_TYPE_CTRL
:
7211 /* can only get here with PS-Poll frames */
7212 wpa_printf(MSG_DEBUG
, "CTRL");
7213 from_unknown_sta(drv
, buf
, len
);
7215 case WLAN_FC_TYPE_DATA
:
7216 from_unknown_sta(drv
, buf
, len
);
7222 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
7224 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
7226 unsigned char buf
[3000];
7227 struct ieee80211_radiotap_iterator iter
;
7229 int datarate
= 0, ssi_signal
= 0;
7230 int injected
= 0, failed
= 0, rxflags
= 0;
7232 len
= recv(sock
, buf
, sizeof(buf
), 0);
7234 wpa_printf(MSG_ERROR
, "nl80211: Monitor socket recv failed: %s",
7239 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
7240 wpa_printf(MSG_INFO
, "nl80211: received invalid radiotap frame");
7245 ret
= ieee80211_radiotap_iterator_next(&iter
);
7249 wpa_printf(MSG_INFO
, "nl80211: received invalid radiotap frame (%d)",
7253 switch (iter
.this_arg_index
) {
7254 case IEEE80211_RADIOTAP_FLAGS
:
7255 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
7258 case IEEE80211_RADIOTAP_RX_FLAGS
:
7261 case IEEE80211_RADIOTAP_TX_FLAGS
:
7263 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
7264 IEEE80211_RADIOTAP_F_TX_FAIL
;
7266 case IEEE80211_RADIOTAP_DATA_RETRIES
:
7268 case IEEE80211_RADIOTAP_CHANNEL
:
7269 /* TODO: convert from freq/flags to channel number */
7271 case IEEE80211_RADIOTAP_RATE
:
7272 datarate
= *iter
.this_arg
* 5;
7274 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
7275 ssi_signal
= (s8
) *iter
.this_arg
;
7280 if (rxflags
&& injected
)
7284 handle_frame(drv
, buf
+ iter
.max_length
,
7285 len
- iter
.max_length
, datarate
, ssi_signal
);
7287 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
7288 len
- iter
.max_length
, !failed
);
7293 * we post-process the filter code later and rewrite
7294 * this to the offset to the last instruction
7299 static struct sock_filter msock_filter_insns
[] = {
7301 * do a little-endian load of the radiotap length field
7303 /* load lower byte into A */
7304 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
7305 /* put it into X (== index register) */
7306 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
7307 /* load upper byte into A */
7308 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
7309 /* left-shift it by 8 */
7310 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
7312 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
7313 /* put result into X */
7314 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
7317 * Allow management frames through, this also gives us those
7318 * management frames that we sent ourselves with status
7320 /* load the lower byte of the IEEE 802.11 frame control field */
7321 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
7322 /* mask off frame type and version */
7323 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
7324 /* accept frame if it's both 0, fall through otherwise */
7325 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
7328 * TODO: add a bit to radiotap RX flags that indicates
7329 * that the sending station is not associated, then
7330 * add a filter here that filters on our DA and that flag
7331 * to allow us to deauth frames to that bad station.
7333 * For now allow all To DS data frames through.
7335 /* load the IEEE 802.11 frame control field */
7336 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
7337 /* mask off frame type, version and DS status */
7338 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
7339 /* accept frame if version 0, type 2 and To DS, fall through otherwise
7341 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
7345 * drop non-data frames
7347 /* load the lower byte of the frame control field */
7348 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
7349 /* mask off QoS bit */
7350 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
7351 /* drop non-data frames */
7352 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
7354 /* load the upper byte of the frame control field */
7355 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
7356 /* mask off toDS/fromDS */
7357 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
7358 /* accept WDS frames */
7359 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
7362 * add header length to index
7364 /* load the lower byte of the frame control field */
7365 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
7366 /* mask off QoS bit */
7367 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
7368 /* right shift it by 6 to give 0 or 2 */
7369 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
7370 /* add data frame header length */
7371 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
7372 /* add index, was start of 802.11 header */
7373 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
7374 /* move to index, now start of LL header */
7375 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
7378 * Accept empty data frames, we use those for
7381 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
7382 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
7385 * Accept EAPOL frames
7387 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
7388 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
7389 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
7390 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
7392 /* keep these last two statements or change the code below */
7393 /* return 0 == "DROP" */
7394 BPF_STMT(BPF_RET
| BPF_K
, 0),
7395 /* return ~0 == "keep all" */
7396 BPF_STMT(BPF_RET
| BPF_K
, ~0),
7399 static struct sock_fprog msock_filter
= {
7400 .len
= ARRAY_SIZE(msock_filter_insns
),
7401 .filter
= msock_filter_insns
,
7405 static int add_monitor_filter(int s
)
7409 /* rewrite all PASS/FAIL jump offsets */
7410 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
7411 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
7413 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
7414 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
7415 if (insn
->k
== PASS
)
7416 insn
->k
= msock_filter
.len
- idx
- 2;
7417 else if (insn
->k
== FAIL
)
7418 insn
->k
= msock_filter
.len
- idx
- 3;
7421 if (insn
->jt
== PASS
)
7422 insn
->jt
= msock_filter
.len
- idx
- 2;
7423 else if (insn
->jt
== FAIL
)
7424 insn
->jt
= msock_filter
.len
- idx
- 3;
7426 if (insn
->jf
== PASS
)
7427 insn
->jf
= msock_filter
.len
- idx
- 2;
7428 else if (insn
->jf
== FAIL
)
7429 insn
->jf
= msock_filter
.len
- idx
- 3;
7433 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
7434 &msock_filter
, sizeof(msock_filter
))) {
7435 wpa_printf(MSG_ERROR
, "nl80211: setsockopt(SO_ATTACH_FILTER) failed: %s",
7444 static void nl80211_remove_monitor_interface(
7445 struct wpa_driver_nl80211_data
*drv
)
7447 if (drv
->monitor_refcount
> 0)
7448 drv
->monitor_refcount
--;
7449 wpa_printf(MSG_DEBUG
, "nl80211: Remove monitor interface: refcount=%d",
7450 drv
->monitor_refcount
);
7451 if (drv
->monitor_refcount
> 0)
7454 if (drv
->monitor_ifidx
>= 0) {
7455 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
7456 drv
->monitor_ifidx
= -1;
7458 if (drv
->monitor_sock
>= 0) {
7459 eloop_unregister_read_sock(drv
->monitor_sock
);
7460 close(drv
->monitor_sock
);
7461 drv
->monitor_sock
= -1;
7467 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
7470 struct sockaddr_ll ll
;
7474 if (drv
->monitor_ifidx
>= 0) {
7475 drv
->monitor_refcount
++;
7476 wpa_printf(MSG_DEBUG
, "nl80211: Re-use existing monitor interface: refcount=%d",
7477 drv
->monitor_refcount
);
7481 if (os_strncmp(drv
->first_bss
->ifname
, "p2p-", 4) == 0) {
7483 * P2P interface name is of the format p2p-%s-%d. For monitor
7484 * interface name corresponding to P2P GO, replace "p2p-" with
7485 * "mon-" to retain the same interface name length and to
7486 * indicate that it is a monitor interface.
7488 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
->ifname
+ 4);
7490 /* Non-P2P interface with AP functionality. */
7491 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
->ifname
);
7494 buf
[IFNAMSIZ
- 1] = '\0';
7496 drv
->monitor_ifidx
=
7497 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
7500 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
7502 * This is backward compatibility for a few versions of
7503 * the kernel only that didn't advertise the right
7504 * attributes for the only driver that then supported
7505 * AP mode w/o monitor -- ath6kl.
7507 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
7508 "monitor interface type - try to run without it");
7509 drv
->device_ap_sme
= 1;
7512 if (drv
->monitor_ifidx
< 0)
7515 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
7518 memset(&ll
, 0, sizeof(ll
));
7519 ll
.sll_family
= AF_PACKET
;
7520 ll
.sll_ifindex
= drv
->monitor_ifidx
;
7521 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
7522 if (drv
->monitor_sock
< 0) {
7523 wpa_printf(MSG_ERROR
, "nl80211: socket[PF_PACKET,SOCK_RAW] failed: %s",
7528 if (add_monitor_filter(drv
->monitor_sock
)) {
7529 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
7530 "interface; do filtering in user space");
7531 /* This works, but will cost in performance. */
7534 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
7535 wpa_printf(MSG_ERROR
, "nl80211: monitor socket bind failed: %s",
7540 optlen
= sizeof(optval
);
7543 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
7544 wpa_printf(MSG_ERROR
, "nl80211: Failed to set socket priority: %s",
7549 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
7551 wpa_printf(MSG_INFO
, "nl80211: Could not register monitor read socket");
7555 drv
->monitor_refcount
++;
7558 nl80211_remove_monitor_interface(drv
);
7563 static int nl80211_setup_ap(struct i802_bss
*bss
)
7565 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7567 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
7568 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
7571 * Disable Probe Request reporting unless we need it in this way for
7572 * devices that include the AP SME, in the other case (unless using
7573 * monitor iface) we'll get it through the nl_mgmt socket instead.
7575 if (!drv
->device_ap_sme
)
7576 wpa_driver_nl80211_probe_req_report(bss
, 0);
7578 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
7579 if (nl80211_mgmt_subscribe_ap(bss
))
7582 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
7583 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
7586 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
7587 nl80211_create_monitor_interface(drv
) &&
7588 !drv
->device_ap_sme
)
7591 if (drv
->device_ap_sme
&&
7592 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
7593 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
7594 "Probe Request frame reporting in AP mode");
7595 /* Try to survive without this */
7602 static void nl80211_teardown_ap(struct i802_bss
*bss
)
7604 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7606 wpa_printf(MSG_DEBUG
, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
7607 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
7608 if (drv
->device_ap_sme
) {
7609 wpa_driver_nl80211_probe_req_report(bss
, 0);
7610 if (!drv
->use_monitor
)
7611 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
7612 } else if (drv
->use_monitor
)
7613 nl80211_remove_monitor_interface(drv
);
7615 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
7617 bss
->beacon_set
= 0;
7621 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
7622 const u8
*addr
, const u8
*data
,
7625 struct sockaddr_ll ll
;
7628 if (bss
->drv
->eapol_tx_sock
< 0) {
7629 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
7633 os_memset(&ll
, 0, sizeof(ll
));
7634 ll
.sll_family
= AF_PACKET
;
7635 ll
.sll_ifindex
= bss
->ifindex
;
7636 ll
.sll_protocol
= htons(ETH_P_PAE
);
7637 ll
.sll_halen
= ETH_ALEN
;
7638 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
7639 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
7640 (struct sockaddr
*) &ll
, sizeof(ll
));
7642 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
7649 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
7651 static int wpa_driver_nl80211_hapd_send_eapol(
7652 void *priv
, const u8
*addr
, const u8
*data
,
7653 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
7655 struct i802_bss
*bss
= priv
;
7656 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7657 struct ieee80211_hdr
*hdr
;
7661 int qos
= flags
& WPA_STA_WMM
;
7663 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
7664 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
7666 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
7668 hdr
= os_zalloc(len
);
7670 wpa_printf(MSG_INFO
, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
7671 (unsigned long) len
);
7675 hdr
->frame_control
=
7676 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
7677 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
7679 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
7681 hdr
->frame_control
|=
7682 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
7685 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
7686 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
7687 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
7688 pos
= (u8
*) (hdr
+ 1);
7691 /* Set highest priority in QoS header */
7697 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
7698 pos
+= sizeof(rfc1042_header
);
7699 WPA_PUT_BE16(pos
, ETH_P_PAE
);
7701 memcpy(pos
, data
, data_len
);
7703 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
7706 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
7708 (unsigned long) len
, errno
, strerror(errno
));
7716 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
7718 int flags_or
, int flags_and
)
7720 struct i802_bss
*bss
= priv
;
7721 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7723 struct nlattr
*flags
;
7724 struct nl80211_sta_flag_update upd
;
7726 msg
= nlmsg_alloc();
7730 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7732 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7733 if_nametoindex(bss
->ifname
));
7734 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7737 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
7738 * can be removed eventually.
7740 flags
= nla_nest_start(msg
, NL80211_ATTR_STA_FLAGS
);
7742 goto nla_put_failure
;
7743 if (total_flags
& WPA_STA_AUTHORIZED
)
7744 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_AUTHORIZED
);
7746 if (total_flags
& WPA_STA_WMM
)
7747 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_WME
);
7749 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
7750 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
7752 if (total_flags
& WPA_STA_MFP
)
7753 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_MFP
);
7755 if (total_flags
& WPA_STA_TDLS_PEER
)
7756 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_TDLS_PEER
);
7758 nla_nest_end(msg
, flags
);
7760 os_memset(&upd
, 0, sizeof(upd
));
7761 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
7762 upd
.set
= sta_flags_nl80211(flags_or
);
7763 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
7765 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7772 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
7773 struct wpa_driver_associate_params
*params
)
7775 enum nl80211_iftype nlmode
, old_mode
;
7776 struct hostapd_freq_params freq
= {
7777 .freq
= params
->freq
,
7781 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
7783 nlmode
= NL80211_IFTYPE_P2P_GO
;
7785 nlmode
= NL80211_IFTYPE_AP
;
7787 old_mode
= drv
->nlmode
;
7788 if (wpa_driver_nl80211_set_mode(drv
->first_bss
, nlmode
)) {
7789 nl80211_remove_monitor_interface(drv
);
7793 if (wpa_driver_nl80211_set_freq(drv
->first_bss
, &freq
)) {
7794 if (old_mode
!= nlmode
)
7795 wpa_driver_nl80211_set_mode(drv
->first_bss
, old_mode
);
7796 nl80211_remove_monitor_interface(drv
);
7804 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
7809 msg
= nlmsg_alloc();
7813 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
7814 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7815 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7818 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
7819 "(%s)", ret
, strerror(-ret
));
7820 goto nla_put_failure
;
7824 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
7827 if (wpa_driver_nl80211_set_mode(drv
->first_bss
,
7828 NL80211_IFTYPE_STATION
)) {
7829 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
7838 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
7839 struct wpa_driver_associate_params
*params
)
7845 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
7847 if (wpa_driver_nl80211_set_mode(drv
->first_bss
,
7848 NL80211_IFTYPE_ADHOC
)) {
7849 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
7855 msg
= nlmsg_alloc();
7859 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
7860 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7862 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
7863 goto nla_put_failure
;
7865 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7866 params
->ssid
, params
->ssid_len
);
7867 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7869 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7870 drv
->ssid_len
= params
->ssid_len
;
7872 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7873 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7875 ret
= nl80211_set_conn_keys(params
, msg
);
7877 goto nla_put_failure
;
7879 if (params
->bssid
&& params
->fixed_bssid
) {
7880 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
7881 MAC2STR(params
->bssid
));
7882 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7885 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
7886 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
7887 params
->key_mgmt_suite
== KEY_MGMT_802_1X_SHA256
||
7888 params
->key_mgmt_suite
== KEY_MGMT_PSK_SHA256
) {
7889 wpa_printf(MSG_DEBUG
, " * control port");
7890 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
7893 if (params
->wpa_ie
) {
7894 wpa_hexdump(MSG_DEBUG
,
7895 " * Extra IEs for Beacon/Probe Response frames",
7896 params
->wpa_ie
, params
->wpa_ie_len
);
7897 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7901 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7904 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
7905 ret
, strerror(-ret
));
7907 if (ret
== -EALREADY
&& count
== 1) {
7908 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
7910 nl80211_leave_ibss(drv
);
7915 goto nla_put_failure
;
7918 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
7926 static int wpa_driver_nl80211_try_connect(
7927 struct wpa_driver_nl80211_data
*drv
,
7928 struct wpa_driver_associate_params
*params
)
7931 enum nl80211_auth_type type
;
7935 msg
= nlmsg_alloc();
7939 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
7940 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
7942 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7943 if (params
->bssid
) {
7944 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
7945 MAC2STR(params
->bssid
));
7946 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7949 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7950 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7951 drv
->assoc_freq
= params
->freq
;
7953 drv
->assoc_freq
= 0;
7954 if (params
->bg_scan_period
>= 0) {
7955 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
7956 params
->bg_scan_period
);
7957 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
7958 params
->bg_scan_period
);
7961 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7962 params
->ssid
, params
->ssid_len
);
7963 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7965 if (params
->ssid_len
> sizeof(drv
->ssid
))
7966 goto nla_put_failure
;
7967 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7968 drv
->ssid_len
= params
->ssid_len
;
7970 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
7972 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7976 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
7978 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
7980 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
7983 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
7985 goto skip_auth_type
;
7988 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
7989 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
7990 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
7991 type
= NL80211_AUTHTYPE_SHARED_KEY
;
7992 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
7993 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
7994 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
7995 type
= NL80211_AUTHTYPE_FT
;
7997 goto nla_put_failure
;
7999 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
8000 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
8003 if (params
->wpa_proto
) {
8004 enum nl80211_wpa_versions ver
= 0;
8006 if (params
->wpa_proto
& WPA_PROTO_WPA
)
8007 ver
|= NL80211_WPA_VERSION_1
;
8008 if (params
->wpa_proto
& WPA_PROTO_RSN
)
8009 ver
|= NL80211_WPA_VERSION_2
;
8011 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
8012 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
8015 if (params
->pairwise_suite
!= CIPHER_NONE
) {
8018 switch (params
->pairwise_suite
) {
8020 cipher
= WLAN_CIPHER_SUITE_SMS4
;
8023 cipher
= WLAN_CIPHER_SUITE_WEP40
;
8026 cipher
= WLAN_CIPHER_SUITE_WEP104
;
8029 cipher
= WLAN_CIPHER_SUITE_CCMP
;
8032 cipher
= WLAN_CIPHER_SUITE_GCMP
;
8036 cipher
= WLAN_CIPHER_SUITE_TKIP
;
8039 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
8042 if (params
->group_suite
!= CIPHER_NONE
) {
8045 switch (params
->group_suite
) {
8047 cipher
= WLAN_CIPHER_SUITE_SMS4
;
8050 cipher
= WLAN_CIPHER_SUITE_WEP40
;
8053 cipher
= WLAN_CIPHER_SUITE_WEP104
;
8056 cipher
= WLAN_CIPHER_SUITE_CCMP
;
8059 cipher
= WLAN_CIPHER_SUITE_GCMP
;
8063 cipher
= WLAN_CIPHER_SUITE_TKIP
;
8066 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
8069 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
8070 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
8071 params
->key_mgmt_suite
== KEY_MGMT_FT_802_1X
||
8072 params
->key_mgmt_suite
== KEY_MGMT_FT_PSK
||
8073 params
->key_mgmt_suite
== KEY_MGMT_CCKM
) {
8074 int mgmt
= WLAN_AKM_SUITE_PSK
;
8076 switch (params
->key_mgmt_suite
) {
8078 mgmt
= WLAN_AKM_SUITE_CCKM
;
8080 case KEY_MGMT_802_1X
:
8081 mgmt
= WLAN_AKM_SUITE_8021X
;
8083 case KEY_MGMT_FT_802_1X
:
8084 mgmt
= WLAN_AKM_SUITE_FT_8021X
;
8086 case KEY_MGMT_FT_PSK
:
8087 mgmt
= WLAN_AKM_SUITE_FT_PSK
;
8091 mgmt
= WLAN_AKM_SUITE_PSK
;
8094 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
8097 #ifdef CONFIG_IEEE80211W
8098 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
8099 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
8100 #endif /* CONFIG_IEEE80211W */
8102 if (params
->disable_ht
)
8103 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
8105 if (params
->htcaps
&& params
->htcaps_mask
) {
8106 int sz
= sizeof(struct ieee80211_ht_capabilities
);
8107 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
8108 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
8109 params
->htcaps_mask
);
8112 #ifdef CONFIG_VHT_OVERRIDES
8113 if (params
->disable_vht
) {
8114 wpa_printf(MSG_DEBUG
, " * VHT disabled");
8115 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_VHT
);
8118 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
8119 int sz
= sizeof(struct ieee80211_vht_capabilities
);
8120 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
, params
->vhtcaps
);
8121 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
8122 params
->vhtcaps_mask
);
8124 #endif /* CONFIG_VHT_OVERRIDES */
8126 ret
= nl80211_set_conn_keys(params
, msg
);
8128 goto nla_put_failure
;
8130 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8133 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
8134 "(%s)", ret
, strerror(-ret
));
8135 goto nla_put_failure
;
8138 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
8147 static int wpa_driver_nl80211_connect(
8148 struct wpa_driver_nl80211_data
*drv
,
8149 struct wpa_driver_associate_params
*params
)
8151 int ret
= wpa_driver_nl80211_try_connect(drv
, params
);
8152 if (ret
== -EALREADY
) {
8154 * cfg80211 does not currently accept new connections if
8155 * we are already connected. As a workaround, force
8156 * disconnection and try again.
8158 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
8159 "disconnecting before reassociation "
8161 if (wpa_driver_nl80211_disconnect(
8162 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
))
8164 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
8170 static int wpa_driver_nl80211_associate(
8171 void *priv
, struct wpa_driver_associate_params
*params
)
8173 struct i802_bss
*bss
= priv
;
8174 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8178 if (params
->mode
== IEEE80211_MODE_AP
)
8179 return wpa_driver_nl80211_ap(drv
, params
);
8181 if (params
->mode
== IEEE80211_MODE_IBSS
)
8182 return wpa_driver_nl80211_ibss(drv
, params
);
8184 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
8185 enum nl80211_iftype nlmode
= params
->p2p
?
8186 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
8188 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
8190 return wpa_driver_nl80211_connect(drv
, params
);
8193 nl80211_mark_disconnected(drv
);
8195 msg
= nlmsg_alloc();
8199 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
8201 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
8203 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8204 if (params
->bssid
) {
8205 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
8206 MAC2STR(params
->bssid
));
8207 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
8210 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
8211 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
8212 drv
->assoc_freq
= params
->freq
;
8214 drv
->assoc_freq
= 0;
8215 if (params
->bg_scan_period
>= 0) {
8216 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
8217 params
->bg_scan_period
);
8218 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
8219 params
->bg_scan_period
);
8222 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
8223 params
->ssid
, params
->ssid_len
);
8224 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
8226 if (params
->ssid_len
> sizeof(drv
->ssid
))
8227 goto nla_put_failure
;
8228 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
8229 drv
->ssid_len
= params
->ssid_len
;
8231 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
8233 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
8236 if (params
->pairwise_suite
!= CIPHER_NONE
) {
8239 switch (params
->pairwise_suite
) {
8241 cipher
= WLAN_CIPHER_SUITE_WEP40
;
8244 cipher
= WLAN_CIPHER_SUITE_WEP104
;
8247 cipher
= WLAN_CIPHER_SUITE_CCMP
;
8250 cipher
= WLAN_CIPHER_SUITE_GCMP
;
8254 cipher
= WLAN_CIPHER_SUITE_TKIP
;
8257 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
8258 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
8261 if (params
->group_suite
!= CIPHER_NONE
) {
8264 switch (params
->group_suite
) {
8266 cipher
= WLAN_CIPHER_SUITE_WEP40
;
8269 cipher
= WLAN_CIPHER_SUITE_WEP104
;
8272 cipher
= WLAN_CIPHER_SUITE_CCMP
;
8275 cipher
= WLAN_CIPHER_SUITE_GCMP
;
8279 cipher
= WLAN_CIPHER_SUITE_TKIP
;
8282 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
8283 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
8286 #ifdef CONFIG_IEEE80211W
8287 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
8288 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
8289 #endif /* CONFIG_IEEE80211W */
8291 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
8293 if (params
->prev_bssid
) {
8294 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
8295 MAC2STR(params
->prev_bssid
));
8296 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
8297 params
->prev_bssid
);
8300 if (params
->disable_ht
)
8301 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
8303 if (params
->htcaps
&& params
->htcaps_mask
) {
8304 int sz
= sizeof(struct ieee80211_ht_capabilities
);
8305 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
8306 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
8307 params
->htcaps_mask
);
8310 #ifdef CONFIG_VHT_OVERRIDES
8311 if (params
->disable_vht
) {
8312 wpa_printf(MSG_DEBUG
, " * VHT disabled");
8313 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_VHT
);
8316 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
8317 int sz
= sizeof(struct ieee80211_vht_capabilities
);
8318 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
, params
->vhtcaps
);
8319 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
8320 params
->vhtcaps_mask
);
8322 #endif /* CONFIG_VHT_OVERRIDES */
8325 wpa_printf(MSG_DEBUG
, " * P2P group");
8327 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8330 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
8331 "nl80211: MLME command failed (assoc): ret=%d (%s)",
8332 ret
, strerror(-ret
));
8333 nl80211_dump_scan(drv
);
8334 goto nla_put_failure
;
8337 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
8346 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
8347 int ifindex
, enum nl80211_iftype mode
)
8352 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
8353 ifindex
, mode
, nl80211_iftype_str(mode
));
8355 msg
= nlmsg_alloc();
8359 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
8360 if (nl80211_set_iface_id(msg
, drv
->first_bss
) < 0)
8361 goto nla_put_failure
;
8362 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
8364 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8370 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
8371 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
8376 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
8377 enum nl80211_iftype nlmode
)
8379 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8382 int was_ap
= is_ap_interface(drv
->nlmode
);
8385 res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
8386 if (res
&& nlmode
== nl80211_get_ifmode(bss
))
8390 drv
->nlmode
= nlmode
;
8398 if (nlmode
== drv
->nlmode
) {
8399 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
8400 "requested mode - ignore error");
8402 goto done
; /* Already in the requested mode */
8405 /* mac80211 doesn't allow mode changes while the device is up, so
8406 * take the device down, try to set the mode again, and bring the
8409 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
8411 for (i
= 0; i
< 10; i
++) {
8412 res
= i802_set_iface_flags(bss
, 0);
8413 if (res
== -EACCES
|| res
== -ENODEV
)
8416 /* Try to set the mode again while the interface is
8418 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
8421 res
= i802_set_iface_flags(bss
, 1);
8424 else if (ret
!= -EBUSY
)
8427 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
8429 os_sleep(0, 100000);
8433 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
8434 "interface is down");
8435 drv
->nlmode
= nlmode
;
8436 drv
->ignore_if_down_event
= 1;
8441 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
8442 "from %d failed", nlmode
, drv
->nlmode
);
8446 if (is_p2p_net_interface(nlmode
))
8447 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
8448 else if (drv
->disabled_11b_rates
)
8449 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
8451 if (is_ap_interface(nlmode
)) {
8452 nl80211_mgmt_unsubscribe(bss
, "start AP");
8453 /* Setup additional AP mode functionality if needed */
8454 if (nl80211_setup_ap(bss
))
8456 } else if (was_ap
) {
8457 /* Remove additional AP mode functionality */
8458 nl80211_teardown_ap(bss
);
8460 nl80211_mgmt_unsubscribe(bss
, "mode change");
8463 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
8464 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
8465 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
8466 "frame processing - ignore for now");
8472 static int wpa_driver_nl80211_get_capa(void *priv
,
8473 struct wpa_driver_capa
*capa
)
8475 struct i802_bss
*bss
= priv
;
8476 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8477 if (!drv
->has_capability
)
8479 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
8480 if (drv
->extended_capa
&& drv
->extended_capa_mask
) {
8481 capa
->extended_capa
= drv
->extended_capa
;
8482 capa
->extended_capa_mask
= drv
->extended_capa_mask
;
8483 capa
->extended_capa_len
= drv
->extended_capa_len
;
8486 if ((capa
->flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
8487 !drv
->allow_p2p_device
) {
8488 wpa_printf(MSG_DEBUG
, "nl80211: Do not indicate P2P_DEVICE support (p2p_device=1 driver param not specified)");
8489 capa
->flags
&= ~WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
;
8496 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
8498 struct i802_bss
*bss
= priv
;
8499 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8501 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
8502 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
8503 drv
->operstate
= state
;
8504 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
8505 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
8509 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
8511 struct i802_bss
*bss
= priv
;
8512 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8514 struct nl80211_sta_flag_update upd
;
8516 wpa_printf(MSG_DEBUG
, "nl80211: Set supplicant port %sauthorized for "
8517 MACSTR
, authorized
? "" : "un", MAC2STR(drv
->bssid
));
8519 msg
= nlmsg_alloc();
8523 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
8525 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8526 if_nametoindex(bss
->ifname
));
8527 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
8529 os_memset(&upd
, 0, sizeof(upd
));
8530 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
8532 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
8533 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
8535 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8542 /* Set kernel driver on given frequency (MHz) */
8543 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
8545 struct i802_bss
*bss
= priv
;
8546 return wpa_driver_nl80211_set_freq(bss
, freq
);
8550 #if defined(HOSTAPD) || defined(CONFIG_AP)
8552 static inline int min_int(int a
, int b
)
8560 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
8562 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8563 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8565 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8566 genlmsg_attrlen(gnlh
, 0), NULL
);
8569 * TODO: validate the key index and mac address!
8570 * Otherwise, there's a race condition as soon as
8571 * the kernel starts sending key notifications.
8574 if (tb
[NL80211_ATTR_KEY_SEQ
])
8575 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
8576 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
8581 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
8584 struct i802_bss
*bss
= priv
;
8585 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8588 msg
= nlmsg_alloc();
8592 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
8595 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8596 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
8597 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
8601 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
8608 static int i802_set_rts(void *priv
, int rts
)
8610 struct i802_bss
*bss
= priv
;
8611 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8616 msg
= nlmsg_alloc();
8625 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8626 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8627 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
8629 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8635 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
8636 "%d (%s)", rts
, ret
, strerror(-ret
));
8641 static int i802_set_frag(void *priv
, int frag
)
8643 struct i802_bss
*bss
= priv
;
8644 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8649 msg
= nlmsg_alloc();
8658 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8659 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8660 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
8662 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8668 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
8669 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
8674 static int i802_flush(void *priv
)
8676 struct i802_bss
*bss
= priv
;
8677 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8681 msg
= nlmsg_alloc();
8685 wpa_printf(MSG_DEBUG
, "nl80211: flush -> DEL_STATION %s (all)",
8687 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
8690 * XXX: FIX! this needs to flush all VLANs too
8692 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8693 if_nametoindex(bss
->ifname
));
8695 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8697 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
8698 "(%s)", res
, strerror(-res
));
8706 #endif /* HOSTAPD || CONFIG_AP */
8709 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
8711 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8712 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8713 struct hostap_sta_driver_data
*data
= arg
;
8714 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
8715 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
8716 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
8717 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
8718 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
8719 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
8720 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
8721 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
8724 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8725 genlmsg_attrlen(gnlh
, 0), NULL
);
8728 * TODO: validate the interface and mac address!
8729 * Otherwise, there's a race condition as soon as
8730 * the kernel starts sending station notifications.
8733 if (!tb
[NL80211_ATTR_STA_INFO
]) {
8734 wpa_printf(MSG_DEBUG
, "sta stats missing!");
8737 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
8738 tb
[NL80211_ATTR_STA_INFO
],
8740 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
8744 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
8745 data
->inactive_msec
=
8746 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
8747 if (stats
[NL80211_STA_INFO_RX_BYTES
])
8748 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
8749 if (stats
[NL80211_STA_INFO_TX_BYTES
])
8750 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
8751 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
8753 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
8754 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
8756 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
8757 if (stats
[NL80211_STA_INFO_TX_FAILED
])
8758 data
->tx_retry_failed
=
8759 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
8764 static int i802_read_sta_data(struct i802_bss
*bss
,
8765 struct hostap_sta_driver_data
*data
,
8768 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8771 os_memset(data
, 0, sizeof(*data
));
8772 msg
= nlmsg_alloc();
8776 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
8778 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8779 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8781 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
8788 #if defined(HOSTAPD) || defined(CONFIG_AP)
8790 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
8791 int cw_min
, int cw_max
, int burst_time
)
8793 struct i802_bss
*bss
= priv
;
8794 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8796 struct nlattr
*txq
, *params
;
8798 msg
= nlmsg_alloc();
8802 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8804 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8806 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
8808 goto nla_put_failure
;
8810 /* We are only sending parameters for a single TXQ at a time */
8811 params
= nla_nest_start(msg
, 1);
8813 goto nla_put_failure
;
8817 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
8820 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
8823 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
8826 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
8829 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
8830 * 32 usec, so need to convert the value here. */
8831 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
8832 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
8833 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
8834 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
8836 nla_nest_end(msg
, params
);
8838 nla_nest_end(msg
, txq
);
8840 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
8849 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
8850 const char *ifname
, int vlan_id
)
8852 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8856 msg
= nlmsg_alloc();
8860 wpa_printf(MSG_DEBUG
, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
8861 ", ifname=%s[%d], vlan_id=%d)",
8862 bss
->ifname
, if_nametoindex(bss
->ifname
),
8863 MAC2STR(addr
), ifname
, if_nametoindex(ifname
), vlan_id
);
8864 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
8866 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8867 if_nametoindex(bss
->ifname
));
8868 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8869 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
8870 if_nametoindex(ifname
));
8872 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8875 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
8876 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
8877 MAC2STR(addr
), ifname
, vlan_id
, ret
,
8886 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
8888 struct hostap_sta_driver_data data
;
8891 data
.inactive_msec
= (unsigned long) -1;
8892 ret
= i802_read_sta_data(priv
, &data
, addr
);
8893 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
8895 return data
.inactive_msec
/ 1000;
8899 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
8908 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
8911 struct i802_bss
*bss
= priv
;
8912 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8913 struct ieee80211_mgmt mgmt
;
8915 if (drv
->device_ap_sme
)
8916 return wpa_driver_nl80211_sta_remove(bss
, addr
);
8918 memset(&mgmt
, 0, sizeof(mgmt
));
8919 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
8920 WLAN_FC_STYPE_DEAUTH
);
8921 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
8922 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
8923 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
8924 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
8925 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
8927 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
8932 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
8935 struct i802_bss
*bss
= priv
;
8936 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8937 struct ieee80211_mgmt mgmt
;
8939 if (drv
->device_ap_sme
)
8940 return wpa_driver_nl80211_sta_remove(bss
, addr
);
8942 memset(&mgmt
, 0, sizeof(mgmt
));
8943 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
8944 WLAN_FC_STYPE_DISASSOC
);
8945 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
8946 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
8947 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
8948 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
8949 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
8951 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
8955 #endif /* HOSTAPD || CONFIG_AP */
8959 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8964 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
8966 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
8967 if (drv
->if_indices
[i
] == 0) {
8968 drv
->if_indices
[i
] = ifidx
;
8973 if (drv
->if_indices
!= drv
->default_if_indices
)
8974 old
= drv
->if_indices
;
8978 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
8980 if (!drv
->if_indices
) {
8982 drv
->if_indices
= drv
->default_if_indices
;
8984 drv
->if_indices
= old
;
8985 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
8987 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
8990 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
8991 sizeof(drv
->default_if_indices
));
8992 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
8993 drv
->num_if_indices
++;
8997 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
9001 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
9002 if (drv
->if_indices
[i
] == ifidx
) {
9003 drv
->if_indices
[i
] = 0;
9010 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
9014 for (i
= 0; i
< drv
->num_if_indices
; i
++)
9015 if (drv
->if_indices
[i
] == ifidx
)
9022 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
9023 const char *bridge_ifname
, char *ifname_wds
)
9025 struct i802_bss
*bss
= priv
;
9026 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9027 char name
[IFNAMSIZ
+ 1];
9029 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
9031 os_strlcpy(ifname_wds
, name
, IFNAMSIZ
+ 1);
9033 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
9034 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
9036 if (!if_nametoindex(name
)) {
9037 if (nl80211_create_iface(drv
, name
,
9038 NL80211_IFTYPE_AP_VLAN
,
9039 bss
->addr
, 1, NULL
, NULL
, 0) <
9042 if (bridge_ifname
&&
9043 linux_br_add_if(drv
->global
->ioctl_sock
,
9044 bridge_ifname
, name
) < 0)
9047 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
9048 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
9049 "interface %s up", name
);
9051 return i802_set_sta_vlan(priv
, addr
, name
, 0);
9054 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
9057 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
9058 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
9064 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
9066 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
9067 struct sockaddr_ll lladdr
;
9068 unsigned char buf
[3000];
9070 socklen_t fromlen
= sizeof(lladdr
);
9072 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
9073 (struct sockaddr
*)&lladdr
, &fromlen
);
9075 wpa_printf(MSG_ERROR
, "nl80211: EAPOL recv failed: %s",
9080 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
9081 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
9085 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
9086 struct i802_bss
*bss
,
9087 const char *brname
, const char *ifname
)
9090 char in_br
[IFNAMSIZ
];
9092 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
9093 ifindex
= if_nametoindex(brname
);
9096 * Bridge was configured, but the bridge device does
9097 * not exist. Try to add it now.
9099 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
9100 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
9101 "bridge interface %s: %s",
9102 brname
, strerror(errno
));
9105 bss
->added_bridge
= 1;
9106 add_ifidx(drv
, if_nametoindex(brname
));
9109 if (linux_br_get(in_br
, ifname
) == 0) {
9110 if (os_strcmp(in_br
, brname
) == 0)
9111 return 0; /* already in the bridge */
9113 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
9114 "bridge %s", ifname
, in_br
);
9115 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
9117 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
9118 "remove interface %s from bridge "
9120 ifname
, brname
, strerror(errno
));
9125 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
9127 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
9128 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
9129 "into bridge %s: %s",
9130 ifname
, brname
, strerror(errno
));
9133 bss
->added_if_into_bridge
= 1;
9139 static void *i802_init(struct hostapd_data
*hapd
,
9140 struct wpa_init_params
*params
)
9142 struct wpa_driver_nl80211_data
*drv
;
9143 struct i802_bss
*bss
;
9145 char brname
[IFNAMSIZ
];
9146 int ifindex
, br_ifindex
;
9149 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
9150 params
->global_priv
);
9155 drv
->nlmode
= NL80211_IFTYPE_AP
;
9156 drv
->eapol_sock
= -1;
9158 if (linux_br_get(brname
, params
->ifname
) == 0) {
9159 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
9160 params
->ifname
, brname
);
9161 br_ifindex
= if_nametoindex(brname
);
9167 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
9168 drv
->if_indices
= drv
->default_if_indices
;
9169 for (i
= 0; i
< params
->num_bridge
; i
++) {
9170 if (params
->bridge
[i
]) {
9171 ifindex
= if_nametoindex(params
->bridge
[i
]);
9173 add_ifidx(drv
, ifindex
);
9174 if (ifindex
== br_ifindex
)
9178 if (!br_added
&& br_ifindex
&&
9179 (params
->num_bridge
== 0 || !params
->bridge
[0]))
9180 add_ifidx(drv
, br_ifindex
);
9182 /* start listening for EAPOL on the default AP interface */
9183 add_ifidx(drv
, drv
->ifindex
);
9185 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
9188 if (params
->bssid
) {
9189 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
9194 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
9195 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
9196 "into AP mode", bss
->ifname
);
9200 if (params
->num_bridge
&& params
->bridge
[0] &&
9201 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
9204 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
9207 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
9208 if (drv
->eapol_sock
< 0) {
9209 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
9214 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
9216 wpa_printf(MSG_INFO
, "nl80211: Could not register read socket for eapol");
9220 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
9224 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
9229 wpa_driver_nl80211_deinit(bss
);
9234 static void i802_deinit(void *priv
)
9236 struct i802_bss
*bss
= priv
;
9237 wpa_driver_nl80211_deinit(bss
);
9240 #endif /* HOSTAPD */
9243 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
9244 enum wpa_driver_if_type type
)
9247 case WPA_IF_STATION
:
9248 return NL80211_IFTYPE_STATION
;
9249 case WPA_IF_P2P_CLIENT
:
9250 case WPA_IF_P2P_GROUP
:
9251 return NL80211_IFTYPE_P2P_CLIENT
;
9252 case WPA_IF_AP_VLAN
:
9253 return NL80211_IFTYPE_AP_VLAN
;
9255 return NL80211_IFTYPE_AP
;
9257 return NL80211_IFTYPE_P2P_GO
;
9258 case WPA_IF_P2P_DEVICE
:
9259 return NL80211_IFTYPE_P2P_DEVICE
;
9267 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
9269 struct wpa_driver_nl80211_data
*drv
;
9270 dl_list_for_each(drv
, &global
->interfaces
,
9271 struct wpa_driver_nl80211_data
, list
) {
9272 if (os_memcmp(addr
, drv
->first_bss
->addr
, ETH_ALEN
) == 0)
9279 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
9287 os_memcpy(new_addr
, drv
->first_bss
->addr
, ETH_ALEN
);
9288 for (idx
= 0; idx
< 64; idx
++) {
9289 new_addr
[0] = drv
->first_bss
->addr
[0] | 0x02;
9290 new_addr
[0] ^= idx
<< 2;
9291 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
9297 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
9298 MACSTR
, MAC2STR(new_addr
));
9303 #endif /* CONFIG_P2P */
9309 u8 macaddr
[ETH_ALEN
];
9312 static int nl80211_wdev_handler(struct nl_msg
*msg
, void *arg
)
9314 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9315 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9316 struct wdev_info
*wi
= arg
;
9318 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9319 genlmsg_attrlen(gnlh
, 0), NULL
);
9320 if (tb
[NL80211_ATTR_WDEV
]) {
9321 wi
->wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
9322 wi
->wdev_id_set
= 1;
9325 if (tb
[NL80211_ATTR_MAC
])
9326 os_memcpy(wi
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
9333 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
9334 const char *ifname
, const u8
*addr
,
9335 void *bss_ctx
, void **drv_priv
,
9336 char *force_ifname
, u8
*if_addr
,
9337 const char *bridge
, int use_existing
)
9339 enum nl80211_iftype nlmode
;
9340 struct i802_bss
*bss
= priv
;
9341 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9346 os_memcpy(if_addr
, addr
, ETH_ALEN
);
9347 nlmode
= wpa_driver_nl80211_if_type(type
);
9348 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
9349 struct wdev_info p2pdev_info
;
9351 os_memset(&p2pdev_info
, 0, sizeof(p2pdev_info
));
9352 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
9353 0, nl80211_wdev_handler
,
9354 &p2pdev_info
, use_existing
);
9355 if (!p2pdev_info
.wdev_id_set
|| ifidx
!= 0) {
9356 wpa_printf(MSG_ERROR
, "nl80211: Failed to create a P2P Device interface %s",
9361 drv
->global
->if_add_wdevid
= p2pdev_info
.wdev_id
;
9362 drv
->global
->if_add_wdevid_set
= p2pdev_info
.wdev_id_set
;
9363 if (!is_zero_ether_addr(p2pdev_info
.macaddr
))
9364 os_memcpy(if_addr
, p2pdev_info
.macaddr
, ETH_ALEN
);
9365 wpa_printf(MSG_DEBUG
, "nl80211: New P2P Device interface %s (0x%llx) created",
9367 (long long unsigned int) p2pdev_info
.wdev_id
);
9369 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
9370 0, NULL
, NULL
, use_existing
);
9371 if (use_existing
&& ifidx
== -ENFILE
) {
9373 ifidx
= if_nametoindex(ifname
);
9374 } else if (ifidx
< 0) {
9380 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
9381 os_memcpy(if_addr
, bss
->addr
, ETH_ALEN
);
9382 else if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
9383 bss
->ifname
, if_addr
) < 0) {
9385 nl80211_remove_iface(drv
, ifidx
);
9392 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
9393 type
== WPA_IF_P2P_GO
)) {
9394 /* Enforce unique P2P Interface Address */
9395 u8 new_addr
[ETH_ALEN
];
9397 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
9399 nl80211_remove_iface(drv
, ifidx
);
9402 if (nl80211_addr_in_use(drv
->global
, new_addr
)) {
9403 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
9404 "for P2P group interface");
9405 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
9406 nl80211_remove_iface(drv
, ifidx
);
9409 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
9411 nl80211_remove_iface(drv
, ifidx
);
9415 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
9417 #endif /* CONFIG_P2P */
9420 if (type
== WPA_IF_AP_BSS
) {
9421 struct i802_bss
*new_bss
= os_zalloc(sizeof(*new_bss
));
9422 if (new_bss
== NULL
) {
9424 nl80211_remove_iface(drv
, ifidx
);
9429 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
9430 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
9431 "interface %s to a bridge %s",
9434 nl80211_remove_iface(drv
, ifidx
);
9439 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
9441 nl80211_remove_iface(drv
, ifidx
);
9445 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
9446 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
9447 new_bss
->ifindex
= ifidx
;
9449 new_bss
->next
= drv
->first_bss
->next
;
9450 new_bss
->freq
= drv
->first_bss
->freq
;
9451 new_bss
->ctx
= bss_ctx
;
9452 new_bss
->added_if
= added
;
9453 drv
->first_bss
->next
= new_bss
;
9455 *drv_priv
= new_bss
;
9456 nl80211_init_bss(new_bss
);
9458 /* Subscribe management frames for this WPA_IF_AP_BSS */
9459 if (nl80211_setup_ap(new_bss
))
9462 #endif /* HOSTAPD */
9465 drv
->global
->if_add_ifindex
= ifidx
;
9471 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
9472 enum wpa_driver_if_type type
,
9475 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9476 int ifindex
= if_nametoindex(ifname
);
9478 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
9479 __func__
, type
, ifname
, ifindex
, bss
->added_if
);
9480 if (ifindex
> 0 && bss
->added_if
)
9481 nl80211_remove_iface(drv
, ifindex
);
9484 if (type
!= WPA_IF_AP_BSS
)
9487 if (bss
->added_if_into_bridge
) {
9488 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
9490 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
9491 "interface %s from bridge %s: %s",
9492 bss
->ifname
, bss
->brname
, strerror(errno
));
9494 if (bss
->added_bridge
) {
9495 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
9496 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
9498 bss
->brname
, strerror(errno
));
9501 if (bss
!= drv
->first_bss
) {
9502 struct i802_bss
*tbss
;
9504 wpa_printf(MSG_DEBUG
, "nl80211: Not the first BSS - remove it");
9505 for (tbss
= drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
9506 if (tbss
->next
== bss
) {
9507 tbss
->next
= bss
->next
;
9508 /* Unsubscribe management frames */
9509 nl80211_teardown_ap(bss
);
9510 nl80211_destroy_bss(bss
);
9517 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
9518 "BSS %p in the list", __func__
, bss
);
9520 wpa_printf(MSG_DEBUG
, "nl80211: First BSS - reassign context");
9521 nl80211_teardown_ap(bss
);
9522 if (!bss
->added_if
&& !drv
->first_bss
->next
)
9523 wpa_driver_nl80211_del_beacon(drv
);
9524 nl80211_destroy_bss(bss
);
9526 i802_set_iface_flags(bss
, 0);
9527 if (drv
->first_bss
->next
) {
9528 drv
->first_bss
= drv
->first_bss
->next
;
9529 drv
->ctx
= drv
->first_bss
->ctx
;
9532 wpa_printf(MSG_DEBUG
, "nl80211: No second BSS to reassign context to");
9535 #endif /* HOSTAPD */
9541 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
9543 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9544 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9546 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9547 genlmsg_attrlen(gnlh
, 0), NULL
);
9548 if (tb
[NL80211_ATTR_COOKIE
])
9549 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
9554 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
9555 unsigned int freq
, unsigned int wait
,
9556 const u8
*buf
, size_t buf_len
,
9557 u64
*cookie_out
, int no_cck
, int no_ack
,
9560 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9565 msg
= nlmsg_alloc();
9569 wpa_printf(MSG_MSGDUMP
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
9570 "no_ack=%d offchanok=%d",
9571 freq
, wait
, no_cck
, no_ack
, offchanok
);
9572 wpa_hexdump(MSG_MSGDUMP
, "CMD_FRAME", buf
, buf_len
);
9573 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
9575 if (nl80211_set_iface_id(msg
, bss
) < 0)
9576 goto nla_put_failure
;
9578 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
9580 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
9581 if (offchanok
&& (drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
))
9582 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
9584 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
9586 NLA_PUT_FLAG(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
);
9588 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
9591 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
9594 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
9595 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
9597 goto nla_put_failure
;
9599 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame TX command accepted%s; "
9600 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
9601 (long long unsigned int) cookie
);
9604 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
9612 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
9614 unsigned int wait_time
,
9615 const u8
*dst
, const u8
*src
,
9617 const u8
*data
, size_t data_len
,
9620 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9623 struct ieee80211_hdr
*hdr
;
9625 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
9626 "freq=%u MHz wait=%d ms no_cck=%d)",
9627 drv
->ifindex
, freq
, wait_time
, no_cck
);
9629 buf
= os_zalloc(24 + data_len
);
9632 os_memcpy(buf
+ 24, data
, data_len
);
9633 hdr
= (struct ieee80211_hdr
*) buf
;
9634 hdr
->frame_control
=
9635 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
9636 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
9637 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
9638 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
9640 if (is_ap_interface(drv
->nlmode
) &&
9641 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
9642 (int) freq
== bss
->freq
|| drv
->device_ap_sme
||
9644 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
9648 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
9650 &drv
->send_action_cookie
,
9658 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
9660 struct i802_bss
*bss
= priv
;
9661 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9665 msg
= nlmsg_alloc();
9669 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
9670 (long long unsigned int) drv
->send_action_cookie
);
9671 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
9673 if (nl80211_set_iface_id(msg
, bss
) < 0)
9674 goto nla_put_failure
;
9675 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
9677 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9680 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
9681 "(%s)", ret
, strerror(-ret
));
9688 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
9689 unsigned int duration
)
9691 struct i802_bss
*bss
= priv
;
9692 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9697 msg
= nlmsg_alloc();
9701 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
9703 if (nl80211_set_iface_id(msg
, bss
) < 0)
9704 goto nla_put_failure
;
9706 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
9707 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
9710 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
9713 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
9714 "0x%llx for freq=%u MHz duration=%u",
9715 (long long unsigned int) cookie
, freq
, duration
);
9716 drv
->remain_on_chan_cookie
= cookie
;
9717 drv
->pending_remain_on_chan
= 1;
9720 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
9721 "(freq=%d duration=%u): %d (%s)",
9722 freq
, duration
, ret
, strerror(-ret
));
9729 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
9731 struct i802_bss
*bss
= priv
;
9732 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9736 if (!drv
->pending_remain_on_chan
) {
9737 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
9742 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
9744 (long long unsigned int) drv
->remain_on_chan_cookie
);
9746 msg
= nlmsg_alloc();
9750 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
9752 if (nl80211_set_iface_id(msg
, bss
) < 0)
9753 goto nla_put_failure
;
9755 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
9757 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9761 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
9762 "%d (%s)", ret
, strerror(-ret
));
9769 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
9771 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9774 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
9775 is_ap_interface(drv
->nlmode
)) {
9777 * Do not disable Probe Request reporting that was
9778 * enabled in nl80211_setup_ap().
9780 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
9781 "Probe Request reporting nl_preq=%p while "
9782 "in AP mode", bss
->nl_preq
);
9783 } else if (bss
->nl_preq
) {
9784 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
9785 "reporting nl_preq=%p", bss
->nl_preq
);
9786 nl80211_destroy_eloop_handle(&bss
->nl_preq
);
9792 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
9793 "already on! nl_preq=%p", bss
->nl_preq
);
9797 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
9798 if (bss
->nl_preq
== NULL
)
9800 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
9801 "reporting nl_preq=%p", bss
->nl_preq
);
9803 if (nl80211_register_frame(bss
, bss
->nl_preq
,
9804 (WLAN_FC_TYPE_MGMT
<< 2) |
9805 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
9809 nl80211_register_eloop_read(&bss
->nl_preq
,
9810 wpa_driver_nl80211_event_receive
,
9816 nl_destroy_handles(&bss
->nl_preq
);
9821 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
9822 int ifindex
, int disabled
)
9825 struct nlattr
*bands
, *band
;
9828 msg
= nlmsg_alloc();
9832 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
9833 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
9835 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
9837 goto nla_put_failure
;
9840 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
9841 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
9842 * rates. All 5 GHz rates are left enabled.
9844 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
9846 goto nla_put_failure
;
9848 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
9849 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
9851 nla_nest_end(msg
, band
);
9853 nla_nest_end(msg
, bands
);
9855 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9858 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
9859 "(%s)", ret
, strerror(-ret
));
9861 drv
->disabled_11b_rates
= disabled
;
9871 static int wpa_driver_nl80211_deinit_ap(void *priv
)
9873 struct i802_bss
*bss
= priv
;
9874 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9875 if (!is_ap_interface(drv
->nlmode
))
9877 wpa_driver_nl80211_del_beacon(drv
);
9880 * If the P2P GO interface was dynamically added, then it is
9881 * possible that the interface change to station is not possible.
9883 if (drv
->nlmode
== NL80211_IFTYPE_P2P_GO
&& bss
->if_dynamic
)
9886 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
9890 static int wpa_driver_nl80211_stop_ap(void *priv
)
9892 struct i802_bss
*bss
= priv
;
9893 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9894 if (!is_ap_interface(drv
->nlmode
))
9896 wpa_driver_nl80211_del_beacon(drv
);
9897 bss
->beacon_set
= 0;
9902 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
9904 struct i802_bss
*bss
= priv
;
9905 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9906 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
9910 * If the P2P Client interface was dynamically added, then it is
9911 * possible that the interface change to station is not possible.
9913 if (bss
->if_dynamic
)
9916 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
9920 static void wpa_driver_nl80211_resume(void *priv
)
9922 struct i802_bss
*bss
= priv
;
9924 if (i802_set_iface_flags(bss
, 1))
9925 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on resume event");
9929 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
9930 const u8
*ies
, size_t ies_len
)
9932 struct i802_bss
*bss
= priv
;
9933 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9937 const u8
*own_addr
= bss
->addr
;
9940 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
9941 "action %d", action
);
9946 * Action frame payload:
9947 * Category[1] = 6 (Fast BSS Transition)
9948 * Action[1] = 1 (Fast BSS Transition Request)
9954 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
9955 data
= os_malloc(data_len
);
9959 *pos
++ = 0x06; /* FT Action category */
9961 os_memcpy(pos
, own_addr
, ETH_ALEN
);
9963 os_memcpy(pos
, target_ap
, ETH_ALEN
);
9965 os_memcpy(pos
, ies
, ies_len
);
9967 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
9968 drv
->bssid
, own_addr
, drv
->bssid
,
9976 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
9978 struct i802_bss
*bss
= priv
;
9979 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9984 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
9985 "hysteresis=%d", threshold
, hysteresis
);
9987 msg
= nlmsg_alloc();
9991 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
9993 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9995 cqm
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
9997 goto nla_put_failure
;
9999 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
10000 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
10001 nla_nest_end(msg
, cqm
);
10003 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10012 /* Converts nl80211_chan_width to a common format */
10013 static enum chan_width
convert2width(int width
)
10016 case NL80211_CHAN_WIDTH_20_NOHT
:
10017 return CHAN_WIDTH_20_NOHT
;
10018 case NL80211_CHAN_WIDTH_20
:
10019 return CHAN_WIDTH_20
;
10020 case NL80211_CHAN_WIDTH_40
:
10021 return CHAN_WIDTH_40
;
10022 case NL80211_CHAN_WIDTH_80
:
10023 return CHAN_WIDTH_80
;
10024 case NL80211_CHAN_WIDTH_80P80
:
10025 return CHAN_WIDTH_80P80
;
10026 case NL80211_CHAN_WIDTH_160
:
10027 return CHAN_WIDTH_160
;
10029 return CHAN_WIDTH_UNKNOWN
;
10033 static int get_channel_width(struct nl_msg
*msg
, void *arg
)
10035 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
10036 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
10037 struct wpa_signal_info
*sig_change
= arg
;
10039 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
10040 genlmsg_attrlen(gnlh
, 0), NULL
);
10042 sig_change
->center_frq1
= -1;
10043 sig_change
->center_frq2
= -1;
10044 sig_change
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
10046 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
]) {
10047 sig_change
->chanwidth
= convert2width(
10048 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
10049 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
10050 sig_change
->center_frq1
=
10051 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
10052 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
10053 sig_change
->center_frq2
=
10054 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
10061 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data
*drv
,
10062 struct wpa_signal_info
*sig
)
10064 struct nl_msg
*msg
;
10066 msg
= nlmsg_alloc();
10070 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
10071 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10073 return send_and_recv_msgs(drv
, msg
, get_channel_width
, sig
);
10081 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
10083 struct i802_bss
*bss
= priv
;
10084 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10087 os_memset(si
, 0, sizeof(*si
));
10088 res
= nl80211_get_link_signal(drv
, si
);
10092 res
= nl80211_get_channel_width(drv
, si
);
10096 return nl80211_get_link_noise(drv
, si
);
10100 static int wpa_driver_nl80211_shared_freq(void *priv
)
10102 struct i802_bss
*bss
= priv
;
10103 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10104 struct wpa_driver_nl80211_data
*driver
;
10108 * If the same PHY is in connected state with some other interface,
10109 * then retrieve the assoc freq.
10111 wpa_printf(MSG_DEBUG
, "nl80211: Get shared freq for PHY %s",
10114 dl_list_for_each(driver
, &drv
->global
->interfaces
,
10115 struct wpa_driver_nl80211_data
, list
) {
10116 if (drv
== driver
||
10117 os_strcmp(drv
->phyname
, driver
->phyname
) != 0 ||
10118 !driver
->associated
)
10121 wpa_printf(MSG_DEBUG
, "nl80211: Found a match for PHY %s - %s "
10123 driver
->phyname
, driver
->first_bss
->ifname
,
10124 MAC2STR(driver
->first_bss
->addr
));
10125 if (is_ap_interface(driver
->nlmode
))
10126 freq
= driver
->first_bss
->freq
;
10128 freq
= nl80211_get_assoc_freq(driver
);
10129 wpa_printf(MSG_DEBUG
, "nl80211: Shared freq for PHY %s: %d",
10130 drv
->phyname
, freq
);
10134 wpa_printf(MSG_DEBUG
, "nl80211: No shared interface for "
10135 "PHY (%s) in associated state", drv
->phyname
);
10141 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
10144 struct i802_bss
*bss
= priv
;
10145 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
10150 static int nl80211_set_param(void *priv
, const char *param
)
10152 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
10157 if (os_strstr(param
, "use_p2p_group_interface=1")) {
10158 struct i802_bss
*bss
= priv
;
10159 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10161 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
10163 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
10164 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
10167 if (os_strstr(param
, "p2p_device=1")) {
10168 struct i802_bss
*bss
= priv
;
10169 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10170 drv
->allow_p2p_device
= 1;
10172 #endif /* CONFIG_P2P */
10178 static void * nl80211_global_init(void)
10180 struct nl80211_global
*global
;
10181 struct netlink_config
*cfg
;
10183 global
= os_zalloc(sizeof(*global
));
10184 if (global
== NULL
)
10186 global
->ioctl_sock
= -1;
10187 dl_list_init(&global
->interfaces
);
10188 global
->if_add_ifindex
= -1;
10190 cfg
= os_zalloc(sizeof(*cfg
));
10195 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
10196 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
10197 global
->netlink
= netlink_init(cfg
);
10198 if (global
->netlink
== NULL
) {
10203 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
10206 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
10207 if (global
->ioctl_sock
< 0) {
10208 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
10216 nl80211_global_deinit(global
);
10221 static void nl80211_global_deinit(void *priv
)
10223 struct nl80211_global
*global
= priv
;
10224 if (global
== NULL
)
10226 if (!dl_list_empty(&global
->interfaces
)) {
10227 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
10228 "nl80211_global_deinit",
10229 dl_list_len(&global
->interfaces
));
10232 if (global
->netlink
)
10233 netlink_deinit(global
->netlink
);
10235 nl_destroy_handles(&global
->nl
);
10237 if (global
->nl_event
)
10238 nl80211_destroy_eloop_handle(&global
->nl_event
);
10240 nl_cb_put(global
->nl_cb
);
10242 if (global
->ioctl_sock
>= 0)
10243 close(global
->ioctl_sock
);
10249 static const char * nl80211_get_radio_name(void *priv
)
10251 struct i802_bss
*bss
= priv
;
10252 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10253 return drv
->phyname
;
10257 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
10260 struct nl_msg
*msg
;
10262 msg
= nlmsg_alloc();
10266 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
10268 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
10270 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
10272 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
10274 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
10281 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
10283 struct i802_bss
*bss
= priv
;
10284 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
10285 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
10289 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
10291 struct i802_bss
*bss
= priv
;
10292 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
10294 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
10298 static int nl80211_flush_pmkid(void *priv
)
10300 struct i802_bss
*bss
= priv
;
10301 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
10302 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
10306 static void clean_survey_results(struct survey_results
*survey_results
)
10308 struct freq_survey
*survey
, *tmp
;
10310 if (dl_list_empty(&survey_results
->survey_list
))
10313 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
10314 struct freq_survey
, list
) {
10315 dl_list_del(&survey
->list
);
10321 static void add_survey(struct nlattr
**sinfo
, u32 ifidx
,
10322 struct dl_list
*survey_list
)
10324 struct freq_survey
*survey
;
10326 survey
= os_zalloc(sizeof(struct freq_survey
));
10330 survey
->ifidx
= ifidx
;
10331 survey
->freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
10332 survey
->filled
= 0;
10334 if (sinfo
[NL80211_SURVEY_INFO_NOISE
]) {
10335 survey
->nf
= (int8_t)
10336 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
10337 survey
->filled
|= SURVEY_HAS_NF
;
10340 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]) {
10341 survey
->channel_time
=
10342 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]);
10343 survey
->filled
|= SURVEY_HAS_CHAN_TIME
;
10346 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]) {
10347 survey
->channel_time_busy
=
10348 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]);
10349 survey
->filled
|= SURVEY_HAS_CHAN_TIME_BUSY
;
10352 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]) {
10353 survey
->channel_time_rx
=
10354 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]);
10355 survey
->filled
|= SURVEY_HAS_CHAN_TIME_RX
;
10358 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]) {
10359 survey
->channel_time_tx
=
10360 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]);
10361 survey
->filled
|= SURVEY_HAS_CHAN_TIME_TX
;
10364 wpa_printf(MSG_DEBUG
, "nl80211: Freq survey dump event (freq=%d MHz noise=%d channel_time=%ld busy_time=%ld tx_time=%ld rx_time=%ld filled=%04x)",
10367 (unsigned long int) survey
->channel_time
,
10368 (unsigned long int) survey
->channel_time_busy
,
10369 (unsigned long int) survey
->channel_time_tx
,
10370 (unsigned long int) survey
->channel_time_rx
,
10373 dl_list_add_tail(survey_list
, &survey
->list
);
10377 static int check_survey_ok(struct nlattr
**sinfo
, u32 surveyed_freq
,
10378 unsigned int freq_filter
)
10383 return freq_filter
== surveyed_freq
;
10387 static int survey_handler(struct nl_msg
*msg
, void *arg
)
10389 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
10390 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
10391 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
10392 struct survey_results
*survey_results
;
10393 u32 surveyed_freq
= 0;
10396 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
10397 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
10398 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
10401 survey_results
= (struct survey_results
*) arg
;
10403 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
10404 genlmsg_attrlen(gnlh
, 0), NULL
);
10406 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
10408 if (!tb
[NL80211_ATTR_SURVEY_INFO
])
10411 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
10412 tb
[NL80211_ATTR_SURVEY_INFO
],
10416 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) {
10417 wpa_printf(MSG_ERROR
, "nl80211: Invalid survey data");
10421 surveyed_freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
10423 if (!check_survey_ok(sinfo
, surveyed_freq
,
10424 survey_results
->freq_filter
))
10427 if (survey_results
->freq_filter
&&
10428 survey_results
->freq_filter
!= surveyed_freq
) {
10429 wpa_printf(MSG_EXCESSIVE
, "nl80211: Ignoring survey data for freq %d MHz",
10434 add_survey(sinfo
, ifidx
, &survey_results
->survey_list
);
10440 static int wpa_driver_nl80211_get_survey(void *priv
, unsigned int freq
)
10442 struct i802_bss
*bss
= priv
;
10443 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10444 struct nl_msg
*msg
;
10445 int err
= -ENOBUFS
;
10446 union wpa_event_data data
;
10447 struct survey_results
*survey_results
;
10449 os_memset(&data
, 0, sizeof(data
));
10450 survey_results
= &data
.survey_results
;
10452 dl_list_init(&survey_results
->survey_list
);
10454 msg
= nlmsg_alloc();
10456 goto nla_put_failure
;
10458 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
10460 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10463 data
.survey_results
.freq_filter
= freq
;
10466 wpa_printf(MSG_DEBUG
, "nl80211: Fetch survey data");
10467 err
= send_and_recv_msgs(drv
, msg
, survey_handler
,
10472 wpa_printf(MSG_ERROR
, "nl80211: Failed to process survey data");
10476 wpa_supplicant_event(drv
->ctx
, EVENT_SURVEY
, &data
);
10479 clean_survey_results(survey_results
);
10485 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
10486 const u8
*replay_ctr
)
10488 struct i802_bss
*bss
= priv
;
10489 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10490 struct nlattr
*replay_nested
;
10491 struct nl_msg
*msg
;
10493 msg
= nlmsg_alloc();
10497 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10499 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
10501 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10502 if (!replay_nested
)
10503 goto nla_put_failure
;
10505 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
10506 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
10507 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
10510 nla_nest_end(msg
, replay_nested
);
10512 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10519 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
10520 const u8
*addr
, int qos
)
10522 /* send data frame to poll STA and check whether
10523 * this frame is ACKed */
10525 struct ieee80211_hdr hdr
;
10527 } STRUCT_PACKED nulldata
;
10530 /* Send data frame to poll STA and check whether this frame is ACKed */
10532 os_memset(&nulldata
, 0, sizeof(nulldata
));
10535 nulldata
.hdr
.frame_control
=
10536 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
10537 WLAN_FC_STYPE_QOS_NULL
);
10538 size
= sizeof(nulldata
);
10540 nulldata
.hdr
.frame_control
=
10541 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
10542 WLAN_FC_STYPE_NULLFUNC
);
10543 size
= sizeof(struct ieee80211_hdr
);
10546 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
10547 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
10548 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
10549 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
10551 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
10553 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
10554 "send poll frame");
10557 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
10560 struct i802_bss
*bss
= priv
;
10561 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10562 struct nl_msg
*msg
;
10564 if (!drv
->poll_command_supported
) {
10565 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
10569 msg
= nlmsg_alloc();
10573 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_PROBE_CLIENT
);
10575 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
10576 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
10578 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10585 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
10587 struct nl_msg
*msg
;
10589 msg
= nlmsg_alloc();
10593 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_SET_POWER_SAVE
);
10594 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
10595 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
,
10596 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
);
10597 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
10604 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
10607 struct i802_bss
*bss
= priv
;
10609 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
10610 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
10612 if (opp_ps
!= -1 || ctwindow
!= -1)
10613 return -1; /* Not yet supported */
10615 if (legacy_ps
== -1)
10617 if (legacy_ps
!= 0 && legacy_ps
!= 1)
10618 return -1; /* Not yet supported */
10620 return nl80211_set_power_save(bss
, legacy_ps
);
10624 static int nl80211_start_radar_detection(void *priv
,
10625 struct hostapd_freq_params
*freq
)
10627 struct i802_bss
*bss
= priv
;
10628 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10629 struct nl_msg
*msg
;
10632 wpa_printf(MSG_DEBUG
, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
10633 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
10634 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
10636 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_RADAR
)) {
10637 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support radar "
10642 msg
= nlmsg_alloc();
10646 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_RADAR_DETECT
);
10647 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10648 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
);
10650 if (freq
->vht_enabled
) {
10651 switch (freq
->bandwidth
) {
10653 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10654 NL80211_CHAN_WIDTH_20
);
10657 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10658 NL80211_CHAN_WIDTH_40
);
10661 if (freq
->center_freq2
)
10662 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10663 NL80211_CHAN_WIDTH_80P80
);
10665 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10666 NL80211_CHAN_WIDTH_80
);
10669 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10670 NL80211_CHAN_WIDTH_160
);
10675 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ1
, freq
->center_freq1
);
10676 if (freq
->center_freq2
)
10677 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ2
,
10678 freq
->center_freq2
);
10679 } else if (freq
->ht_enabled
) {
10680 switch (freq
->sec_channel_offset
) {
10682 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10683 NL80211_CHAN_HT40MINUS
);
10686 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10687 NL80211_CHAN_HT40PLUS
);
10690 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10691 NL80211_CHAN_HT20
);
10696 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10699 wpa_printf(MSG_DEBUG
, "nl80211: Failed to start radar detection: "
10700 "%d (%s)", ret
, strerror(-ret
));
10707 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
10708 u8 dialog_token
, u16 status_code
,
10709 const u8
*buf
, size_t len
)
10711 struct i802_bss
*bss
= priv
;
10712 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10713 struct nl_msg
*msg
;
10715 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
10716 return -EOPNOTSUPP
;
10721 msg
= nlmsg_alloc();
10725 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_MGMT
);
10726 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10727 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
10728 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
);
10729 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
);
10730 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
);
10731 NLA_PUT(msg
, NL80211_ATTR_IE
, len
, buf
);
10733 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10741 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
10743 struct i802_bss
*bss
= priv
;
10744 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10745 struct nl_msg
*msg
;
10746 enum nl80211_tdls_operation nl80211_oper
;
10748 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
10749 return -EOPNOTSUPP
;
10752 case TDLS_DISCOVERY_REQ
:
10753 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
10756 nl80211_oper
= NL80211_TDLS_SETUP
;
10758 case TDLS_TEARDOWN
:
10759 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
10761 case TDLS_ENABLE_LINK
:
10762 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
10764 case TDLS_DISABLE_LINK
:
10765 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
10775 msg
= nlmsg_alloc();
10779 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_OPER
);
10780 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
);
10781 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10782 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
10784 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10791 #endif /* CONFIG TDLS */
10796 typedef struct android_wifi_priv_cmd
{
10800 } android_wifi_priv_cmd
;
10802 static int drv_errors
= 0;
10804 static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data
*drv
)
10807 if (drv_errors
> DRV_NUMBER_SEQUENTIAL_ERRORS
) {
10809 wpa_msg(drv
->ctx
, MSG_INFO
, WPA_EVENT_DRIVER_STATE
"HANGED");
10814 static int android_priv_cmd(struct i802_bss
*bss
, const char *cmd
)
10816 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10818 android_wifi_priv_cmd priv_cmd
;
10819 char buf
[MAX_DRV_CMD_SIZE
];
10822 os_memset(&ifr
, 0, sizeof(ifr
));
10823 os_memset(&priv_cmd
, 0, sizeof(priv_cmd
));
10824 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
10826 os_memset(buf
, 0, sizeof(buf
));
10827 os_strlcpy(buf
, cmd
, sizeof(buf
));
10829 priv_cmd
.buf
= buf
;
10830 priv_cmd
.used_len
= sizeof(buf
);
10831 priv_cmd
.total_len
= sizeof(buf
);
10832 ifr
.ifr_data
= &priv_cmd
;
10834 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
10836 wpa_printf(MSG_ERROR
, "%s: failed to issue private commands",
10838 wpa_driver_send_hang_msg(drv
);
10847 static int android_pno_start(struct i802_bss
*bss
,
10848 struct wpa_driver_scan_params
*params
)
10850 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10852 android_wifi_priv_cmd priv_cmd
;
10853 int ret
= 0, i
= 0, bp
;
10854 char buf
[WEXT_PNO_MAX_COMMAND_SIZE
];
10856 bp
= WEXT_PNOSETUP_HEADER_SIZE
;
10857 os_memcpy(buf
, WEXT_PNOSETUP_HEADER
, bp
);
10858 buf
[bp
++] = WEXT_PNO_TLV_PREFIX
;
10859 buf
[bp
++] = WEXT_PNO_TLV_VERSION
;
10860 buf
[bp
++] = WEXT_PNO_TLV_SUBVERSION
;
10861 buf
[bp
++] = WEXT_PNO_TLV_RESERVED
;
10863 while (i
< WEXT_PNO_AMOUNT
&& (size_t) i
< params
->num_ssids
) {
10864 /* Check that there is enough space needed for 1 more SSID, the
10865 * other sections and null termination */
10866 if ((bp
+ WEXT_PNO_SSID_HEADER_SIZE
+ MAX_SSID_LEN
+
10867 WEXT_PNO_NONSSID_SECTIONS_SIZE
+ 1) >= (int) sizeof(buf
))
10869 wpa_hexdump_ascii(MSG_DEBUG
, "For PNO Scan",
10870 params
->ssids
[i
].ssid
,
10871 params
->ssids
[i
].ssid_len
);
10872 buf
[bp
++] = WEXT_PNO_SSID_SECTION
;
10873 buf
[bp
++] = params
->ssids
[i
].ssid_len
;
10874 os_memcpy(&buf
[bp
], params
->ssids
[i
].ssid
,
10875 params
->ssids
[i
].ssid_len
);
10876 bp
+= params
->ssids
[i
].ssid_len
;
10880 buf
[bp
++] = WEXT_PNO_SCAN_INTERVAL_SECTION
;
10881 os_snprintf(&buf
[bp
], WEXT_PNO_SCAN_INTERVAL_LENGTH
+ 1, "%x",
10882 WEXT_PNO_SCAN_INTERVAL
);
10883 bp
+= WEXT_PNO_SCAN_INTERVAL_LENGTH
;
10885 buf
[bp
++] = WEXT_PNO_REPEAT_SECTION
;
10886 os_snprintf(&buf
[bp
], WEXT_PNO_REPEAT_LENGTH
+ 1, "%x",
10888 bp
+= WEXT_PNO_REPEAT_LENGTH
;
10890 buf
[bp
++] = WEXT_PNO_MAX_REPEAT_SECTION
;
10891 os_snprintf(&buf
[bp
], WEXT_PNO_MAX_REPEAT_LENGTH
+ 1, "%x",
10892 WEXT_PNO_MAX_REPEAT
);
10893 bp
+= WEXT_PNO_MAX_REPEAT_LENGTH
+ 1;
10895 memset(&ifr
, 0, sizeof(ifr
));
10896 memset(&priv_cmd
, 0, sizeof(priv_cmd
));
10897 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
10899 priv_cmd
.buf
= buf
;
10900 priv_cmd
.used_len
= bp
;
10901 priv_cmd
.total_len
= bp
;
10902 ifr
.ifr_data
= &priv_cmd
;
10904 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
10907 wpa_printf(MSG_ERROR
, "ioctl[SIOCSIWPRIV] (pnosetup): %d",
10909 wpa_driver_send_hang_msg(drv
);
10915 return android_priv_cmd(bss
, "PNOFORCE 1");
10919 static int android_pno_stop(struct i802_bss
*bss
)
10921 return android_priv_cmd(bss
, "PNOFORCE 0");
10924 #endif /* ANDROID */
10927 static int driver_nl80211_set_key(const char *ifname
, void *priv
,
10928 enum wpa_alg alg
, const u8
*addr
,
10929 int key_idx
, int set_tx
,
10930 const u8
*seq
, size_t seq_len
,
10931 const u8
*key
, size_t key_len
)
10933 struct i802_bss
*bss
= priv
;
10934 return wpa_driver_nl80211_set_key(ifname
, bss
, alg
, addr
, key_idx
,
10935 set_tx
, seq
, seq_len
, key
, key_len
);
10939 static int driver_nl80211_scan2(void *priv
,
10940 struct wpa_driver_scan_params
*params
)
10942 struct i802_bss
*bss
= priv
;
10943 return wpa_driver_nl80211_scan(bss
, params
);
10947 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
10950 struct i802_bss
*bss
= priv
;
10951 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
10955 static int driver_nl80211_authenticate(void *priv
,
10956 struct wpa_driver_auth_params
*params
)
10958 struct i802_bss
*bss
= priv
;
10959 return wpa_driver_nl80211_authenticate(bss
, params
);
10963 static void driver_nl80211_deinit(void *priv
)
10965 struct i802_bss
*bss
= priv
;
10966 wpa_driver_nl80211_deinit(bss
);
10970 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
10971 const char *ifname
)
10973 struct i802_bss
*bss
= priv
;
10974 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
10978 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
10979 size_t data_len
, int noack
)
10981 struct i802_bss
*bss
= priv
;
10982 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
10987 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
10989 struct i802_bss
*bss
= priv
;
10990 return wpa_driver_nl80211_sta_remove(bss
, addr
);
10994 #if defined(HOSTAPD) || defined(CONFIG_AP)
10995 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
10996 const char *ifname
, int vlan_id
)
10998 struct i802_bss
*bss
= priv
;
10999 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
11001 #endif /* HOSTAPD || CONFIG_AP */
11004 static int driver_nl80211_read_sta_data(void *priv
,
11005 struct hostap_sta_driver_data
*data
,
11008 struct i802_bss
*bss
= priv
;
11009 return i802_read_sta_data(bss
, data
, addr
);
11013 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
11014 unsigned int wait_time
,
11015 const u8
*dst
, const u8
*src
,
11017 const u8
*data
, size_t data_len
,
11020 struct i802_bss
*bss
= priv
;
11021 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
11022 bssid
, data
, data_len
, no_cck
);
11026 static int driver_nl80211_probe_req_report(void *priv
, int report
)
11028 struct i802_bss
*bss
= priv
;
11029 return wpa_driver_nl80211_probe_req_report(bss
, report
);
11033 static int wpa_driver_nl80211_update_ft_ies(void *priv
, const u8
*md
,
11034 const u8
*ies
, size_t ies_len
)
11037 struct nl_msg
*msg
;
11038 struct i802_bss
*bss
= priv
;
11039 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11040 u16 mdid
= WPA_GET_LE16(md
);
11042 msg
= nlmsg_alloc();
11046 wpa_printf(MSG_DEBUG
, "nl80211: Updating FT IEs");
11047 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UPDATE_FT_IES
);
11048 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
11049 NLA_PUT(msg
, NL80211_ATTR_IE
, ies_len
, ies
);
11050 NLA_PUT_U16(msg
, NL80211_ATTR_MDID
, mdid
);
11052 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
11054 wpa_printf(MSG_DEBUG
, "nl80211: update_ft_ies failed "
11055 "err=%d (%s)", ret
, strerror(-ret
));
11066 const u8
* wpa_driver_nl80211_get_macaddr(void *priv
)
11068 struct i802_bss
*bss
= priv
;
11069 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11071 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
11078 static const char * scan_state_str(enum scan_states scan_state
)
11080 switch (scan_state
) {
11083 case SCAN_REQUESTED
:
11084 return "SCAN_REQUESTED";
11086 return "SCAN_STARTED";
11087 case SCAN_COMPLETED
:
11088 return "SCAN_COMPLETED";
11090 return "SCAN_ABORTED";
11091 case SCHED_SCAN_STARTED
:
11092 return "SCHED_SCAN_STARTED";
11093 case SCHED_SCAN_STOPPED
:
11094 return "SCHED_SCAN_STOPPED";
11095 case SCHED_SCAN_RESULTS
:
11096 return "SCHED_SCAN_RESULTS";
11103 static int wpa_driver_nl80211_status(void *priv
, char *buf
, size_t buflen
)
11105 struct i802_bss
*bss
= priv
;
11106 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11111 end
= buf
+ buflen
;
11113 res
= os_snprintf(pos
, end
- pos
,
11117 "addr=" MACSTR
"\n"
11123 MAC2STR(bss
->addr
),
11125 bss
->beacon_set
? "beacon_set=1\n" : "",
11126 bss
->added_if_into_bridge
?
11127 "added_if_into_bridge=1\n" : "",
11128 bss
->added_bridge
? "added_bridge=1\n" : "",
11129 bss
->in_deinit
? "in_deinit=1\n" : "",
11130 bss
->if_dynamic
? "if_dynamic=1\n" : "");
11131 if (res
< 0 || res
>= end
- pos
)
11135 if (bss
->wdev_id_set
) {
11136 res
= os_snprintf(pos
, end
- pos
, "wdev_id=%llu\n",
11137 (unsigned long long) bss
->wdev_id
);
11138 if (res
< 0 || res
>= end
- pos
)
11143 res
= os_snprintf(pos
, end
- pos
,
11148 "auth_bssid=" MACSTR
"\n"
11149 "auth_attempt_bssid=" MACSTR
"\n"
11150 "bssid=" MACSTR
"\n"
11151 "prev_bssid=" MACSTR
"\n"
11154 "monitor_sock=%d\n"
11155 "monitor_ifidx=%d\n"
11156 "monitor_refcount=%d\n"
11157 "last_mgmt_freq=%u\n"
11158 "eapol_tx_sock=%d\n"
11159 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
11163 scan_state_str(drv
->scan_state
),
11164 MAC2STR(drv
->auth_bssid
),
11165 MAC2STR(drv
->auth_attempt_bssid
),
11166 MAC2STR(drv
->bssid
),
11167 MAC2STR(drv
->prev_bssid
),
11171 drv
->monitor_ifidx
,
11172 drv
->monitor_refcount
,
11173 drv
->last_mgmt_freq
,
11174 drv
->eapol_tx_sock
,
11175 drv
->ignore_if_down_event
?
11176 "ignore_if_down_event=1\n" : "",
11177 drv
->scan_complete_events
?
11178 "scan_complete_events=1\n" : "",
11179 drv
->disabled_11b_rates
?
11180 "disabled_11b_rates=1\n" : "",
11181 drv
->pending_remain_on_chan
?
11182 "pending_remain_on_chan=1\n" : "",
11183 drv
->in_interface_list
? "in_interface_list=1\n" : "",
11184 drv
->device_ap_sme
? "device_ap_sme=1\n" : "",
11185 drv
->poll_command_supported
?
11186 "poll_command_supported=1\n" : "",
11187 drv
->data_tx_status
? "data_tx_status=1\n" : "",
11188 drv
->scan_for_auth
? "scan_for_auth=1\n" : "",
11189 drv
->retry_auth
? "retry_auth=1\n" : "",
11190 drv
->use_monitor
? "use_monitor=1\n" : "",
11191 drv
->ignore_next_local_disconnect
?
11192 "ignore_next_local_disconnect=1\n" : "",
11193 drv
->allow_p2p_device
? "allow_p2p_device=1\n" : "");
11194 if (res
< 0 || res
>= end
- pos
)
11198 if (drv
->has_capability
) {
11199 res
= os_snprintf(pos
, end
- pos
,
11200 "capa.key_mgmt=0x%x\n"
11203 "capa.flags=0x%x\n"
11204 "capa.max_scan_ssids=%d\n"
11205 "capa.max_sched_scan_ssids=%d\n"
11206 "capa.sched_scan_supported=%d\n"
11207 "capa.max_match_sets=%d\n"
11208 "capa.max_remain_on_chan=%u\n"
11209 "capa.max_stations=%u\n"
11210 "capa.probe_resp_offloads=0x%x\n"
11211 "capa.max_acl_mac_addrs=%u\n"
11212 "capa.num_multichan_concurrent=%u\n",
11213 drv
->capa
.key_mgmt
,
11217 drv
->capa
.max_scan_ssids
,
11218 drv
->capa
.max_sched_scan_ssids
,
11219 drv
->capa
.sched_scan_supported
,
11220 drv
->capa
.max_match_sets
,
11221 drv
->capa
.max_remain_on_chan
,
11222 drv
->capa
.max_stations
,
11223 drv
->capa
.probe_resp_offloads
,
11224 drv
->capa
.max_acl_mac_addrs
,
11225 drv
->capa
.num_multichan_concurrent
);
11226 if (res
< 0 || res
>= end
- pos
)
11235 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
11237 .desc
= "Linux nl80211/cfg80211",
11238 .get_bssid
= wpa_driver_nl80211_get_bssid
,
11239 .get_ssid
= wpa_driver_nl80211_get_ssid
,
11240 .set_key
= driver_nl80211_set_key
,
11241 .scan2
= driver_nl80211_scan2
,
11242 .sched_scan
= wpa_driver_nl80211_sched_scan
,
11243 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
11244 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
11245 .deauthenticate
= driver_nl80211_deauthenticate
,
11246 .authenticate
= driver_nl80211_authenticate
,
11247 .associate
= wpa_driver_nl80211_associate
,
11248 .global_init
= nl80211_global_init
,
11249 .global_deinit
= nl80211_global_deinit
,
11250 .init2
= wpa_driver_nl80211_init
,
11251 .deinit
= driver_nl80211_deinit
,
11252 .get_capa
= wpa_driver_nl80211_get_capa
,
11253 .set_operstate
= wpa_driver_nl80211_set_operstate
,
11254 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
11255 .set_country
= wpa_driver_nl80211_set_country
,
11256 .get_country
= wpa_driver_nl80211_get_country
,
11257 .set_ap
= wpa_driver_nl80211_set_ap
,
11258 .set_acl
= wpa_driver_nl80211_set_acl
,
11259 .if_add
= wpa_driver_nl80211_if_add
,
11260 .if_remove
= driver_nl80211_if_remove
,
11261 .send_mlme
= driver_nl80211_send_mlme
,
11262 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
11263 .sta_add
= wpa_driver_nl80211_sta_add
,
11264 .sta_remove
= driver_nl80211_sta_remove
,
11265 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
11266 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
11268 .hapd_init
= i802_init
,
11269 .hapd_deinit
= i802_deinit
,
11270 .set_wds_sta
= i802_set_wds_sta
,
11271 #endif /* HOSTAPD */
11272 #if defined(HOSTAPD) || defined(CONFIG_AP)
11273 .get_seqnum
= i802_get_seqnum
,
11274 .flush
= i802_flush
,
11275 .get_inact_sec
= i802_get_inact_sec
,
11276 .sta_clear_stats
= i802_sta_clear_stats
,
11277 .set_rts
= i802_set_rts
,
11278 .set_frag
= i802_set_frag
,
11279 .set_tx_queue_params
= i802_set_tx_queue_params
,
11280 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
11281 .sta_deauth
= i802_sta_deauth
,
11282 .sta_disassoc
= i802_sta_disassoc
,
11283 #endif /* HOSTAPD || CONFIG_AP */
11284 .read_sta_data
= driver_nl80211_read_sta_data
,
11285 .set_freq
= i802_set_freq
,
11286 .send_action
= driver_nl80211_send_action
,
11287 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
11288 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
11289 .cancel_remain_on_channel
=
11290 wpa_driver_nl80211_cancel_remain_on_channel
,
11291 .probe_req_report
= driver_nl80211_probe_req_report
,
11292 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
11293 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
11294 .resume
= wpa_driver_nl80211_resume
,
11295 .send_ft_action
= nl80211_send_ft_action
,
11296 .signal_monitor
= nl80211_signal_monitor
,
11297 .signal_poll
= nl80211_signal_poll
,
11298 .send_frame
= nl80211_send_frame
,
11299 .shared_freq
= wpa_driver_nl80211_shared_freq
,
11300 .set_param
= nl80211_set_param
,
11301 .get_radio_name
= nl80211_get_radio_name
,
11302 .add_pmkid
= nl80211_add_pmkid
,
11303 .remove_pmkid
= nl80211_remove_pmkid
,
11304 .flush_pmkid
= nl80211_flush_pmkid
,
11305 .set_rekey_info
= nl80211_set_rekey_info
,
11306 .poll_client
= nl80211_poll_client
,
11307 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
11308 .start_dfs_cac
= nl80211_start_radar_detection
,
11309 .stop_ap
= wpa_driver_nl80211_stop_ap
,
11311 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
11312 .tdls_oper
= nl80211_tdls_oper
,
11313 #endif /* CONFIG_TDLS */
11314 .update_ft_ies
= wpa_driver_nl80211_update_ft_ies
,
11315 .get_mac_addr
= wpa_driver_nl80211_get_macaddr
,
11316 .get_survey
= wpa_driver_nl80211_get_survey
,
11317 .status
= wpa_driver_nl80211_status
,