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"
64 /* system/core/libnl_2 in AOSP does not include nla_put_u32() */
65 int nla_put_u32(struct nl_msg
*msg
, int attrtype
, uint32_t value
)
67 return nla_put(msg
, attrtype
, sizeof(uint32_t), &value
);
71 /* libnl 2.0 compatibility code */
72 #define nl_handle nl_sock
73 #define nl80211_handle_alloc nl_socket_alloc_cb
74 #define nl80211_handle_destroy nl_socket_free
77 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
78 * but when you free a socket again it will mess up its bitmap and
79 * and use the wrong number the next time it needs a socket ID.
80 * Therefore, we wrap the handle alloc/destroy and add our own pid
83 static uint32_t port_bitmap
[32] = { 0 };
85 static struct nl_handle
*nl80211_handle_alloc(void *cb
)
87 struct nl_handle
*handle
;
88 uint32_t pid
= getpid() & 0x3FFFFF;
91 handle
= nl_handle_alloc_cb(cb
);
93 for (i
= 0; i
< 1024; i
++) {
94 if (port_bitmap
[i
/ 32] & (1 << (i
% 32)))
96 port_bitmap
[i
/ 32] |= 1 << (i
% 32);
101 nl_socket_set_local_port(handle
, pid
);
106 static void nl80211_handle_destroy(struct nl_handle
*handle
)
108 uint32_t port
= nl_socket_get_local_port(handle
);
111 port_bitmap
[port
/ 32] &= ~(1 << (port
% 32));
113 nl_handle_destroy(handle
);
115 #endif /* CONFIG_LIBNL20 */
118 static struct nl_handle
* nl_create_handle(struct nl_cb
*cb
, const char *dbg
)
120 struct nl_handle
*handle
;
122 handle
= nl80211_handle_alloc(cb
);
123 if (handle
== NULL
) {
124 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
125 "callbacks (%s)", dbg
);
129 if (genl_connect(handle
)) {
130 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect to generic "
131 "netlink (%s)", dbg
);
132 nl80211_handle_destroy(handle
);
140 static void nl_destroy_handles(struct nl_handle
**handle
)
144 nl80211_handle_destroy(*handle
);
150 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
153 #define IFF_DORMANT 0x20000 /* driver signals dormant */
156 #ifndef IF_OPER_DORMANT
157 #define IF_OPER_DORMANT 5
163 struct nl80211_global
{
164 struct dl_list interfaces
;
166 struct netlink_data
*netlink
;
168 struct nl_handle
*nl
;
170 int ioctl_sock
; /* socket for ioctl() use */
172 struct nl_handle
*nl_event
;
175 struct nl80211_wiphy_data
{
180 struct nl_handle
*nl_beacons
;
186 static void nl80211_global_deinit(void *priv
);
187 static void wpa_driver_nl80211_deinit(void *priv
);
190 struct wpa_driver_nl80211_data
*drv
;
191 struct i802_bss
*next
;
193 char ifname
[IFNAMSIZ
+ 1];
194 char brname
[IFNAMSIZ
];
195 unsigned int beacon_set
:1;
196 unsigned int added_if_into_bridge
:1;
197 unsigned int added_bridge
:1;
198 unsigned int in_deinit
:1;
204 struct nl_handle
*nl_preq
, *nl_mgmt
;
207 struct nl80211_wiphy_data
*wiphy_data
;
208 struct dl_list wiphy_list
;
211 struct wpa_driver_nl80211_data
{
212 struct nl80211_global
*global
;
214 struct dl_list wiphy_list
;
220 int ignore_if_down_event
;
221 struct rfkill_data
*rfkill
;
222 struct wpa_driver_capa capa
;
227 int scan_complete_events
;
231 u8 auth_bssid
[ETH_ALEN
];
236 enum nl80211_iftype nlmode
;
237 enum nl80211_iftype ap_scan_as_station
;
238 unsigned int assoc_freq
;
242 int monitor_refcount
;
244 unsigned int disabled_11b_rates
:1;
245 unsigned int pending_remain_on_chan
:1;
246 unsigned int in_interface_list
:1;
247 unsigned int device_ap_sme
:1;
248 unsigned int poll_command_supported
:1;
249 unsigned int data_tx_status
:1;
250 unsigned int scan_for_auth
:1;
251 unsigned int retry_auth
:1;
252 unsigned int use_monitor
:1;
254 u64 remain_on_chan_cookie
;
255 u64 send_action_cookie
;
257 unsigned int last_mgmt_freq
;
259 struct wpa_driver_scan_filter
*filter_ssids
;
260 size_t num_filter_ssids
;
262 struct i802_bss first_bss
;
267 int eapol_sock
; /* socket for EAPOL frames */
269 int default_if_indices
[16];
277 /* From failed authentication command */
279 u8 auth_bssid_
[ETH_ALEN
];
281 size_t auth_ssid_len
;
285 u8 auth_wep_key
[4][16];
286 size_t auth_wep_key_len
[4];
287 int auth_wep_tx_keyidx
;
288 int auth_local_state_change
;
293 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
,
295 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
296 enum nl80211_iftype nlmode
);
298 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
);
299 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
300 const u8
*addr
, int cmd
, u16 reason_code
,
301 int local_state_change
);
302 static void nl80211_remove_monitor_interface(
303 struct wpa_driver_nl80211_data
*drv
);
304 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
305 unsigned int freq
, unsigned int wait
,
306 const u8
*buf
, size_t buf_len
, u64
*cookie
,
307 int no_cck
, int no_ack
, int offchanok
);
308 static int wpa_driver_nl80211_probe_req_report(void *priv
, int report
);
310 static int android_pno_start(struct i802_bss
*bss
,
311 struct wpa_driver_scan_params
*params
);
312 static int android_pno_stop(struct i802_bss
*bss
);
316 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
317 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
318 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
319 static int wpa_driver_nl80211_if_remove(void *priv
,
320 enum wpa_driver_if_type type
,
323 static inline void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
327 static inline void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
331 static inline int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
337 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
);
338 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
339 int ifindex
, int disabled
);
341 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
);
342 static int wpa_driver_nl80211_authenticate_retry(
343 struct wpa_driver_nl80211_data
*drv
);
346 static int is_ap_interface(enum nl80211_iftype nlmode
)
348 return (nlmode
== NL80211_IFTYPE_AP
||
349 nlmode
== NL80211_IFTYPE_P2P_GO
);
353 static int is_sta_interface(enum nl80211_iftype nlmode
)
355 return (nlmode
== NL80211_IFTYPE_STATION
||
356 nlmode
== NL80211_IFTYPE_P2P_CLIENT
);
360 static int is_p2p_interface(enum nl80211_iftype nlmode
)
362 return (nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
363 nlmode
== NL80211_IFTYPE_P2P_GO
);
367 struct nl80211_bss_info_arg
{
368 struct wpa_driver_nl80211_data
*drv
;
369 struct wpa_scan_results
*res
;
370 unsigned int assoc_freq
;
371 u8 assoc_bssid
[ETH_ALEN
];
374 static int bss_info_handler(struct nl_msg
*msg
, void *arg
);
378 static int ack_handler(struct nl_msg
*msg
, void *arg
)
385 static int finish_handler(struct nl_msg
*msg
, void *arg
)
392 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
401 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
407 static int send_and_recv(struct nl80211_global
*global
,
408 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
409 int (*valid_handler
)(struct nl_msg
*, void *),
415 cb
= nl_cb_clone(global
->nl_cb
);
419 err
= nl_send_auto_complete(nl_handle
, msg
);
425 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
426 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
427 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
430 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
431 valid_handler
, valid_data
);
434 nl_recvmsgs(nl_handle
, cb
);
442 static int send_and_recv_msgs_global(struct nl80211_global
*global
,
444 int (*valid_handler
)(struct nl_msg
*, void *),
447 return send_and_recv(global
, global
->nl
, msg
, valid_handler
,
452 static int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
454 int (*valid_handler
)(struct nl_msg
*, void *),
457 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
458 valid_handler
, valid_data
);
468 static int family_handler(struct nl_msg
*msg
, void *arg
)
470 struct family_data
*res
= arg
;
471 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
472 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
473 struct nlattr
*mcgrp
;
476 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
477 genlmsg_attrlen(gnlh
, 0), NULL
);
478 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
481 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
482 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
483 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
484 nla_len(mcgrp
), NULL
);
485 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
486 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
487 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
489 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
491 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
499 static int nl_get_multicast_id(struct nl80211_global
*global
,
500 const char *family
, const char *group
)
504 struct family_data res
= { group
, -ENOENT
};
509 genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
510 0, 0, CTRL_CMD_GETFAMILY
, 0);
511 NLA_PUT_STRING(msg
, CTRL_ATTR_FAMILY_NAME
, family
);
513 ret
= send_and_recv_msgs_global(global
, msg
, family_handler
, &res
);
524 static void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
525 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
527 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
532 struct wiphy_idx_data
{
537 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
539 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
540 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
541 struct wiphy_idx_data
*info
= arg
;
543 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
544 genlmsg_attrlen(gnlh
, 0), NULL
);
546 if (tb
[NL80211_ATTR_WIPHY
])
547 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
553 static int nl80211_get_wiphy_index(struct i802_bss
*bss
)
556 struct wiphy_idx_data data
= {
564 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
566 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
568 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
569 return data
.wiphy_idx
;
577 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
578 struct nl80211_wiphy_data
*w
)
587 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
);
589 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
);
591 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
594 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
595 "failed: ret=%d (%s)",
596 ret
, strerror(-ret
));
597 goto nla_put_failure
;
606 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
608 struct nl80211_wiphy_data
*w
= eloop_ctx
;
610 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
612 nl_recvmsgs(handle
, w
->nl_cb
);
616 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
618 struct nl80211_wiphy_data
*w
= arg
;
619 struct wpa_driver_nl80211_data
*drv
;
620 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
621 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
622 union wpa_event_data event
;
624 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
625 genlmsg_attrlen(gnlh
, 0), NULL
);
627 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
628 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
633 if (!tb
[NL80211_ATTR_FRAME
])
636 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
638 os_memset(&event
, 0, sizeof(event
));
639 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
640 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
641 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
648 static struct nl80211_wiphy_data
*
649 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
651 static DEFINE_DL_LIST(nl80211_wiphys
);
652 struct nl80211_wiphy_data
*w
;
653 int wiphy_idx
, found
= 0;
654 struct i802_bss
*tmp_bss
;
656 if (bss
->wiphy_data
!= NULL
)
657 return bss
->wiphy_data
;
659 wiphy_idx
= nl80211_get_wiphy_index(bss
);
661 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
662 if (w
->wiphy_idx
== wiphy_idx
)
667 w
= os_zalloc(sizeof(*w
));
670 w
->wiphy_idx
= wiphy_idx
;
671 dl_list_init(&w
->bsss
);
672 dl_list_init(&w
->drvs
);
674 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
679 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
680 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
683 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
685 if (w
->nl_beacons
== NULL
) {
690 if (nl80211_register_beacons(bss
->drv
, w
)) {
691 nl_destroy_handles(&w
->nl_beacons
);
696 eloop_register_read_sock(nl_socket_get_fd(w
->nl_beacons
),
697 nl80211_recv_beacons
, w
, w
->nl_beacons
);
699 dl_list_add(&nl80211_wiphys
, &w
->list
);
702 /* drv entry for this bss already there? */
703 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
704 if (tmp_bss
->drv
== bss
->drv
) {
711 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
713 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
719 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
721 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
722 struct i802_bss
*tmp_bss
;
727 bss
->wiphy_data
= NULL
;
728 dl_list_del(&bss
->wiphy_list
);
730 /* still any for this drv present? */
731 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
732 if (tmp_bss
->drv
== bss
->drv
) {
737 /* if not remove it */
739 dl_list_del(&bss
->drv
->wiphy_list
);
741 if (!dl_list_empty(&w
->bsss
))
744 eloop_unregister_read_sock(nl_socket_get_fd(w
->nl_beacons
));
747 nl_destroy_handles(&w
->nl_beacons
);
748 dl_list_del(&w
->list
);
753 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
755 struct i802_bss
*bss
= priv
;
756 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
757 if (!drv
->associated
)
759 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
764 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
766 struct i802_bss
*bss
= priv
;
767 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
768 if (!drv
->associated
)
770 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
771 return drv
->ssid_len
;
775 static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data
*drv
,
776 char *buf
, size_t len
, int del
)
778 union wpa_event_data event
;
780 os_memset(&event
, 0, sizeof(event
));
781 if (len
> sizeof(event
.interface_status
.ifname
))
782 len
= sizeof(event
.interface_status
.ifname
) - 1;
783 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
784 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
785 EVENT_INTERFACE_ADDED
;
787 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
789 event
.interface_status
.ifname
,
790 del
? "removed" : "added");
792 if (os_strcmp(drv
->first_bss
.ifname
, event
.interface_status
.ifname
) == 0) {
794 if (drv
->if_removed
) {
795 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
796 "already set - ignore event");
801 if (if_nametoindex(drv
->first_bss
.ifname
) == 0) {
802 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s "
803 "does not exist - ignore "
805 drv
->first_bss
.ifname
);
808 if (!drv
->if_removed
) {
809 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
810 "already cleared - ignore event");
817 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
821 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
824 int attrlen
, rta_len
;
828 attr
= (struct rtattr
*) buf
;
830 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
831 while (RTA_OK(attr
, attrlen
)) {
832 if (attr
->rta_type
== IFLA_IFNAME
) {
833 if (os_strcmp(((char *) attr
) + rta_len
, drv
->first_bss
.ifname
)
839 attr
= RTA_NEXT(attr
, attrlen
);
846 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
847 int ifindex
, u8
*buf
, size_t len
)
849 if (drv
->ifindex
== ifindex
)
852 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
853 drv
->first_bss
.ifindex
= if_nametoindex(drv
->first_bss
.ifname
);
854 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
856 wpa_driver_nl80211_finish_drv_init(drv
);
864 static struct wpa_driver_nl80211_data
*
865 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
867 struct wpa_driver_nl80211_data
*drv
;
868 dl_list_for_each(drv
, &global
->interfaces
,
869 struct wpa_driver_nl80211_data
, list
) {
870 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
871 have_ifidx(drv
, idx
))
878 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
879 struct ifinfomsg
*ifi
,
882 struct nl80211_global
*global
= ctx
;
883 struct wpa_driver_nl80211_data
*drv
;
884 int attrlen
, rta_len
;
887 char namebuf
[IFNAMSIZ
];
889 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
891 wpa_printf(MSG_DEBUG
, "nl80211: Ignore event for foreign "
892 "ifindex %d", ifi
->ifi_index
);
896 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
898 drv
->operstate
, ifi
->ifi_flags
,
899 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
900 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
901 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
902 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
904 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
905 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
906 linux_iface_up(drv
->global
->ioctl_sock
,
907 drv
->first_bss
.ifname
) > 0) {
908 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
909 "event since interface %s is up", namebuf
);
912 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
913 if (drv
->ignore_if_down_event
) {
914 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
915 "event generated by mode change");
916 drv
->ignore_if_down_event
= 0;
918 drv
->if_disabled
= 1;
919 wpa_supplicant_event(drv
->ctx
,
920 EVENT_INTERFACE_DISABLED
, NULL
);
924 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
925 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
926 linux_iface_up(drv
->global
->ioctl_sock
,
927 drv
->first_bss
.ifname
) == 0) {
928 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
929 "event since interface %s is down",
931 } else if (if_nametoindex(drv
->first_bss
.ifname
) == 0) {
932 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
933 "event since interface %s does not exist",
934 drv
->first_bss
.ifname
);
935 } else if (drv
->if_removed
) {
936 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
937 "event since interface %s is marked "
938 "removed", drv
->first_bss
.ifname
);
940 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
941 drv
->if_disabled
= 0;
942 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
948 * Some drivers send the association event before the operup event--in
949 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
950 * fails. This will hit us when wpa_supplicant does not need to do
951 * IEEE 802.1X authentication
953 if (drv
->operstate
== 1 &&
954 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
955 !(ifi
->ifi_flags
& IFF_RUNNING
))
956 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
960 attr
= (struct rtattr
*) buf
;
961 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
962 while (RTA_OK(attr
, attrlen
)) {
963 if (attr
->rta_type
== IFLA_IFNAME
) {
964 wpa_driver_nl80211_event_link(
966 ((char *) attr
) + rta_len
,
967 attr
->rta_len
- rta_len
, 0);
968 } else if (attr
->rta_type
== IFLA_MASTER
)
969 brid
= nla_get_u32((struct nlattr
*) attr
);
970 attr
= RTA_NEXT(attr
, attrlen
);
973 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
974 /* device has been added to bridge */
975 if_indextoname(brid
, namebuf
);
976 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
978 add_ifidx(drv
, brid
);
983 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
984 struct ifinfomsg
*ifi
,
987 struct nl80211_global
*global
= ctx
;
988 struct wpa_driver_nl80211_data
*drv
;
989 int attrlen
, rta_len
;
993 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
995 wpa_printf(MSG_DEBUG
, "nl80211: Ignore dellink event for "
996 "foreign ifindex %d", ifi
->ifi_index
);
1001 attr
= (struct rtattr
*) buf
;
1003 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1004 while (RTA_OK(attr
, attrlen
)) {
1005 if (attr
->rta_type
== IFLA_IFNAME
) {
1006 wpa_driver_nl80211_event_link(
1008 ((char *) attr
) + rta_len
,
1009 attr
->rta_len
- rta_len
, 1);
1010 } else if (attr
->rta_type
== IFLA_MASTER
)
1011 brid
= nla_get_u32((struct nlattr
*) attr
);
1012 attr
= RTA_NEXT(attr
, attrlen
);
1015 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1016 /* device has been removed from bridge */
1017 char namebuf
[IFNAMSIZ
];
1018 if_indextoname(brid
, namebuf
);
1019 wpa_printf(MSG_DEBUG
, "nl80211: Remove ifindex %u for bridge "
1020 "%s", brid
, namebuf
);
1021 del_ifidx(drv
, brid
);
1026 static void mlme_event_auth(struct wpa_driver_nl80211_data
*drv
,
1027 const u8
*frame
, size_t len
)
1029 const struct ieee80211_mgmt
*mgmt
;
1030 union wpa_event_data event
;
1032 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1033 if (len
< 24 + sizeof(mgmt
->u
.auth
)) {
1034 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1039 os_memcpy(drv
->auth_bssid
, mgmt
->sa
, ETH_ALEN
);
1040 os_memset(&event
, 0, sizeof(event
));
1041 os_memcpy(event
.auth
.peer
, mgmt
->sa
, ETH_ALEN
);
1042 event
.auth
.auth_type
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
1043 event
.auth
.status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
1044 if (len
> 24 + sizeof(mgmt
->u
.auth
)) {
1045 event
.auth
.ies
= mgmt
->u
.auth
.variable
;
1046 event
.auth
.ies_len
= len
- 24 - sizeof(mgmt
->u
.auth
);
1049 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH
, &event
);
1053 static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1057 struct nl80211_bss_info_arg arg
;
1059 os_memset(&arg
, 0, sizeof(arg
));
1060 msg
= nlmsg_alloc();
1062 goto nla_put_failure
;
1064 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1065 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1068 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
1071 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1072 "associated BSS from scan results: %u MHz",
1074 return arg
.assoc_freq
? arg
.assoc_freq
: drv
->assoc_freq
;
1076 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1077 "(%s)", ret
, strerror(-ret
));
1080 return drv
->assoc_freq
;
1084 static void mlme_event_assoc(struct wpa_driver_nl80211_data
*drv
,
1085 const u8
*frame
, size_t len
)
1087 const struct ieee80211_mgmt
*mgmt
;
1088 union wpa_event_data event
;
1091 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1092 if (len
< 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1093 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1098 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
1099 if (status
!= WLAN_STATUS_SUCCESS
) {
1100 os_memset(&event
, 0, sizeof(event
));
1101 event
.assoc_reject
.bssid
= mgmt
->bssid
;
1102 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1103 event
.assoc_reject
.resp_ies
=
1104 (u8
*) mgmt
->u
.assoc_resp
.variable
;
1105 event
.assoc_reject
.resp_ies_len
=
1106 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1108 event
.assoc_reject
.status_code
= status
;
1110 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1114 drv
->associated
= 1;
1115 os_memcpy(drv
->bssid
, mgmt
->sa
, ETH_ALEN
);
1117 os_memset(&event
, 0, sizeof(event
));
1118 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1119 event
.assoc_info
.resp_ies
= (u8
*) mgmt
->u
.assoc_resp
.variable
;
1120 event
.assoc_info
.resp_ies_len
=
1121 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1124 event
.assoc_info
.freq
= drv
->assoc_freq
;
1126 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1130 static void mlme_event_connect(struct wpa_driver_nl80211_data
*drv
,
1131 enum nl80211_commands cmd
, struct nlattr
*status
,
1132 struct nlattr
*addr
, struct nlattr
*req_ie
,
1133 struct nlattr
*resp_ie
)
1135 union wpa_event_data event
;
1137 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1139 * Avoid reporting two association events that would confuse
1142 wpa_printf(MSG_DEBUG
, "nl80211: Ignore connect event (cmd=%d) "
1143 "when using userspace SME", cmd
);
1147 os_memset(&event
, 0, sizeof(event
));
1148 if (cmd
== NL80211_CMD_CONNECT
&&
1149 nla_get_u16(status
) != WLAN_STATUS_SUCCESS
) {
1151 event
.assoc_reject
.bssid
= nla_data(addr
);
1153 event
.assoc_reject
.resp_ies
= nla_data(resp_ie
);
1154 event
.assoc_reject
.resp_ies_len
= nla_len(resp_ie
);
1156 event
.assoc_reject
.status_code
= nla_get_u16(status
);
1157 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1161 drv
->associated
= 1;
1163 os_memcpy(drv
->bssid
, nla_data(addr
), ETH_ALEN
);
1166 event
.assoc_info
.req_ies
= nla_data(req_ie
);
1167 event
.assoc_info
.req_ies_len
= nla_len(req_ie
);
1170 event
.assoc_info
.resp_ies
= nla_data(resp_ie
);
1171 event
.assoc_info
.resp_ies_len
= nla_len(resp_ie
);
1174 event
.assoc_info
.freq
= nl80211_get_assoc_freq(drv
);
1176 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1180 static void mlme_event_disconnect(struct wpa_driver_nl80211_data
*drv
,
1181 struct nlattr
*reason
, struct nlattr
*addr
,
1182 struct nlattr
*by_ap
)
1184 union wpa_event_data data
;
1186 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1188 * Avoid reporting two disassociation events that could
1189 * confuse the core code.
1191 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1192 "event when using userspace SME");
1196 drv
->associated
= 0;
1197 os_memset(&data
, 0, sizeof(data
));
1199 data
.deauth_info
.reason_code
= nla_get_u16(reason
);
1200 data
.deauth_info
.locally_generated
= by_ap
== NULL
;
1201 wpa_supplicant_event(drv
->ctx
, EVENT_DEAUTH
, &data
);
1205 static void mlme_event_ch_switch(struct wpa_driver_nl80211_data
*drv
,
1206 struct nlattr
*freq
, struct nlattr
*type
)
1208 union wpa_event_data data
;
1210 int chan_offset
= 0;
1212 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch event");
1217 switch (nla_get_u32(type
)) {
1218 case NL80211_CHAN_NO_HT
:
1221 case NL80211_CHAN_HT20
:
1223 case NL80211_CHAN_HT40PLUS
:
1226 case NL80211_CHAN_HT40MINUS
:
1231 data
.ch_switch
.freq
= nla_get_u32(freq
);
1232 data
.ch_switch
.ht_enabled
= ht_enabled
;
1233 data
.ch_switch
.ch_offset
= chan_offset
;
1235 wpa_supplicant_event(drv
->ctx
, EVENT_CH_SWITCH
, &data
);
1239 static void mlme_timeout_event(struct wpa_driver_nl80211_data
*drv
,
1240 enum nl80211_commands cmd
, struct nlattr
*addr
)
1242 union wpa_event_data event
;
1243 enum wpa_event_type ev
;
1245 if (nla_len(addr
) != ETH_ALEN
)
1248 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d; timeout with " MACSTR
,
1249 cmd
, MAC2STR((u8
*) nla_data(addr
)));
1251 if (cmd
== NL80211_CMD_AUTHENTICATE
)
1252 ev
= EVENT_AUTH_TIMED_OUT
;
1253 else if (cmd
== NL80211_CMD_ASSOCIATE
)
1254 ev
= EVENT_ASSOC_TIMED_OUT
;
1258 os_memset(&event
, 0, sizeof(event
));
1259 os_memcpy(event
.timeout_event
.addr
, nla_data(addr
), ETH_ALEN
);
1260 wpa_supplicant_event(drv
->ctx
, ev
, &event
);
1264 static void mlme_event_mgmt(struct wpa_driver_nl80211_data
*drv
,
1265 struct nlattr
*freq
, struct nlattr
*sig
,
1266 const u8
*frame
, size_t len
)
1268 const struct ieee80211_mgmt
*mgmt
;
1269 union wpa_event_data event
;
1273 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1275 wpa_printf(MSG_DEBUG
, "nl80211: Too short action frame");
1279 fc
= le_to_host16(mgmt
->frame_control
);
1280 stype
= WLAN_FC_GET_STYPE(fc
);
1283 ssi_signal
= (s32
) nla_get_u32(sig
);
1285 os_memset(&event
, 0, sizeof(event
));
1287 event
.rx_action
.freq
= nla_get_u32(freq
);
1288 drv
->last_mgmt_freq
= event
.rx_action
.freq
;
1290 if (stype
== WLAN_FC_STYPE_ACTION
) {
1291 event
.rx_action
.da
= mgmt
->da
;
1292 event
.rx_action
.sa
= mgmt
->sa
;
1293 event
.rx_action
.bssid
= mgmt
->bssid
;
1294 event
.rx_action
.category
= mgmt
->u
.action
.category
;
1295 event
.rx_action
.data
= &mgmt
->u
.action
.category
+ 1;
1296 event
.rx_action
.len
= frame
+ len
- event
.rx_action
.data
;
1297 wpa_supplicant_event(drv
->ctx
, EVENT_RX_ACTION
, &event
);
1299 event
.rx_mgmt
.frame
= frame
;
1300 event
.rx_mgmt
.frame_len
= len
;
1301 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1302 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
1307 static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data
*drv
,
1308 struct nlattr
*cookie
, const u8
*frame
,
1309 size_t len
, struct nlattr
*ack
)
1311 union wpa_event_data event
;
1312 const struct ieee80211_hdr
*hdr
;
1315 if (!is_ap_interface(drv
->nlmode
)) {
1321 cookie_val
= nla_get_u64(cookie
);
1322 wpa_printf(MSG_DEBUG
, "nl80211: Action TX status:"
1323 " cookie=0%llx%s (ack=%d)",
1324 (long long unsigned int) cookie_val
,
1325 cookie_val
== drv
->send_action_cookie
?
1326 " (match)" : " (unknown)", ack
!= NULL
);
1327 if (cookie_val
!= drv
->send_action_cookie
)
1331 hdr
= (const struct ieee80211_hdr
*) frame
;
1332 fc
= le_to_host16(hdr
->frame_control
);
1334 os_memset(&event
, 0, sizeof(event
));
1335 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
1336 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
1337 event
.tx_status
.dst
= hdr
->addr1
;
1338 event
.tx_status
.data
= frame
;
1339 event
.tx_status
.data_len
= len
;
1340 event
.tx_status
.ack
= ack
!= NULL
;
1341 wpa_supplicant_event(drv
->ctx
, EVENT_TX_STATUS
, &event
);
1345 static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data
*drv
,
1346 enum wpa_event_type type
,
1347 const u8
*frame
, size_t len
)
1349 const struct ieee80211_mgmt
*mgmt
;
1350 union wpa_event_data event
;
1351 const u8
*bssid
= NULL
;
1352 u16 reason_code
= 0;
1354 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1356 bssid
= mgmt
->bssid
;
1358 if (drv
->associated
!= 0 &&
1359 os_memcmp(bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
1360 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0) {
1362 * We have presumably received this deauth as a
1363 * response to a clear_state_mismatch() outgoing
1364 * deauth. Don't let it take us offline!
1366 wpa_printf(MSG_DEBUG
, "nl80211: Deauth received "
1367 "from Unknown BSSID " MACSTR
" -- ignoring",
1373 drv
->associated
= 0;
1374 os_memset(&event
, 0, sizeof(event
));
1376 /* Note: Same offset for Reason Code in both frame subtypes */
1377 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1378 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1380 if (type
== EVENT_DISASSOC
) {
1381 event
.disassoc_info
.locally_generated
=
1382 !os_memcmp(mgmt
->sa
, drv
->first_bss
.addr
, ETH_ALEN
);
1383 event
.disassoc_info
.addr
= bssid
;
1384 event
.disassoc_info
.reason_code
= reason_code
;
1385 if (frame
+ len
> mgmt
->u
.disassoc
.variable
) {
1386 event
.disassoc_info
.ie
= mgmt
->u
.disassoc
.variable
;
1387 event
.disassoc_info
.ie_len
= frame
+ len
-
1388 mgmt
->u
.disassoc
.variable
;
1391 event
.deauth_info
.locally_generated
=
1392 !os_memcmp(mgmt
->sa
, drv
->first_bss
.addr
, ETH_ALEN
);
1393 event
.deauth_info
.addr
= bssid
;
1394 event
.deauth_info
.reason_code
= reason_code
;
1395 if (frame
+ len
> mgmt
->u
.deauth
.variable
) {
1396 event
.deauth_info
.ie
= mgmt
->u
.deauth
.variable
;
1397 event
.deauth_info
.ie_len
= frame
+ len
-
1398 mgmt
->u
.deauth
.variable
;
1402 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1406 static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data
*drv
,
1407 enum wpa_event_type type
,
1408 const u8
*frame
, size_t len
)
1410 const struct ieee80211_mgmt
*mgmt
;
1411 union wpa_event_data event
;
1412 u16 reason_code
= 0;
1417 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1419 os_memset(&event
, 0, sizeof(event
));
1420 /* Note: Same offset for Reason Code in both frame subtypes */
1421 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1422 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1424 if (type
== EVENT_UNPROT_DISASSOC
) {
1425 event
.unprot_disassoc
.sa
= mgmt
->sa
;
1426 event
.unprot_disassoc
.da
= mgmt
->da
;
1427 event
.unprot_disassoc
.reason_code
= reason_code
;
1429 event
.unprot_deauth
.sa
= mgmt
->sa
;
1430 event
.unprot_deauth
.da
= mgmt
->da
;
1431 event
.unprot_deauth
.reason_code
= reason_code
;
1434 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1438 static void mlme_event(struct wpa_driver_nl80211_data
*drv
,
1439 enum nl80211_commands cmd
, struct nlattr
*frame
,
1440 struct nlattr
*addr
, struct nlattr
*timed_out
,
1441 struct nlattr
*freq
, struct nlattr
*ack
,
1442 struct nlattr
*cookie
, struct nlattr
*sig
)
1444 if (timed_out
&& addr
) {
1445 mlme_timeout_event(drv
, cmd
, addr
);
1449 if (frame
== NULL
) {
1450 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d without frame "
1455 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d", cmd
);
1456 wpa_hexdump(MSG_MSGDUMP
, "nl80211: MLME event frame",
1457 nla_data(frame
), nla_len(frame
));
1460 case NL80211_CMD_AUTHENTICATE
:
1461 mlme_event_auth(drv
, nla_data(frame
), nla_len(frame
));
1463 case NL80211_CMD_ASSOCIATE
:
1464 mlme_event_assoc(drv
, nla_data(frame
), nla_len(frame
));
1466 case NL80211_CMD_DEAUTHENTICATE
:
1467 mlme_event_deauth_disassoc(drv
, EVENT_DEAUTH
,
1468 nla_data(frame
), nla_len(frame
));
1470 case NL80211_CMD_DISASSOCIATE
:
1471 mlme_event_deauth_disassoc(drv
, EVENT_DISASSOC
,
1472 nla_data(frame
), nla_len(frame
));
1474 case NL80211_CMD_FRAME
:
1475 mlme_event_mgmt(drv
, freq
, sig
, nla_data(frame
),
1478 case NL80211_CMD_FRAME_TX_STATUS
:
1479 mlme_event_mgmt_tx_status(drv
, cookie
, nla_data(frame
),
1480 nla_len(frame
), ack
);
1482 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1483 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DEAUTH
,
1484 nla_data(frame
), nla_len(frame
));
1486 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1487 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DISASSOC
,
1488 nla_data(frame
), nla_len(frame
));
1496 static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data
*drv
,
1497 struct nlattr
*tb
[])
1499 union wpa_event_data data
;
1501 wpa_printf(MSG_DEBUG
, "nl80211: MLME event Michael MIC failure");
1502 os_memset(&data
, 0, sizeof(data
));
1503 if (tb
[NL80211_ATTR_MAC
]) {
1504 wpa_hexdump(MSG_DEBUG
, "nl80211: Source MAC address",
1505 nla_data(tb
[NL80211_ATTR_MAC
]),
1506 nla_len(tb
[NL80211_ATTR_MAC
]));
1507 data
.michael_mic_failure
.src
= nla_data(tb
[NL80211_ATTR_MAC
]);
1509 if (tb
[NL80211_ATTR_KEY_SEQ
]) {
1510 wpa_hexdump(MSG_DEBUG
, "nl80211: TSC",
1511 nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
1512 nla_len(tb
[NL80211_ATTR_KEY_SEQ
]));
1514 if (tb
[NL80211_ATTR_KEY_TYPE
]) {
1515 enum nl80211_key_type key_type
=
1516 nla_get_u32(tb
[NL80211_ATTR_KEY_TYPE
]);
1517 wpa_printf(MSG_DEBUG
, "nl80211: Key Type %d", key_type
);
1518 if (key_type
== NL80211_KEYTYPE_PAIRWISE
)
1519 data
.michael_mic_failure
.unicast
= 1;
1521 data
.michael_mic_failure
.unicast
= 1;
1523 if (tb
[NL80211_ATTR_KEY_IDX
]) {
1524 u8 key_id
= nla_get_u8(tb
[NL80211_ATTR_KEY_IDX
]);
1525 wpa_printf(MSG_DEBUG
, "nl80211: Key Id %d", key_id
);
1528 wpa_supplicant_event(drv
->ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
1532 static void mlme_event_join_ibss(struct wpa_driver_nl80211_data
*drv
,
1533 struct nlattr
*tb
[])
1535 if (tb
[NL80211_ATTR_MAC
] == NULL
) {
1536 wpa_printf(MSG_DEBUG
, "nl80211: No address in IBSS joined "
1540 os_memcpy(drv
->bssid
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1541 drv
->associated
= 1;
1542 wpa_printf(MSG_DEBUG
, "nl80211: IBSS " MACSTR
" joined",
1543 MAC2STR(drv
->bssid
));
1545 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1549 static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data
*drv
,
1550 int cancel_event
, struct nlattr
*tb
[])
1552 unsigned int freq
, chan_type
, duration
;
1553 union wpa_event_data data
;
1556 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1557 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1561 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1562 chan_type
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1566 if (tb
[NL80211_ATTR_DURATION
])
1567 duration
= nla_get_u32(tb
[NL80211_ATTR_DURATION
]);
1571 if (tb
[NL80211_ATTR_COOKIE
])
1572 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
1576 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel event (cancel=%d "
1577 "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
1578 cancel_event
, freq
, chan_type
, duration
,
1579 (long long unsigned int) cookie
,
1580 cookie
== drv
->remain_on_chan_cookie
? "match" : "unknown");
1582 if (cookie
!= drv
->remain_on_chan_cookie
)
1583 return; /* not for us */
1586 drv
->pending_remain_on_chan
= 0;
1588 os_memset(&data
, 0, sizeof(data
));
1589 data
.remain_on_channel
.freq
= freq
;
1590 data
.remain_on_channel
.duration
= duration
;
1591 wpa_supplicant_event(drv
->ctx
, cancel_event
?
1592 EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1593 EVENT_REMAIN_ON_CHANNEL
, &data
);
1597 static void send_scan_event(struct wpa_driver_nl80211_data
*drv
, int aborted
,
1598 struct nlattr
*tb
[])
1600 union wpa_event_data event
;
1603 struct scan_info
*info
;
1604 #define MAX_REPORT_FREQS 50
1605 int freqs
[MAX_REPORT_FREQS
];
1608 if (drv
->scan_for_auth
) {
1609 drv
->scan_for_auth
= 0;
1610 wpa_printf(MSG_DEBUG
, "nl80211: Scan results for missing "
1611 "cfg80211 BSS entry");
1612 wpa_driver_nl80211_authenticate_retry(drv
);
1616 os_memset(&event
, 0, sizeof(event
));
1617 info
= &event
.scan_info
;
1618 info
->aborted
= aborted
;
1620 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
1621 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem
) {
1622 struct wpa_driver_scan_ssid
*s
=
1623 &info
->ssids
[info
->num_ssids
];
1624 s
->ssid
= nla_data(nl
);
1625 s
->ssid_len
= nla_len(nl
);
1627 if (info
->num_ssids
== WPAS_MAX_SCAN_SSIDS
)
1631 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
1632 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem
)
1634 freqs
[num_freqs
] = nla_get_u32(nl
);
1636 if (num_freqs
== MAX_REPORT_FREQS
- 1)
1639 info
->freqs
= freqs
;
1640 info
->num_freqs
= num_freqs
;
1642 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
, &event
);
1646 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1648 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1649 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1650 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1651 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1652 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1654 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1655 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1656 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1657 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1658 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1659 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1661 struct wpa_signal_info
*sig_change
= arg
;
1663 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1664 genlmsg_attrlen(gnlh
, 0), NULL
);
1665 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1666 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1667 tb
[NL80211_ATTR_STA_INFO
], policy
))
1669 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1672 sig_change
->current_signal
=
1673 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1675 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1676 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1677 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1679 sig_change
->current_txrate
= 0;
1681 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1682 sig_change
->current_txrate
=
1684 NL80211_RATE_INFO_BITRATE
]) * 100;
1693 static int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1694 struct wpa_signal_info
*sig
)
1698 sig
->current_signal
= -9999;
1699 sig
->current_txrate
= 0;
1701 msg
= nlmsg_alloc();
1705 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
1707 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1708 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
1710 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1717 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1719 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1720 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1721 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1722 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1723 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1724 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1726 struct wpa_signal_info
*sig_change
= arg
;
1728 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1729 genlmsg_attrlen(gnlh
, 0), NULL
);
1731 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1732 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1736 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1737 tb
[NL80211_ATTR_SURVEY_INFO
],
1739 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1744 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1747 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1748 sig_change
->frequency
)
1751 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1754 sig_change
->current_noise
=
1755 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1761 static int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1762 struct wpa_signal_info
*sig_change
)
1766 sig_change
->current_noise
= 9999;
1767 sig_change
->frequency
= drv
->assoc_freq
;
1769 msg
= nlmsg_alloc();
1773 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1775 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1777 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1784 static int get_noise_for_scan_results(struct nl_msg
*msg
, void *arg
)
1786 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1787 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1788 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1789 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1790 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1791 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1793 struct wpa_scan_results
*scan_results
= arg
;
1794 struct wpa_scan_res
*scan_res
;
1797 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1798 genlmsg_attrlen(gnlh
, 0), NULL
);
1800 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1801 wpa_printf(MSG_DEBUG
, "nl80211: Survey data missing");
1805 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1806 tb
[NL80211_ATTR_SURVEY_INFO
],
1808 wpa_printf(MSG_DEBUG
, "nl80211: Failed to parse nested "
1813 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1816 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1819 for (i
= 0; i
< scan_results
->num
; ++i
) {
1820 scan_res
= scan_results
->res
[i
];
1823 if ((int) nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1826 if (!(scan_res
->flags
& WPA_SCAN_NOISE_INVALID
))
1828 scan_res
->noise
= (s8
)
1829 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1830 scan_res
->flags
&= ~WPA_SCAN_NOISE_INVALID
;
1837 static int nl80211_get_noise_for_scan_results(
1838 struct wpa_driver_nl80211_data
*drv
,
1839 struct wpa_scan_results
*scan_res
)
1843 msg
= nlmsg_alloc();
1847 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1849 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1851 return send_and_recv_msgs(drv
, msg
, get_noise_for_scan_results
,
1859 static void nl80211_cqm_event(struct wpa_driver_nl80211_data
*drv
,
1860 struct nlattr
*tb
[])
1862 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
1863 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
1864 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U8
},
1865 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
1866 [NL80211_ATTR_CQM_PKT_LOSS_EVENT
] = { .type
= NLA_U32
},
1868 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
1869 enum nl80211_cqm_rssi_threshold_event event
;
1870 union wpa_event_data ed
;
1871 struct wpa_signal_info sig
;
1874 if (tb
[NL80211_ATTR_CQM
] == NULL
||
1875 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, tb
[NL80211_ATTR_CQM
],
1877 wpa_printf(MSG_DEBUG
, "nl80211: Ignore invalid CQM event");
1881 os_memset(&ed
, 0, sizeof(ed
));
1883 if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
1884 if (!tb
[NL80211_ATTR_MAC
])
1886 os_memcpy(ed
.low_ack
.addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
1888 wpa_supplicant_event(drv
->ctx
, EVENT_STATION_LOW_ACK
, &ed
);
1892 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] == NULL
)
1894 event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
1896 if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
) {
1897 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1898 "event: RSSI high");
1899 ed
.signal_change
.above_threshold
= 1;
1900 } else if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
) {
1901 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1903 ed
.signal_change
.above_threshold
= 0;
1907 res
= nl80211_get_link_signal(drv
, &sig
);
1909 ed
.signal_change
.current_signal
= sig
.current_signal
;
1910 ed
.signal_change
.current_txrate
= sig
.current_txrate
;
1911 wpa_printf(MSG_DEBUG
, "nl80211: Signal: %d dBm txrate: %d",
1912 sig
.current_signal
, sig
.current_txrate
);
1915 res
= nl80211_get_link_noise(drv
, &sig
);
1917 ed
.signal_change
.current_noise
= sig
.current_noise
;
1918 wpa_printf(MSG_DEBUG
, "nl80211: Noise: %d dBm",
1922 wpa_supplicant_event(drv
->ctx
, EVENT_SIGNAL_CHANGE
, &ed
);
1926 static void nl80211_new_station_event(struct wpa_driver_nl80211_data
*drv
,
1930 union wpa_event_data data
;
1932 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1934 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1935 wpa_printf(MSG_DEBUG
, "nl80211: New station " MACSTR
, MAC2STR(addr
));
1937 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
1940 if (tb
[NL80211_ATTR_IE
]) {
1941 ies
= nla_data(tb
[NL80211_ATTR_IE
]);
1942 ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
1944 wpa_hexdump(MSG_DEBUG
, "nl80211: Assoc Req IEs", ies
, ies_len
);
1945 drv_event_assoc(drv
->ctx
, addr
, ies
, ies_len
, 0);
1949 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1952 os_memset(&data
, 0, sizeof(data
));
1953 os_memcpy(data
.ibss_rsn_start
.peer
, addr
, ETH_ALEN
);
1954 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_RSN_START
, &data
);
1958 static void nl80211_del_station_event(struct wpa_driver_nl80211_data
*drv
,
1962 union wpa_event_data data
;
1964 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1966 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1967 wpa_printf(MSG_DEBUG
, "nl80211: Delete station " MACSTR
,
1970 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
1971 drv_event_disassoc(drv
->ctx
, addr
);
1975 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1978 os_memset(&data
, 0, sizeof(data
));
1979 os_memcpy(data
.ibss_peer_lost
.peer
, addr
, ETH_ALEN
);
1980 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_PEER_LOST
, &data
);
1984 static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data
*drv
,
1987 struct nlattr
*rekey_info
[NUM_NL80211_REKEY_DATA
];
1988 static struct nla_policy rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
1989 [NL80211_REKEY_DATA_KEK
] = {
1990 .minlen
= NL80211_KEK_LEN
,
1991 .maxlen
= NL80211_KEK_LEN
,
1993 [NL80211_REKEY_DATA_KCK
] = {
1994 .minlen
= NL80211_KCK_LEN
,
1995 .maxlen
= NL80211_KCK_LEN
,
1997 [NL80211_REKEY_DATA_REPLAY_CTR
] = {
1998 .minlen
= NL80211_REPLAY_CTR_LEN
,
1999 .maxlen
= NL80211_REPLAY_CTR_LEN
,
2002 union wpa_event_data data
;
2004 if (!tb
[NL80211_ATTR_MAC
])
2006 if (!tb
[NL80211_ATTR_REKEY_DATA
])
2008 if (nla_parse_nested(rekey_info
, MAX_NL80211_REKEY_DATA
,
2009 tb
[NL80211_ATTR_REKEY_DATA
], rekey_policy
))
2011 if (!rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
])
2014 os_memset(&data
, 0, sizeof(data
));
2015 data
.driver_gtk_rekey
.bssid
= nla_data(tb
[NL80211_ATTR_MAC
]);
2016 wpa_printf(MSG_DEBUG
, "nl80211: Rekey offload event for BSSID " MACSTR
,
2017 MAC2STR(data
.driver_gtk_rekey
.bssid
));
2018 data
.driver_gtk_rekey
.replay_ctr
=
2019 nla_data(rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
]);
2020 wpa_hexdump(MSG_DEBUG
, "nl80211: Rekey offload - Replay Counter",
2021 data
.driver_gtk_rekey
.replay_ctr
, NL80211_REPLAY_CTR_LEN
);
2022 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_GTK_REKEY
, &data
);
2026 static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data
*drv
,
2029 struct nlattr
*cand
[NUM_NL80211_PMKSA_CANDIDATE
];
2030 static struct nla_policy cand_policy
[NUM_NL80211_PMKSA_CANDIDATE
] = {
2031 [NL80211_PMKSA_CANDIDATE_INDEX
] = { .type
= NLA_U32
},
2032 [NL80211_PMKSA_CANDIDATE_BSSID
] = {
2036 [NL80211_PMKSA_CANDIDATE_PREAUTH
] = { .type
= NLA_FLAG
},
2038 union wpa_event_data data
;
2040 if (!tb
[NL80211_ATTR_PMKSA_CANDIDATE
])
2042 if (nla_parse_nested(cand
, MAX_NL80211_PMKSA_CANDIDATE
,
2043 tb
[NL80211_ATTR_PMKSA_CANDIDATE
], cand_policy
))
2045 if (!cand
[NL80211_PMKSA_CANDIDATE_INDEX
] ||
2046 !cand
[NL80211_PMKSA_CANDIDATE_BSSID
])
2049 os_memset(&data
, 0, sizeof(data
));
2050 os_memcpy(data
.pmkid_candidate
.bssid
,
2051 nla_data(cand
[NL80211_PMKSA_CANDIDATE_BSSID
]), ETH_ALEN
);
2052 data
.pmkid_candidate
.index
=
2053 nla_get_u32(cand
[NL80211_PMKSA_CANDIDATE_INDEX
]);
2054 data
.pmkid_candidate
.preauth
=
2055 cand
[NL80211_PMKSA_CANDIDATE_PREAUTH
] != NULL
;
2056 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
2060 static void nl80211_client_probe_event(struct wpa_driver_nl80211_data
*drv
,
2063 union wpa_event_data data
;
2065 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_ACK
])
2068 os_memset(&data
, 0, sizeof(data
));
2069 os_memcpy(data
.client_poll
.addr
,
2070 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2072 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_CLIENT_POLL_OK
, &data
);
2076 static void nl80211_spurious_frame(struct i802_bss
*bss
, struct nlattr
**tb
,
2079 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2080 union wpa_event_data event
;
2082 if (!tb
[NL80211_ATTR_MAC
])
2085 os_memset(&event
, 0, sizeof(event
));
2086 event
.rx_from_unknown
.bssid
= bss
->addr
;
2087 event
.rx_from_unknown
.addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2088 event
.rx_from_unknown
.wds
= wds
;
2090 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
2094 static void do_process_drv_event(struct wpa_driver_nl80211_data
*drv
,
2095 int cmd
, struct nlattr
**tb
)
2097 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
&&
2098 (cmd
== NL80211_CMD_NEW_SCAN_RESULTS
||
2099 cmd
== NL80211_CMD_SCAN_ABORTED
)) {
2100 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
2101 drv
->ap_scan_as_station
);
2102 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2106 case NL80211_CMD_TRIGGER_SCAN
:
2107 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger");
2109 case NL80211_CMD_START_SCHED_SCAN
:
2110 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan started");
2112 case NL80211_CMD_SCHED_SCAN_STOPPED
:
2113 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stopped");
2114 wpa_supplicant_event(drv
->ctx
, EVENT_SCHED_SCAN_STOPPED
, NULL
);
2116 case NL80211_CMD_NEW_SCAN_RESULTS
:
2117 wpa_printf(MSG_DEBUG
, "nl80211: New scan results available");
2118 drv
->scan_complete_events
= 1;
2119 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2121 send_scan_event(drv
, 0, tb
);
2123 case NL80211_CMD_SCHED_SCAN_RESULTS
:
2124 wpa_printf(MSG_DEBUG
,
2125 "nl80211: New sched scan results available");
2126 send_scan_event(drv
, 0, tb
);
2128 case NL80211_CMD_SCAN_ABORTED
:
2129 wpa_printf(MSG_DEBUG
, "nl80211: Scan aborted");
2131 * Need to indicate that scan results are available in order
2132 * not to make wpa_supplicant stop its scanning.
2134 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2136 send_scan_event(drv
, 1, tb
);
2138 case NL80211_CMD_AUTHENTICATE
:
2139 case NL80211_CMD_ASSOCIATE
:
2140 case NL80211_CMD_DEAUTHENTICATE
:
2141 case NL80211_CMD_DISASSOCIATE
:
2142 case NL80211_CMD_FRAME_TX_STATUS
:
2143 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
2144 case NL80211_CMD_UNPROT_DISASSOCIATE
:
2145 mlme_event(drv
, cmd
, tb
[NL80211_ATTR_FRAME
],
2146 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2147 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2148 tb
[NL80211_ATTR_COOKIE
],
2149 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2151 case NL80211_CMD_CONNECT
:
2152 case NL80211_CMD_ROAM
:
2153 mlme_event_connect(drv
, cmd
,
2154 tb
[NL80211_ATTR_STATUS_CODE
],
2155 tb
[NL80211_ATTR_MAC
],
2156 tb
[NL80211_ATTR_REQ_IE
],
2157 tb
[NL80211_ATTR_RESP_IE
]);
2159 case NL80211_CMD_CH_SWITCH_NOTIFY
:
2160 mlme_event_ch_switch(drv
, tb
[NL80211_ATTR_WIPHY_FREQ
],
2161 tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2163 case NL80211_CMD_DISCONNECT
:
2164 mlme_event_disconnect(drv
, tb
[NL80211_ATTR_REASON_CODE
],
2165 tb
[NL80211_ATTR_MAC
],
2166 tb
[NL80211_ATTR_DISCONNECTED_BY_AP
]);
2168 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
2169 mlme_event_michael_mic_failure(drv
, tb
);
2171 case NL80211_CMD_JOIN_IBSS
:
2172 mlme_event_join_ibss(drv
, tb
);
2174 case NL80211_CMD_REMAIN_ON_CHANNEL
:
2175 mlme_event_remain_on_channel(drv
, 0, tb
);
2177 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
2178 mlme_event_remain_on_channel(drv
, 1, tb
);
2180 case NL80211_CMD_NOTIFY_CQM
:
2181 nl80211_cqm_event(drv
, tb
);
2183 case NL80211_CMD_REG_CHANGE
:
2184 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory domain change");
2185 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2188 case NL80211_CMD_REG_BEACON_HINT
:
2189 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory beacon hint");
2190 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2193 case NL80211_CMD_NEW_STATION
:
2194 nl80211_new_station_event(drv
, tb
);
2196 case NL80211_CMD_DEL_STATION
:
2197 nl80211_del_station_event(drv
, tb
);
2199 case NL80211_CMD_SET_REKEY_OFFLOAD
:
2200 nl80211_rekey_offload_event(drv
, tb
);
2202 case NL80211_CMD_PMKSA_CANDIDATE
:
2203 nl80211_pmksa_candidate_event(drv
, tb
);
2205 case NL80211_CMD_PROBE_CLIENT
:
2206 nl80211_client_probe_event(drv
, tb
);
2209 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2216 static int process_drv_event(struct nl_msg
*msg
, void *arg
)
2218 struct wpa_driver_nl80211_data
*drv
= arg
;
2219 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2220 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2222 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2223 genlmsg_attrlen(gnlh
, 0), NULL
);
2225 if (tb
[NL80211_ATTR_IFINDEX
]) {
2226 int ifindex
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2227 if (ifindex
!= drv
->ifindex
&& !have_ifidx(drv
, ifindex
)) {
2228 wpa_printf(MSG_DEBUG
, "nl80211: Ignored event (cmd=%d)"
2229 " for foreign interface (ifindex %d)",
2230 gnlh
->cmd
, ifindex
);
2235 do_process_drv_event(drv
, gnlh
->cmd
, tb
);
2240 static int process_global_event(struct nl_msg
*msg
, void *arg
)
2242 struct nl80211_global
*global
= arg
;
2243 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2244 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2245 struct wpa_driver_nl80211_data
*drv
, *tmp
;
2248 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2249 genlmsg_attrlen(gnlh
, 0), NULL
);
2251 if (tb
[NL80211_ATTR_IFINDEX
])
2252 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2254 dl_list_for_each_safe(drv
, tmp
, &global
->interfaces
,
2255 struct wpa_driver_nl80211_data
, list
) {
2256 if (ifidx
== -1 || ifidx
== drv
->ifindex
||
2257 have_ifidx(drv
, ifidx
))
2258 do_process_drv_event(drv
, gnlh
->cmd
, tb
);
2265 static int process_bss_event(struct nl_msg
*msg
, void *arg
)
2267 struct i802_bss
*bss
= arg
;
2268 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2269 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2271 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2272 genlmsg_attrlen(gnlh
, 0), NULL
);
2274 switch (gnlh
->cmd
) {
2275 case NL80211_CMD_FRAME
:
2276 case NL80211_CMD_FRAME_TX_STATUS
:
2277 mlme_event(bss
->drv
, gnlh
->cmd
, tb
[NL80211_ATTR_FRAME
],
2278 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2279 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2280 tb
[NL80211_ATTR_COOKIE
],
2281 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2283 case NL80211_CMD_UNEXPECTED_FRAME
:
2284 nl80211_spurious_frame(bss
, tb
, 0);
2286 case NL80211_CMD_UNEXPECTED_4ADDR_FRAME
:
2287 nl80211_spurious_frame(bss
, tb
, 1);
2290 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2291 "(cmd=%d)", gnlh
->cmd
);
2299 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
2302 struct nl_cb
*cb
= eloop_ctx
;
2304 wpa_printf(MSG_DEBUG
, "nl80211: Event message available");
2306 nl_recvmsgs(handle
, cb
);
2311 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
2312 * @priv: driver_nl80211 private data
2313 * @alpha2_arg: country to which to switch to
2314 * Returns: 0 on success, -1 on failure
2316 * This asks nl80211 to set the regulatory domain for given
2317 * country ISO / IEC alpha2.
2319 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
2321 struct i802_bss
*bss
= priv
;
2322 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2326 msg
= nlmsg_alloc();
2330 alpha2
[0] = alpha2_arg
[0];
2331 alpha2
[1] = alpha2_arg
[1];
2334 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
);
2336 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
);
2337 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
2346 struct wiphy_info_data
{
2347 struct wpa_driver_capa
*capa
;
2349 unsigned int error
:1;
2350 unsigned int device_ap_sme
:1;
2351 unsigned int poll_command_supported
:1;
2352 unsigned int data_tx_status
:1;
2353 unsigned int monitor_supported
:1;
2357 static unsigned int probe_resp_offload_support(int supp_protocols
)
2359 unsigned int prot
= 0;
2361 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
)
2362 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
;
2363 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
)
2364 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
;
2365 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
)
2366 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
;
2367 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
)
2368 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
;
2374 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
2376 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2377 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2378 struct wiphy_info_data
*info
= arg
;
2379 int p2p_go_supported
= 0, p2p_client_supported
= 0;
2380 int p2p_concurrent
= 0;
2381 int auth_supported
= 0, connect_supported
= 0;
2382 struct wpa_driver_capa
*capa
= info
->capa
;
2383 static struct nla_policy
2384 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
2385 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
2386 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
2387 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
2388 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
2390 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
2391 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
2392 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
2395 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2396 genlmsg_attrlen(gnlh
, 0), NULL
);
2398 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
2399 capa
->max_scan_ssids
=
2400 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
2402 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
2403 capa
->max_sched_scan_ssids
=
2404 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
2406 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
2407 capa
->max_match_sets
=
2408 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
2410 if (tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]) {
2411 struct nlattr
*nl_mode
;
2413 nla_for_each_nested(nl_mode
,
2414 tb
[NL80211_ATTR_SUPPORTED_IFTYPES
], i
) {
2415 switch (nla_type(nl_mode
)) {
2416 case NL80211_IFTYPE_AP
:
2417 capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
2419 case NL80211_IFTYPE_P2P_GO
:
2420 p2p_go_supported
= 1;
2422 case NL80211_IFTYPE_P2P_CLIENT
:
2423 p2p_client_supported
= 1;
2425 case NL80211_IFTYPE_MONITOR
:
2426 info
->monitor_supported
= 1;
2432 if (tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]) {
2433 struct nlattr
*nl_combi
;
2436 nla_for_each_nested(nl_combi
,
2437 tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
],
2439 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
2440 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
2441 struct nlattr
*nl_limit
, *nl_mode
;
2442 int err
, rem_limit
, rem_mode
;
2443 int combination_has_p2p
= 0, combination_has_mgd
= 0;
2445 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
2447 iface_combination_policy
);
2448 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
2449 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
2450 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
2451 goto broken_combination
;
2453 nla_for_each_nested(nl_limit
,
2454 tb_comb
[NL80211_IFACE_COMB_LIMITS
],
2456 err
= nla_parse_nested(tb_limit
,
2457 MAX_NL80211_IFACE_LIMIT
,
2459 iface_limit_policy
);
2461 !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
2462 goto broken_combination
;
2464 nla_for_each_nested(
2466 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
2468 int ift
= nla_type(nl_mode
);
2469 if (ift
== NL80211_IFTYPE_P2P_GO
||
2470 ift
== NL80211_IFTYPE_P2P_CLIENT
)
2471 combination_has_p2p
= 1;
2472 if (ift
== NL80211_IFTYPE_STATION
)
2473 combination_has_mgd
= 1;
2475 if (combination_has_p2p
&& combination_has_mgd
)
2479 if (combination_has_p2p
&& combination_has_mgd
) {
2489 if (tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]) {
2490 struct nlattr
*nl_cmd
;
2493 nla_for_each_nested(nl_cmd
,
2494 tb
[NL80211_ATTR_SUPPORTED_COMMANDS
], i
) {
2495 switch (nla_get_u32(nl_cmd
)) {
2496 case NL80211_CMD_AUTHENTICATE
:
2499 case NL80211_CMD_CONNECT
:
2500 connect_supported
= 1;
2502 case NL80211_CMD_START_SCHED_SCAN
:
2503 capa
->sched_scan_supported
= 1;
2505 case NL80211_CMD_PROBE_CLIENT
:
2506 info
->poll_command_supported
= 1;
2512 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
2513 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
2515 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
2518 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
2519 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
2520 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
2523 /* default to 5000 since early versions of mac80211 don't set it */
2524 capa
->max_remain_on_chan
= 5000;
2526 if (tb
[NL80211_ATTR_SUPPORT_AP_UAPSD
])
2527 capa
->flags
|= WPA_DRIVER_FLAGS_AP_UAPSD
;
2529 if (tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
])
2530 capa
->max_remain_on_chan
=
2531 nla_get_u32(tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
2534 capa
->flags
|= WPA_DRIVER_FLAGS_SME
;
2535 else if (!connect_supported
) {
2536 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
2537 "authentication/association or connect commands");
2541 if (p2p_go_supported
&& p2p_client_supported
)
2542 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
2543 if (p2p_concurrent
) {
2544 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
2545 "interface (driver advertised support)");
2546 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
2547 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
2550 if (tb
[NL80211_ATTR_TDLS_SUPPORT
]) {
2551 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
2552 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
2554 if (tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]) {
2555 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
2557 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
2561 if (tb
[NL80211_ATTR_DEVICE_AP_SME
])
2562 info
->device_ap_sme
= 1;
2564 if (tb
[NL80211_ATTR_FEATURE_FLAGS
]) {
2565 u32 flags
= nla_get_u32(tb
[NL80211_ATTR_FEATURE_FLAGS
]);
2567 if (flags
& NL80211_FEATURE_SK_TX_STATUS
)
2568 info
->data_tx_status
= 1;
2570 if (flags
& NL80211_FEATURE_INACTIVITY_TIMER
)
2571 capa
->flags
|= WPA_DRIVER_FLAGS_INACTIVITY_TIMER
;
2574 if (tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]) {
2576 nla_get_u32(tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]);
2577 wpa_printf(MSG_DEBUG
, "nl80211: Supports Probe Response "
2578 "offload in AP mode");
2579 capa
->flags
|= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
;
2580 capa
->probe_resp_offloads
=
2581 probe_resp_offload_support(protocols
);
2588 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
2589 struct wiphy_info_data
*info
)
2593 os_memset(info
, 0, sizeof(*info
));
2594 info
->capa
= &drv
->capa
;
2596 msg
= nlmsg_alloc();
2600 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
2602 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->first_bss
.ifindex
);
2604 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
) == 0)
2613 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
2615 struct wiphy_info_data info
;
2616 if (wpa_driver_nl80211_get_info(drv
, &info
))
2622 drv
->has_capability
= 1;
2623 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
2624 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2625 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2626 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2627 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
2628 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
2629 WPA_DRIVER_CAPA_ENC_WEP104
|
2630 WPA_DRIVER_CAPA_ENC_TKIP
|
2631 WPA_DRIVER_CAPA_ENC_CCMP
;
2632 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
2633 WPA_DRIVER_AUTH_SHARED
|
2634 WPA_DRIVER_AUTH_LEAP
;
2636 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
2637 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
2638 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2640 if (!info
.device_ap_sme
) {
2641 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
2644 * No AP SME is currently assumed to also indicate no AP MLME
2645 * in the driver/firmware.
2647 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP_MLME
;
2650 drv
->device_ap_sme
= info
.device_ap_sme
;
2651 drv
->poll_command_supported
= info
.poll_command_supported
;
2652 drv
->data_tx_status
= info
.data_tx_status
;
2655 * If poll command is supported mac80211 is new enough to
2656 * have everything we need to not need monitor interfaces.
2658 drv
->use_monitor
= !info
.poll_command_supported
;
2660 if (drv
->device_ap_sme
&& drv
->use_monitor
) {
2662 * Non-mac80211 drivers may not support monitor interface.
2663 * Make sure we do not get stuck with incorrect capability here
2664 * by explicitly testing this.
2666 if (!info
.monitor_supported
) {
2667 wpa_printf(MSG_DEBUG
, "nl80211: Disable use_monitor "
2668 "with device_ap_sme since no monitor mode "
2669 "support detected");
2670 drv
->use_monitor
= 0;
2675 * If we aren't going to use monitor interfaces, but the
2676 * driver doesn't support data TX status, we won't get TX
2677 * status for EAPOL frames.
2679 if (!drv
->use_monitor
&& !info
.data_tx_status
)
2680 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2687 static int android_genl_ctrl_resolve(struct nl_handle
*handle
,
2691 * Android ICS has very minimal genl_ctrl_resolve() implementation, so
2692 * need to work around that.
2694 struct nl_cache
*cache
= NULL
;
2695 struct genl_family
*nl80211
= NULL
;
2698 if (genl_ctrl_alloc_cache(handle
, &cache
) < 0) {
2699 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate generic "
2704 nl80211
= genl_ctrl_search_by_name(cache
, name
);
2705 if (nl80211
== NULL
)
2708 id
= genl_family_get_id(nl80211
);
2712 genl_family_put(nl80211
);
2714 nl_cache_free(cache
);
2718 #define genl_ctrl_resolve android_genl_ctrl_resolve
2719 #endif /* ANDROID */
2722 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
2726 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2727 if (global
->nl_cb
== NULL
) {
2728 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
2733 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
2734 if (global
->nl
== NULL
)
2737 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
2738 if (global
->nl80211_id
< 0) {
2739 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
2744 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
2745 if (global
->nl_event
== NULL
)
2748 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
2750 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2752 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2753 "membership for scan events: %d (%s)",
2754 ret
, strerror(-ret
));
2758 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
2760 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2762 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2763 "membership for mlme events: %d (%s)",
2764 ret
, strerror(-ret
));
2768 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
2770 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2772 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
2773 "membership for regulatory events: %d (%s)",
2774 ret
, strerror(-ret
));
2775 /* Continue without regulatory events */
2778 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2779 no_seq_check
, NULL
);
2780 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2781 process_global_event
, global
);
2783 eloop_register_read_sock(nl_socket_get_fd(global
->nl_event
),
2784 wpa_driver_nl80211_event_receive
,
2785 global
->nl_cb
, global
->nl_event
);
2790 nl_destroy_handles(&global
->nl_event
);
2791 nl_destroy_handles(&global
->nl
);
2792 nl_cb_put(global
->nl_cb
);
2793 global
->nl_cb
= NULL
;
2798 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
2800 drv
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2802 wpa_printf(MSG_ERROR
, "nl80211: Failed to alloc cb struct");
2806 nl_cb_set(drv
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2807 no_seq_check
, NULL
);
2808 nl_cb_set(drv
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2809 process_drv_event
, drv
);
2815 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
2817 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
2819 * This may be for any interface; use ifdown event to disable
2825 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
2827 struct wpa_driver_nl80211_data
*drv
= ctx
;
2828 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
2829 if (linux_set_iface_flags(drv
->global
->ioctl_sock
,
2830 drv
->first_bss
.ifname
, 1)) {
2831 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
2832 "after rfkill unblock");
2835 /* rtnetlink ifup handler will report interface as enabled */
2839 static void nl80211_get_phy_name(struct wpa_driver_nl80211_data
*drv
)
2841 /* Find phy (radio) to which this interface belongs */
2845 drv
->phyname
[0] = '\0';
2846 snprintf(buf
, sizeof(buf
) - 1, "/sys/class/net/%s/phy80211/name",
2847 drv
->first_bss
.ifname
);
2848 f
= open(buf
, O_RDONLY
);
2850 wpa_printf(MSG_DEBUG
, "Could not open file %s: %s",
2851 buf
, strerror(errno
));
2855 rv
= read(f
, drv
->phyname
, sizeof(drv
->phyname
) - 1);
2858 wpa_printf(MSG_DEBUG
, "Could not read file %s: %s",
2859 buf
, strerror(errno
));
2863 drv
->phyname
[rv
] = '\0';
2864 pos
= os_strchr(drv
->phyname
, '\n');
2867 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2868 drv
->first_bss
.ifname
, drv
->phyname
);
2872 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
2876 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
2881 struct cmsghdr
*cmsg
;
2882 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
2883 union wpa_event_data event
;
2885 memset(&msg
, 0, sizeof(msg
));
2886 msg
.msg_iov
= &entry
;
2888 entry
.iov_base
= data
;
2889 entry
.iov_len
= sizeof(data
);
2890 msg
.msg_control
= &control
;
2891 msg
.msg_controllen
= sizeof(control
);
2893 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
2894 /* if error or not fitting 802.3 header, return */
2898 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
2900 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
2901 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
2905 ack
= (void *)CMSG_DATA(cmsg
);
2909 if (cmsg
->cmsg_level
== SOL_PACKET
&&
2910 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
2911 struct sock_extended_err
*err
=
2912 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
2914 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
2919 if (!found_ee
|| !found_wifi
)
2922 memset(&event
, 0, sizeof(event
));
2923 event
.eapol_tx_status
.dst
= data
;
2924 event
.eapol_tx_status
.data
= data
+ 14;
2925 event
.eapol_tx_status
.data_len
= res
- 14;
2926 event
.eapol_tx_status
.ack
= acked
;
2927 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
2931 static int nl80211_init_bss(struct i802_bss
*bss
)
2933 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2937 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2938 no_seq_check
, NULL
);
2939 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2940 process_bss_event
, bss
);
2946 static void nl80211_destroy_bss(struct i802_bss
*bss
)
2948 nl_cb_put(bss
->nl_cb
);
2954 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2955 * @ctx: context to be used when calling wpa_supplicant functions,
2956 * e.g., wpa_supplicant_event()
2957 * @ifname: interface name, e.g., wlan0
2958 * @global_priv: private driver global data from global_init()
2959 * Returns: Pointer to private data, %NULL on failure
2961 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
2964 struct wpa_driver_nl80211_data
*drv
;
2965 struct rfkill_config
*rcfg
;
2966 struct i802_bss
*bss
;
2968 if (global_priv
== NULL
)
2970 drv
= os_zalloc(sizeof(*drv
));
2973 drv
->global
= global_priv
;
2975 bss
= &drv
->first_bss
;
2977 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
2978 drv
->monitor_ifidx
= -1;
2979 drv
->monitor_sock
= -1;
2980 drv
->eapol_tx_sock
= -1;
2981 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2983 if (wpa_driver_nl80211_init_nl(drv
)) {
2988 if (nl80211_init_bss(bss
))
2991 nl80211_get_phy_name(drv
);
2993 rcfg
= os_zalloc(sizeof(*rcfg
));
2997 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
2998 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
2999 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
3000 drv
->rfkill
= rfkill_init(rcfg
);
3001 if (drv
->rfkill
== NULL
) {
3002 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
3006 if (wpa_driver_nl80211_finish_drv_init(drv
))
3009 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
3010 if (drv
->eapol_tx_sock
< 0)
3013 if (drv
->data_tx_status
) {
3016 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
3017 &enabled
, sizeof(enabled
)) < 0) {
3018 wpa_printf(MSG_DEBUG
,
3019 "nl80211: wifi status sockopt failed\n");
3020 drv
->data_tx_status
= 0;
3021 if (!drv
->use_monitor
)
3023 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3025 eloop_register_read_sock(drv
->eapol_tx_sock
,
3026 wpa_driver_nl80211_handle_eapol_tx_status
,
3032 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
3033 drv
->in_interface_list
= 1;
3039 wpa_driver_nl80211_deinit(bss
);
3044 static int nl80211_register_frame(struct i802_bss
*bss
,
3045 struct nl_handle
*nl_handle
,
3046 u16 type
, const u8
*match
, size_t match_len
)
3048 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3052 msg
= nlmsg_alloc();
3056 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x nl_handle=%p",
3058 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3061 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
3063 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3064 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
3065 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
3067 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
3070 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
3071 "failed (type=%u): ret=%d (%s)",
3072 type
, ret
, strerror(-ret
));
3073 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3075 goto nla_put_failure
;
3084 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
3086 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3089 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
3090 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
3094 bss
->nl_mgmt
= nl_create_handle(drv
->nl_cb
, "mgmt");
3095 if (bss
->nl_mgmt
== NULL
)
3098 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_mgmt
),
3099 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
3106 static int nl80211_register_action_frame(struct i802_bss
*bss
,
3107 const u8
*match
, size_t match_len
)
3109 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
3110 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
3111 type
, match
, match_len
);
3115 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
3117 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3119 if (nl80211_alloc_mgmt_handle(bss
))
3121 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
3122 "handle %p", bss
->nl_mgmt
);
3124 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
3125 /* GAS Initial Request */
3126 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
3128 /* GAS Initial Response */
3129 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
3131 /* GAS Comeback Request */
3132 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
3134 /* GAS Comeback Response */
3135 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
3137 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
3139 /* P2P Public Action */
3140 if (nl80211_register_action_frame(bss
,
3141 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
3145 if (nl80211_register_action_frame(bss
,
3146 (u8
*) "\x7f\x50\x6f\x9a\x09",
3149 #endif /* CONFIG_P2P */
3150 #ifdef CONFIG_IEEE80211W
3151 /* SA Query Response */
3152 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
3154 #endif /* CONFIG_IEEE80211W */
3156 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
3157 /* TDLS Discovery Response */
3158 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
3162 #endif /* CONFIG_TDLS */
3164 /* FT Action frames */
3165 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
3168 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
3169 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
3171 /* WNM - BSS Transition Management Request */
3172 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
3179 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
3181 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3185 msg
= nlmsg_alloc();
3189 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
3191 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3193 ret
= send_and_recv(drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
3196 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
3197 "failed: ret=%d (%s)",
3198 ret
, strerror(-ret
));
3199 goto nla_put_failure
;
3208 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
3210 static const int stypes
[] = {
3212 WLAN_FC_STYPE_ASSOC_REQ
,
3213 WLAN_FC_STYPE_REASSOC_REQ
,
3214 WLAN_FC_STYPE_DISASSOC
,
3215 WLAN_FC_STYPE_DEAUTH
,
3216 WLAN_FC_STYPE_ACTION
,
3217 WLAN_FC_STYPE_PROBE_REQ
,
3218 /* Beacon doesn't work as mac80211 doesn't currently allow
3219 * it, but it wouldn't really be the right thing anyway as
3220 * it isn't per interface ... maybe just dump the scan
3221 * results periodically for OLBC?
3223 // WLAN_FC_STYPE_BEACON,
3227 if (nl80211_alloc_mgmt_handle(bss
))
3229 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3230 "handle %p", bss
->nl_mgmt
);
3232 for (i
= 0; i
< sizeof(stypes
) / sizeof(stypes
[0]); i
++) {
3233 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3234 (WLAN_FC_TYPE_MGMT
<< 2) |
3241 if (nl80211_register_spurious_class3(bss
))
3244 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
3250 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3251 nl_destroy_handles(&bss
->nl_mgmt
);
3256 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
3258 if (nl80211_alloc_mgmt_handle(bss
))
3260 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3261 "handle %p (device SME)", bss
->nl_mgmt
);
3263 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3264 (WLAN_FC_TYPE_MGMT
<< 2) |
3265 (WLAN_FC_STYPE_ACTION
<< 4),
3272 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3273 nl_destroy_handles(&bss
->nl_mgmt
);
3278 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
3280 if (bss
->nl_mgmt
== NULL
)
3282 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
3283 "(%s)", bss
->nl_mgmt
, reason
);
3284 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3285 nl_destroy_handles(&bss
->nl_mgmt
);
3287 nl80211_put_wiphy_data_ap(bss
);
3291 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
3293 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
3298 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
3300 struct i802_bss
*bss
= &drv
->first_bss
;
3301 int send_rfkill_event
= 0;
3303 drv
->ifindex
= if_nametoindex(bss
->ifname
);
3304 drv
->first_bss
.ifindex
= drv
->ifindex
;
3308 * Make sure the interface starts up in station mode unless this is a
3309 * dynamically added interface (e.g., P2P) that was already configured
3310 * with proper iftype.
3312 if (drv
->ifindex
!= drv
->global
->if_add_ifindex
&&
3313 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
) < 0) {
3314 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to "
3315 "use managed mode");
3319 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
3320 if (rfkill_is_blocked(drv
->rfkill
)) {
3321 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
3322 "interface '%s' due to rfkill",
3324 drv
->if_disabled
= 1;
3325 send_rfkill_event
= 1;
3327 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
3328 "interface '%s' UP", bss
->ifname
);
3333 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
3334 1, IF_OPER_DORMANT
);
3335 #endif /* HOSTAPD */
3337 if (wpa_driver_nl80211_capa(drv
))
3340 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
3344 if (send_rfkill_event
) {
3345 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
3353 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
3357 msg
= nlmsg_alloc();
3361 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
3362 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3364 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3372 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
3373 * @priv: Pointer to private nl80211 data from wpa_driver_nl80211_init()
3375 * Shut down driver interface and processing of driver events. Free
3376 * private data buffer if one was allocated in wpa_driver_nl80211_init().
3378 static void wpa_driver_nl80211_deinit(void *priv
)
3380 struct i802_bss
*bss
= priv
;
3381 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3384 if (drv
->data_tx_status
)
3385 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
3386 if (drv
->eapol_tx_sock
>= 0)
3387 close(drv
->eapol_tx_sock
);
3390 wpa_driver_nl80211_probe_req_report(bss
, 0);
3391 if (bss
->added_if_into_bridge
) {
3392 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
3394 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
3395 "interface %s from bridge %s: %s",
3396 bss
->ifname
, bss
->brname
, strerror(errno
));
3398 if (bss
->added_bridge
) {
3399 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
3400 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
3402 bss
->brname
, strerror(errno
));
3405 nl80211_remove_monitor_interface(drv
);
3407 if (is_ap_interface(drv
->nlmode
))
3408 wpa_driver_nl80211_del_beacon(drv
);
3411 if (drv
->last_freq_ht
) {
3412 /* Clear HT flags from the driver */
3413 struct hostapd_freq_params freq
;
3414 os_memset(&freq
, 0, sizeof(freq
));
3415 freq
.freq
= drv
->last_freq
;
3416 i802_set_freq(priv
, &freq
);
3419 if (drv
->eapol_sock
>= 0) {
3420 eloop_unregister_read_sock(drv
->eapol_sock
);
3421 close(drv
->eapol_sock
);
3424 if (drv
->if_indices
!= drv
->default_if_indices
)
3425 os_free(drv
->if_indices
);
3426 #endif /* HOSTAPD */
3428 if (drv
->disabled_11b_rates
)
3429 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
3431 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
3433 rfkill_deinit(drv
->rfkill
);
3435 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
3437 (void) linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0);
3438 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
3439 nl80211_mgmt_unsubscribe(bss
, "deinit");
3441 nl_cb_put(drv
->nl_cb
);
3443 nl80211_destroy_bss(&drv
->first_bss
);
3445 os_free(drv
->filter_ssids
);
3447 os_free(drv
->auth_ie
);
3449 if (drv
->in_interface_list
)
3450 dl_list_del(&drv
->list
);
3457 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
3458 * @eloop_ctx: Driver private data
3459 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
3461 * This function can be used as registered timeout when starting a scan to
3462 * generate a scan completed event if the driver does not report this.
3464 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
3466 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
3467 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
3468 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
3469 drv
->ap_scan_as_station
);
3470 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
3472 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
3473 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
3477 static struct nl_msg
*
3478 nl80211_scan_common(struct wpa_driver_nl80211_data
*drv
, u8 cmd
,
3479 struct wpa_driver_scan_params
*params
)
3485 msg
= nlmsg_alloc();
3489 nl80211_cmd(drv
, msg
, 0, cmd
);
3491 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
) < 0)
3494 if (params
->num_ssids
) {
3495 struct nl_msg
*ssids
= nlmsg_alloc();
3498 for (i
= 0; i
< params
->num_ssids
; i
++) {
3499 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
3500 params
->ssids
[i
].ssid
,
3501 params
->ssids
[i
].ssid_len
);
3502 if (nla_put(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
3503 params
->ssids
[i
].ssid
) < 0) {
3508 err
= nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
3514 if (params
->extra_ies
) {
3515 wpa_hexdump(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
3516 params
->extra_ies
, params
->extra_ies_len
);
3517 if (nla_put(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
3518 params
->extra_ies
) < 0)
3522 if (params
->freqs
) {
3523 struct nl_msg
*freqs
= nlmsg_alloc();
3526 for (i
= 0; params
->freqs
[i
]; i
++) {
3527 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
3528 "MHz", params
->freqs
[i
]);
3529 if (nla_put_u32(freqs
, i
+ 1, params
->freqs
[i
]) < 0) {
3534 err
= nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
,
3541 os_free(drv
->filter_ssids
);
3542 drv
->filter_ssids
= params
->filter_ssids
;
3543 params
->filter_ssids
= NULL
;
3544 drv
->num_filter_ssids
= params
->num_filter_ssids
;
3555 * wpa_driver_nl80211_scan - Request the driver to initiate scan
3556 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3557 * @params: Scan parameters
3558 * Returns: 0 on success, -1 on failure
3560 static int wpa_driver_nl80211_scan(void *priv
,
3561 struct wpa_driver_scan_params
*params
)
3563 struct i802_bss
*bss
= priv
;
3564 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3565 int ret
= -1, timeout
;
3566 struct nl_msg
*msg
, *rates
= NULL
;
3568 drv
->scan_for_auth
= 0;
3570 msg
= nl80211_scan_common(drv
, NL80211_CMD_TRIGGER_SCAN
, params
);
3574 if (params
->p2p_probe
) {
3575 wpa_printf(MSG_DEBUG
, "nl80211: P2P probe - mask SuppRates");
3577 rates
= nlmsg_alloc();
3579 goto nla_put_failure
;
3582 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
3583 * by masking out everything else apart from the OFDM rates 6,
3584 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
3585 * rates are left enabled.
3587 NLA_PUT(rates
, NL80211_BAND_2GHZ
, 8,
3588 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
3589 if (nla_put_nested(msg
, NL80211_ATTR_SCAN_SUPP_RATES
, rates
) <
3591 goto nla_put_failure
;
3593 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
3596 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3599 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
3600 "(%s)", ret
, strerror(-ret
));
3602 if (is_ap_interface(drv
->nlmode
)) {
3604 * mac80211 does not allow scan requests in AP mode, so
3605 * try to do this in station mode.
3607 if (wpa_driver_nl80211_set_mode(
3608 bss
, NL80211_IFTYPE_STATION
))
3609 goto nla_put_failure
;
3611 if (wpa_driver_nl80211_scan(drv
, params
)) {
3612 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
3613 goto nla_put_failure
;
3616 /* Restore AP mode when processing scan results */
3617 drv
->ap_scan_as_station
= drv
->nlmode
;
3620 goto nla_put_failure
;
3622 goto nla_put_failure
;
3623 #endif /* HOSTAPD */
3626 /* Not all drivers generate "scan completed" wireless event, so try to
3627 * read results after a timeout. */
3629 if (drv
->scan_complete_events
) {
3631 * The driver seems to deliver events to notify when scan is
3632 * complete, so use longer timeout to avoid race conditions
3633 * with scanning and following association request.
3637 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
3638 "seconds", ret
, timeout
);
3639 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
3640 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
3651 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
3652 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3653 * @params: Scan parameters
3654 * @interval: Interval between scan cycles in milliseconds
3655 * Returns: 0 on success, -1 on failure or if not supported
3657 static int wpa_driver_nl80211_sched_scan(void *priv
,
3658 struct wpa_driver_scan_params
*params
,
3661 struct i802_bss
*bss
= priv
;
3662 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3665 struct nl_msg
*match_set_ssid
= NULL
, *match_sets
= NULL
;
3666 struct nl_msg
*match_set_rssi
= NULL
;
3670 if (!drv
->capa
.sched_scan_supported
)
3671 return android_pno_start(bss
, params
);
3672 #endif /* ANDROID */
3674 msg
= nl80211_scan_common(drv
, NL80211_CMD_START_SCHED_SCAN
, params
);
3676 goto nla_put_failure
;
3678 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
3680 if ((drv
->num_filter_ssids
&&
3681 (int) drv
->num_filter_ssids
<= drv
->capa
.max_match_sets
) ||
3682 params
->filter_rssi
) {
3683 match_sets
= nlmsg_alloc();
3684 if (match_sets
== NULL
)
3685 goto nla_put_failure
;
3687 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
3688 wpa_hexdump_ascii(MSG_MSGDUMP
,
3689 "nl80211: Sched scan filter SSID",
3690 drv
->filter_ssids
[i
].ssid
,
3691 drv
->filter_ssids
[i
].ssid_len
);
3693 match_set_ssid
= nlmsg_alloc();
3694 if (match_set_ssid
== NULL
)
3695 goto nla_put_failure
;
3696 NLA_PUT(match_set_ssid
,
3697 NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
3698 drv
->filter_ssids
[i
].ssid_len
,
3699 drv
->filter_ssids
[i
].ssid
);
3701 if (nla_put_nested(match_sets
, i
+ 1, match_set_ssid
) <
3703 goto nla_put_failure
;
3706 if (params
->filter_rssi
) {
3707 match_set_rssi
= nlmsg_alloc();
3708 if (match_set_rssi
== NULL
)
3709 goto nla_put_failure
;
3710 NLA_PUT_U32(match_set_rssi
,
3711 NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
,
3712 params
->filter_rssi
);
3713 wpa_printf(MSG_MSGDUMP
,
3714 "nl80211: Sched scan RSSI filter %d dBm",
3715 params
->filter_rssi
);
3716 if (nla_put_nested(match_sets
, 0, match_set_rssi
) < 0)
3717 goto nla_put_failure
;
3720 if (nla_put_nested(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
,
3722 goto nla_put_failure
;
3725 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3727 /* TODO: if we get an error here, we should fall back to normal scan */
3731 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
3732 "ret=%d (%s)", ret
, strerror(-ret
));
3733 goto nla_put_failure
;
3736 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
3737 "scan interval %d msec", ret
, interval
);
3740 nlmsg_free(match_set_ssid
);
3741 nlmsg_free(match_sets
);
3742 nlmsg_free(match_set_rssi
);
3749 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
3750 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3751 * Returns: 0 on success, -1 on failure or if not supported
3753 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
3755 struct i802_bss
*bss
= priv
;
3756 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3761 if (!drv
->capa
.sched_scan_supported
)
3762 return android_pno_stop(bss
);
3763 #endif /* ANDROID */
3765 msg
= nlmsg_alloc();
3769 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
3771 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3773 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3776 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
3777 "ret=%d (%s)", ret
, strerror(-ret
));
3778 goto nla_put_failure
;
3781 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
3789 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
3791 const u8
*end
, *pos
;
3797 end
= ies
+ ies_len
;
3799 while (pos
+ 1 < end
) {
3800 if (pos
+ 2 + pos
[1] > end
)
3811 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
3812 const u8
*ie
, size_t ie_len
)
3817 if (drv
->filter_ssids
== NULL
)
3820 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
3824 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
3825 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
3826 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
3835 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
3837 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
3838 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3839 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
3840 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
3841 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
3842 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
3843 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
3844 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
3845 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
3846 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
3847 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
3848 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
3849 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
3850 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
3851 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
3853 struct nl80211_bss_info_arg
*_arg
= arg
;
3854 struct wpa_scan_results
*res
= _arg
->res
;
3855 struct wpa_scan_res
**tmp
;
3856 struct wpa_scan_res
*r
;
3857 const u8
*ie
, *beacon_ie
;
3858 size_t ie_len
, beacon_ie_len
;
3862 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3863 genlmsg_attrlen(gnlh
, 0), NULL
);
3864 if (!tb
[NL80211_ATTR_BSS
])
3866 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
3869 if (bss
[NL80211_BSS_STATUS
]) {
3870 enum nl80211_bss_status status
;
3871 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
3872 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
3873 bss
[NL80211_BSS_FREQUENCY
]) {
3875 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
3876 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
3879 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
3880 bss
[NL80211_BSS_BSSID
]) {
3881 os_memcpy(_arg
->assoc_bssid
,
3882 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
3883 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
3884 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
3889 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
3890 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
3891 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
3896 if (bss
[NL80211_BSS_BEACON_IES
]) {
3897 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
3898 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
3904 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
3905 ie
? ie_len
: beacon_ie_len
))
3908 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
3911 if (bss
[NL80211_BSS_BSSID
])
3912 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
3914 if (bss
[NL80211_BSS_FREQUENCY
])
3915 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
3916 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
3917 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
3918 if (bss
[NL80211_BSS_CAPABILITY
])
3919 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
3920 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
3921 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
3922 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
3923 r
->level
/= 100; /* mBm to dBm */
3924 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
3925 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
3926 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
3927 r
->flags
|= WPA_SCAN_QUAL_INVALID
;
3929 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
3930 if (bss
[NL80211_BSS_TSF
])
3931 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
3932 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
3933 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
3935 pos
= (u8
*) (r
+ 1);
3937 os_memcpy(pos
, ie
, ie_len
);
3940 r
->beacon_ie_len
= beacon_ie_len
;
3942 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
3944 if (bss
[NL80211_BSS_STATUS
]) {
3945 enum nl80211_bss_status status
;
3946 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
3948 case NL80211_BSS_STATUS_AUTHENTICATED
:
3949 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
3951 case NL80211_BSS_STATUS_ASSOCIATED
:
3952 r
->flags
|= WPA_SCAN_ASSOCIATED
;
3960 * cfg80211 maintains separate BSS table entries for APs if the same
3961 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
3962 * not use frequency as a separate key in the BSS table, so filter out
3963 * duplicated entries. Prefer associated BSS entry in such a case in
3964 * order to get the correct frequency into the BSS table.
3966 for (i
= 0; i
< res
->num
; i
++) {
3968 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
3971 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
3972 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
3973 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
3974 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
3975 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
3978 /* Same BSSID,SSID was already included in scan results */
3979 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
3980 "for " MACSTR
, MAC2STR(r
->bssid
));
3982 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
3983 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
3984 os_free(res
->res
[i
]);
3991 tmp
= os_realloc_array(res
->res
, res
->num
+ 1,
3992 sizeof(struct wpa_scan_res
*));
3997 tmp
[res
->num
++] = r
;
4004 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
4007 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
4008 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
4009 "mismatch (" MACSTR
")", MAC2STR(addr
));
4010 wpa_driver_nl80211_mlme(drv
, addr
,
4011 NL80211_CMD_DEAUTHENTICATE
,
4012 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
4017 static void wpa_driver_nl80211_check_bss_status(
4018 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
4022 for (i
= 0; i
< res
->num
; i
++) {
4023 struct wpa_scan_res
*r
= res
->res
[i
];
4024 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
4025 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4026 "indicates BSS status with " MACSTR
4027 " as authenticated",
4029 if (is_sta_interface(drv
->nlmode
) &&
4030 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
4031 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
4033 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
4034 " in local state (auth=" MACSTR
4035 " assoc=" MACSTR
")",
4036 MAC2STR(drv
->auth_bssid
),
4037 MAC2STR(drv
->bssid
));
4038 clear_state_mismatch(drv
, r
->bssid
);
4042 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
4043 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4044 "indicate BSS status with " MACSTR
4047 if (is_sta_interface(drv
->nlmode
) &&
4049 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4050 "(not associated) does not match "
4052 clear_state_mismatch(drv
, r
->bssid
);
4053 } else if (is_sta_interface(drv
->nlmode
) &&
4054 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
4056 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4057 "(associated with " MACSTR
") does "
4058 "not match with BSS state",
4059 MAC2STR(drv
->bssid
));
4060 clear_state_mismatch(drv
, r
->bssid
);
4061 clear_state_mismatch(drv
, drv
->bssid
);
4068 static struct wpa_scan_results
*
4069 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
4072 struct wpa_scan_results
*res
;
4074 struct nl80211_bss_info_arg arg
;
4076 res
= os_zalloc(sizeof(*res
));
4079 msg
= nlmsg_alloc();
4081 goto nla_put_failure
;
4083 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
4084 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4088 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
4091 wpa_printf(MSG_DEBUG
, "nl80211: Received scan results (%lu "
4092 "BSSes)", (unsigned long) res
->num
);
4093 nl80211_get_noise_for_scan_results(drv
, res
);
4096 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
4097 "(%s)", ret
, strerror(-ret
));
4100 wpa_scan_results_free(res
);
4106 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
4107 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
4108 * Returns: Scan results on success, -1 on failure
4110 static struct wpa_scan_results
*
4111 wpa_driver_nl80211_get_scan_results(void *priv
)
4113 struct i802_bss
*bss
= priv
;
4114 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4115 struct wpa_scan_results
*res
;
4117 res
= nl80211_get_scan_results(drv
);
4119 wpa_driver_nl80211_check_bss_status(drv
, res
);
4124 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
4126 struct wpa_scan_results
*res
;
4129 res
= nl80211_get_scan_results(drv
);
4131 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
4135 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
4136 for (i
= 0; i
< res
->num
; i
++) {
4137 struct wpa_scan_res
*r
= res
->res
[i
];
4138 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
4139 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
4140 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
4141 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
4144 wpa_scan_results_free(res
);
4148 static int wpa_driver_nl80211_set_key(const char *ifname
, void *priv
,
4149 enum wpa_alg alg
, const u8
*addr
,
4150 int key_idx
, int set_tx
,
4151 const u8
*seq
, size_t seq_len
,
4152 const u8
*key
, size_t key_len
)
4154 struct i802_bss
*bss
= priv
;
4155 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4156 int ifindex
= if_nametoindex(ifname
);
4160 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d alg=%d addr=%p key_idx=%d "
4161 "set_tx=%d seq_len=%lu key_len=%lu",
4162 __func__
, ifindex
, alg
, addr
, key_idx
, set_tx
,
4163 (unsigned long) seq_len
, (unsigned long) key_len
);
4167 #endif /* CONFIG_TDLS */
4169 msg
= nlmsg_alloc();
4173 if (alg
== WPA_ALG_NONE
) {
4174 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
4176 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
4177 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
4181 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4182 WLAN_CIPHER_SUITE_WEP40
);
4184 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4185 WLAN_CIPHER_SUITE_WEP104
);
4188 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4189 WLAN_CIPHER_SUITE_TKIP
);
4192 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4193 WLAN_CIPHER_SUITE_CCMP
);
4196 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4197 WLAN_CIPHER_SUITE_AES_CMAC
);
4200 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4201 "algorithm %d", __func__
, alg
);
4208 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
4210 if (addr
&& !is_broadcast_ether_addr(addr
)) {
4211 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
4212 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4214 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
4215 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
4216 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
4217 NL80211_KEYTYPE_GROUP
);
4219 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
4220 struct nl_msg
*types
;
4222 wpa_printf(MSG_DEBUG
, " broadcast key");
4223 types
= nlmsg_alloc();
4225 goto nla_put_failure
;
4226 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4227 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4231 goto nla_put_failure
;
4233 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4234 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4236 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4237 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
4240 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
4241 ret
, strerror(-ret
));
4244 * If we failed or don't need to set the default TX key (below),
4247 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
)
4249 if (is_ap_interface(drv
->nlmode
) && addr
&&
4250 !is_broadcast_ether_addr(addr
))
4253 msg
= nlmsg_alloc();
4257 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
4258 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4259 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4260 if (alg
== WPA_ALG_IGTK
)
4261 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
4263 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
4264 if (addr
&& is_broadcast_ether_addr(addr
)) {
4265 struct nl_msg
*types
;
4267 types
= nlmsg_alloc();
4269 goto nla_put_failure
;
4270 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4271 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4275 goto nla_put_failure
;
4277 struct nl_msg
*types
;
4279 types
= nlmsg_alloc();
4281 goto nla_put_failure
;
4282 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
4283 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4287 goto nla_put_failure
;
4290 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4294 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
4295 "err=%d %s)", ret
, strerror(-ret
));
4304 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
4305 int key_idx
, int defkey
,
4306 const u8
*seq
, size_t seq_len
,
4307 const u8
*key
, size_t key_len
)
4309 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
4313 if (defkey
&& alg
== WPA_ALG_IGTK
)
4314 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
4316 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4318 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
4323 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4324 WLAN_CIPHER_SUITE_WEP40
);
4326 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4327 WLAN_CIPHER_SUITE_WEP104
);
4330 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
4333 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
4336 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4337 WLAN_CIPHER_SUITE_AES_CMAC
);
4340 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4341 "algorithm %d", __func__
, alg
);
4346 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
4348 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
4350 nla_nest_end(msg
, key_attr
);
4358 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
4362 struct nlattr
*nl_keys
, *nl_key
;
4364 for (i
= 0; i
< 4; i
++) {
4365 if (!params
->wep_key
[i
])
4370 if (params
->wps
== WPS_MODE_PRIVACY
)
4372 if (params
->pairwise_suite
&&
4373 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
4379 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
4381 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
4383 goto nla_put_failure
;
4385 for (i
= 0; i
< 4; i
++) {
4386 if (!params
->wep_key
[i
])
4389 nl_key
= nla_nest_start(msg
, i
);
4391 goto nla_put_failure
;
4393 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
4394 params
->wep_key
[i
]);
4395 if (params
->wep_key_len
[i
] == 5)
4396 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4397 WLAN_CIPHER_SUITE_WEP40
);
4399 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4400 WLAN_CIPHER_SUITE_WEP104
);
4402 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
4404 if (i
== params
->wep_tx_keyidx
)
4405 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4407 nla_nest_end(msg
, nl_key
);
4409 nla_nest_end(msg
, nl_keys
);
4418 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
4419 const u8
*addr
, int cmd
, u16 reason_code
,
4420 int local_state_change
)
4425 msg
= nlmsg_alloc();
4429 nl80211_cmd(drv
, msg
, 0, cmd
);
4431 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4432 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
4433 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4434 if (local_state_change
)
4435 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
4437 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4440 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4441 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
4442 reason_code
, ret
, strerror(-ret
));
4443 goto nla_put_failure
;
4453 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
4454 const u8
*addr
, int reason_code
)
4456 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
4457 __func__
, MAC2STR(addr
), reason_code
);
4458 drv
->associated
= 0;
4459 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISCONNECT
,
4464 static int wpa_driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
4467 struct i802_bss
*bss
= priv
;
4468 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4469 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
4470 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
4471 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
4472 __func__
, MAC2STR(addr
), reason_code
);
4473 drv
->associated
= 0;
4474 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
4475 return nl80211_leave_ibss(drv
);
4476 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
4481 static int wpa_driver_nl80211_disassociate(void *priv
, const u8
*addr
,
4484 struct i802_bss
*bss
= priv
;
4485 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4486 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
4487 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
4488 wpa_printf(MSG_DEBUG
, "%s", __func__
);
4489 drv
->associated
= 0;
4490 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISASSOCIATE
,
4495 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
4496 struct wpa_driver_auth_params
*params
)
4500 drv
->auth_freq
= params
->freq
;
4501 drv
->auth_alg
= params
->auth_alg
;
4502 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
4503 drv
->auth_local_state_change
= params
->local_state_change
;
4504 drv
->auth_p2p
= params
->p2p
;
4507 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
4509 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
4512 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
4513 drv
->auth_ssid_len
= params
->ssid_len
;
4515 drv
->auth_ssid_len
= 0;
4518 os_free(drv
->auth_ie
);
4519 drv
->auth_ie
= NULL
;
4520 drv
->auth_ie_len
= 0;
4522 drv
->auth_ie
= os_malloc(params
->ie_len
);
4524 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
4525 drv
->auth_ie_len
= params
->ie_len
;
4529 for (i
= 0; i
< 4; i
++) {
4530 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
4531 params
->wep_key_len
[i
] <= 16) {
4532 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
4533 params
->wep_key_len
[i
]);
4534 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
4536 drv
->auth_wep_key_len
[i
] = 0;
4541 static int wpa_driver_nl80211_authenticate(
4542 void *priv
, struct wpa_driver_auth_params
*params
)
4544 struct i802_bss
*bss
= priv
;
4545 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4548 enum nl80211_auth_type type
;
4549 enum nl80211_iftype nlmode
;
4553 is_retry
= drv
->retry_auth
;
4554 drv
->retry_auth
= 0;
4556 drv
->associated
= 0;
4557 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
4558 /* FIX: IBSS mode */
4559 nlmode
= params
->p2p
?
4560 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
4561 if (drv
->nlmode
!= nlmode
&&
4562 wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
4566 msg
= nlmsg_alloc();
4570 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
4573 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
4575 for (i
= 0; i
< 4; i
++) {
4576 if (!params
->wep_key
[i
])
4578 wpa_driver_nl80211_set_key(bss
->ifname
, priv
, WPA_ALG_WEP
,
4580 i
== params
->wep_tx_keyidx
, NULL
, 0,
4582 params
->wep_key_len
[i
]);
4583 if (params
->wep_tx_keyidx
!= i
)
4585 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
4586 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
4592 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4593 if (params
->bssid
) {
4594 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
4595 MAC2STR(params
->bssid
));
4596 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
4599 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
4600 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
4603 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4604 params
->ssid
, params
->ssid_len
);
4605 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
4608 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
4610 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
4611 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
4612 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
4613 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
4614 type
= NL80211_AUTHTYPE_SHARED_KEY
;
4615 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
4616 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
4617 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
4618 type
= NL80211_AUTHTYPE_FT
;
4620 goto nla_put_failure
;
4621 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
4622 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
4623 if (params
->local_state_change
) {
4624 wpa_printf(MSG_DEBUG
, " * Local state change only");
4625 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
4628 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4631 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4632 "nl80211: MLME command failed (auth): ret=%d (%s)",
4633 ret
, strerror(-ret
));
4635 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
4636 !params
->local_state_change
) {
4638 * mac80211 does not currently accept new
4639 * authentication if we are already authenticated. As a
4640 * workaround, force deauthentication and try again.
4642 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
4643 "after forced deauthentication");
4644 wpa_driver_nl80211_deauthenticate(
4646 WLAN_REASON_PREV_AUTH_NOT_VALID
);
4651 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
4653 * cfg80211 has likely expired the BSS entry even
4654 * though it was previously available in our internal
4655 * BSS table. To recover quickly, start a single
4656 * channel scan on the specified channel.
4658 struct wpa_driver_scan_params scan
;
4661 os_memset(&scan
, 0, sizeof(scan
));
4664 scan
.ssids
[0].ssid
= params
->ssid
;
4665 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
4667 freqs
[0] = params
->freq
;
4670 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
4671 "channel scan to refresh cfg80211 BSS "
4673 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
4675 nl80211_copy_auth_params(drv
, params
);
4676 drv
->scan_for_auth
= 1;
4678 } else if (is_retry
) {
4680 * Need to indicate this with an event since the return
4681 * value from the retry is not delivered to core code.
4683 union wpa_event_data event
;
4684 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
4686 os_memset(&event
, 0, sizeof(event
));
4687 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
4689 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
4693 goto nla_put_failure
;
4696 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
4705 static int wpa_driver_nl80211_authenticate_retry(
4706 struct wpa_driver_nl80211_data
*drv
)
4708 struct wpa_driver_auth_params params
;
4709 struct i802_bss
*bss
= &drv
->first_bss
;
4712 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
4714 os_memset(¶ms
, 0, sizeof(params
));
4715 params
.freq
= drv
->auth_freq
;
4716 params
.auth_alg
= drv
->auth_alg
;
4717 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
4718 params
.local_state_change
= drv
->auth_local_state_change
;
4719 params
.p2p
= drv
->auth_p2p
;
4721 if (!is_zero_ether_addr(drv
->auth_bssid_
))
4722 params
.bssid
= drv
->auth_bssid_
;
4724 if (drv
->auth_ssid_len
) {
4725 params
.ssid
= drv
->auth_ssid
;
4726 params
.ssid_len
= drv
->auth_ssid_len
;
4729 params
.ie
= drv
->auth_ie
;
4730 params
.ie_len
= drv
->auth_ie_len
;
4732 for (i
= 0; i
< 4; i
++) {
4733 if (drv
->auth_wep_key_len
[i
]) {
4734 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
4735 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
4739 drv
->retry_auth
= 1;
4740 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
4744 struct phy_info_arg
{
4746 struct hostapd_hw_modes
*modes
;
4749 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
4751 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
4752 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4753 struct phy_info_arg
*phy_info
= arg
;
4755 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
4757 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
4758 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
4759 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
4760 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
4761 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
4762 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
4763 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
4764 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
4767 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
4768 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
4769 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
4770 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] = { .type
= NLA_FLAG
},
4773 struct nlattr
*nl_band
;
4774 struct nlattr
*nl_freq
;
4775 struct nlattr
*nl_rate
;
4776 int rem_band
, rem_freq
, rem_rate
;
4777 struct hostapd_hw_modes
*mode
;
4778 int idx
, mode_is_set
;
4780 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4781 genlmsg_attrlen(gnlh
, 0), NULL
);
4783 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
4786 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
) {
4787 mode
= os_realloc_array(phy_info
->modes
,
4788 *phy_info
->num_modes
+ 1,
4792 phy_info
->modes
= mode
;
4796 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
4797 memset(mode
, 0, sizeof(*mode
));
4798 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
;
4799 *(phy_info
->num_modes
) += 1;
4801 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
4802 nla_len(nl_band
), NULL
);
4804 if (tb_band
[NL80211_BAND_ATTR_HT_CAPA
]) {
4805 mode
->ht_capab
= nla_get_u16(
4806 tb_band
[NL80211_BAND_ATTR_HT_CAPA
]);
4809 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) {
4810 mode
->a_mpdu_params
|= nla_get_u8(
4811 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) &
4815 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) {
4816 mode
->a_mpdu_params
|= nla_get_u8(
4817 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) <<
4821 if (tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
] &&
4822 nla_len(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
])) {
4824 mcs
= nla_data(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
4825 os_memcpy(mode
->mcs_set
, mcs
, 16);
4828 if (tb_band
[NL80211_BAND_ATTR_VHT_CAPA
]) {
4829 mode
->vht_capab
= nla_get_u32(
4830 tb_band
[NL80211_BAND_ATTR_VHT_CAPA
]);
4833 if (tb_band
[NL80211_BAND_ATTR_VHT_MCS_SET
] &&
4834 nla_len(tb_band
[NL80211_BAND_ATTR_VHT_MCS_SET
])) {
4836 mcs
= nla_data(tb_band
[NL80211_BAND_ATTR_VHT_MCS_SET
]);
4837 os_memcpy(mode
->vht_mcs_set
, mcs
, 8);
4840 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
4841 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
4842 nla_len(nl_freq
), freq_policy
);
4843 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
4845 mode
->num_channels
++;
4848 mode
->channels
= os_calloc(mode
->num_channels
,
4849 sizeof(struct hostapd_channel_data
));
4850 if (!mode
->channels
)
4855 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
4856 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
4857 nla_len(nl_freq
), freq_policy
);
4858 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
4861 mode
->channels
[idx
].freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
4862 mode
->channels
[idx
].flag
= 0;
4865 /* crude heuristic */
4866 if (mode
->channels
[idx
].freq
< 4000)
4867 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
4869 mode
->mode
= HOSTAPD_MODE_IEEE80211A
;
4873 /* crude heuristic */
4874 if (mode
->channels
[idx
].freq
< 4000)
4875 if (mode
->channels
[idx
].freq
== 2484)
4876 mode
->channels
[idx
].chan
= 14;
4878 mode
->channels
[idx
].chan
= (mode
->channels
[idx
].freq
- 2407) / 5;
4880 mode
->channels
[idx
].chan
= mode
->channels
[idx
].freq
/5 - 1000;
4882 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
4883 mode
->channels
[idx
].flag
|=
4884 HOSTAPD_CHAN_DISABLED
;
4885 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
4886 mode
->channels
[idx
].flag
|=
4887 HOSTAPD_CHAN_PASSIVE_SCAN
;
4888 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
4889 mode
->channels
[idx
].flag
|=
4890 HOSTAPD_CHAN_NO_IBSS
;
4891 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
4892 mode
->channels
[idx
].flag
|=
4895 if (tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] &&
4896 !tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
4897 mode
->channels
[idx
].max_tx_power
=
4898 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
]) / 100;
4903 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
4904 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
4905 nla_len(nl_rate
), rate_policy
);
4906 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
4911 mode
->rates
= os_calloc(mode
->num_rates
, sizeof(int));
4917 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
4918 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
4919 nla_len(nl_rate
), rate_policy
);
4920 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
4922 mode
->rates
[idx
] = nla_get_u32(tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
4924 /* crude heuristic */
4925 if (mode
->mode
== HOSTAPD_MODE_IEEE80211B
&&
4926 mode
->rates
[idx
] > 200)
4927 mode
->mode
= HOSTAPD_MODE_IEEE80211G
;
4936 static struct hostapd_hw_modes
*
4937 wpa_driver_nl80211_add_11b(struct hostapd_hw_modes
*modes
, u16
*num_modes
)
4940 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
4941 int i
, mode11g_idx
= -1;
4943 /* If only 802.11g mode is included, use it to construct matching
4944 * 802.11b mode data. */
4946 for (m
= 0; m
< *num_modes
; m
++) {
4947 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
4948 return modes
; /* 802.11b already included */
4949 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
4953 if (mode11g_idx
< 0)
4954 return modes
; /* 2.4 GHz band not supported at all */
4956 nmodes
= os_realloc_array(modes
, *num_modes
+ 1, sizeof(*nmodes
));
4958 return modes
; /* Could not add 802.11b mode */
4960 mode
= &nmodes
[*num_modes
];
4961 os_memset(mode
, 0, sizeof(*mode
));
4965 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
4967 mode11g
= &modes
[mode11g_idx
];
4968 mode
->num_channels
= mode11g
->num_channels
;
4969 mode
->channels
= os_malloc(mode11g
->num_channels
*
4970 sizeof(struct hostapd_channel_data
));
4971 if (mode
->channels
== NULL
) {
4973 return modes
; /* Could not add 802.11b mode */
4975 os_memcpy(mode
->channels
, mode11g
->channels
,
4976 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
4978 mode
->num_rates
= 0;
4979 mode
->rates
= os_malloc(4 * sizeof(int));
4980 if (mode
->rates
== NULL
) {
4981 os_free(mode
->channels
);
4983 return modes
; /* Could not add 802.11b mode */
4986 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
4987 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
4988 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
4990 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
4992 if (mode
->num_rates
== 4)
4996 if (mode
->num_rates
== 0) {
4997 os_free(mode
->channels
);
4998 os_free(mode
->rates
);
5000 return modes
; /* No 802.11b rates */
5003 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
5010 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
5015 for (c
= 0; c
< mode
->num_channels
; c
++) {
5016 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5017 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
5018 chan
->flag
|= HOSTAPD_CHAN_HT40
;
5023 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
5028 for (c
= 0; c
< mode
->num_channels
; c
++) {
5029 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5030 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
5032 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
5033 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
5034 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
5035 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
5040 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
5041 struct phy_info_arg
*results
)
5043 u32 start
, end
, max_bw
;
5046 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
5047 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
5048 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
5051 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
5052 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
5053 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
5055 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
5056 start
, end
, max_bw
);
5060 for (m
= 0; m
< *results
->num_modes
; m
++) {
5061 if (!(results
->modes
[m
].ht_capab
&
5062 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
5064 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
5069 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
5070 struct phy_info_arg
*results
)
5072 u32 start
, end
, max_bw
;
5075 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
5076 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
5077 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
5080 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
5081 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
5082 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
5087 for (m
= 0; m
< *results
->num_modes
; m
++) {
5088 if (!(results
->modes
[m
].ht_capab
&
5089 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
5091 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
5096 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
5098 struct phy_info_arg
*results
= arg
;
5099 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
5100 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5101 struct nlattr
*nl_rule
;
5102 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
5104 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
5105 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
5106 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
5107 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
5108 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
5109 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
5110 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
5113 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5114 genlmsg_attrlen(gnlh
, 0), NULL
);
5115 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
5116 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
5117 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
5122 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
5123 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
5125 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
5127 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
5128 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
5129 nl80211_reg_rule_ht40(tb_rule
, results
);
5132 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
5134 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
5135 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
5136 nl80211_reg_rule_sec(tb_rule
, results
);
5143 static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data
*drv
,
5144 struct phy_info_arg
*results
)
5148 msg
= nlmsg_alloc();
5152 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
5153 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
5157 static struct hostapd_hw_modes
*
5158 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
5160 struct i802_bss
*bss
= priv
;
5161 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5163 struct phy_info_arg result
= {
5164 .num_modes
= num_modes
,
5171 msg
= nlmsg_alloc();
5175 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
5177 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5179 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
5180 nl80211_set_ht40_flags(drv
, &result
);
5181 return wpa_driver_nl80211_add_11b(result
.modes
, num_modes
);
5190 static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data
*drv
,
5191 const void *data
, size_t len
,
5192 int encrypt
, int noack
)
5195 0x00, 0x00, /* radiotap version */
5196 0x0e, 0x00, /* radiotap length */
5197 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
5198 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
5200 0x00, 0x00, /* RX and TX flags to indicate that */
5201 0x00, 0x00, /* this is the injected frame directly */
5203 struct iovec iov
[2] = {
5205 .iov_base
= &rtap_hdr
,
5206 .iov_len
= sizeof(rtap_hdr
),
5209 .iov_base
= (void *) data
,
5213 struct msghdr msg
= {
5218 .msg_control
= NULL
,
5219 .msg_controllen
= 0,
5226 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
5228 if (drv
->monitor_sock
< 0) {
5229 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
5230 "for %s", __func__
);
5235 txflags
|= IEEE80211_RADIOTAP_F_TX_NOACK
;
5236 *(le16
*) &rtap_hdr
[12] = host_to_le16(txflags
);
5238 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
5240 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
5247 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
5248 const void *data
, size_t len
,
5249 int encrypt
, int noack
,
5250 unsigned int freq
, int no_cck
,
5251 int offchanok
, unsigned int wait_time
)
5253 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5259 if (drv
->use_monitor
)
5260 return wpa_driver_nl80211_send_mntr(drv
, data
, len
,
5263 return nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
5264 &cookie
, no_cck
, noack
, offchanok
);
5268 static int wpa_driver_nl80211_send_mlme_freq(struct i802_bss
*bss
,
5270 size_t data_len
, int noack
,
5271 unsigned int freq
, int no_cck
,
5273 unsigned int wait_time
)
5275 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5276 struct ieee80211_mgmt
*mgmt
;
5280 mgmt
= (struct ieee80211_mgmt
*) data
;
5281 fc
= le_to_host16(mgmt
->frame_control
);
5283 if (is_sta_interface(drv
->nlmode
) &&
5284 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5285 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
5287 * The use of last_mgmt_freq is a bit of a hack,
5288 * but it works due to the single-threaded nature
5289 * of wpa_supplicant.
5292 freq
= drv
->last_mgmt_freq
;
5293 return nl80211_send_frame_cmd(bss
, freq
, 0,
5294 data
, data_len
, NULL
, 1, noack
,
5298 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
5301 return nl80211_send_frame_cmd(bss
, freq
,
5302 (int) freq
== bss
->freq
? 0 :
5305 &drv
->send_action_cookie
,
5306 no_cck
, noack
, offchanok
);
5309 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5310 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
5312 * Only one of the authentication frame types is encrypted.
5313 * In order for static WEP encryption to work properly (i.e.,
5314 * to not encrypt the frame), we need to tell mac80211 about
5315 * the frames that must not be encrypted.
5317 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
5318 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
5319 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
5323 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
5324 noack
, freq
, no_cck
, offchanok
,
5329 static int wpa_driver_nl80211_send_mlme(void *priv
, const u8
*data
,
5330 size_t data_len
, int noack
)
5332 struct i802_bss
*bss
= priv
;
5333 return wpa_driver_nl80211_send_mlme_freq(bss
, data
, data_len
, noack
,
5338 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
5339 int slot
, int ht_opmode
, int ap_isolate
,
5342 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5345 msg
= nlmsg_alloc();
5349 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
5352 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
5354 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
5356 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
5358 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
5359 if (ap_isolate
>= 0)
5360 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
);
5363 u8 rates
[NL80211_MAX_SUPP_RATES
];
5367 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0;
5369 rates
[rates_len
++] = basic_rates
[i
] / 5;
5371 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
5374 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5376 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5383 static int wpa_driver_nl80211_set_ap(void *priv
,
5384 struct wpa_driver_ap_params
*params
)
5386 struct i802_bss
*bss
= priv
;
5387 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5389 u8 cmd
= NL80211_CMD_NEW_BEACON
;
5392 int ifindex
= if_nametoindex(bss
->ifname
);
5397 beacon_set
= bss
->beacon_set
;
5399 msg
= nlmsg_alloc();
5403 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
5406 cmd
= NL80211_CMD_SET_BEACON
;
5408 nl80211_cmd(drv
, msg
, 0, cmd
);
5409 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
5410 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
5411 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5412 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
5413 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
5414 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5416 if (params
->proberesp
&& params
->proberesp_len
)
5417 NLA_PUT(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
5419 switch (params
->hide_ssid
) {
5420 case NO_SSID_HIDING
:
5421 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5422 NL80211_HIDDEN_SSID_NOT_IN_USE
);
5424 case HIDDEN_SSID_ZERO_LEN
:
5425 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5426 NL80211_HIDDEN_SSID_ZERO_LEN
);
5428 case HIDDEN_SSID_ZERO_CONTENTS
:
5429 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5430 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
5433 if (params
->privacy
)
5434 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
5435 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
5436 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
5437 /* Leave out the attribute */
5438 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
5439 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
5440 NL80211_AUTHTYPE_SHARED_KEY
);
5442 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
5443 NL80211_AUTHTYPE_OPEN_SYSTEM
);
5446 if (params
->wpa_version
& WPA_PROTO_WPA
)
5447 ver
|= NL80211_WPA_VERSION_1
;
5448 if (params
->wpa_version
& WPA_PROTO_RSN
)
5449 ver
|= NL80211_WPA_VERSION_2
;
5451 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
5454 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
5455 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
5456 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
5457 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
5459 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
5460 num_suites
* sizeof(u32
), suites
);
5463 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
&&
5464 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
))
5465 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
);
5468 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
5469 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
5470 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
5471 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
5472 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
5473 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
5474 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
5475 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
5477 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
5478 num_suites
* sizeof(u32
), suites
);
5481 switch (params
->group_cipher
) {
5482 case WPA_CIPHER_CCMP
:
5483 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5484 WLAN_CIPHER_SUITE_CCMP
);
5486 case WPA_CIPHER_TKIP
:
5487 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5488 WLAN_CIPHER_SUITE_TKIP
);
5490 case WPA_CIPHER_WEP104
:
5491 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5492 WLAN_CIPHER_SUITE_WEP104
);
5494 case WPA_CIPHER_WEP40
:
5495 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5496 WLAN_CIPHER_SUITE_WEP40
);
5500 if (params
->beacon_ies
) {
5501 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
5502 wpabuf_head(params
->beacon_ies
));
5504 if (params
->proberesp_ies
) {
5505 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
5506 wpabuf_len(params
->proberesp_ies
),
5507 wpabuf_head(params
->proberesp_ies
));
5509 if (params
->assocresp_ies
) {
5510 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
5511 wpabuf_len(params
->assocresp_ies
),
5512 wpabuf_head(params
->assocresp_ies
));
5515 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
5516 NLA_PUT_U16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
5517 params
->ap_max_inactivity
);
5520 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5522 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
5523 ret
, strerror(-ret
));
5525 bss
->beacon_set
= 1;
5526 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
5527 params
->short_slot_time
, params
->ht_opmode
,
5528 params
->isolate
, params
->basic_rates
);
5537 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
5538 int freq
, int ht_enabled
,
5539 int sec_channel_offset
)
5541 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5545 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d "
5546 "sec_channel_offset=%d)",
5547 freq
, ht_enabled
, sec_channel_offset
);
5548 msg
= nlmsg_alloc();
5552 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
5554 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5555 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5557 switch (sec_channel_offset
) {
5559 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5560 NL80211_CHAN_HT40MINUS
);
5563 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5564 NL80211_CHAN_HT40PLUS
);
5567 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5573 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5579 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
5580 "%d (%s)", freq
, ret
, strerror(-ret
));
5587 static u32
sta_flags_nl80211(int flags
)
5591 if (flags
& WPA_STA_AUTHORIZED
)
5592 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5593 if (flags
& WPA_STA_WMM
)
5594 f
|= BIT(NL80211_STA_FLAG_WME
);
5595 if (flags
& WPA_STA_SHORT_PREAMBLE
)
5596 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
5597 if (flags
& WPA_STA_MFP
)
5598 f
|= BIT(NL80211_STA_FLAG_MFP
);
5599 if (flags
& WPA_STA_TDLS_PEER
)
5600 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
5606 static int wpa_driver_nl80211_sta_add(void *priv
,
5607 struct hostapd_sta_add_params
*params
)
5609 struct i802_bss
*bss
= priv
;
5610 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5611 struct nl_msg
*msg
, *wme
= NULL
;
5612 struct nl80211_sta_flag_update upd
;
5615 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
5616 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
5619 msg
= nlmsg_alloc();
5623 nl80211_cmd(drv
, msg
, 0, params
->set
? NL80211_CMD_SET_STATION
:
5624 NL80211_CMD_NEW_STATION
);
5626 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5627 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
5628 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
5629 params
->supp_rates
);
5631 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
5632 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
5633 params
->listen_interval
);
5635 if (params
->ht_capabilities
) {
5636 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
5637 sizeof(*params
->ht_capabilities
),
5638 params
->ht_capabilities
);
5641 os_memset(&upd
, 0, sizeof(upd
));
5642 upd
.mask
= sta_flags_nl80211(params
->flags
);
5644 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
5646 if (params
->flags
& WPA_STA_WMM
) {
5647 wme
= nlmsg_alloc();
5649 goto nla_put_failure
;
5651 NLA_PUT_U8(wme
, NL80211_STA_WME_UAPSD_QUEUES
,
5652 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
);
5653 NLA_PUT_U8(wme
, NL80211_STA_WME_MAX_SP
,
5654 (params
->qosinfo
> WMM_QOSINFO_STA_SP_SHIFT
) &
5655 WMM_QOSINFO_STA_SP_MASK
);
5656 if (nla_put_nested(msg
, NL80211_ATTR_STA_WME
, wme
) < 0)
5657 goto nla_put_failure
;
5660 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5663 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
5664 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
5675 static int wpa_driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
5677 struct i802_bss
*bss
= priv
;
5678 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5682 msg
= nlmsg_alloc();
5686 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
5688 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5689 if_nametoindex(bss
->ifname
));
5690 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5692 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5702 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
5707 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
5709 /* stop listening for EAPOL on this interface */
5710 del_ifidx(drv
, ifidx
);
5712 msg
= nlmsg_alloc();
5714 goto nla_put_failure
;
5716 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
5717 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
5719 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
5724 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
5728 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
5731 case NL80211_IFTYPE_ADHOC
:
5733 case NL80211_IFTYPE_STATION
:
5735 case NL80211_IFTYPE_AP
:
5737 case NL80211_IFTYPE_MONITOR
:
5739 case NL80211_IFTYPE_P2P_CLIENT
:
5740 return "P2P_CLIENT";
5741 case NL80211_IFTYPE_P2P_GO
:
5749 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
5751 enum nl80211_iftype iftype
,
5752 const u8
*addr
, int wds
)
5754 struct nl_msg
*msg
, *flags
= NULL
;
5758 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
5759 iftype
, nl80211_iftype_str(iftype
));
5761 msg
= nlmsg_alloc();
5765 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
5766 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5767 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
5768 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
5770 if (iftype
== NL80211_IFTYPE_MONITOR
) {
5773 flags
= nlmsg_alloc();
5775 goto nla_put_failure
;
5777 NLA_PUT_FLAG(flags
, NL80211_MNTR_FLAG_COOK_FRAMES
);
5779 err
= nla_put_nested(msg
, NL80211_ATTR_MNTR_FLAGS
, flags
);
5784 goto nla_put_failure
;
5786 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
5789 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5794 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
5795 ifname
, ret
, strerror(-ret
));
5799 ifidx
= if_nametoindex(ifname
);
5800 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
5806 /* start listening for EAPOL on this interface */
5807 add_ifidx(drv
, ifidx
);
5809 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
5810 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
5811 nl80211_remove_iface(drv
, ifidx
);
5819 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
5820 const char *ifname
, enum nl80211_iftype iftype
,
5821 const u8
*addr
, int wds
)
5825 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
);
5827 /* if error occurred and interface exists already */
5828 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
5829 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
5831 /* Try to remove the interface that was already there. */
5832 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
5834 /* Try to create the interface again */
5835 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
5839 if (ret
>= 0 && is_p2p_interface(iftype
))
5840 nl80211_disable_11b_rates(drv
, ret
, 1);
5846 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
5848 struct ieee80211_hdr
*hdr
;
5850 union wpa_event_data event
;
5852 hdr
= (struct ieee80211_hdr
*) buf
;
5853 fc
= le_to_host16(hdr
->frame_control
);
5855 os_memset(&event
, 0, sizeof(event
));
5856 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
5857 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
5858 event
.tx_status
.dst
= hdr
->addr1
;
5859 event
.tx_status
.data
= buf
;
5860 event
.tx_status
.data_len
= len
;
5861 event
.tx_status
.ack
= ok
;
5862 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
5866 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
5867 u8
*buf
, size_t len
)
5869 struct ieee80211_hdr
*hdr
= (void *)buf
;
5871 union wpa_event_data event
;
5873 if (len
< sizeof(*hdr
))
5876 fc
= le_to_host16(hdr
->frame_control
);
5878 os_memset(&event
, 0, sizeof(event
));
5879 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
5880 event
.rx_from_unknown
.addr
= hdr
->addr2
;
5881 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
5882 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
5883 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
5887 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
5888 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
5890 struct ieee80211_hdr
*hdr
;
5892 union wpa_event_data event
;
5894 hdr
= (struct ieee80211_hdr
*) buf
;
5895 fc
= le_to_host16(hdr
->frame_control
);
5897 switch (WLAN_FC_GET_TYPE(fc
)) {
5898 case WLAN_FC_TYPE_MGMT
:
5899 os_memset(&event
, 0, sizeof(event
));
5900 event
.rx_mgmt
.frame
= buf
;
5901 event
.rx_mgmt
.frame_len
= len
;
5902 event
.rx_mgmt
.datarate
= datarate
;
5903 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
5904 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
5906 case WLAN_FC_TYPE_CTRL
:
5907 /* can only get here with PS-Poll frames */
5908 wpa_printf(MSG_DEBUG
, "CTRL");
5909 from_unknown_sta(drv
, buf
, len
);
5911 case WLAN_FC_TYPE_DATA
:
5912 from_unknown_sta(drv
, buf
, len
);
5918 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
5920 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
5922 unsigned char buf
[3000];
5923 struct ieee80211_radiotap_iterator iter
;
5925 int datarate
= 0, ssi_signal
= 0;
5926 int injected
= 0, failed
= 0, rxflags
= 0;
5928 len
= recv(sock
, buf
, sizeof(buf
), 0);
5934 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
5935 printf("received invalid radiotap frame\n");
5940 ret
= ieee80211_radiotap_iterator_next(&iter
);
5944 printf("received invalid radiotap frame (%d)\n", ret
);
5947 switch (iter
.this_arg_index
) {
5948 case IEEE80211_RADIOTAP_FLAGS
:
5949 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
5952 case IEEE80211_RADIOTAP_RX_FLAGS
:
5955 case IEEE80211_RADIOTAP_TX_FLAGS
:
5957 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
5958 IEEE80211_RADIOTAP_F_TX_FAIL
;
5960 case IEEE80211_RADIOTAP_DATA_RETRIES
:
5962 case IEEE80211_RADIOTAP_CHANNEL
:
5963 /* TODO: convert from freq/flags to channel number */
5965 case IEEE80211_RADIOTAP_RATE
:
5966 datarate
= *iter
.this_arg
* 5;
5968 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
5969 ssi_signal
= (s8
) *iter
.this_arg
;
5974 if (rxflags
&& injected
)
5978 handle_frame(drv
, buf
+ iter
.max_length
,
5979 len
- iter
.max_length
, datarate
, ssi_signal
);
5981 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
5982 len
- iter
.max_length
, !failed
);
5987 * we post-process the filter code later and rewrite
5988 * this to the offset to the last instruction
5993 static struct sock_filter msock_filter_insns
[] = {
5995 * do a little-endian load of the radiotap length field
5997 /* load lower byte into A */
5998 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
5999 /* put it into X (== index register) */
6000 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6001 /* load upper byte into A */
6002 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
6003 /* left-shift it by 8 */
6004 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
6006 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
6007 /* put result into X */
6008 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6011 * Allow management frames through, this also gives us those
6012 * management frames that we sent ourselves with status
6014 /* load the lower byte of the IEEE 802.11 frame control field */
6015 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6016 /* mask off frame type and version */
6017 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
6018 /* accept frame if it's both 0, fall through otherwise */
6019 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
6022 * TODO: add a bit to radiotap RX flags that indicates
6023 * that the sending station is not associated, then
6024 * add a filter here that filters on our DA and that flag
6025 * to allow us to deauth frames to that bad station.
6027 * For now allow all To DS data frames through.
6029 /* load the IEEE 802.11 frame control field */
6030 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
6031 /* mask off frame type, version and DS status */
6032 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
6033 /* accept frame if version 0, type 2 and To DS, fall through otherwise
6035 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
6039 * drop non-data frames
6041 /* load the lower byte of the frame control field */
6042 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6043 /* mask off QoS bit */
6044 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
6045 /* drop non-data frames */
6046 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
6048 /* load the upper byte of the frame control field */
6049 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
6050 /* mask off toDS/fromDS */
6051 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
6052 /* accept WDS frames */
6053 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
6056 * add header length to index
6058 /* load the lower byte of the frame control field */
6059 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6060 /* mask off QoS bit */
6061 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
6062 /* right shift it by 6 to give 0 or 2 */
6063 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
6064 /* add data frame header length */
6065 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
6066 /* add index, was start of 802.11 header */
6067 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
6068 /* move to index, now start of LL header */
6069 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6072 * Accept empty data frames, we use those for
6075 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
6076 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
6079 * Accept EAPOL frames
6081 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
6082 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
6083 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
6084 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
6086 /* keep these last two statements or change the code below */
6087 /* return 0 == "DROP" */
6088 BPF_STMT(BPF_RET
| BPF_K
, 0),
6089 /* return ~0 == "keep all" */
6090 BPF_STMT(BPF_RET
| BPF_K
, ~0),
6093 static struct sock_fprog msock_filter
= {
6094 .len
= sizeof(msock_filter_insns
)/sizeof(msock_filter_insns
[0]),
6095 .filter
= msock_filter_insns
,
6099 static int add_monitor_filter(int s
)
6103 /* rewrite all PASS/FAIL jump offsets */
6104 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
6105 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
6107 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
6108 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
6109 if (insn
->k
== PASS
)
6110 insn
->k
= msock_filter
.len
- idx
- 2;
6111 else if (insn
->k
== FAIL
)
6112 insn
->k
= msock_filter
.len
- idx
- 3;
6115 if (insn
->jt
== PASS
)
6116 insn
->jt
= msock_filter
.len
- idx
- 2;
6117 else if (insn
->jt
== FAIL
)
6118 insn
->jt
= msock_filter
.len
- idx
- 3;
6120 if (insn
->jf
== PASS
)
6121 insn
->jf
= msock_filter
.len
- idx
- 2;
6122 else if (insn
->jf
== FAIL
)
6123 insn
->jf
= msock_filter
.len
- idx
- 3;
6127 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
6128 &msock_filter
, sizeof(msock_filter
))) {
6129 perror("SO_ATTACH_FILTER");
6137 static void nl80211_remove_monitor_interface(
6138 struct wpa_driver_nl80211_data
*drv
)
6140 drv
->monitor_refcount
--;
6141 if (drv
->monitor_refcount
> 0)
6144 if (drv
->monitor_ifidx
>= 0) {
6145 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
6146 drv
->monitor_ifidx
= -1;
6148 if (drv
->monitor_sock
>= 0) {
6149 eloop_unregister_read_sock(drv
->monitor_sock
);
6150 close(drv
->monitor_sock
);
6151 drv
->monitor_sock
= -1;
6157 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
6160 struct sockaddr_ll ll
;
6164 if (drv
->monitor_ifidx
>= 0) {
6165 drv
->monitor_refcount
++;
6169 if (os_strncmp(drv
->first_bss
.ifname
, "p2p-", 4) == 0) {
6171 * P2P interface name is of the format p2p-%s-%d. For monitor
6172 * interface name corresponding to P2P GO, replace "p2p-" with
6173 * "mon-" to retain the same interface name length and to
6174 * indicate that it is a monitor interface.
6176 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
.ifname
+ 4);
6178 /* Non-P2P interface with AP functionality. */
6179 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
.ifname
);
6182 buf
[IFNAMSIZ
- 1] = '\0';
6184 drv
->monitor_ifidx
=
6185 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
6188 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
6190 * This is backward compatibility for a few versions of
6191 * the kernel only that didn't advertise the right
6192 * attributes for the only driver that then supported
6193 * AP mode w/o monitor -- ath6kl.
6195 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
6196 "monitor interface type - try to run without it");
6197 drv
->device_ap_sme
= 1;
6200 if (drv
->monitor_ifidx
< 0)
6203 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
6206 memset(&ll
, 0, sizeof(ll
));
6207 ll
.sll_family
= AF_PACKET
;
6208 ll
.sll_ifindex
= drv
->monitor_ifidx
;
6209 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
6210 if (drv
->monitor_sock
< 0) {
6211 perror("socket[PF_PACKET,SOCK_RAW]");
6215 if (add_monitor_filter(drv
->monitor_sock
)) {
6216 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
6217 "interface; do filtering in user space");
6218 /* This works, but will cost in performance. */
6221 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
6222 perror("monitor socket bind");
6226 optlen
= sizeof(optval
);
6229 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
6230 perror("Failed to set socket priority");
6234 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
6236 printf("Could not register monitor read socket\n");
6242 nl80211_remove_monitor_interface(drv
);
6247 static int nl80211_setup_ap(struct i802_bss
*bss
)
6249 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6251 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP - device_ap_sme=%d "
6252 "use_monitor=%d", drv
->device_ap_sme
, drv
->use_monitor
);
6255 * Disable Probe Request reporting unless we need it in this way for
6256 * devices that include the AP SME, in the other case (unless using
6257 * monitor iface) we'll get it through the nl_mgmt socket instead.
6259 if (!drv
->device_ap_sme
)
6260 wpa_driver_nl80211_probe_req_report(bss
, 0);
6262 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
6263 if (nl80211_mgmt_subscribe_ap(bss
))
6266 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
6267 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
6270 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
6271 nl80211_create_monitor_interface(drv
) &&
6272 !drv
->device_ap_sme
)
6275 if (drv
->device_ap_sme
&&
6276 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
6277 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
6278 "Probe Request frame reporting in AP mode");
6279 /* Try to survive without this */
6286 static void nl80211_teardown_ap(struct i802_bss
*bss
)
6288 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6290 if (drv
->device_ap_sme
) {
6291 wpa_driver_nl80211_probe_req_report(bss
, 0);
6292 if (!drv
->use_monitor
)
6293 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
6294 } else if (drv
->use_monitor
)
6295 nl80211_remove_monitor_interface(drv
);
6297 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
6299 bss
->beacon_set
= 0;
6303 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
6304 const u8
*addr
, const u8
*data
,
6307 struct sockaddr_ll ll
;
6310 if (bss
->drv
->eapol_tx_sock
< 0) {
6311 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
6315 os_memset(&ll
, 0, sizeof(ll
));
6316 ll
.sll_family
= AF_PACKET
;
6317 ll
.sll_ifindex
= bss
->ifindex
;
6318 ll
.sll_protocol
= htons(ETH_P_PAE
);
6319 ll
.sll_halen
= ETH_ALEN
;
6320 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
6321 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
6322 (struct sockaddr
*) &ll
, sizeof(ll
));
6324 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
6331 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
6333 static int wpa_driver_nl80211_hapd_send_eapol(
6334 void *priv
, const u8
*addr
, const u8
*data
,
6335 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
6337 struct i802_bss
*bss
= priv
;
6338 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6339 struct ieee80211_hdr
*hdr
;
6343 int qos
= flags
& WPA_STA_WMM
;
6345 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
6346 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
6348 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
6350 hdr
= os_zalloc(len
);
6352 printf("malloc() failed for i802_send_data(len=%lu)\n",
6353 (unsigned long) len
);
6357 hdr
->frame_control
=
6358 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
6359 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
6361 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
6363 hdr
->frame_control
|=
6364 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
6367 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
6368 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
6369 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
6370 pos
= (u8
*) (hdr
+ 1);
6373 /* add an empty QoS header if needed */
6379 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
6380 pos
+= sizeof(rfc1042_header
);
6381 WPA_PUT_BE16(pos
, ETH_P_PAE
);
6383 memcpy(pos
, data
, data_len
);
6385 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
6388 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
6390 (unsigned long) len
, errno
, strerror(errno
));
6398 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
6400 int flags_or
, int flags_and
)
6402 struct i802_bss
*bss
= priv
;
6403 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6404 struct nl_msg
*msg
, *flags
= NULL
;
6405 struct nl80211_sta_flag_update upd
;
6407 msg
= nlmsg_alloc();
6411 flags
= nlmsg_alloc();
6417 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
6419 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6420 if_nametoindex(bss
->ifname
));
6421 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6424 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
6425 * can be removed eventually.
6427 if (total_flags
& WPA_STA_AUTHORIZED
)
6428 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_AUTHORIZED
);
6430 if (total_flags
& WPA_STA_WMM
)
6431 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_WME
);
6433 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
6434 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
6436 if (total_flags
& WPA_STA_MFP
)
6437 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_MFP
);
6439 if (total_flags
& WPA_STA_TDLS_PEER
)
6440 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_TDLS_PEER
);
6442 if (nla_put_nested(msg
, NL80211_ATTR_STA_FLAGS
, flags
))
6443 goto nla_put_failure
;
6445 os_memset(&upd
, 0, sizeof(upd
));
6446 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
6447 upd
.set
= sta_flags_nl80211(flags_or
);
6448 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6452 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6460 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
6461 struct wpa_driver_associate_params
*params
)
6463 enum nl80211_iftype nlmode
;
6466 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
6468 nlmode
= NL80211_IFTYPE_P2P_GO
;
6470 nlmode
= NL80211_IFTYPE_AP
;
6472 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
, nlmode
) ||
6473 wpa_driver_nl80211_set_freq(&drv
->first_bss
, params
->freq
, 0, 0)) {
6474 nl80211_remove_monitor_interface(drv
);
6482 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
6487 msg
= nlmsg_alloc();
6491 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
6492 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6493 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6496 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
6497 "(%s)", ret
, strerror(-ret
));
6498 goto nla_put_failure
;
6502 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
6510 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
6511 struct wpa_driver_associate_params
*params
)
6517 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
6519 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
6520 NL80211_IFTYPE_ADHOC
)) {
6521 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
6527 msg
= nlmsg_alloc();
6531 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
6532 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6534 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
6535 goto nla_put_failure
;
6537 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6538 params
->ssid
, params
->ssid_len
);
6539 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6541 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6542 drv
->ssid_len
= params
->ssid_len
;
6544 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6545 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6547 ret
= nl80211_set_conn_keys(params
, msg
);
6549 goto nla_put_failure
;
6551 if (params
->bssid
&& params
->fixed_bssid
) {
6552 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
6553 MAC2STR(params
->bssid
));
6554 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
6557 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
6558 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
6559 params
->key_mgmt_suite
== KEY_MGMT_802_1X_SHA256
||
6560 params
->key_mgmt_suite
== KEY_MGMT_PSK_SHA256
) {
6561 wpa_printf(MSG_DEBUG
, " * control port");
6562 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
6565 if (params
->wpa_ie
) {
6566 wpa_hexdump(MSG_DEBUG
,
6567 " * Extra IEs for Beacon/Probe Response frames",
6568 params
->wpa_ie
, params
->wpa_ie_len
);
6569 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6573 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6576 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
6577 ret
, strerror(-ret
));
6579 if (ret
== -EALREADY
&& count
== 1) {
6580 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
6582 nl80211_leave_ibss(drv
);
6587 goto nla_put_failure
;
6590 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
6598 static unsigned int nl80211_get_assoc_bssid(struct wpa_driver_nl80211_data
*drv
,
6603 struct nl80211_bss_info_arg arg
;
6605 os_memset(&arg
, 0, sizeof(arg
));
6606 msg
= nlmsg_alloc();
6608 goto nla_put_failure
;
6610 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
6611 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6614 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
6617 if (is_zero_ether_addr(arg
.assoc_bssid
))
6619 os_memcpy(bssid
, arg
.assoc_bssid
, ETH_ALEN
);
6622 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
6623 "(%s)", ret
, strerror(-ret
));
6626 return drv
->assoc_freq
;
6630 static int nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
6635 if (bssid
== NULL
) {
6636 int res
= nl80211_get_assoc_bssid(drv
, addr
);
6642 return wpa_driver_nl80211_disconnect(drv
, bssid
,
6643 WLAN_REASON_PREV_AUTH_NOT_VALID
);
6647 static int wpa_driver_nl80211_connect(
6648 struct wpa_driver_nl80211_data
*drv
,
6649 struct wpa_driver_associate_params
*params
)
6652 enum nl80211_auth_type type
;
6656 msg
= nlmsg_alloc();
6660 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
6661 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
6663 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6664 if (params
->bssid
) {
6665 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
6666 MAC2STR(params
->bssid
));
6667 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
6670 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6671 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6673 if (params
->bg_scan_period
>= 0) {
6674 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
6675 params
->bg_scan_period
);
6676 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
6677 params
->bg_scan_period
);
6680 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6681 params
->ssid
, params
->ssid_len
);
6682 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6684 if (params
->ssid_len
> sizeof(drv
->ssid
))
6685 goto nla_put_failure
;
6686 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6687 drv
->ssid_len
= params
->ssid_len
;
6689 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
6691 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6695 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
6697 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
6699 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
6702 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
6704 goto skip_auth_type
;
6707 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
6708 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
6709 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
6710 type
= NL80211_AUTHTYPE_SHARED_KEY
;
6711 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
6712 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
6713 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
6714 type
= NL80211_AUTHTYPE_FT
;
6716 goto nla_put_failure
;
6718 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
6719 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
6722 if (params
->wpa_proto
) {
6723 enum nl80211_wpa_versions ver
= 0;
6725 if (params
->wpa_proto
& WPA_PROTO_WPA
)
6726 ver
|= NL80211_WPA_VERSION_1
;
6727 if (params
->wpa_proto
& WPA_PROTO_RSN
)
6728 ver
|= NL80211_WPA_VERSION_2
;
6730 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
6731 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
6734 if (params
->pairwise_suite
!= CIPHER_NONE
) {
6737 switch (params
->pairwise_suite
) {
6739 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6742 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6745 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6749 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6752 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
6755 if (params
->group_suite
!= CIPHER_NONE
) {
6758 switch (params
->group_suite
) {
6760 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6763 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6766 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6770 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6773 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
6776 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
6777 params
->key_mgmt_suite
== KEY_MGMT_PSK
) {
6778 int mgmt
= WLAN_AKM_SUITE_PSK
;
6780 switch (params
->key_mgmt_suite
) {
6781 case KEY_MGMT_802_1X
:
6782 mgmt
= WLAN_AKM_SUITE_8021X
;
6786 mgmt
= WLAN_AKM_SUITE_PSK
;
6789 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
6792 if (params
->disable_ht
)
6793 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
6795 if (params
->htcaps
&& params
->htcaps_mask
) {
6796 int sz
= sizeof(struct ieee80211_ht_capabilities
);
6797 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
6798 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
6799 params
->htcaps_mask
);
6802 ret
= nl80211_set_conn_keys(params
, msg
);
6804 goto nla_put_failure
;
6806 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6809 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
6810 "(%s)", ret
, strerror(-ret
));
6812 * cfg80211 does not currently accept new connection if we are
6813 * already connected. As a workaround, force disconnection and
6814 * try again once the driver indicates it completed
6817 if (ret
== -EALREADY
)
6818 nl80211_disconnect(drv
, params
->bssid
);
6819 goto nla_put_failure
;
6822 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
6831 static int wpa_driver_nl80211_associate(
6832 void *priv
, struct wpa_driver_associate_params
*params
)
6834 struct i802_bss
*bss
= priv
;
6835 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6839 if (params
->mode
== IEEE80211_MODE_AP
)
6840 return wpa_driver_nl80211_ap(drv
, params
);
6842 if (params
->mode
== IEEE80211_MODE_IBSS
)
6843 return wpa_driver_nl80211_ibss(drv
, params
);
6845 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
6846 enum nl80211_iftype nlmode
= params
->p2p
?
6847 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
6849 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
6851 return wpa_driver_nl80211_connect(drv
, params
);
6854 drv
->associated
= 0;
6856 msg
= nlmsg_alloc();
6860 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
6862 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
6864 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6865 if (params
->bssid
) {
6866 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
6867 MAC2STR(params
->bssid
));
6868 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
6871 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6872 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6873 drv
->assoc_freq
= params
->freq
;
6875 drv
->assoc_freq
= 0;
6876 if (params
->bg_scan_period
>= 0) {
6877 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
6878 params
->bg_scan_period
);
6879 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
6880 params
->bg_scan_period
);
6883 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6884 params
->ssid
, params
->ssid_len
);
6885 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6887 if (params
->ssid_len
> sizeof(drv
->ssid
))
6888 goto nla_put_failure
;
6889 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6890 drv
->ssid_len
= params
->ssid_len
;
6892 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
6894 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6897 if (params
->pairwise_suite
!= CIPHER_NONE
) {
6900 switch (params
->pairwise_suite
) {
6902 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6905 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6908 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6912 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6915 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
6916 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
6919 if (params
->group_suite
!= CIPHER_NONE
) {
6922 switch (params
->group_suite
) {
6924 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6927 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6930 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6934 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6937 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
6938 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
6941 #ifdef CONFIG_IEEE80211W
6942 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
6943 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
6944 #endif /* CONFIG_IEEE80211W */
6946 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
6948 if (params
->prev_bssid
) {
6949 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
6950 MAC2STR(params
->prev_bssid
));
6951 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
6952 params
->prev_bssid
);
6955 if (params
->disable_ht
)
6956 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
6958 if (params
->htcaps
&& params
->htcaps_mask
) {
6959 int sz
= sizeof(struct ieee80211_ht_capabilities
);
6960 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
6961 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
6962 params
->htcaps_mask
);
6966 wpa_printf(MSG_DEBUG
, " * P2P group");
6968 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6971 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
6972 "nl80211: MLME command failed (assoc): ret=%d (%s)",
6973 ret
, strerror(-ret
));
6974 nl80211_dump_scan(drv
);
6975 goto nla_put_failure
;
6978 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
6987 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
6988 int ifindex
, enum nl80211_iftype mode
)
6993 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
6994 ifindex
, mode
, nl80211_iftype_str(mode
));
6996 msg
= nlmsg_alloc();
7000 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
7001 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
7002 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
7004 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7010 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
7011 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
7016 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
7017 enum nl80211_iftype nlmode
)
7019 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7022 int was_ap
= is_ap_interface(drv
->nlmode
);
7025 res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
7027 drv
->nlmode
= nlmode
;
7035 if (nlmode
== drv
->nlmode
) {
7036 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
7037 "requested mode - ignore error");
7039 goto done
; /* Already in the requested mode */
7042 /* mac80211 doesn't allow mode changes while the device is up, so
7043 * take the device down, try to set the mode again, and bring the
7046 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
7048 for (i
= 0; i
< 10; i
++) {
7049 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
7051 if (res
== -EACCES
|| res
== -ENODEV
)
7054 /* Try to set the mode again while the interface is
7056 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
7059 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
7063 else if (ret
!= -EBUSY
)
7066 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
7068 os_sleep(0, 100000);
7072 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
7073 "interface is down");
7074 drv
->nlmode
= nlmode
;
7075 drv
->ignore_if_down_event
= 1;
7080 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
7081 "from %d failed", nlmode
, drv
->nlmode
);
7085 if (is_p2p_interface(nlmode
))
7086 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
7087 else if (drv
->disabled_11b_rates
)
7088 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
7090 if (is_ap_interface(nlmode
)) {
7091 nl80211_mgmt_unsubscribe(bss
, "start AP");
7092 /* Setup additional AP mode functionality if needed */
7093 if (nl80211_setup_ap(bss
))
7095 } else if (was_ap
) {
7096 /* Remove additional AP mode functionality */
7097 nl80211_teardown_ap(bss
);
7099 nl80211_mgmt_unsubscribe(bss
, "mode change");
7102 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
7103 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
7104 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
7105 "frame processing - ignore for now");
7111 static int wpa_driver_nl80211_get_capa(void *priv
,
7112 struct wpa_driver_capa
*capa
)
7114 struct i802_bss
*bss
= priv
;
7115 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7116 if (!drv
->has_capability
)
7118 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
7123 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
7125 struct i802_bss
*bss
= priv
;
7126 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7128 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
7129 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
7130 drv
->operstate
= state
;
7131 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
7132 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
7136 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
7138 struct i802_bss
*bss
= priv
;
7139 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7141 struct nl80211_sta_flag_update upd
;
7143 msg
= nlmsg_alloc();
7147 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7149 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7150 if_nametoindex(bss
->ifname
));
7151 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
7153 os_memset(&upd
, 0, sizeof(upd
));
7154 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
7156 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
7157 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
7159 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7166 /* Set kernel driver on given frequency (MHz) */
7167 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
7169 struct i802_bss
*bss
= priv
;
7170 return wpa_driver_nl80211_set_freq(bss
, freq
->freq
, freq
->ht_enabled
,
7171 freq
->sec_channel_offset
);
7175 #if defined(HOSTAPD) || defined(CONFIG_AP)
7177 static inline int min_int(int a
, int b
)
7185 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
7187 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7188 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7190 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7191 genlmsg_attrlen(gnlh
, 0), NULL
);
7194 * TODO: validate the key index and mac address!
7195 * Otherwise, there's a race condition as soon as
7196 * the kernel starts sending key notifications.
7199 if (tb
[NL80211_ATTR_KEY_SEQ
])
7200 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
7201 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
7206 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
7209 struct i802_bss
*bss
= priv
;
7210 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7213 msg
= nlmsg_alloc();
7217 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
7220 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7221 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
7222 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
7226 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
7233 static int i802_set_rts(void *priv
, int rts
)
7235 struct i802_bss
*bss
= priv
;
7236 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7241 msg
= nlmsg_alloc();
7250 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7251 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7252 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
7254 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7260 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
7261 "%d (%s)", rts
, ret
, strerror(-ret
));
7266 static int i802_set_frag(void *priv
, int frag
)
7268 struct i802_bss
*bss
= priv
;
7269 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7274 msg
= nlmsg_alloc();
7283 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7284 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7285 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
7287 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7293 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
7294 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
7299 static int i802_flush(void *priv
)
7301 struct i802_bss
*bss
= priv
;
7302 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7306 msg
= nlmsg_alloc();
7310 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
7313 * XXX: FIX! this needs to flush all VLANs too
7315 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7316 if_nametoindex(bss
->ifname
));
7318 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7320 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
7321 "(%s)", res
, strerror(-res
));
7330 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
7332 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7333 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7334 struct hostap_sta_driver_data
*data
= arg
;
7335 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
7336 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
7337 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
7338 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
7339 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
7340 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
7341 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
7344 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7345 genlmsg_attrlen(gnlh
, 0), NULL
);
7348 * TODO: validate the interface and mac address!
7349 * Otherwise, there's a race condition as soon as
7350 * the kernel starts sending station notifications.
7353 if (!tb
[NL80211_ATTR_STA_INFO
]) {
7354 wpa_printf(MSG_DEBUG
, "sta stats missing!");
7357 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
7358 tb
[NL80211_ATTR_STA_INFO
],
7360 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
7364 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
7365 data
->inactive_msec
=
7366 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
7367 if (stats
[NL80211_STA_INFO_RX_BYTES
])
7368 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
7369 if (stats
[NL80211_STA_INFO_TX_BYTES
])
7370 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
7371 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
7373 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
7374 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
7376 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
7381 static int i802_read_sta_data(void *priv
, struct hostap_sta_driver_data
*data
,
7384 struct i802_bss
*bss
= priv
;
7385 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7388 os_memset(data
, 0, sizeof(*data
));
7389 msg
= nlmsg_alloc();
7393 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
7395 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7396 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7398 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
7405 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
7406 int cw_min
, int cw_max
, int burst_time
)
7408 struct i802_bss
*bss
= priv
;
7409 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7411 struct nlattr
*txq
, *params
;
7413 msg
= nlmsg_alloc();
7417 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7419 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7421 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
7423 goto nla_put_failure
;
7425 /* We are only sending parameters for a single TXQ at a time */
7426 params
= nla_nest_start(msg
, 1);
7428 goto nla_put_failure
;
7432 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
7435 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
7438 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
7441 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
7444 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
7445 * 32 usec, so need to convert the value here. */
7446 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
7447 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
7448 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
7449 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
7451 nla_nest_end(msg
, params
);
7453 nla_nest_end(msg
, txq
);
7455 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
7464 static int i802_set_sta_vlan(void *priv
, const u8
*addr
,
7465 const char *ifname
, int vlan_id
)
7467 struct i802_bss
*bss
= priv
;
7468 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7472 msg
= nlmsg_alloc();
7476 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7478 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7479 if_nametoindex(bss
->ifname
));
7480 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7481 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
7482 if_nametoindex(ifname
));
7484 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7487 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
7488 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
7489 MAC2STR(addr
), ifname
, vlan_id
, ret
,
7498 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
7500 struct hostap_sta_driver_data data
;
7503 data
.inactive_msec
= (unsigned long) -1;
7504 ret
= i802_read_sta_data(priv
, &data
, addr
);
7505 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
7507 return data
.inactive_msec
/ 1000;
7511 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
7520 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
7523 struct i802_bss
*bss
= priv
;
7524 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7525 struct ieee80211_mgmt mgmt
;
7527 if (drv
->device_ap_sme
)
7528 return wpa_driver_nl80211_sta_remove(bss
, addr
);
7530 memset(&mgmt
, 0, sizeof(mgmt
));
7531 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
7532 WLAN_FC_STYPE_DEAUTH
);
7533 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
7534 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
7535 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
7536 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
7537 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
7539 sizeof(mgmt
.u
.deauth
), 0);
7543 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
7546 struct i802_bss
*bss
= priv
;
7547 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7548 struct ieee80211_mgmt mgmt
;
7550 if (drv
->device_ap_sme
)
7551 return wpa_driver_nl80211_sta_remove(bss
, addr
);
7553 memset(&mgmt
, 0, sizeof(mgmt
));
7554 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
7555 WLAN_FC_STYPE_DISASSOC
);
7556 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
7557 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
7558 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
7559 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
7560 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
7562 sizeof(mgmt
.u
.disassoc
), 0);
7565 #endif /* HOSTAPD || CONFIG_AP */
7569 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7574 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
7576 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
7577 if (drv
->if_indices
[i
] == 0) {
7578 drv
->if_indices
[i
] = ifidx
;
7583 if (drv
->if_indices
!= drv
->default_if_indices
)
7584 old
= drv
->if_indices
;
7588 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
7590 if (!drv
->if_indices
) {
7592 drv
->if_indices
= drv
->default_if_indices
;
7594 drv
->if_indices
= old
;
7595 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
7597 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
7600 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
7601 sizeof(drv
->default_if_indices
));
7602 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
7603 drv
->num_if_indices
++;
7607 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7611 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
7612 if (drv
->if_indices
[i
] == ifidx
) {
7613 drv
->if_indices
[i
] = 0;
7620 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7624 for (i
= 0; i
< drv
->num_if_indices
; i
++)
7625 if (drv
->if_indices
[i
] == ifidx
)
7632 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
7633 const char *bridge_ifname
)
7635 struct i802_bss
*bss
= priv
;
7636 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7637 char name
[IFNAMSIZ
+ 1];
7639 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
7640 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
7641 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
7643 if (!if_nametoindex(name
)) {
7644 if (nl80211_create_iface(drv
, name
,
7645 NL80211_IFTYPE_AP_VLAN
,
7648 if (bridge_ifname
&&
7649 linux_br_add_if(drv
->global
->ioctl_sock
,
7650 bridge_ifname
, name
) < 0)
7653 linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1);
7654 return i802_set_sta_vlan(priv
, addr
, name
, 0);
7656 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
7657 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
7663 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
7665 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
7666 struct sockaddr_ll lladdr
;
7667 unsigned char buf
[3000];
7669 socklen_t fromlen
= sizeof(lladdr
);
7671 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
7672 (struct sockaddr
*)&lladdr
, &fromlen
);
7678 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
7679 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
7683 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
7684 struct i802_bss
*bss
,
7685 const char *brname
, const char *ifname
)
7688 char in_br
[IFNAMSIZ
];
7690 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
7691 ifindex
= if_nametoindex(brname
);
7694 * Bridge was configured, but the bridge device does
7695 * not exist. Try to add it now.
7697 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
7698 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
7699 "bridge interface %s: %s",
7700 brname
, strerror(errno
));
7703 bss
->added_bridge
= 1;
7704 add_ifidx(drv
, if_nametoindex(brname
));
7707 if (linux_br_get(in_br
, ifname
) == 0) {
7708 if (os_strcmp(in_br
, brname
) == 0)
7709 return 0; /* already in the bridge */
7711 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
7712 "bridge %s", ifname
, in_br
);
7713 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
7715 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
7716 "remove interface %s from bridge "
7718 ifname
, brname
, strerror(errno
));
7723 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
7725 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
7726 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
7727 "into bridge %s: %s",
7728 ifname
, brname
, strerror(errno
));
7731 bss
->added_if_into_bridge
= 1;
7737 static void *i802_init(struct hostapd_data
*hapd
,
7738 struct wpa_init_params
*params
)
7740 struct wpa_driver_nl80211_data
*drv
;
7741 struct i802_bss
*bss
;
7743 char brname
[IFNAMSIZ
];
7744 int ifindex
, br_ifindex
;
7747 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
7748 params
->global_priv
);
7753 drv
->nlmode
= NL80211_IFTYPE_AP
;
7754 drv
->eapol_sock
= -1;
7756 if (linux_br_get(brname
, params
->ifname
) == 0) {
7757 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
7758 params
->ifname
, brname
);
7759 br_ifindex
= if_nametoindex(brname
);
7765 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
7766 drv
->if_indices
= drv
->default_if_indices
;
7767 for (i
= 0; i
< params
->num_bridge
; i
++) {
7768 if (params
->bridge
[i
]) {
7769 ifindex
= if_nametoindex(params
->bridge
[i
]);
7771 add_ifidx(drv
, ifindex
);
7772 if (ifindex
== br_ifindex
)
7776 if (!br_added
&& br_ifindex
&&
7777 (params
->num_bridge
== 0 || !params
->bridge
[0]))
7778 add_ifidx(drv
, br_ifindex
);
7780 /* start listening for EAPOL on the default AP interface */
7781 add_ifidx(drv
, drv
->ifindex
);
7783 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
7786 if (params
->bssid
) {
7787 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7792 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
7793 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
7794 "into AP mode", bss
->ifname
);
7798 if (params
->num_bridge
&& params
->bridge
[0] &&
7799 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
7802 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
7805 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
7806 if (drv
->eapol_sock
< 0) {
7807 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
7811 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
7813 printf("Could not register read socket for eapol\n");
7817 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7821 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
7826 wpa_driver_nl80211_deinit(bss
);
7831 static void i802_deinit(void *priv
)
7833 wpa_driver_nl80211_deinit(priv
);
7836 #endif /* HOSTAPD */
7839 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
7840 enum wpa_driver_if_type type
)
7843 case WPA_IF_STATION
:
7844 return NL80211_IFTYPE_STATION
;
7845 case WPA_IF_P2P_CLIENT
:
7846 case WPA_IF_P2P_GROUP
:
7847 return NL80211_IFTYPE_P2P_CLIENT
;
7848 case WPA_IF_AP_VLAN
:
7849 return NL80211_IFTYPE_AP_VLAN
;
7851 return NL80211_IFTYPE_AP
;
7853 return NL80211_IFTYPE_P2P_GO
;
7861 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
7863 struct wpa_driver_nl80211_data
*drv
;
7864 dl_list_for_each(drv
, &global
->interfaces
,
7865 struct wpa_driver_nl80211_data
, list
) {
7866 if (os_memcmp(addr
, drv
->first_bss
.addr
, ETH_ALEN
) == 0)
7873 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
7881 os_memcpy(new_addr
, drv
->first_bss
.addr
, ETH_ALEN
);
7882 for (idx
= 0; idx
< 64; idx
++) {
7883 new_addr
[0] = drv
->first_bss
.addr
[0] | 0x02;
7884 new_addr
[0] ^= idx
<< 2;
7885 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
7891 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
7892 MACSTR
, MAC2STR(new_addr
));
7897 #endif /* CONFIG_P2P */
7900 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
7901 const char *ifname
, const u8
*addr
,
7902 void *bss_ctx
, void **drv_priv
,
7903 char *force_ifname
, u8
*if_addr
,
7906 struct i802_bss
*bss
= priv
;
7907 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7910 struct i802_bss
*new_bss
= NULL
;
7912 if (type
== WPA_IF_AP_BSS
) {
7913 new_bss
= os_zalloc(sizeof(*new_bss
));
7914 if (new_bss
== NULL
)
7917 #endif /* HOSTAPD */
7920 os_memcpy(if_addr
, addr
, ETH_ALEN
);
7921 ifidx
= nl80211_create_iface(drv
, ifname
,
7922 wpa_driver_nl80211_if_type(type
), addr
,
7927 #endif /* HOSTAPD */
7932 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7934 nl80211_remove_iface(drv
, ifidx
);
7940 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
7941 type
== WPA_IF_P2P_GO
)) {
7942 /* Enforce unique P2P Interface Address */
7943 u8 new_addr
[ETH_ALEN
], own_addr
[ETH_ALEN
];
7945 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7947 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
7949 nl80211_remove_iface(drv
, ifidx
);
7952 if (os_memcmp(own_addr
, new_addr
, ETH_ALEN
) == 0) {
7953 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
7954 "for P2P group interface");
7955 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
7956 nl80211_remove_iface(drv
, ifidx
);
7959 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
7961 nl80211_remove_iface(drv
, ifidx
);
7965 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
7967 #endif /* CONFIG_P2P */
7971 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
7972 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
7973 "interface %s to a bridge %s", ifname
, bridge
);
7974 nl80211_remove_iface(drv
, ifidx
);
7979 if (type
== WPA_IF_AP_BSS
) {
7980 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
7982 nl80211_remove_iface(drv
, ifidx
);
7986 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
7987 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
7988 new_bss
->ifindex
= ifidx
;
7990 new_bss
->next
= drv
->first_bss
.next
;
7991 new_bss
->freq
= drv
->first_bss
.freq
;
7992 drv
->first_bss
.next
= new_bss
;
7994 *drv_priv
= new_bss
;
7995 nl80211_init_bss(new_bss
);
7997 /* Subscribe management frames for this WPA_IF_AP_BSS */
7998 if (nl80211_setup_ap(new_bss
))
8001 #endif /* HOSTAPD */
8004 drv
->global
->if_add_ifindex
= ifidx
;
8010 static int wpa_driver_nl80211_if_remove(void *priv
,
8011 enum wpa_driver_if_type type
,
8014 struct i802_bss
*bss
= priv
;
8015 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8016 int ifindex
= if_nametoindex(ifname
);
8018 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d",
8019 __func__
, type
, ifname
, ifindex
);
8024 if (bss
->added_if_into_bridge
) {
8025 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
8027 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
8028 "interface %s from bridge %s: %s",
8029 bss
->ifname
, bss
->brname
, strerror(errno
));
8031 if (bss
->added_bridge
) {
8032 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
8033 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
8035 bss
->brname
, strerror(errno
));
8037 #endif /* HOSTAPD */
8039 nl80211_remove_iface(drv
, ifindex
);
8042 if (type
!= WPA_IF_AP_BSS
)
8045 if (bss
!= &drv
->first_bss
) {
8046 struct i802_bss
*tbss
;
8048 for (tbss
= &drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
8049 if (tbss
->next
== bss
) {
8050 tbss
->next
= bss
->next
;
8051 /* Unsubscribe management frames */
8052 nl80211_teardown_ap(bss
);
8053 nl80211_destroy_bss(bss
);
8060 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
8061 "BSS %p in the list", __func__
, bss
);
8063 #endif /* HOSTAPD */
8069 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
8071 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8072 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8074 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8075 genlmsg_attrlen(gnlh
, 0), NULL
);
8076 if (tb
[NL80211_ATTR_COOKIE
])
8077 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
8082 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
8083 unsigned int freq
, unsigned int wait
,
8084 const u8
*buf
, size_t buf_len
,
8085 u64
*cookie_out
, int no_cck
, int no_ack
,
8088 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8093 msg
= nlmsg_alloc();
8097 wpa_printf(MSG_DEBUG
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
8098 "no_ack=%d offchanok=%d",
8099 freq
, wait
, no_cck
, no_ack
, offchanok
);
8100 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
8102 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8103 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
8105 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
8106 if (offchanok
&& (drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
))
8107 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
8109 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
8111 NLA_PUT_FLAG(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
);
8113 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
8116 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
8119 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
8120 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
8122 goto nla_put_failure
;
8124 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX command accepted%s; "
8125 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
8126 (long long unsigned int) cookie
);
8129 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
8137 static int wpa_driver_nl80211_send_action(void *priv
, unsigned int freq
,
8138 unsigned int wait_time
,
8139 const u8
*dst
, const u8
*src
,
8141 const u8
*data
, size_t data_len
,
8144 struct i802_bss
*bss
= priv
;
8145 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8148 struct ieee80211_hdr
*hdr
;
8150 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
8151 "freq=%u MHz wait=%d ms no_cck=%d)",
8152 drv
->ifindex
, freq
, wait_time
, no_cck
);
8154 buf
= os_zalloc(24 + data_len
);
8157 os_memcpy(buf
+ 24, data
, data_len
);
8158 hdr
= (struct ieee80211_hdr
*) buf
;
8159 hdr
->frame_control
=
8160 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
8161 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
8162 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
8163 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
8165 if (is_ap_interface(drv
->nlmode
))
8166 ret
= wpa_driver_nl80211_send_mlme_freq(priv
, buf
,
8171 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
8173 &drv
->send_action_cookie
,
8181 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
8183 struct i802_bss
*bss
= priv
;
8184 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8188 msg
= nlmsg_alloc();
8192 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
8194 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8195 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
8197 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8200 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
8201 "(%s)", ret
, strerror(-ret
));
8208 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
8209 unsigned int duration
)
8211 struct i802_bss
*bss
= priv
;
8212 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8217 msg
= nlmsg_alloc();
8221 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
8223 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8224 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
8225 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
8228 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
8231 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
8232 "0x%llx for freq=%u MHz duration=%u",
8233 (long long unsigned int) cookie
, freq
, duration
);
8234 drv
->remain_on_chan_cookie
= cookie
;
8235 drv
->pending_remain_on_chan
= 1;
8238 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
8239 "(freq=%d duration=%u): %d (%s)",
8240 freq
, duration
, ret
, strerror(-ret
));
8247 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
8249 struct i802_bss
*bss
= priv
;
8250 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8254 if (!drv
->pending_remain_on_chan
) {
8255 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
8260 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
8262 (long long unsigned int) drv
->remain_on_chan_cookie
);
8264 msg
= nlmsg_alloc();
8268 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
8270 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8271 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
8273 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8277 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
8278 "%d (%s)", ret
, strerror(-ret
));
8285 static int wpa_driver_nl80211_probe_req_report(void *priv
, int report
)
8287 struct i802_bss
*bss
= priv
;
8288 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8291 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
8292 is_ap_interface(drv
->nlmode
)) {
8294 * Do not disable Probe Request reporting that was
8295 * enabled in nl80211_setup_ap().
8297 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
8298 "Probe Request reporting nl_preq=%p while "
8299 "in AP mode", bss
->nl_preq
);
8300 } else if (bss
->nl_preq
) {
8301 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
8302 "reporting nl_preq=%p", bss
->nl_preq
);
8303 eloop_unregister_read_sock(
8304 nl_socket_get_fd(bss
->nl_preq
));
8305 nl_destroy_handles(&bss
->nl_preq
);
8311 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
8312 "already on! nl_preq=%p", bss
->nl_preq
);
8316 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
8317 if (bss
->nl_preq
== NULL
)
8319 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
8320 "reporting nl_preq=%p", bss
->nl_preq
);
8322 if (nl80211_register_frame(bss
, bss
->nl_preq
,
8323 (WLAN_FC_TYPE_MGMT
<< 2) |
8324 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
8328 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_preq
),
8329 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
8335 nl_destroy_handles(&bss
->nl_preq
);
8340 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
8341 int ifindex
, int disabled
)
8344 struct nlattr
*bands
, *band
;
8347 msg
= nlmsg_alloc();
8351 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
8352 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
8354 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
8356 goto nla_put_failure
;
8359 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
8360 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
8361 * rates. All 5 GHz rates are left enabled.
8363 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
8365 goto nla_put_failure
;
8367 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
8368 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
8370 nla_nest_end(msg
, band
);
8372 nla_nest_end(msg
, bands
);
8374 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8377 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
8378 "(%s)", ret
, strerror(-ret
));
8380 drv
->disabled_11b_rates
= disabled
;
8390 static int wpa_driver_nl80211_deinit_ap(void *priv
)
8392 struct i802_bss
*bss
= priv
;
8393 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8394 if (!is_ap_interface(drv
->nlmode
))
8396 wpa_driver_nl80211_del_beacon(drv
);
8397 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
8401 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
8403 struct i802_bss
*bss
= priv
;
8404 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8405 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
8407 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
8411 static void wpa_driver_nl80211_resume(void *priv
)
8413 struct i802_bss
*bss
= priv
;
8414 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8415 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
8416 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on "
8422 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
8423 const u8
*ies
, size_t ies_len
)
8425 struct i802_bss
*bss
= priv
;
8426 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8430 const u8
*own_addr
= bss
->addr
;
8433 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
8434 "action %d", action
);
8439 * Action frame payload:
8440 * Category[1] = 6 (Fast BSS Transition)
8441 * Action[1] = 1 (Fast BSS Transition Request)
8447 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
8448 data
= os_malloc(data_len
);
8452 *pos
++ = 0x06; /* FT Action category */
8454 os_memcpy(pos
, own_addr
, ETH_ALEN
);
8456 os_memcpy(pos
, target_ap
, ETH_ALEN
);
8458 os_memcpy(pos
, ies
, ies_len
);
8460 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
8461 drv
->bssid
, own_addr
, drv
->bssid
,
8469 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
8471 struct i802_bss
*bss
= priv
;
8472 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8473 struct nl_msg
*msg
, *cqm
= NULL
;
8476 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
8477 "hysteresis=%d", threshold
, hysteresis
);
8479 msg
= nlmsg_alloc();
8483 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
8485 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8487 cqm
= nlmsg_alloc();
8489 goto nla_put_failure
;
8491 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
8492 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
8493 if (nla_put_nested(msg
, NL80211_ATTR_CQM
, cqm
) < 0)
8494 goto nla_put_failure
;
8496 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8506 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
8508 struct i802_bss
*bss
= priv
;
8509 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8512 os_memset(si
, 0, sizeof(*si
));
8513 res
= nl80211_get_link_signal(drv
, si
);
8517 return nl80211_get_link_noise(drv
, si
);
8521 static int wpa_driver_nl80211_shared_freq(void *priv
)
8523 struct i802_bss
*bss
= priv
;
8524 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8525 struct wpa_driver_nl80211_data
*driver
;
8529 * If the same PHY is in connected state with some other interface,
8530 * then retrieve the assoc freq.
8532 wpa_printf(MSG_DEBUG
, "nl80211: Get shared freq for PHY %s",
8535 dl_list_for_each(driver
, &drv
->global
->interfaces
,
8536 struct wpa_driver_nl80211_data
, list
) {
8537 if (drv
== driver
||
8538 os_strcmp(drv
->phyname
, driver
->phyname
) != 0 ||
8539 !driver
->associated
)
8542 wpa_printf(MSG_DEBUG
, "nl80211: Found a match for PHY %s - %s "
8544 driver
->phyname
, driver
->first_bss
.ifname
,
8545 MAC2STR(driver
->first_bss
.addr
));
8546 if (is_ap_interface(driver
->nlmode
))
8547 freq
= driver
->first_bss
.freq
;
8549 freq
= nl80211_get_assoc_freq(driver
);
8550 wpa_printf(MSG_DEBUG
, "nl80211: Shared freq for PHY %s: %d",
8551 drv
->phyname
, freq
);
8555 wpa_printf(MSG_DEBUG
, "nl80211: No shared interface for "
8556 "PHY (%s) in associated state", drv
->phyname
);
8562 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
8565 struct i802_bss
*bss
= priv
;
8566 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
8571 static int nl80211_set_param(void *priv
, const char *param
)
8573 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
8578 if (os_strstr(param
, "use_p2p_group_interface=1")) {
8579 struct i802_bss
*bss
= priv
;
8580 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8582 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
8584 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
8585 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
8587 #endif /* CONFIG_P2P */
8593 static void * nl80211_global_init(void)
8595 struct nl80211_global
*global
;
8596 struct netlink_config
*cfg
;
8598 global
= os_zalloc(sizeof(*global
));
8601 global
->ioctl_sock
= -1;
8602 dl_list_init(&global
->interfaces
);
8603 global
->if_add_ifindex
= -1;
8605 cfg
= os_zalloc(sizeof(*cfg
));
8610 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
8611 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
8612 global
->netlink
= netlink_init(cfg
);
8613 if (global
->netlink
== NULL
) {
8618 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
8621 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
8622 if (global
->ioctl_sock
< 0) {
8623 perror("socket(PF_INET,SOCK_DGRAM)");
8630 nl80211_global_deinit(global
);
8635 static void nl80211_global_deinit(void *priv
)
8637 struct nl80211_global
*global
= priv
;
8640 if (!dl_list_empty(&global
->interfaces
)) {
8641 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
8642 "nl80211_global_deinit",
8643 dl_list_len(&global
->interfaces
));
8646 if (global
->netlink
)
8647 netlink_deinit(global
->netlink
);
8649 nl_destroy_handles(&global
->nl
);
8651 if (global
->nl_event
) {
8652 eloop_unregister_read_sock(
8653 nl_socket_get_fd(global
->nl_event
));
8654 nl_destroy_handles(&global
->nl_event
);
8657 nl_cb_put(global
->nl_cb
);
8659 if (global
->ioctl_sock
>= 0)
8660 close(global
->ioctl_sock
);
8666 static const char * nl80211_get_radio_name(void *priv
)
8668 struct i802_bss
*bss
= priv
;
8669 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8670 return drv
->phyname
;
8674 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
8679 msg
= nlmsg_alloc();
8683 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
8685 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8687 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
8689 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
8691 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8698 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
8700 struct i802_bss
*bss
= priv
;
8701 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
8702 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
8706 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
8708 struct i802_bss
*bss
= priv
;
8709 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
8711 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
8715 static int nl80211_flush_pmkid(void *priv
)
8717 struct i802_bss
*bss
= priv
;
8718 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
8719 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
8723 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
8724 const u8
*replay_ctr
)
8726 struct i802_bss
*bss
= priv
;
8727 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8728 struct nlattr
*replay_nested
;
8731 msg
= nlmsg_alloc();
8735 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8737 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8739 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8741 goto nla_put_failure
;
8743 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
8744 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
8745 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
8748 nla_nest_end(msg
, replay_nested
);
8750 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8757 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
8758 const u8
*addr
, int qos
)
8760 /* send data frame to poll STA and check whether
8761 * this frame is ACKed */
8763 struct ieee80211_hdr hdr
;
8765 } STRUCT_PACKED nulldata
;
8768 /* Send data frame to poll STA and check whether this frame is ACKed */
8770 os_memset(&nulldata
, 0, sizeof(nulldata
));
8773 nulldata
.hdr
.frame_control
=
8774 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
8775 WLAN_FC_STYPE_QOS_NULL
);
8776 size
= sizeof(nulldata
);
8778 nulldata
.hdr
.frame_control
=
8779 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
8780 WLAN_FC_STYPE_NULLFUNC
);
8781 size
= sizeof(struct ieee80211_hdr
);
8784 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
8785 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
8786 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
8787 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
8789 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0) < 0)
8790 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
8794 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
8797 struct i802_bss
*bss
= priv
;
8798 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8801 if (!drv
->poll_command_supported
) {
8802 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
8806 msg
= nlmsg_alloc();
8810 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_PROBE_CLIENT
);
8812 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8813 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8815 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8822 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
8826 msg
= nlmsg_alloc();
8830 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_SET_POWER_SAVE
);
8831 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8832 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
,
8833 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
);
8834 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8841 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
8844 struct i802_bss
*bss
= priv
;
8846 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
8847 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
8849 if (opp_ps
!= -1 || ctwindow
!= -1)
8850 return -1; /* Not yet supported */
8852 if (legacy_ps
== -1)
8854 if (legacy_ps
!= 0 && legacy_ps
!= 1)
8855 return -1; /* Not yet supported */
8857 return nl80211_set_power_save(bss
, legacy_ps
);
8863 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
8864 u8 dialog_token
, u16 status_code
,
8865 const u8
*buf
, size_t len
)
8867 struct i802_bss
*bss
= priv
;
8868 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8871 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8877 msg
= nlmsg_alloc();
8881 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_MGMT
);
8882 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8883 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
8884 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
);
8885 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
);
8886 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
);
8887 NLA_PUT(msg
, NL80211_ATTR_IE
, len
, buf
);
8889 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8897 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
8899 struct i802_bss
*bss
= priv
;
8900 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8902 enum nl80211_tdls_operation nl80211_oper
;
8904 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8908 case TDLS_DISCOVERY_REQ
:
8909 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
8912 nl80211_oper
= NL80211_TDLS_SETUP
;
8915 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
8917 case TDLS_ENABLE_LINK
:
8918 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
8920 case TDLS_DISABLE_LINK
:
8921 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
8931 msg
= nlmsg_alloc();
8935 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_OPER
);
8936 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
);
8937 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8938 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
8940 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8947 #endif /* CONFIG TDLS */
8952 typedef struct android_wifi_priv_cmd
{
8956 } android_wifi_priv_cmd
;
8958 static int drv_errors
= 0;
8960 static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data
*drv
)
8963 if (drv_errors
> DRV_NUMBER_SEQUENTIAL_ERRORS
) {
8965 wpa_msg(drv
->ctx
, MSG_INFO
, WPA_EVENT_DRIVER_STATE
"HANGED");
8970 static int android_priv_cmd(struct i802_bss
*bss
, const char *cmd
)
8972 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8974 android_wifi_priv_cmd priv_cmd
;
8975 char buf
[MAX_DRV_CMD_SIZE
];
8978 os_memset(&ifr
, 0, sizeof(ifr
));
8979 os_memset(&priv_cmd
, 0, sizeof(priv_cmd
));
8980 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
8982 os_memset(buf
, 0, sizeof(buf
));
8983 os_strlcpy(buf
, cmd
, sizeof(buf
));
8986 priv_cmd
.used_len
= sizeof(buf
);
8987 priv_cmd
.total_len
= sizeof(buf
);
8988 ifr
.ifr_data
= &priv_cmd
;
8990 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
8992 wpa_printf(MSG_ERROR
, "%s: failed to issue private commands",
8994 wpa_driver_send_hang_msg(drv
);
9003 static int android_pno_start(struct i802_bss
*bss
,
9004 struct wpa_driver_scan_params
*params
)
9006 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9008 android_wifi_priv_cmd priv_cmd
;
9009 int ret
= 0, i
= 0, bp
;
9010 char buf
[WEXT_PNO_MAX_COMMAND_SIZE
];
9012 bp
= WEXT_PNOSETUP_HEADER_SIZE
;
9013 os_memcpy(buf
, WEXT_PNOSETUP_HEADER
, bp
);
9014 buf
[bp
++] = WEXT_PNO_TLV_PREFIX
;
9015 buf
[bp
++] = WEXT_PNO_TLV_VERSION
;
9016 buf
[bp
++] = WEXT_PNO_TLV_SUBVERSION
;
9017 buf
[bp
++] = WEXT_PNO_TLV_RESERVED
;
9019 while (i
< WEXT_PNO_AMOUNT
&& (size_t) i
< params
->num_ssids
) {
9020 /* Check that there is enough space needed for 1 more SSID, the
9021 * other sections and null termination */
9022 if ((bp
+ WEXT_PNO_SSID_HEADER_SIZE
+ MAX_SSID_LEN
+
9023 WEXT_PNO_NONSSID_SECTIONS_SIZE
+ 1) >= (int) sizeof(buf
))
9025 wpa_hexdump_ascii(MSG_DEBUG
, "For PNO Scan",
9026 params
->ssids
[i
].ssid
,
9027 params
->ssids
[i
].ssid_len
);
9028 buf
[bp
++] = WEXT_PNO_SSID_SECTION
;
9029 buf
[bp
++] = params
->ssids
[i
].ssid_len
;
9030 os_memcpy(&buf
[bp
], params
->ssids
[i
].ssid
,
9031 params
->ssids
[i
].ssid_len
);
9032 bp
+= params
->ssids
[i
].ssid_len
;
9036 buf
[bp
++] = WEXT_PNO_SCAN_INTERVAL_SECTION
;
9037 os_snprintf(&buf
[bp
], WEXT_PNO_SCAN_INTERVAL_LENGTH
+ 1, "%x",
9038 WEXT_PNO_SCAN_INTERVAL
);
9039 bp
+= WEXT_PNO_SCAN_INTERVAL_LENGTH
;
9041 buf
[bp
++] = WEXT_PNO_REPEAT_SECTION
;
9042 os_snprintf(&buf
[bp
], WEXT_PNO_REPEAT_LENGTH
+ 1, "%x",
9044 bp
+= WEXT_PNO_REPEAT_LENGTH
;
9046 buf
[bp
++] = WEXT_PNO_MAX_REPEAT_SECTION
;
9047 os_snprintf(&buf
[bp
], WEXT_PNO_MAX_REPEAT_LENGTH
+ 1, "%x",
9048 WEXT_PNO_MAX_REPEAT
);
9049 bp
+= WEXT_PNO_MAX_REPEAT_LENGTH
+ 1;
9051 memset(&ifr
, 0, sizeof(ifr
));
9052 memset(&priv_cmd
, 0, sizeof(priv_cmd
));
9053 os_strncpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
9056 priv_cmd
.used_len
= bp
;
9057 priv_cmd
.total_len
= bp
;
9058 ifr
.ifr_data
= &priv_cmd
;
9060 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
9063 wpa_printf(MSG_ERROR
, "ioctl[SIOCSIWPRIV] (pnosetup): %d",
9065 wpa_driver_send_hang_msg(drv
);
9071 return android_priv_cmd(bss
, "PNOFORCE 1");
9075 static int android_pno_stop(struct i802_bss
*bss
)
9077 return android_priv_cmd(bss
, "PNOFORCE 0");
9080 #endif /* ANDROID */
9083 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
9085 .desc
= "Linux nl80211/cfg80211",
9086 .get_bssid
= wpa_driver_nl80211_get_bssid
,
9087 .get_ssid
= wpa_driver_nl80211_get_ssid
,
9088 .set_key
= wpa_driver_nl80211_set_key
,
9089 .scan2
= wpa_driver_nl80211_scan
,
9090 .sched_scan
= wpa_driver_nl80211_sched_scan
,
9091 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
9092 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
9093 .deauthenticate
= wpa_driver_nl80211_deauthenticate
,
9094 .disassociate
= wpa_driver_nl80211_disassociate
,
9095 .authenticate
= wpa_driver_nl80211_authenticate
,
9096 .associate
= wpa_driver_nl80211_associate
,
9097 .global_init
= nl80211_global_init
,
9098 .global_deinit
= nl80211_global_deinit
,
9099 .init2
= wpa_driver_nl80211_init
,
9100 .deinit
= wpa_driver_nl80211_deinit
,
9101 .get_capa
= wpa_driver_nl80211_get_capa
,
9102 .set_operstate
= wpa_driver_nl80211_set_operstate
,
9103 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
9104 .set_country
= wpa_driver_nl80211_set_country
,
9105 .set_ap
= wpa_driver_nl80211_set_ap
,
9106 .if_add
= wpa_driver_nl80211_if_add
,
9107 .if_remove
= wpa_driver_nl80211_if_remove
,
9108 .send_mlme
= wpa_driver_nl80211_send_mlme
,
9109 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
9110 .sta_add
= wpa_driver_nl80211_sta_add
,
9111 .sta_remove
= wpa_driver_nl80211_sta_remove
,
9112 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
9113 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
9115 .hapd_init
= i802_init
,
9116 .hapd_deinit
= i802_deinit
,
9117 .set_wds_sta
= i802_set_wds_sta
,
9118 #endif /* HOSTAPD */
9119 #if defined(HOSTAPD) || defined(CONFIG_AP)
9120 .get_seqnum
= i802_get_seqnum
,
9121 .flush
= i802_flush
,
9122 .read_sta_data
= i802_read_sta_data
,
9123 .get_inact_sec
= i802_get_inact_sec
,
9124 .sta_clear_stats
= i802_sta_clear_stats
,
9125 .set_rts
= i802_set_rts
,
9126 .set_frag
= i802_set_frag
,
9127 .set_tx_queue_params
= i802_set_tx_queue_params
,
9128 .set_sta_vlan
= i802_set_sta_vlan
,
9129 .sta_deauth
= i802_sta_deauth
,
9130 .sta_disassoc
= i802_sta_disassoc
,
9131 #endif /* HOSTAPD || CONFIG_AP */
9132 .set_freq
= i802_set_freq
,
9133 .send_action
= wpa_driver_nl80211_send_action
,
9134 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
9135 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
9136 .cancel_remain_on_channel
=
9137 wpa_driver_nl80211_cancel_remain_on_channel
,
9138 .probe_req_report
= wpa_driver_nl80211_probe_req_report
,
9139 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
9140 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
9141 .resume
= wpa_driver_nl80211_resume
,
9142 .send_ft_action
= nl80211_send_ft_action
,
9143 .signal_monitor
= nl80211_signal_monitor
,
9144 .signal_poll
= nl80211_signal_poll
,
9145 .send_frame
= nl80211_send_frame
,
9146 .shared_freq
= wpa_driver_nl80211_shared_freq
,
9147 .set_param
= nl80211_set_param
,
9148 .get_radio_name
= nl80211_get_radio_name
,
9149 .add_pmkid
= nl80211_add_pmkid
,
9150 .remove_pmkid
= nl80211_remove_pmkid
,
9151 .flush_pmkid
= nl80211_flush_pmkid
,
9152 .set_rekey_info
= nl80211_set_rekey_info
,
9153 .poll_client
= nl80211_poll_client
,
9154 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
9156 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
9157 .tdls_oper
= nl80211_tdls_oper
,
9158 #endif /* CONFIG_TDLS */