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
);
189 struct wpa_driver_nl80211_data
*drv
;
190 struct i802_bss
*next
;
192 char ifname
[IFNAMSIZ
+ 1];
193 char brname
[IFNAMSIZ
];
194 unsigned int beacon_set
:1;
195 unsigned int added_if_into_bridge
:1;
196 unsigned int added_bridge
:1;
197 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;
253 unsigned int ignore_next_local_disconnect
:1;
255 u64 remain_on_chan_cookie
;
256 u64 send_action_cookie
;
258 unsigned int last_mgmt_freq
;
260 struct wpa_driver_scan_filter
*filter_ssids
;
261 size_t num_filter_ssids
;
263 struct i802_bss first_bss
;
268 int eapol_sock
; /* socket for EAPOL frames */
270 int default_if_indices
[16];
278 /* From failed authentication command */
280 u8 auth_bssid_
[ETH_ALEN
];
282 size_t auth_ssid_len
;
286 u8 auth_wep_key
[4][16];
287 size_t auth_wep_key_len
[4];
288 int auth_wep_tx_keyidx
;
289 int auth_local_state_change
;
294 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
);
295 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
,
297 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
298 enum nl80211_iftype nlmode
);
300 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
);
301 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
302 const u8
*addr
, int cmd
, u16 reason_code
,
303 int local_state_change
);
304 static void nl80211_remove_monitor_interface(
305 struct wpa_driver_nl80211_data
*drv
);
306 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
307 unsigned int freq
, unsigned int wait
,
308 const u8
*buf
, size_t buf_len
, u64
*cookie
,
309 int no_cck
, int no_ack
, int offchanok
);
310 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
,
313 static int android_pno_start(struct i802_bss
*bss
,
314 struct wpa_driver_scan_params
*params
);
315 static int android_pno_stop(struct i802_bss
*bss
);
319 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
320 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
321 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
322 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
323 enum wpa_driver_if_type type
,
326 static inline void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
330 static inline void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
334 static inline int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
340 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
341 struct hostapd_freq_params
*freq
);
342 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
343 int ifindex
, int disabled
);
345 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
);
346 static int wpa_driver_nl80211_authenticate_retry(
347 struct wpa_driver_nl80211_data
*drv
);
350 static int is_ap_interface(enum nl80211_iftype nlmode
)
352 return (nlmode
== NL80211_IFTYPE_AP
||
353 nlmode
== NL80211_IFTYPE_P2P_GO
);
357 static int is_sta_interface(enum nl80211_iftype nlmode
)
359 return (nlmode
== NL80211_IFTYPE_STATION
||
360 nlmode
== NL80211_IFTYPE_P2P_CLIENT
);
364 static int is_p2p_interface(enum nl80211_iftype nlmode
)
366 return (nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
367 nlmode
== NL80211_IFTYPE_P2P_GO
);
371 struct nl80211_bss_info_arg
{
372 struct wpa_driver_nl80211_data
*drv
;
373 struct wpa_scan_results
*res
;
374 unsigned int assoc_freq
;
375 u8 assoc_bssid
[ETH_ALEN
];
378 static int bss_info_handler(struct nl_msg
*msg
, void *arg
);
382 static int ack_handler(struct nl_msg
*msg
, void *arg
)
389 static int finish_handler(struct nl_msg
*msg
, void *arg
)
396 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
405 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
411 static int send_and_recv(struct nl80211_global
*global
,
412 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
413 int (*valid_handler
)(struct nl_msg
*, void *),
419 cb
= nl_cb_clone(global
->nl_cb
);
423 err
= nl_send_auto_complete(nl_handle
, msg
);
429 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
430 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
431 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
434 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
435 valid_handler
, valid_data
);
438 nl_recvmsgs(nl_handle
, cb
);
446 static int send_and_recv_msgs_global(struct nl80211_global
*global
,
448 int (*valid_handler
)(struct nl_msg
*, void *),
451 return send_and_recv(global
, global
->nl
, msg
, valid_handler
,
456 static int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
458 int (*valid_handler
)(struct nl_msg
*, void *),
461 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
462 valid_handler
, valid_data
);
472 static int family_handler(struct nl_msg
*msg
, void *arg
)
474 struct family_data
*res
= arg
;
475 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
476 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
477 struct nlattr
*mcgrp
;
480 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
481 genlmsg_attrlen(gnlh
, 0), NULL
);
482 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
485 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
486 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
487 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
488 nla_len(mcgrp
), NULL
);
489 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
490 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
491 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
493 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
495 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
503 static int nl_get_multicast_id(struct nl80211_global
*global
,
504 const char *family
, const char *group
)
508 struct family_data res
= { group
, -ENOENT
};
513 genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
514 0, 0, CTRL_CMD_GETFAMILY
, 0);
515 NLA_PUT_STRING(msg
, CTRL_ATTR_FAMILY_NAME
, family
);
517 ret
= send_and_recv_msgs_global(global
, msg
, family_handler
, &res
);
528 static void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
529 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
531 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
536 struct wiphy_idx_data
{
541 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
543 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
544 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
545 struct wiphy_idx_data
*info
= arg
;
547 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
548 genlmsg_attrlen(gnlh
, 0), NULL
);
550 if (tb
[NL80211_ATTR_WIPHY
])
551 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
557 static int nl80211_get_wiphy_index(struct i802_bss
*bss
)
560 struct wiphy_idx_data data
= {
568 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
570 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
572 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
573 return data
.wiphy_idx
;
581 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
582 struct nl80211_wiphy_data
*w
)
591 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
);
593 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
);
595 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
598 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
599 "failed: ret=%d (%s)",
600 ret
, strerror(-ret
));
601 goto nla_put_failure
;
610 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
612 struct nl80211_wiphy_data
*w
= eloop_ctx
;
614 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
616 nl_recvmsgs(handle
, w
->nl_cb
);
620 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
622 struct nl80211_wiphy_data
*w
= arg
;
623 struct wpa_driver_nl80211_data
*drv
;
624 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
625 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
626 union wpa_event_data event
;
628 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
629 genlmsg_attrlen(gnlh
, 0), NULL
);
631 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
632 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
637 if (!tb
[NL80211_ATTR_FRAME
])
640 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
642 os_memset(&event
, 0, sizeof(event
));
643 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
644 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
645 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
652 static struct nl80211_wiphy_data
*
653 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
655 static DEFINE_DL_LIST(nl80211_wiphys
);
656 struct nl80211_wiphy_data
*w
;
657 int wiphy_idx
, found
= 0;
658 struct i802_bss
*tmp_bss
;
660 if (bss
->wiphy_data
!= NULL
)
661 return bss
->wiphy_data
;
663 wiphy_idx
= nl80211_get_wiphy_index(bss
);
665 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
666 if (w
->wiphy_idx
== wiphy_idx
)
671 w
= os_zalloc(sizeof(*w
));
674 w
->wiphy_idx
= wiphy_idx
;
675 dl_list_init(&w
->bsss
);
676 dl_list_init(&w
->drvs
);
678 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
683 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
684 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
687 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
689 if (w
->nl_beacons
== NULL
) {
694 if (nl80211_register_beacons(bss
->drv
, w
)) {
695 nl_destroy_handles(&w
->nl_beacons
);
700 eloop_register_read_sock(nl_socket_get_fd(w
->nl_beacons
),
701 nl80211_recv_beacons
, w
, w
->nl_beacons
);
703 dl_list_add(&nl80211_wiphys
, &w
->list
);
706 /* drv entry for this bss already there? */
707 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
708 if (tmp_bss
->drv
== bss
->drv
) {
715 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
717 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
723 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
725 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
726 struct i802_bss
*tmp_bss
;
731 bss
->wiphy_data
= NULL
;
732 dl_list_del(&bss
->wiphy_list
);
734 /* still any for this drv present? */
735 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
736 if (tmp_bss
->drv
== bss
->drv
) {
741 /* if not remove it */
743 dl_list_del(&bss
->drv
->wiphy_list
);
745 if (!dl_list_empty(&w
->bsss
))
748 eloop_unregister_read_sock(nl_socket_get_fd(w
->nl_beacons
));
751 nl_destroy_handles(&w
->nl_beacons
);
752 dl_list_del(&w
->list
);
757 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
759 struct i802_bss
*bss
= priv
;
760 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
761 if (!drv
->associated
)
763 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
768 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
770 struct i802_bss
*bss
= priv
;
771 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
772 if (!drv
->associated
)
774 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
775 return drv
->ssid_len
;
779 static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data
*drv
,
780 char *buf
, size_t len
, int del
)
782 union wpa_event_data event
;
784 os_memset(&event
, 0, sizeof(event
));
785 if (len
> sizeof(event
.interface_status
.ifname
))
786 len
= sizeof(event
.interface_status
.ifname
) - 1;
787 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
788 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
789 EVENT_INTERFACE_ADDED
;
791 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
793 event
.interface_status
.ifname
,
794 del
? "removed" : "added");
796 if (os_strcmp(drv
->first_bss
.ifname
, event
.interface_status
.ifname
) == 0) {
798 if (drv
->if_removed
) {
799 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
800 "already set - ignore event");
805 if (if_nametoindex(drv
->first_bss
.ifname
) == 0) {
806 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s "
807 "does not exist - ignore "
809 drv
->first_bss
.ifname
);
812 if (!drv
->if_removed
) {
813 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
814 "already cleared - ignore event");
821 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
825 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
828 int attrlen
, rta_len
;
832 attr
= (struct rtattr
*) buf
;
834 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
835 while (RTA_OK(attr
, attrlen
)) {
836 if (attr
->rta_type
== IFLA_IFNAME
) {
837 if (os_strcmp(((char *) attr
) + rta_len
, drv
->first_bss
.ifname
)
843 attr
= RTA_NEXT(attr
, attrlen
);
850 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
851 int ifindex
, u8
*buf
, size_t len
)
853 if (drv
->ifindex
== ifindex
)
856 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
857 drv
->first_bss
.ifindex
= if_nametoindex(drv
->first_bss
.ifname
);
858 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
860 wpa_driver_nl80211_finish_drv_init(drv
);
868 static struct wpa_driver_nl80211_data
*
869 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
871 struct wpa_driver_nl80211_data
*drv
;
872 dl_list_for_each(drv
, &global
->interfaces
,
873 struct wpa_driver_nl80211_data
, list
) {
874 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
875 have_ifidx(drv
, idx
))
882 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
883 struct ifinfomsg
*ifi
,
886 struct nl80211_global
*global
= ctx
;
887 struct wpa_driver_nl80211_data
*drv
;
888 int attrlen
, rta_len
;
891 char namebuf
[IFNAMSIZ
];
893 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
895 wpa_printf(MSG_DEBUG
, "nl80211: Ignore event for foreign "
896 "ifindex %d", ifi
->ifi_index
);
900 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
902 drv
->operstate
, ifi
->ifi_flags
,
903 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
904 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
905 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
906 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
908 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
909 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
910 linux_iface_up(drv
->global
->ioctl_sock
,
911 drv
->first_bss
.ifname
) > 0) {
912 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
913 "event since interface %s is up", namebuf
);
916 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
917 if (drv
->ignore_if_down_event
) {
918 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
919 "event generated by mode change");
920 drv
->ignore_if_down_event
= 0;
922 drv
->if_disabled
= 1;
923 wpa_supplicant_event(drv
->ctx
,
924 EVENT_INTERFACE_DISABLED
, NULL
);
928 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
929 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
930 linux_iface_up(drv
->global
->ioctl_sock
,
931 drv
->first_bss
.ifname
) == 0) {
932 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
933 "event since interface %s is down",
935 } else if (if_nametoindex(drv
->first_bss
.ifname
) == 0) {
936 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
937 "event since interface %s does not exist",
938 drv
->first_bss
.ifname
);
939 } else if (drv
->if_removed
) {
940 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
941 "event since interface %s is marked "
942 "removed", drv
->first_bss
.ifname
);
944 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
945 drv
->if_disabled
= 0;
946 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
952 * Some drivers send the association event before the operup event--in
953 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
954 * fails. This will hit us when wpa_supplicant does not need to do
955 * IEEE 802.1X authentication
957 if (drv
->operstate
== 1 &&
958 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
959 !(ifi
->ifi_flags
& IFF_RUNNING
))
960 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
964 attr
= (struct rtattr
*) buf
;
965 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
966 while (RTA_OK(attr
, attrlen
)) {
967 if (attr
->rta_type
== IFLA_IFNAME
) {
968 wpa_driver_nl80211_event_link(
970 ((char *) attr
) + rta_len
,
971 attr
->rta_len
- rta_len
, 0);
972 } else if (attr
->rta_type
== IFLA_MASTER
)
973 brid
= nla_get_u32((struct nlattr
*) attr
);
974 attr
= RTA_NEXT(attr
, attrlen
);
977 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
978 /* device has been added to bridge */
979 if_indextoname(brid
, namebuf
);
980 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
982 add_ifidx(drv
, brid
);
987 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
988 struct ifinfomsg
*ifi
,
991 struct nl80211_global
*global
= ctx
;
992 struct wpa_driver_nl80211_data
*drv
;
993 int attrlen
, rta_len
;
997 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
999 wpa_printf(MSG_DEBUG
, "nl80211: Ignore dellink event for "
1000 "foreign ifindex %d", ifi
->ifi_index
);
1005 attr
= (struct rtattr
*) buf
;
1007 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1008 while (RTA_OK(attr
, attrlen
)) {
1009 if (attr
->rta_type
== IFLA_IFNAME
) {
1010 wpa_driver_nl80211_event_link(
1012 ((char *) attr
) + rta_len
,
1013 attr
->rta_len
- rta_len
, 1);
1014 } else if (attr
->rta_type
== IFLA_MASTER
)
1015 brid
= nla_get_u32((struct nlattr
*) attr
);
1016 attr
= RTA_NEXT(attr
, attrlen
);
1019 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1020 /* device has been removed from bridge */
1021 char namebuf
[IFNAMSIZ
];
1022 if_indextoname(brid
, namebuf
);
1023 wpa_printf(MSG_DEBUG
, "nl80211: Remove ifindex %u for bridge "
1024 "%s", brid
, namebuf
);
1025 del_ifidx(drv
, brid
);
1030 static void mlme_event_auth(struct wpa_driver_nl80211_data
*drv
,
1031 const u8
*frame
, size_t len
)
1033 const struct ieee80211_mgmt
*mgmt
;
1034 union wpa_event_data event
;
1036 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate event");
1037 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1038 if (len
< 24 + sizeof(mgmt
->u
.auth
)) {
1039 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1044 os_memcpy(drv
->auth_bssid
, mgmt
->sa
, ETH_ALEN
);
1045 os_memset(&event
, 0, sizeof(event
));
1046 os_memcpy(event
.auth
.peer
, mgmt
->sa
, ETH_ALEN
);
1047 event
.auth
.auth_type
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
1048 event
.auth
.auth_transaction
=
1049 le_to_host16(mgmt
->u
.auth
.auth_transaction
);
1050 event
.auth
.status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
1051 if (len
> 24 + sizeof(mgmt
->u
.auth
)) {
1052 event
.auth
.ies
= mgmt
->u
.auth
.variable
;
1053 event
.auth
.ies_len
= len
- 24 - sizeof(mgmt
->u
.auth
);
1056 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH
, &event
);
1060 static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1064 struct nl80211_bss_info_arg arg
;
1066 os_memset(&arg
, 0, sizeof(arg
));
1067 msg
= nlmsg_alloc();
1069 goto nla_put_failure
;
1071 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1072 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1075 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
1078 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1079 "associated BSS from scan results: %u MHz",
1081 return arg
.assoc_freq
? arg
.assoc_freq
: drv
->assoc_freq
;
1083 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1084 "(%s)", ret
, strerror(-ret
));
1087 return drv
->assoc_freq
;
1091 static void mlme_event_assoc(struct wpa_driver_nl80211_data
*drv
,
1092 const u8
*frame
, size_t len
)
1094 const struct ieee80211_mgmt
*mgmt
;
1095 union wpa_event_data event
;
1098 wpa_printf(MSG_DEBUG
, "nl80211: Associate event");
1099 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1100 if (len
< 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1101 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1106 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
1107 if (status
!= WLAN_STATUS_SUCCESS
) {
1108 os_memset(&event
, 0, sizeof(event
));
1109 event
.assoc_reject
.bssid
= mgmt
->bssid
;
1110 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1111 event
.assoc_reject
.resp_ies
=
1112 (u8
*) mgmt
->u
.assoc_resp
.variable
;
1113 event
.assoc_reject
.resp_ies_len
=
1114 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1116 event
.assoc_reject
.status_code
= status
;
1118 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1122 drv
->associated
= 1;
1123 os_memcpy(drv
->bssid
, mgmt
->sa
, ETH_ALEN
);
1125 os_memset(&event
, 0, sizeof(event
));
1126 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1127 event
.assoc_info
.resp_ies
= (u8
*) mgmt
->u
.assoc_resp
.variable
;
1128 event
.assoc_info
.resp_ies_len
=
1129 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1132 event
.assoc_info
.freq
= drv
->assoc_freq
;
1134 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1138 static void mlme_event_connect(struct wpa_driver_nl80211_data
*drv
,
1139 enum nl80211_commands cmd
, struct nlattr
*status
,
1140 struct nlattr
*addr
, struct nlattr
*req_ie
,
1141 struct nlattr
*resp_ie
)
1143 union wpa_event_data event
;
1145 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1147 * Avoid reporting two association events that would confuse
1150 wpa_printf(MSG_DEBUG
, "nl80211: Ignore connect event (cmd=%d) "
1151 "when using userspace SME", cmd
);
1155 if (cmd
== NL80211_CMD_CONNECT
)
1156 wpa_printf(MSG_DEBUG
, "nl80211: Connect event");
1157 else if (cmd
== NL80211_CMD_ROAM
)
1158 wpa_printf(MSG_DEBUG
, "nl80211: Roam event");
1160 os_memset(&event
, 0, sizeof(event
));
1161 if (cmd
== NL80211_CMD_CONNECT
&&
1162 nla_get_u16(status
) != WLAN_STATUS_SUCCESS
) {
1164 event
.assoc_reject
.bssid
= nla_data(addr
);
1166 event
.assoc_reject
.resp_ies
= nla_data(resp_ie
);
1167 event
.assoc_reject
.resp_ies_len
= nla_len(resp_ie
);
1169 event
.assoc_reject
.status_code
= nla_get_u16(status
);
1170 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1174 drv
->associated
= 1;
1176 os_memcpy(drv
->bssid
, nla_data(addr
), ETH_ALEN
);
1179 event
.assoc_info
.req_ies
= nla_data(req_ie
);
1180 event
.assoc_info
.req_ies_len
= nla_len(req_ie
);
1183 event
.assoc_info
.resp_ies
= nla_data(resp_ie
);
1184 event
.assoc_info
.resp_ies_len
= nla_len(resp_ie
);
1187 event
.assoc_info
.freq
= nl80211_get_assoc_freq(drv
);
1189 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1193 static void mlme_event_disconnect(struct wpa_driver_nl80211_data
*drv
,
1194 struct nlattr
*reason
, struct nlattr
*addr
,
1195 struct nlattr
*by_ap
)
1197 union wpa_event_data data
;
1198 unsigned int locally_generated
= by_ap
== NULL
;
1200 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1202 * Avoid reporting two disassociation events that could
1203 * confuse the core code.
1205 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1206 "event when using userspace SME");
1210 if (drv
->ignore_next_local_disconnect
) {
1211 drv
->ignore_next_local_disconnect
= 0;
1212 if (locally_generated
) {
1213 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1214 "event triggered during reassociation");
1217 wpa_printf(MSG_WARNING
, "nl80211: Was expecting local "
1218 "disconnect but got another disconnect "
1222 wpa_printf(MSG_DEBUG
, "nl80211: Disconnect event");
1223 drv
->associated
= 0;
1224 os_memset(&data
, 0, sizeof(data
));
1226 data
.deauth_info
.reason_code
= nla_get_u16(reason
);
1227 data
.deauth_info
.locally_generated
= by_ap
== NULL
;
1228 wpa_supplicant_event(drv
->ctx
, EVENT_DEAUTH
, &data
);
1232 static void mlme_event_ch_switch(struct wpa_driver_nl80211_data
*drv
,
1233 struct nlattr
*freq
, struct nlattr
*type
)
1235 union wpa_event_data data
;
1237 int chan_offset
= 0;
1239 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch event");
1244 switch (nla_get_u32(type
)) {
1245 case NL80211_CHAN_NO_HT
:
1248 case NL80211_CHAN_HT20
:
1250 case NL80211_CHAN_HT40PLUS
:
1253 case NL80211_CHAN_HT40MINUS
:
1258 data
.ch_switch
.freq
= nla_get_u32(freq
);
1259 data
.ch_switch
.ht_enabled
= ht_enabled
;
1260 data
.ch_switch
.ch_offset
= chan_offset
;
1262 wpa_supplicant_event(drv
->ctx
, EVENT_CH_SWITCH
, &data
);
1266 static void mlme_timeout_event(struct wpa_driver_nl80211_data
*drv
,
1267 enum nl80211_commands cmd
, struct nlattr
*addr
)
1269 union wpa_event_data event
;
1270 enum wpa_event_type ev
;
1272 if (nla_len(addr
) != ETH_ALEN
)
1275 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d; timeout with " MACSTR
,
1276 cmd
, MAC2STR((u8
*) nla_data(addr
)));
1278 if (cmd
== NL80211_CMD_AUTHENTICATE
)
1279 ev
= EVENT_AUTH_TIMED_OUT
;
1280 else if (cmd
== NL80211_CMD_ASSOCIATE
)
1281 ev
= EVENT_ASSOC_TIMED_OUT
;
1285 os_memset(&event
, 0, sizeof(event
));
1286 os_memcpy(event
.timeout_event
.addr
, nla_data(addr
), ETH_ALEN
);
1287 wpa_supplicant_event(drv
->ctx
, ev
, &event
);
1291 static void mlme_event_mgmt(struct wpa_driver_nl80211_data
*drv
,
1292 struct nlattr
*freq
, struct nlattr
*sig
,
1293 const u8
*frame
, size_t len
)
1295 const struct ieee80211_mgmt
*mgmt
;
1296 union wpa_event_data event
;
1300 wpa_printf(MSG_DEBUG
, "nl80211: Frame event");
1301 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1303 wpa_printf(MSG_DEBUG
, "nl80211: Too short action frame");
1307 fc
= le_to_host16(mgmt
->frame_control
);
1308 stype
= WLAN_FC_GET_STYPE(fc
);
1311 ssi_signal
= (s32
) nla_get_u32(sig
);
1313 os_memset(&event
, 0, sizeof(event
));
1315 event
.rx_action
.freq
= nla_get_u32(freq
);
1316 drv
->last_mgmt_freq
= event
.rx_action
.freq
;
1318 if (stype
== WLAN_FC_STYPE_ACTION
) {
1319 event
.rx_action
.da
= mgmt
->da
;
1320 event
.rx_action
.sa
= mgmt
->sa
;
1321 event
.rx_action
.bssid
= mgmt
->bssid
;
1322 event
.rx_action
.category
= mgmt
->u
.action
.category
;
1323 event
.rx_action
.data
= &mgmt
->u
.action
.category
+ 1;
1324 event
.rx_action
.len
= frame
+ len
- event
.rx_action
.data
;
1325 wpa_supplicant_event(drv
->ctx
, EVENT_RX_ACTION
, &event
);
1327 event
.rx_mgmt
.frame
= frame
;
1328 event
.rx_mgmt
.frame_len
= len
;
1329 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1330 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
1335 static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data
*drv
,
1336 struct nlattr
*cookie
, const u8
*frame
,
1337 size_t len
, struct nlattr
*ack
)
1339 union wpa_event_data event
;
1340 const struct ieee80211_hdr
*hdr
;
1343 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX status event");
1344 if (!is_ap_interface(drv
->nlmode
)) {
1350 cookie_val
= nla_get_u64(cookie
);
1351 wpa_printf(MSG_DEBUG
, "nl80211: Action TX status:"
1352 " cookie=0%llx%s (ack=%d)",
1353 (long long unsigned int) cookie_val
,
1354 cookie_val
== drv
->send_action_cookie
?
1355 " (match)" : " (unknown)", ack
!= NULL
);
1356 if (cookie_val
!= drv
->send_action_cookie
)
1360 hdr
= (const struct ieee80211_hdr
*) frame
;
1361 fc
= le_to_host16(hdr
->frame_control
);
1363 os_memset(&event
, 0, sizeof(event
));
1364 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
1365 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
1366 event
.tx_status
.dst
= hdr
->addr1
;
1367 event
.tx_status
.data
= frame
;
1368 event
.tx_status
.data_len
= len
;
1369 event
.tx_status
.ack
= ack
!= NULL
;
1370 wpa_supplicant_event(drv
->ctx
, EVENT_TX_STATUS
, &event
);
1374 static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data
*drv
,
1375 enum wpa_event_type type
,
1376 const u8
*frame
, size_t len
)
1378 const struct ieee80211_mgmt
*mgmt
;
1379 union wpa_event_data event
;
1380 const u8
*bssid
= NULL
;
1381 u16 reason_code
= 0;
1383 if (type
== EVENT_DEAUTH
)
1384 wpa_printf(MSG_DEBUG
, "nl80211: Deauthenticate event");
1386 wpa_printf(MSG_DEBUG
, "nl80211: Disassociate event");
1388 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1390 bssid
= mgmt
->bssid
;
1392 if (drv
->associated
!= 0 &&
1393 os_memcmp(bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
1394 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0) {
1396 * We have presumably received this deauth as a
1397 * response to a clear_state_mismatch() outgoing
1398 * deauth. Don't let it take us offline!
1400 wpa_printf(MSG_DEBUG
, "nl80211: Deauth received "
1401 "from Unknown BSSID " MACSTR
" -- ignoring",
1407 drv
->associated
= 0;
1408 os_memset(&event
, 0, sizeof(event
));
1410 /* Note: Same offset for Reason Code in both frame subtypes */
1411 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1412 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1414 if (type
== EVENT_DISASSOC
) {
1415 event
.disassoc_info
.locally_generated
=
1416 !os_memcmp(mgmt
->sa
, drv
->first_bss
.addr
, ETH_ALEN
);
1417 event
.disassoc_info
.addr
= bssid
;
1418 event
.disassoc_info
.reason_code
= reason_code
;
1419 if (frame
+ len
> mgmt
->u
.disassoc
.variable
) {
1420 event
.disassoc_info
.ie
= mgmt
->u
.disassoc
.variable
;
1421 event
.disassoc_info
.ie_len
= frame
+ len
-
1422 mgmt
->u
.disassoc
.variable
;
1425 event
.deauth_info
.locally_generated
=
1426 !os_memcmp(mgmt
->sa
, drv
->first_bss
.addr
, ETH_ALEN
);
1427 event
.deauth_info
.addr
= bssid
;
1428 event
.deauth_info
.reason_code
= reason_code
;
1429 if (frame
+ len
> mgmt
->u
.deauth
.variable
) {
1430 event
.deauth_info
.ie
= mgmt
->u
.deauth
.variable
;
1431 event
.deauth_info
.ie_len
= frame
+ len
-
1432 mgmt
->u
.deauth
.variable
;
1436 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1440 static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data
*drv
,
1441 enum wpa_event_type type
,
1442 const u8
*frame
, size_t len
)
1444 const struct ieee80211_mgmt
*mgmt
;
1445 union wpa_event_data event
;
1446 u16 reason_code
= 0;
1448 if (type
== EVENT_UNPROT_DEAUTH
)
1449 wpa_printf(MSG_DEBUG
, "nl80211: Unprot Deauthenticate event");
1451 wpa_printf(MSG_DEBUG
, "nl80211: Unprot Disassociate event");
1456 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1458 os_memset(&event
, 0, sizeof(event
));
1459 /* Note: Same offset for Reason Code in both frame subtypes */
1460 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1461 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1463 if (type
== EVENT_UNPROT_DISASSOC
) {
1464 event
.unprot_disassoc
.sa
= mgmt
->sa
;
1465 event
.unprot_disassoc
.da
= mgmt
->da
;
1466 event
.unprot_disassoc
.reason_code
= reason_code
;
1468 event
.unprot_deauth
.sa
= mgmt
->sa
;
1469 event
.unprot_deauth
.da
= mgmt
->da
;
1470 event
.unprot_deauth
.reason_code
= reason_code
;
1473 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1477 static void mlme_event(struct wpa_driver_nl80211_data
*drv
,
1478 enum nl80211_commands cmd
, struct nlattr
*frame
,
1479 struct nlattr
*addr
, struct nlattr
*timed_out
,
1480 struct nlattr
*freq
, struct nlattr
*ack
,
1481 struct nlattr
*cookie
, struct nlattr
*sig
)
1483 if (timed_out
&& addr
) {
1484 mlme_timeout_event(drv
, cmd
, addr
);
1488 if (frame
== NULL
) {
1489 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d without frame "
1494 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d", cmd
);
1495 wpa_hexdump(MSG_MSGDUMP
, "nl80211: MLME event frame",
1496 nla_data(frame
), nla_len(frame
));
1499 case NL80211_CMD_AUTHENTICATE
:
1500 mlme_event_auth(drv
, nla_data(frame
), nla_len(frame
));
1502 case NL80211_CMD_ASSOCIATE
:
1503 mlme_event_assoc(drv
, nla_data(frame
), nla_len(frame
));
1505 case NL80211_CMD_DEAUTHENTICATE
:
1506 mlme_event_deauth_disassoc(drv
, EVENT_DEAUTH
,
1507 nla_data(frame
), nla_len(frame
));
1509 case NL80211_CMD_DISASSOCIATE
:
1510 mlme_event_deauth_disassoc(drv
, EVENT_DISASSOC
,
1511 nla_data(frame
), nla_len(frame
));
1513 case NL80211_CMD_FRAME
:
1514 mlme_event_mgmt(drv
, freq
, sig
, nla_data(frame
),
1517 case NL80211_CMD_FRAME_TX_STATUS
:
1518 mlme_event_mgmt_tx_status(drv
, cookie
, nla_data(frame
),
1519 nla_len(frame
), ack
);
1521 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1522 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DEAUTH
,
1523 nla_data(frame
), nla_len(frame
));
1525 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1526 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DISASSOC
,
1527 nla_data(frame
), nla_len(frame
));
1535 static void mlme_event_michael_mic_failure(struct i802_bss
*bss
,
1536 struct nlattr
*tb
[])
1538 union wpa_event_data data
;
1540 wpa_printf(MSG_DEBUG
, "nl80211: MLME event Michael MIC failure");
1541 os_memset(&data
, 0, sizeof(data
));
1542 if (tb
[NL80211_ATTR_MAC
]) {
1543 wpa_hexdump(MSG_DEBUG
, "nl80211: Source MAC address",
1544 nla_data(tb
[NL80211_ATTR_MAC
]),
1545 nla_len(tb
[NL80211_ATTR_MAC
]));
1546 data
.michael_mic_failure
.src
= nla_data(tb
[NL80211_ATTR_MAC
]);
1548 if (tb
[NL80211_ATTR_KEY_SEQ
]) {
1549 wpa_hexdump(MSG_DEBUG
, "nl80211: TSC",
1550 nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
1551 nla_len(tb
[NL80211_ATTR_KEY_SEQ
]));
1553 if (tb
[NL80211_ATTR_KEY_TYPE
]) {
1554 enum nl80211_key_type key_type
=
1555 nla_get_u32(tb
[NL80211_ATTR_KEY_TYPE
]);
1556 wpa_printf(MSG_DEBUG
, "nl80211: Key Type %d", key_type
);
1557 if (key_type
== NL80211_KEYTYPE_PAIRWISE
)
1558 data
.michael_mic_failure
.unicast
= 1;
1560 data
.michael_mic_failure
.unicast
= 1;
1562 if (tb
[NL80211_ATTR_KEY_IDX
]) {
1563 u8 key_id
= nla_get_u8(tb
[NL80211_ATTR_KEY_IDX
]);
1564 wpa_printf(MSG_DEBUG
, "nl80211: Key Id %d", key_id
);
1567 wpa_supplicant_event(bss
->ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
1571 static void mlme_event_join_ibss(struct wpa_driver_nl80211_data
*drv
,
1572 struct nlattr
*tb
[])
1574 if (tb
[NL80211_ATTR_MAC
] == NULL
) {
1575 wpa_printf(MSG_DEBUG
, "nl80211: No address in IBSS joined "
1579 os_memcpy(drv
->bssid
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1580 drv
->associated
= 1;
1581 wpa_printf(MSG_DEBUG
, "nl80211: IBSS " MACSTR
" joined",
1582 MAC2STR(drv
->bssid
));
1584 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1588 static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data
*drv
,
1589 int cancel_event
, struct nlattr
*tb
[])
1591 unsigned int freq
, chan_type
, duration
;
1592 union wpa_event_data data
;
1595 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1596 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1600 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1601 chan_type
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1605 if (tb
[NL80211_ATTR_DURATION
])
1606 duration
= nla_get_u32(tb
[NL80211_ATTR_DURATION
]);
1610 if (tb
[NL80211_ATTR_COOKIE
])
1611 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
1615 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel event (cancel=%d "
1616 "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
1617 cancel_event
, freq
, chan_type
, duration
,
1618 (long long unsigned int) cookie
,
1619 cookie
== drv
->remain_on_chan_cookie
? "match" : "unknown");
1621 if (cookie
!= drv
->remain_on_chan_cookie
)
1622 return; /* not for us */
1625 drv
->pending_remain_on_chan
= 0;
1627 os_memset(&data
, 0, sizeof(data
));
1628 data
.remain_on_channel
.freq
= freq
;
1629 data
.remain_on_channel
.duration
= duration
;
1630 wpa_supplicant_event(drv
->ctx
, cancel_event
?
1631 EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1632 EVENT_REMAIN_ON_CHANNEL
, &data
);
1636 static void send_scan_event(struct wpa_driver_nl80211_data
*drv
, int aborted
,
1637 struct nlattr
*tb
[])
1639 union wpa_event_data event
;
1642 struct scan_info
*info
;
1643 #define MAX_REPORT_FREQS 50
1644 int freqs
[MAX_REPORT_FREQS
];
1647 if (drv
->scan_for_auth
) {
1648 drv
->scan_for_auth
= 0;
1649 wpa_printf(MSG_DEBUG
, "nl80211: Scan results for missing "
1650 "cfg80211 BSS entry");
1651 wpa_driver_nl80211_authenticate_retry(drv
);
1655 os_memset(&event
, 0, sizeof(event
));
1656 info
= &event
.scan_info
;
1657 info
->aborted
= aborted
;
1659 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
1660 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem
) {
1661 struct wpa_driver_scan_ssid
*s
=
1662 &info
->ssids
[info
->num_ssids
];
1663 s
->ssid
= nla_data(nl
);
1664 s
->ssid_len
= nla_len(nl
);
1666 if (info
->num_ssids
== WPAS_MAX_SCAN_SSIDS
)
1670 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
1671 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem
)
1673 freqs
[num_freqs
] = nla_get_u32(nl
);
1675 if (num_freqs
== MAX_REPORT_FREQS
- 1)
1678 info
->freqs
= freqs
;
1679 info
->num_freqs
= num_freqs
;
1681 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
, &event
);
1685 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1687 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1688 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1689 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1690 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1691 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1693 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1694 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1695 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1696 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1697 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1698 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1700 struct wpa_signal_info
*sig_change
= arg
;
1702 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1703 genlmsg_attrlen(gnlh
, 0), NULL
);
1704 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1705 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1706 tb
[NL80211_ATTR_STA_INFO
], policy
))
1708 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1711 sig_change
->current_signal
=
1712 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1714 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1715 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1716 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1718 sig_change
->current_txrate
= 0;
1720 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1721 sig_change
->current_txrate
=
1723 NL80211_RATE_INFO_BITRATE
]) * 100;
1732 static int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1733 struct wpa_signal_info
*sig
)
1737 sig
->current_signal
= -9999;
1738 sig
->current_txrate
= 0;
1740 msg
= nlmsg_alloc();
1744 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
1746 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1747 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
1749 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1756 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1758 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1759 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1760 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1761 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1762 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1763 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1765 struct wpa_signal_info
*sig_change
= arg
;
1767 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1768 genlmsg_attrlen(gnlh
, 0), NULL
);
1770 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1771 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1775 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1776 tb
[NL80211_ATTR_SURVEY_INFO
],
1778 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1783 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1786 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1787 sig_change
->frequency
)
1790 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1793 sig_change
->current_noise
=
1794 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1800 static int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1801 struct wpa_signal_info
*sig_change
)
1805 sig_change
->current_noise
= 9999;
1806 sig_change
->frequency
= drv
->assoc_freq
;
1808 msg
= nlmsg_alloc();
1812 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1814 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1816 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1823 static int get_noise_for_scan_results(struct nl_msg
*msg
, void *arg
)
1825 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1826 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1827 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1828 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1829 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1830 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1832 struct wpa_scan_results
*scan_results
= arg
;
1833 struct wpa_scan_res
*scan_res
;
1836 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1837 genlmsg_attrlen(gnlh
, 0), NULL
);
1839 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1840 wpa_printf(MSG_DEBUG
, "nl80211: Survey data missing");
1844 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1845 tb
[NL80211_ATTR_SURVEY_INFO
],
1847 wpa_printf(MSG_DEBUG
, "nl80211: Failed to parse nested "
1852 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1855 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1858 for (i
= 0; i
< scan_results
->num
; ++i
) {
1859 scan_res
= scan_results
->res
[i
];
1862 if ((int) nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1865 if (!(scan_res
->flags
& WPA_SCAN_NOISE_INVALID
))
1867 scan_res
->noise
= (s8
)
1868 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1869 scan_res
->flags
&= ~WPA_SCAN_NOISE_INVALID
;
1876 static int nl80211_get_noise_for_scan_results(
1877 struct wpa_driver_nl80211_data
*drv
,
1878 struct wpa_scan_results
*scan_res
)
1882 msg
= nlmsg_alloc();
1886 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1888 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1890 return send_and_recv_msgs(drv
, msg
, get_noise_for_scan_results
,
1898 static void nl80211_cqm_event(struct wpa_driver_nl80211_data
*drv
,
1899 struct nlattr
*tb
[])
1901 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
1902 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
1903 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U8
},
1904 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
1905 [NL80211_ATTR_CQM_PKT_LOSS_EVENT
] = { .type
= NLA_U32
},
1907 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
1908 enum nl80211_cqm_rssi_threshold_event event
;
1909 union wpa_event_data ed
;
1910 struct wpa_signal_info sig
;
1913 if (tb
[NL80211_ATTR_CQM
] == NULL
||
1914 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, tb
[NL80211_ATTR_CQM
],
1916 wpa_printf(MSG_DEBUG
, "nl80211: Ignore invalid CQM event");
1920 os_memset(&ed
, 0, sizeof(ed
));
1922 if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
1923 if (!tb
[NL80211_ATTR_MAC
])
1925 os_memcpy(ed
.low_ack
.addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
1927 wpa_supplicant_event(drv
->ctx
, EVENT_STATION_LOW_ACK
, &ed
);
1931 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] == NULL
)
1933 event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
1935 if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
) {
1936 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1937 "event: RSSI high");
1938 ed
.signal_change
.above_threshold
= 1;
1939 } else if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
) {
1940 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1942 ed
.signal_change
.above_threshold
= 0;
1946 res
= nl80211_get_link_signal(drv
, &sig
);
1948 ed
.signal_change
.current_signal
= sig
.current_signal
;
1949 ed
.signal_change
.current_txrate
= sig
.current_txrate
;
1950 wpa_printf(MSG_DEBUG
, "nl80211: Signal: %d dBm txrate: %d",
1951 sig
.current_signal
, sig
.current_txrate
);
1954 res
= nl80211_get_link_noise(drv
, &sig
);
1956 ed
.signal_change
.current_noise
= sig
.current_noise
;
1957 wpa_printf(MSG_DEBUG
, "nl80211: Noise: %d dBm",
1961 wpa_supplicant_event(drv
->ctx
, EVENT_SIGNAL_CHANGE
, &ed
);
1965 static void nl80211_new_station_event(struct wpa_driver_nl80211_data
*drv
,
1969 union wpa_event_data data
;
1971 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1973 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1974 wpa_printf(MSG_DEBUG
, "nl80211: New station " MACSTR
, MAC2STR(addr
));
1976 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
1979 if (tb
[NL80211_ATTR_IE
]) {
1980 ies
= nla_data(tb
[NL80211_ATTR_IE
]);
1981 ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
1983 wpa_hexdump(MSG_DEBUG
, "nl80211: Assoc Req IEs", ies
, ies_len
);
1984 drv_event_assoc(drv
->ctx
, addr
, ies
, ies_len
, 0);
1988 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1991 os_memset(&data
, 0, sizeof(data
));
1992 os_memcpy(data
.ibss_rsn_start
.peer
, addr
, ETH_ALEN
);
1993 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_RSN_START
, &data
);
1997 static void nl80211_del_station_event(struct wpa_driver_nl80211_data
*drv
,
2001 union wpa_event_data data
;
2003 if (tb
[NL80211_ATTR_MAC
] == NULL
)
2005 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2006 wpa_printf(MSG_DEBUG
, "nl80211: Delete station " MACSTR
,
2009 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
2010 drv_event_disassoc(drv
->ctx
, addr
);
2014 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
2017 os_memset(&data
, 0, sizeof(data
));
2018 os_memcpy(data
.ibss_peer_lost
.peer
, addr
, ETH_ALEN
);
2019 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_PEER_LOST
, &data
);
2023 static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data
*drv
,
2026 struct nlattr
*rekey_info
[NUM_NL80211_REKEY_DATA
];
2027 static struct nla_policy rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
2028 [NL80211_REKEY_DATA_KEK
] = {
2029 .minlen
= NL80211_KEK_LEN
,
2030 .maxlen
= NL80211_KEK_LEN
,
2032 [NL80211_REKEY_DATA_KCK
] = {
2033 .minlen
= NL80211_KCK_LEN
,
2034 .maxlen
= NL80211_KCK_LEN
,
2036 [NL80211_REKEY_DATA_REPLAY_CTR
] = {
2037 .minlen
= NL80211_REPLAY_CTR_LEN
,
2038 .maxlen
= NL80211_REPLAY_CTR_LEN
,
2041 union wpa_event_data data
;
2043 if (!tb
[NL80211_ATTR_MAC
])
2045 if (!tb
[NL80211_ATTR_REKEY_DATA
])
2047 if (nla_parse_nested(rekey_info
, MAX_NL80211_REKEY_DATA
,
2048 tb
[NL80211_ATTR_REKEY_DATA
], rekey_policy
))
2050 if (!rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
])
2053 os_memset(&data
, 0, sizeof(data
));
2054 data
.driver_gtk_rekey
.bssid
= nla_data(tb
[NL80211_ATTR_MAC
]);
2055 wpa_printf(MSG_DEBUG
, "nl80211: Rekey offload event for BSSID " MACSTR
,
2056 MAC2STR(data
.driver_gtk_rekey
.bssid
));
2057 data
.driver_gtk_rekey
.replay_ctr
=
2058 nla_data(rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
]);
2059 wpa_hexdump(MSG_DEBUG
, "nl80211: Rekey offload - Replay Counter",
2060 data
.driver_gtk_rekey
.replay_ctr
, NL80211_REPLAY_CTR_LEN
);
2061 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_GTK_REKEY
, &data
);
2065 static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data
*drv
,
2068 struct nlattr
*cand
[NUM_NL80211_PMKSA_CANDIDATE
];
2069 static struct nla_policy cand_policy
[NUM_NL80211_PMKSA_CANDIDATE
] = {
2070 [NL80211_PMKSA_CANDIDATE_INDEX
] = { .type
= NLA_U32
},
2071 [NL80211_PMKSA_CANDIDATE_BSSID
] = {
2075 [NL80211_PMKSA_CANDIDATE_PREAUTH
] = { .type
= NLA_FLAG
},
2077 union wpa_event_data data
;
2079 wpa_printf(MSG_DEBUG
, "nl80211: PMKSA candidate event");
2081 if (!tb
[NL80211_ATTR_PMKSA_CANDIDATE
])
2083 if (nla_parse_nested(cand
, MAX_NL80211_PMKSA_CANDIDATE
,
2084 tb
[NL80211_ATTR_PMKSA_CANDIDATE
], cand_policy
))
2086 if (!cand
[NL80211_PMKSA_CANDIDATE_INDEX
] ||
2087 !cand
[NL80211_PMKSA_CANDIDATE_BSSID
])
2090 os_memset(&data
, 0, sizeof(data
));
2091 os_memcpy(data
.pmkid_candidate
.bssid
,
2092 nla_data(cand
[NL80211_PMKSA_CANDIDATE_BSSID
]), ETH_ALEN
);
2093 data
.pmkid_candidate
.index
=
2094 nla_get_u32(cand
[NL80211_PMKSA_CANDIDATE_INDEX
]);
2095 data
.pmkid_candidate
.preauth
=
2096 cand
[NL80211_PMKSA_CANDIDATE_PREAUTH
] != NULL
;
2097 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
2101 static void nl80211_client_probe_event(struct wpa_driver_nl80211_data
*drv
,
2104 union wpa_event_data data
;
2106 wpa_printf(MSG_DEBUG
, "nl80211: Probe client event");
2108 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_ACK
])
2111 os_memset(&data
, 0, sizeof(data
));
2112 os_memcpy(data
.client_poll
.addr
,
2113 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2115 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_CLIENT_POLL_OK
, &data
);
2119 static void nl80211_tdls_oper_event(struct wpa_driver_nl80211_data
*drv
,
2122 union wpa_event_data data
;
2124 wpa_printf(MSG_DEBUG
, "nl80211: TDLS operation event");
2126 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_TDLS_OPERATION
])
2129 os_memset(&data
, 0, sizeof(data
));
2130 os_memcpy(data
.tdls
.peer
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2131 switch (nla_get_u8(tb
[NL80211_ATTR_TDLS_OPERATION
])) {
2132 case NL80211_TDLS_SETUP
:
2133 wpa_printf(MSG_DEBUG
, "nl80211: TDLS setup request for peer "
2134 MACSTR
, MAC2STR(data
.tdls
.peer
));
2135 data
.tdls
.oper
= TDLS_REQUEST_SETUP
;
2137 case NL80211_TDLS_TEARDOWN
:
2138 wpa_printf(MSG_DEBUG
, "nl80211: TDLS teardown request for peer "
2139 MACSTR
, MAC2STR(data
.tdls
.peer
));
2140 data
.tdls
.oper
= TDLS_REQUEST_TEARDOWN
;
2143 wpa_printf(MSG_DEBUG
, "nl80211: Unsupported TDLS operatione "
2147 if (tb
[NL80211_ATTR_REASON_CODE
]) {
2148 data
.tdls
.reason_code
=
2149 nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
]);
2152 wpa_supplicant_event(drv
->ctx
, EVENT_TDLS
, &data
);
2156 static void nl80211_connect_failed_event(struct wpa_driver_nl80211_data
*drv
,
2159 union wpa_event_data data
;
2162 wpa_printf(MSG_DEBUG
, "nl80211: Connect failed event");
2164 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_CONN_FAILED_REASON
])
2167 os_memset(&data
, 0, sizeof(data
));
2168 os_memcpy(data
.connect_failed_reason
.addr
,
2169 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2171 reason
= nla_get_u32(tb
[NL80211_ATTR_CONN_FAILED_REASON
]);
2173 case NL80211_CONN_FAIL_MAX_CLIENTS
:
2174 wpa_printf(MSG_DEBUG
, "nl80211: Max client reached");
2175 data
.connect_failed_reason
.code
= MAX_CLIENT_REACHED
;
2177 case NL80211_CONN_FAIL_BLOCKED_CLIENT
:
2178 wpa_printf(MSG_DEBUG
, "nl80211: Blocked client " MACSTR
2179 " tried to connect",
2180 MAC2STR(data
.connect_failed_reason
.addr
));
2181 data
.connect_failed_reason
.code
= BLOCKED_CLIENT
;
2184 wpa_printf(MSG_DEBUG
, "nl8021l: Unknown connect failed reason "
2189 wpa_supplicant_event(drv
->ctx
, EVENT_CONNECT_FAILED_REASON
, &data
);
2193 static void nl80211_spurious_frame(struct i802_bss
*bss
, struct nlattr
**tb
,
2196 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2197 union wpa_event_data event
;
2199 if (!tb
[NL80211_ATTR_MAC
])
2202 os_memset(&event
, 0, sizeof(event
));
2203 event
.rx_from_unknown
.bssid
= bss
->addr
;
2204 event
.rx_from_unknown
.addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2205 event
.rx_from_unknown
.wds
= wds
;
2207 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
2211 static void do_process_drv_event(struct i802_bss
*bss
, int cmd
,
2214 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2216 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
&&
2217 (cmd
== NL80211_CMD_NEW_SCAN_RESULTS
||
2218 cmd
== NL80211_CMD_SCAN_ABORTED
)) {
2219 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
2220 drv
->ap_scan_as_station
);
2221 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2225 case NL80211_CMD_TRIGGER_SCAN
:
2226 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger");
2228 case NL80211_CMD_START_SCHED_SCAN
:
2229 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan started");
2231 case NL80211_CMD_SCHED_SCAN_STOPPED
:
2232 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stopped");
2233 wpa_supplicant_event(drv
->ctx
, EVENT_SCHED_SCAN_STOPPED
, NULL
);
2235 case NL80211_CMD_NEW_SCAN_RESULTS
:
2236 wpa_printf(MSG_DEBUG
, "nl80211: New scan results available");
2237 drv
->scan_complete_events
= 1;
2238 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2240 send_scan_event(drv
, 0, tb
);
2242 case NL80211_CMD_SCHED_SCAN_RESULTS
:
2243 wpa_printf(MSG_DEBUG
,
2244 "nl80211: New sched scan results available");
2245 send_scan_event(drv
, 0, tb
);
2247 case NL80211_CMD_SCAN_ABORTED
:
2248 wpa_printf(MSG_DEBUG
, "nl80211: Scan aborted");
2250 * Need to indicate that scan results are available in order
2251 * not to make wpa_supplicant stop its scanning.
2253 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2255 send_scan_event(drv
, 1, tb
);
2257 case NL80211_CMD_AUTHENTICATE
:
2258 case NL80211_CMD_ASSOCIATE
:
2259 case NL80211_CMD_DEAUTHENTICATE
:
2260 case NL80211_CMD_DISASSOCIATE
:
2261 case NL80211_CMD_FRAME_TX_STATUS
:
2262 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
2263 case NL80211_CMD_UNPROT_DISASSOCIATE
:
2264 mlme_event(drv
, cmd
, tb
[NL80211_ATTR_FRAME
],
2265 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2266 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2267 tb
[NL80211_ATTR_COOKIE
],
2268 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2270 case NL80211_CMD_CONNECT
:
2271 case NL80211_CMD_ROAM
:
2272 mlme_event_connect(drv
, cmd
,
2273 tb
[NL80211_ATTR_STATUS_CODE
],
2274 tb
[NL80211_ATTR_MAC
],
2275 tb
[NL80211_ATTR_REQ_IE
],
2276 tb
[NL80211_ATTR_RESP_IE
]);
2278 case NL80211_CMD_CH_SWITCH_NOTIFY
:
2279 mlme_event_ch_switch(drv
, tb
[NL80211_ATTR_WIPHY_FREQ
],
2280 tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2282 case NL80211_CMD_DISCONNECT
:
2283 mlme_event_disconnect(drv
, tb
[NL80211_ATTR_REASON_CODE
],
2284 tb
[NL80211_ATTR_MAC
],
2285 tb
[NL80211_ATTR_DISCONNECTED_BY_AP
]);
2287 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
2288 mlme_event_michael_mic_failure(bss
, tb
);
2290 case NL80211_CMD_JOIN_IBSS
:
2291 mlme_event_join_ibss(drv
, tb
);
2293 case NL80211_CMD_REMAIN_ON_CHANNEL
:
2294 mlme_event_remain_on_channel(drv
, 0, tb
);
2296 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
2297 mlme_event_remain_on_channel(drv
, 1, tb
);
2299 case NL80211_CMD_NOTIFY_CQM
:
2300 nl80211_cqm_event(drv
, tb
);
2302 case NL80211_CMD_REG_CHANGE
:
2303 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory domain change");
2304 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2307 case NL80211_CMD_REG_BEACON_HINT
:
2308 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory beacon hint");
2309 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2312 case NL80211_CMD_NEW_STATION
:
2313 nl80211_new_station_event(drv
, tb
);
2315 case NL80211_CMD_DEL_STATION
:
2316 nl80211_del_station_event(drv
, tb
);
2318 case NL80211_CMD_SET_REKEY_OFFLOAD
:
2319 nl80211_rekey_offload_event(drv
, tb
);
2321 case NL80211_CMD_PMKSA_CANDIDATE
:
2322 nl80211_pmksa_candidate_event(drv
, tb
);
2324 case NL80211_CMD_PROBE_CLIENT
:
2325 nl80211_client_probe_event(drv
, tb
);
2327 case NL80211_CMD_TDLS_OPER
:
2328 nl80211_tdls_oper_event(drv
, tb
);
2330 case NL80211_CMD_CONN_FAILED
:
2331 nl80211_connect_failed_event(drv
, tb
);
2334 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2341 static int process_drv_event(struct nl_msg
*msg
, void *arg
)
2343 struct wpa_driver_nl80211_data
*drv
= arg
;
2344 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2345 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2346 struct i802_bss
*bss
;
2349 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2350 genlmsg_attrlen(gnlh
, 0), NULL
);
2352 if (tb
[NL80211_ATTR_IFINDEX
])
2353 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2355 for (bss
= &drv
->first_bss
; bss
; bss
= bss
->next
) {
2356 if (ifidx
== -1 || ifidx
== bss
->ifindex
) {
2357 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2362 wpa_printf(MSG_DEBUG
, "nl80211: Ignored event (cmd=%d) for foreign "
2363 "interface (ifindex %d)", gnlh
->cmd
, ifidx
);
2369 static int process_global_event(struct nl_msg
*msg
, void *arg
)
2371 struct nl80211_global
*global
= arg
;
2372 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2373 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2374 struct wpa_driver_nl80211_data
*drv
, *tmp
;
2376 struct i802_bss
*bss
;
2378 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2379 genlmsg_attrlen(gnlh
, 0), NULL
);
2381 if (tb
[NL80211_ATTR_IFINDEX
])
2382 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2384 dl_list_for_each_safe(drv
, tmp
, &global
->interfaces
,
2385 struct wpa_driver_nl80211_data
, list
) {
2386 for (bss
= &drv
->first_bss
; bss
; bss
= bss
->next
) {
2387 if (ifidx
== -1 || ifidx
== bss
->ifindex
) {
2388 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2398 static int process_bss_event(struct nl_msg
*msg
, void *arg
)
2400 struct i802_bss
*bss
= arg
;
2401 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2402 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2404 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2405 genlmsg_attrlen(gnlh
, 0), NULL
);
2407 switch (gnlh
->cmd
) {
2408 case NL80211_CMD_FRAME
:
2409 case NL80211_CMD_FRAME_TX_STATUS
:
2410 mlme_event(bss
->drv
, gnlh
->cmd
, tb
[NL80211_ATTR_FRAME
],
2411 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2412 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2413 tb
[NL80211_ATTR_COOKIE
],
2414 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2416 case NL80211_CMD_UNEXPECTED_FRAME
:
2417 nl80211_spurious_frame(bss
, tb
, 0);
2419 case NL80211_CMD_UNEXPECTED_4ADDR_FRAME
:
2420 nl80211_spurious_frame(bss
, tb
, 1);
2423 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2424 "(cmd=%d)", gnlh
->cmd
);
2432 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
2435 struct nl_cb
*cb
= eloop_ctx
;
2437 wpa_printf(MSG_DEBUG
, "nl80211: Event message available");
2439 nl_recvmsgs(handle
, cb
);
2444 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
2445 * @priv: driver_nl80211 private data
2446 * @alpha2_arg: country to which to switch to
2447 * Returns: 0 on success, -1 on failure
2449 * This asks nl80211 to set the regulatory domain for given
2450 * country ISO / IEC alpha2.
2452 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
2454 struct i802_bss
*bss
= priv
;
2455 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2459 msg
= nlmsg_alloc();
2463 alpha2
[0] = alpha2_arg
[0];
2464 alpha2
[1] = alpha2_arg
[1];
2467 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
);
2469 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
);
2470 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
2479 static int protocol_feature_handler(struct nl_msg
*msg
, void *arg
)
2482 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
2483 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2485 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2486 genlmsg_attrlen(gnlh
, 0), NULL
);
2488 if (tb_msg
[NL80211_ATTR_PROTOCOL_FEATURES
])
2489 *feat
= nla_get_u32(tb_msg
[NL80211_ATTR_PROTOCOL_FEATURES
]);
2495 static u32
get_nl80211_protocol_features(struct wpa_driver_nl80211_data
*drv
)
2500 msg
= nlmsg_alloc();
2502 goto nla_put_failure
;
2504 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_PROTOCOL_FEATURES
);
2505 if (send_and_recv_msgs(drv
, msg
, protocol_feature_handler
, &feat
) == 0)
2515 struct wiphy_info_data
{
2516 struct wpa_driver_capa
*capa
;
2518 unsigned int error
:1;
2519 unsigned int device_ap_sme
:1;
2520 unsigned int poll_command_supported
:1;
2521 unsigned int data_tx_status
:1;
2522 unsigned int monitor_supported
:1;
2523 unsigned int auth_supported
:1;
2524 unsigned int connect_supported
:1;
2525 unsigned int p2p_go_supported
:1;
2526 unsigned int p2p_client_supported
:1;
2527 unsigned int p2p_concurrent
:1;
2528 unsigned int p2p_multichan_concurrent
:1;
2532 static unsigned int probe_resp_offload_support(int supp_protocols
)
2534 unsigned int prot
= 0;
2536 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
)
2537 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
;
2538 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
)
2539 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
;
2540 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
)
2541 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
;
2542 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
)
2543 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
;
2549 static void wiphy_info_supported_iftypes(struct wiphy_info_data
*info
,
2552 struct nlattr
*nl_mode
;
2558 nla_for_each_nested(nl_mode
, tb
, i
) {
2559 switch (nla_type(nl_mode
)) {
2560 case NL80211_IFTYPE_AP
:
2561 info
->capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
2563 case NL80211_IFTYPE_P2P_GO
:
2564 info
->p2p_go_supported
= 1;
2566 case NL80211_IFTYPE_P2P_CLIENT
:
2567 info
->p2p_client_supported
= 1;
2569 case NL80211_IFTYPE_MONITOR
:
2570 info
->monitor_supported
= 1;
2577 static int wiphy_info_iface_comb_process(struct wiphy_info_data
*info
,
2578 struct nlattr
*nl_combi
)
2580 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
2581 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
2582 struct nlattr
*nl_limit
, *nl_mode
;
2583 int err
, rem_limit
, rem_mode
;
2584 int combination_has_p2p
= 0, combination_has_mgd
= 0;
2585 static struct nla_policy
2586 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
2587 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
2588 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
2589 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
2590 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
2592 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
2593 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
2594 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
2597 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
2598 nl_combi
, iface_combination_policy
);
2599 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
2600 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
2601 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
2602 return 0; /* broken combination */
2604 nla_for_each_nested(nl_limit
, tb_comb
[NL80211_IFACE_COMB_LIMITS
],
2606 err
= nla_parse_nested(tb_limit
, MAX_NL80211_IFACE_LIMIT
,
2607 nl_limit
, iface_limit_policy
);
2608 if (err
|| !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
2609 return 0; /* broken combination */
2611 nla_for_each_nested(nl_mode
,
2612 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
2614 int ift
= nla_type(nl_mode
);
2615 if (ift
== NL80211_IFTYPE_P2P_GO
||
2616 ift
== NL80211_IFTYPE_P2P_CLIENT
)
2617 combination_has_p2p
= 1;
2618 if (ift
== NL80211_IFTYPE_STATION
)
2619 combination_has_mgd
= 1;
2621 if (combination_has_p2p
&& combination_has_mgd
)
2625 if (combination_has_p2p
&& combination_has_mgd
) {
2626 info
->p2p_concurrent
= 1;
2627 if (nla_get_u32(tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]) > 1)
2628 info
->p2p_multichan_concurrent
= 1;
2636 static void wiphy_info_iface_comb(struct wiphy_info_data
*info
,
2639 struct nlattr
*nl_combi
;
2645 nla_for_each_nested(nl_combi
, tb
, rem_combi
) {
2646 if (wiphy_info_iface_comb_process(info
, nl_combi
) > 0)
2652 static void wiphy_info_supp_cmds(struct wiphy_info_data
*info
,
2655 struct nlattr
*nl_cmd
;
2661 nla_for_each_nested(nl_cmd
, tb
, i
) {
2662 switch (nla_get_u32(nl_cmd
)) {
2663 case NL80211_CMD_AUTHENTICATE
:
2664 info
->auth_supported
= 1;
2666 case NL80211_CMD_CONNECT
:
2667 info
->connect_supported
= 1;
2669 case NL80211_CMD_START_SCHED_SCAN
:
2670 info
->capa
->sched_scan_supported
= 1;
2672 case NL80211_CMD_PROBE_CLIENT
:
2673 info
->poll_command_supported
= 1;
2680 static void wiphy_info_max_roc(struct wpa_driver_capa
*capa
,
2683 /* default to 5000 since early versions of mac80211 don't set it */
2684 capa
->max_remain_on_chan
= 5000;
2687 capa
->max_remain_on_chan
= nla_get_u32(tb
);
2691 static void wiphy_info_tdls(struct wpa_driver_capa
*capa
, struct nlattr
*tdls
,
2692 struct nlattr
*ext_setup
)
2697 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
2698 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
2701 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
2702 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
2707 static void wiphy_info_feature_flags(struct wiphy_info_data
*info
,
2711 struct wpa_driver_capa
*capa
= info
->capa
;
2716 flags
= nla_get_u32(tb
);
2718 if (flags
& NL80211_FEATURE_SK_TX_STATUS
)
2719 info
->data_tx_status
= 1;
2721 if (flags
& NL80211_FEATURE_INACTIVITY_TIMER
)
2722 capa
->flags
|= WPA_DRIVER_FLAGS_INACTIVITY_TIMER
;
2724 if (flags
& NL80211_FEATURE_SAE
)
2725 capa
->flags
|= WPA_DRIVER_FLAGS_SAE
;
2727 if (flags
& NL80211_FEATURE_NEED_OBSS_SCAN
)
2728 capa
->flags
|= WPA_DRIVER_FLAGS_OBSS_SCAN
;
2732 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa
*capa
,
2740 protocols
= nla_get_u32(tb
);
2741 wpa_printf(MSG_DEBUG
, "nl80211: Supports Probe Response offload in AP "
2743 capa
->flags
|= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
;
2744 capa
->probe_resp_offloads
= probe_resp_offload_support(protocols
);
2748 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
2750 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2751 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2752 struct wiphy_info_data
*info
= arg
;
2753 struct wpa_driver_capa
*capa
= info
->capa
;
2755 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2756 genlmsg_attrlen(gnlh
, 0), NULL
);
2758 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
2759 capa
->max_scan_ssids
=
2760 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
2762 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
2763 capa
->max_sched_scan_ssids
=
2764 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
2766 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
2767 capa
->max_match_sets
=
2768 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
2770 wiphy_info_supported_iftypes(info
, tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]);
2771 wiphy_info_iface_comb(info
, tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]);
2772 wiphy_info_supp_cmds(info
, tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]);
2774 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
2775 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
2777 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
2780 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
2781 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
2782 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
2785 wiphy_info_max_roc(capa
,
2786 tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
2788 if (tb
[NL80211_ATTR_SUPPORT_AP_UAPSD
])
2789 capa
->flags
|= WPA_DRIVER_FLAGS_AP_UAPSD
;
2791 wiphy_info_tdls(capa
, tb
[NL80211_ATTR_TDLS_SUPPORT
],
2792 tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]);
2794 if (tb
[NL80211_ATTR_DEVICE_AP_SME
])
2795 info
->device_ap_sme
= 1;
2797 wiphy_info_feature_flags(info
, tb
[NL80211_ATTR_FEATURE_FLAGS
]);
2798 wiphy_info_probe_resp_offload(capa
,
2799 tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]);
2805 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
2806 struct wiphy_info_data
*info
)
2811 os_memset(info
, 0, sizeof(*info
));
2812 info
->capa
= &drv
->capa
;
2814 msg
= nlmsg_alloc();
2818 feat
= get_nl80211_protocol_features(drv
);
2819 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
2820 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_WIPHY
);
2822 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
2824 NLA_PUT_FLAG(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
);
2825 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->first_bss
.ifindex
);
2827 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
))
2830 if (info
->auth_supported
)
2831 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SME
;
2832 else if (!info
->connect_supported
) {
2833 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
2834 "authentication/association or connect commands");
2838 if (info
->p2p_go_supported
&& info
->p2p_client_supported
)
2839 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
2840 if (info
->p2p_concurrent
) {
2841 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
2842 "interface (driver advertised support)");
2843 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
2844 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
2846 if (info
->p2p_multichan_concurrent
) {
2847 wpa_printf(MSG_DEBUG
, "nl80211: Enable multi-channel "
2848 "concurrent (driver advertised support)");
2849 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
;
2858 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
2860 struct wiphy_info_data info
;
2861 if (wpa_driver_nl80211_get_info(drv
, &info
))
2867 drv
->has_capability
= 1;
2868 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
2869 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2870 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2871 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2872 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
2873 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
2874 WPA_DRIVER_CAPA_ENC_WEP104
|
2875 WPA_DRIVER_CAPA_ENC_TKIP
|
2876 WPA_DRIVER_CAPA_ENC_CCMP
;
2877 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
2878 WPA_DRIVER_AUTH_SHARED
|
2879 WPA_DRIVER_AUTH_LEAP
;
2881 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
2882 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
2883 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2885 if (!info
.device_ap_sme
) {
2886 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
2889 * No AP SME is currently assumed to also indicate no AP MLME
2890 * in the driver/firmware.
2892 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP_MLME
;
2895 drv
->device_ap_sme
= info
.device_ap_sme
;
2896 drv
->poll_command_supported
= info
.poll_command_supported
;
2897 drv
->data_tx_status
= info
.data_tx_status
;
2900 * If poll command and tx status are supported, mac80211 is new enough
2901 * to have everything we need to not need monitor interfaces.
2903 drv
->use_monitor
= !info
.poll_command_supported
|| !info
.data_tx_status
;
2905 if (drv
->device_ap_sme
&& drv
->use_monitor
) {
2907 * Non-mac80211 drivers may not support monitor interface.
2908 * Make sure we do not get stuck with incorrect capability here
2909 * by explicitly testing this.
2911 if (!info
.monitor_supported
) {
2912 wpa_printf(MSG_DEBUG
, "nl80211: Disable use_monitor "
2913 "with device_ap_sme since no monitor mode "
2914 "support detected");
2915 drv
->use_monitor
= 0;
2920 * If we aren't going to use monitor interfaces, but the
2921 * driver doesn't support data TX status, we won't get TX
2922 * status for EAPOL frames.
2924 if (!drv
->use_monitor
&& !info
.data_tx_status
)
2925 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2932 static int android_genl_ctrl_resolve(struct nl_handle
*handle
,
2936 * Android ICS has very minimal genl_ctrl_resolve() implementation, so
2937 * need to work around that.
2939 struct nl_cache
*cache
= NULL
;
2940 struct genl_family
*nl80211
= NULL
;
2943 if (genl_ctrl_alloc_cache(handle
, &cache
) < 0) {
2944 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate generic "
2949 nl80211
= genl_ctrl_search_by_name(cache
, name
);
2950 if (nl80211
== NULL
)
2953 id
= genl_family_get_id(nl80211
);
2957 genl_family_put(nl80211
);
2959 nl_cache_free(cache
);
2963 #define genl_ctrl_resolve android_genl_ctrl_resolve
2964 #endif /* ANDROID */
2967 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
2971 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2972 if (global
->nl_cb
== NULL
) {
2973 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
2978 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
2979 if (global
->nl
== NULL
)
2982 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
2983 if (global
->nl80211_id
< 0) {
2984 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
2989 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
2990 if (global
->nl_event
== NULL
)
2993 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
2995 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2997 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2998 "membership for scan events: %d (%s)",
2999 ret
, strerror(-ret
));
3003 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
3005 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3007 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
3008 "membership for mlme events: %d (%s)",
3009 ret
, strerror(-ret
));
3013 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
3015 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3017 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
3018 "membership for regulatory events: %d (%s)",
3019 ret
, strerror(-ret
));
3020 /* Continue without regulatory events */
3023 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3024 no_seq_check
, NULL
);
3025 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3026 process_global_event
, global
);
3028 eloop_register_read_sock(nl_socket_get_fd(global
->nl_event
),
3029 wpa_driver_nl80211_event_receive
,
3030 global
->nl_cb
, global
->nl_event
);
3035 nl_destroy_handles(&global
->nl_event
);
3036 nl_destroy_handles(&global
->nl
);
3037 nl_cb_put(global
->nl_cb
);
3038 global
->nl_cb
= NULL
;
3043 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
3045 drv
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3047 wpa_printf(MSG_ERROR
, "nl80211: Failed to alloc cb struct");
3051 nl_cb_set(drv
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3052 no_seq_check
, NULL
);
3053 nl_cb_set(drv
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3054 process_drv_event
, drv
);
3060 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
3062 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
3064 * This may be for any interface; use ifdown event to disable
3070 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
3072 struct wpa_driver_nl80211_data
*drv
= ctx
;
3073 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
3074 if (linux_set_iface_flags(drv
->global
->ioctl_sock
,
3075 drv
->first_bss
.ifname
, 1)) {
3076 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
3077 "after rfkill unblock");
3080 /* rtnetlink ifup handler will report interface as enabled */
3084 static void nl80211_get_phy_name(struct wpa_driver_nl80211_data
*drv
)
3086 /* Find phy (radio) to which this interface belongs */
3090 drv
->phyname
[0] = '\0';
3091 snprintf(buf
, sizeof(buf
) - 1, "/sys/class/net/%s/phy80211/name",
3092 drv
->first_bss
.ifname
);
3093 f
= open(buf
, O_RDONLY
);
3095 wpa_printf(MSG_DEBUG
, "Could not open file %s: %s",
3096 buf
, strerror(errno
));
3100 rv
= read(f
, drv
->phyname
, sizeof(drv
->phyname
) - 1);
3103 wpa_printf(MSG_DEBUG
, "Could not read file %s: %s",
3104 buf
, strerror(errno
));
3108 drv
->phyname
[rv
] = '\0';
3109 pos
= os_strchr(drv
->phyname
, '\n');
3112 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
3113 drv
->first_bss
.ifname
, drv
->phyname
);
3117 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
3121 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
3126 struct cmsghdr
*cmsg
;
3127 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
3128 union wpa_event_data event
;
3130 memset(&msg
, 0, sizeof(msg
));
3131 msg
.msg_iov
= &entry
;
3133 entry
.iov_base
= data
;
3134 entry
.iov_len
= sizeof(data
);
3135 msg
.msg_control
= &control
;
3136 msg
.msg_controllen
= sizeof(control
);
3138 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
3139 /* if error or not fitting 802.3 header, return */
3143 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
3145 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
3146 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
3150 ack
= (void *)CMSG_DATA(cmsg
);
3154 if (cmsg
->cmsg_level
== SOL_PACKET
&&
3155 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
3156 struct sock_extended_err
*err
=
3157 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
3159 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
3164 if (!found_ee
|| !found_wifi
)
3167 memset(&event
, 0, sizeof(event
));
3168 event
.eapol_tx_status
.dst
= data
;
3169 event
.eapol_tx_status
.data
= data
+ 14;
3170 event
.eapol_tx_status
.data_len
= res
- 14;
3171 event
.eapol_tx_status
.ack
= acked
;
3172 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
3176 static int nl80211_init_bss(struct i802_bss
*bss
)
3178 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3182 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3183 no_seq_check
, NULL
);
3184 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3185 process_bss_event
, bss
);
3191 static void nl80211_destroy_bss(struct i802_bss
*bss
)
3193 nl_cb_put(bss
->nl_cb
);
3199 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
3200 * @ctx: context to be used when calling wpa_supplicant functions,
3201 * e.g., wpa_supplicant_event()
3202 * @ifname: interface name, e.g., wlan0
3203 * @global_priv: private driver global data from global_init()
3204 * Returns: Pointer to private data, %NULL on failure
3206 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
3209 struct wpa_driver_nl80211_data
*drv
;
3210 struct rfkill_config
*rcfg
;
3211 struct i802_bss
*bss
;
3213 if (global_priv
== NULL
)
3215 drv
= os_zalloc(sizeof(*drv
));
3218 drv
->global
= global_priv
;
3220 bss
= &drv
->first_bss
;
3224 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
3225 drv
->monitor_ifidx
= -1;
3226 drv
->monitor_sock
= -1;
3227 drv
->eapol_tx_sock
= -1;
3228 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
3230 if (wpa_driver_nl80211_init_nl(drv
)) {
3235 if (nl80211_init_bss(bss
))
3238 nl80211_get_phy_name(drv
);
3240 rcfg
= os_zalloc(sizeof(*rcfg
));
3244 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
3245 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
3246 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
3247 drv
->rfkill
= rfkill_init(rcfg
);
3248 if (drv
->rfkill
== NULL
) {
3249 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
3253 if (wpa_driver_nl80211_finish_drv_init(drv
))
3256 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
3257 if (drv
->eapol_tx_sock
< 0)
3260 if (drv
->data_tx_status
) {
3263 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
3264 &enabled
, sizeof(enabled
)) < 0) {
3265 wpa_printf(MSG_DEBUG
,
3266 "nl80211: wifi status sockopt failed\n");
3267 drv
->data_tx_status
= 0;
3268 if (!drv
->use_monitor
)
3270 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3272 eloop_register_read_sock(drv
->eapol_tx_sock
,
3273 wpa_driver_nl80211_handle_eapol_tx_status
,
3279 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
3280 drv
->in_interface_list
= 1;
3286 wpa_driver_nl80211_deinit(bss
);
3291 static int nl80211_register_frame(struct i802_bss
*bss
,
3292 struct nl_handle
*nl_handle
,
3293 u16 type
, const u8
*match
, size_t match_len
)
3295 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3299 msg
= nlmsg_alloc();
3303 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x nl_handle=%p",
3305 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3308 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
3310 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3311 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
3312 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
3314 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
3317 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
3318 "failed (type=%u): ret=%d (%s)",
3319 type
, ret
, strerror(-ret
));
3320 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3322 goto nla_put_failure
;
3331 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
3333 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3336 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
3337 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
3341 bss
->nl_mgmt
= nl_create_handle(drv
->nl_cb
, "mgmt");
3342 if (bss
->nl_mgmt
== NULL
)
3345 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_mgmt
),
3346 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
3353 static int nl80211_register_action_frame(struct i802_bss
*bss
,
3354 const u8
*match
, size_t match_len
)
3356 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
3357 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
3358 type
, match
, match_len
);
3362 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
3364 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3366 if (nl80211_alloc_mgmt_handle(bss
))
3368 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
3369 "handle %p", bss
->nl_mgmt
);
3371 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
3372 /* GAS Initial Request */
3373 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
3375 /* GAS Initial Response */
3376 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
3378 /* GAS Comeback Request */
3379 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
3381 /* GAS Comeback Response */
3382 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
3384 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
3386 /* P2P Public Action */
3387 if (nl80211_register_action_frame(bss
,
3388 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
3392 if (nl80211_register_action_frame(bss
,
3393 (u8
*) "\x7f\x50\x6f\x9a\x09",
3396 #endif /* CONFIG_P2P */
3397 #ifdef CONFIG_IEEE80211W
3398 /* SA Query Response */
3399 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
3401 #endif /* CONFIG_IEEE80211W */
3403 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
3404 /* TDLS Discovery Response */
3405 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
3409 #endif /* CONFIG_TDLS */
3411 /* FT Action frames */
3412 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
3415 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
3416 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
3418 /* WNM - BSS Transition Management Request */
3419 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
3421 /* WNM-Sleep Mode Response */
3422 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
3429 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
3431 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3435 msg
= nlmsg_alloc();
3439 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
3441 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3443 ret
= send_and_recv(drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
3446 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
3447 "failed: ret=%d (%s)",
3448 ret
, strerror(-ret
));
3449 goto nla_put_failure
;
3458 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
3460 static const int stypes
[] = {
3462 WLAN_FC_STYPE_ASSOC_REQ
,
3463 WLAN_FC_STYPE_REASSOC_REQ
,
3464 WLAN_FC_STYPE_DISASSOC
,
3465 WLAN_FC_STYPE_DEAUTH
,
3466 WLAN_FC_STYPE_ACTION
,
3467 WLAN_FC_STYPE_PROBE_REQ
,
3468 /* Beacon doesn't work as mac80211 doesn't currently allow
3469 * it, but it wouldn't really be the right thing anyway as
3470 * it isn't per interface ... maybe just dump the scan
3471 * results periodically for OLBC?
3473 // WLAN_FC_STYPE_BEACON,
3477 if (nl80211_alloc_mgmt_handle(bss
))
3479 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3480 "handle %p", bss
->nl_mgmt
);
3482 for (i
= 0; i
< sizeof(stypes
) / sizeof(stypes
[0]); i
++) {
3483 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3484 (WLAN_FC_TYPE_MGMT
<< 2) |
3491 if (nl80211_register_spurious_class3(bss
))
3494 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
3500 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3501 nl_destroy_handles(&bss
->nl_mgmt
);
3506 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
3508 if (nl80211_alloc_mgmt_handle(bss
))
3510 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3511 "handle %p (device SME)", bss
->nl_mgmt
);
3513 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3514 (WLAN_FC_TYPE_MGMT
<< 2) |
3515 (WLAN_FC_STYPE_ACTION
<< 4),
3522 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3523 nl_destroy_handles(&bss
->nl_mgmt
);
3528 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
3530 if (bss
->nl_mgmt
== NULL
)
3532 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
3533 "(%s)", bss
->nl_mgmt
, reason
);
3534 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3535 nl_destroy_handles(&bss
->nl_mgmt
);
3537 nl80211_put_wiphy_data_ap(bss
);
3541 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
3543 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
3548 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
3550 struct i802_bss
*bss
= &drv
->first_bss
;
3551 int send_rfkill_event
= 0;
3553 drv
->ifindex
= if_nametoindex(bss
->ifname
);
3554 drv
->first_bss
.ifindex
= drv
->ifindex
;
3558 * Make sure the interface starts up in station mode unless this is a
3559 * dynamically added interface (e.g., P2P) that was already configured
3560 * with proper iftype.
3562 if (drv
->ifindex
!= drv
->global
->if_add_ifindex
&&
3563 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
) < 0) {
3564 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to "
3565 "use managed mode");
3569 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
3570 if (rfkill_is_blocked(drv
->rfkill
)) {
3571 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
3572 "interface '%s' due to rfkill",
3574 drv
->if_disabled
= 1;
3575 send_rfkill_event
= 1;
3577 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
3578 "interface '%s' UP", bss
->ifname
);
3583 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
3584 1, IF_OPER_DORMANT
);
3585 #endif /* HOSTAPD */
3587 if (wpa_driver_nl80211_capa(drv
))
3590 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
3594 if (send_rfkill_event
) {
3595 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
3603 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
3607 msg
= nlmsg_alloc();
3611 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
3612 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3614 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3622 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
3623 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
3625 * Shut down driver interface and processing of driver events. Free
3626 * private data buffer if one was allocated in wpa_driver_nl80211_init().
3628 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
3630 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3633 if (drv
->data_tx_status
)
3634 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
3635 if (drv
->eapol_tx_sock
>= 0)
3636 close(drv
->eapol_tx_sock
);
3639 wpa_driver_nl80211_probe_req_report(bss
, 0);
3640 if (bss
->added_if_into_bridge
) {
3641 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
3643 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
3644 "interface %s from bridge %s: %s",
3645 bss
->ifname
, bss
->brname
, strerror(errno
));
3647 if (bss
->added_bridge
) {
3648 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
3649 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
3651 bss
->brname
, strerror(errno
));
3654 nl80211_remove_monitor_interface(drv
);
3656 if (is_ap_interface(drv
->nlmode
))
3657 wpa_driver_nl80211_del_beacon(drv
);
3660 if (drv
->last_freq_ht
) {
3661 /* Clear HT flags from the driver */
3662 struct hostapd_freq_params freq
;
3663 os_memset(&freq
, 0, sizeof(freq
));
3664 freq
.freq
= drv
->last_freq
;
3665 wpa_driver_nl80211_set_freq(bss
, &freq
);
3668 if (drv
->eapol_sock
>= 0) {
3669 eloop_unregister_read_sock(drv
->eapol_sock
);
3670 close(drv
->eapol_sock
);
3673 if (drv
->if_indices
!= drv
->default_if_indices
)
3674 os_free(drv
->if_indices
);
3675 #endif /* HOSTAPD */
3677 if (drv
->disabled_11b_rates
)
3678 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
3680 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
3682 rfkill_deinit(drv
->rfkill
);
3684 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
3686 (void) linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0);
3687 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
3688 nl80211_mgmt_unsubscribe(bss
, "deinit");
3690 nl_cb_put(drv
->nl_cb
);
3692 nl80211_destroy_bss(&drv
->first_bss
);
3694 os_free(drv
->filter_ssids
);
3696 os_free(drv
->auth_ie
);
3698 if (drv
->in_interface_list
)
3699 dl_list_del(&drv
->list
);
3706 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
3707 * @eloop_ctx: Driver private data
3708 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
3710 * This function can be used as registered timeout when starting a scan to
3711 * generate a scan completed event if the driver does not report this.
3713 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
3715 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
3716 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
3717 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
3718 drv
->ap_scan_as_station
);
3719 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
3721 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
3722 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
3726 static struct nl_msg
*
3727 nl80211_scan_common(struct wpa_driver_nl80211_data
*drv
, u8 cmd
,
3728 struct wpa_driver_scan_params
*params
)
3734 msg
= nlmsg_alloc();
3738 nl80211_cmd(drv
, msg
, 0, cmd
);
3740 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
) < 0)
3743 if (params
->num_ssids
) {
3744 struct nl_msg
*ssids
= nlmsg_alloc();
3747 for (i
= 0; i
< params
->num_ssids
; i
++) {
3748 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
3749 params
->ssids
[i
].ssid
,
3750 params
->ssids
[i
].ssid_len
);
3751 if (nla_put(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
3752 params
->ssids
[i
].ssid
) < 0) {
3757 err
= nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
3763 if (params
->extra_ies
) {
3764 wpa_hexdump(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
3765 params
->extra_ies
, params
->extra_ies_len
);
3766 if (nla_put(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
3767 params
->extra_ies
) < 0)
3771 if (params
->freqs
) {
3772 struct nl_msg
*freqs
= nlmsg_alloc();
3775 for (i
= 0; params
->freqs
[i
]; i
++) {
3776 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
3777 "MHz", params
->freqs
[i
]);
3778 if (nla_put_u32(freqs
, i
+ 1, params
->freqs
[i
]) < 0) {
3783 err
= nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
,
3790 os_free(drv
->filter_ssids
);
3791 drv
->filter_ssids
= params
->filter_ssids
;
3792 params
->filter_ssids
= NULL
;
3793 drv
->num_filter_ssids
= params
->num_filter_ssids
;
3804 * wpa_driver_nl80211_scan - Request the driver to initiate scan
3805 * @bss: Pointer to private driver data from wpa_driver_nl80211_init()
3806 * @params: Scan parameters
3807 * Returns: 0 on success, -1 on failure
3809 static int wpa_driver_nl80211_scan(struct i802_bss
*bss
,
3810 struct wpa_driver_scan_params
*params
)
3812 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3813 int ret
= -1, timeout
;
3814 struct nl_msg
*msg
, *rates
= NULL
;
3816 drv
->scan_for_auth
= 0;
3818 msg
= nl80211_scan_common(drv
, NL80211_CMD_TRIGGER_SCAN
, params
);
3822 if (params
->p2p_probe
) {
3823 wpa_printf(MSG_DEBUG
, "nl80211: P2P probe - mask SuppRates");
3825 rates
= nlmsg_alloc();
3827 goto nla_put_failure
;
3830 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
3831 * by masking out everything else apart from the OFDM rates 6,
3832 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
3833 * rates are left enabled.
3835 NLA_PUT(rates
, NL80211_BAND_2GHZ
, 8,
3836 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
3837 if (nla_put_nested(msg
, NL80211_ATTR_SCAN_SUPP_RATES
, rates
) <
3839 goto nla_put_failure
;
3841 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
3844 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3847 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
3848 "(%s)", ret
, strerror(-ret
));
3850 if (is_ap_interface(drv
->nlmode
)) {
3852 * mac80211 does not allow scan requests in AP mode, so
3853 * try to do this in station mode.
3855 if (wpa_driver_nl80211_set_mode(
3856 bss
, NL80211_IFTYPE_STATION
))
3857 goto nla_put_failure
;
3859 if (wpa_driver_nl80211_scan(bss
, params
)) {
3860 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
3861 goto nla_put_failure
;
3864 /* Restore AP mode when processing scan results */
3865 drv
->ap_scan_as_station
= drv
->nlmode
;
3868 goto nla_put_failure
;
3870 goto nla_put_failure
;
3871 #endif /* HOSTAPD */
3874 /* Not all drivers generate "scan completed" wireless event, so try to
3875 * read results after a timeout. */
3877 if (drv
->scan_complete_events
) {
3879 * The driver seems to deliver events to notify when scan is
3880 * complete, so use longer timeout to avoid race conditions
3881 * with scanning and following association request.
3885 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
3886 "seconds", ret
, timeout
);
3887 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
3888 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
3899 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
3900 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3901 * @params: Scan parameters
3902 * @interval: Interval between scan cycles in milliseconds
3903 * Returns: 0 on success, -1 on failure or if not supported
3905 static int wpa_driver_nl80211_sched_scan(void *priv
,
3906 struct wpa_driver_scan_params
*params
,
3909 struct i802_bss
*bss
= priv
;
3910 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3913 struct nl_msg
*match_set_ssid
= NULL
, *match_sets
= NULL
;
3914 struct nl_msg
*match_set_rssi
= NULL
;
3918 if (!drv
->capa
.sched_scan_supported
)
3919 return android_pno_start(bss
, params
);
3920 #endif /* ANDROID */
3922 msg
= nl80211_scan_common(drv
, NL80211_CMD_START_SCHED_SCAN
, params
);
3924 goto nla_put_failure
;
3926 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
3928 if ((drv
->num_filter_ssids
&&
3929 (int) drv
->num_filter_ssids
<= drv
->capa
.max_match_sets
) ||
3930 params
->filter_rssi
) {
3931 match_sets
= nlmsg_alloc();
3932 if (match_sets
== NULL
)
3933 goto nla_put_failure
;
3935 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
3936 wpa_hexdump_ascii(MSG_MSGDUMP
,
3937 "nl80211: Sched scan filter SSID",
3938 drv
->filter_ssids
[i
].ssid
,
3939 drv
->filter_ssids
[i
].ssid_len
);
3941 match_set_ssid
= nlmsg_alloc();
3942 if (match_set_ssid
== NULL
)
3943 goto nla_put_failure
;
3944 NLA_PUT(match_set_ssid
,
3945 NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
3946 drv
->filter_ssids
[i
].ssid_len
,
3947 drv
->filter_ssids
[i
].ssid
);
3949 if (nla_put_nested(match_sets
, i
+ 1, match_set_ssid
) <
3951 goto nla_put_failure
;
3954 if (params
->filter_rssi
) {
3955 match_set_rssi
= nlmsg_alloc();
3956 if (match_set_rssi
== NULL
)
3957 goto nla_put_failure
;
3958 NLA_PUT_U32(match_set_rssi
,
3959 NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
,
3960 params
->filter_rssi
);
3961 wpa_printf(MSG_MSGDUMP
,
3962 "nl80211: Sched scan RSSI filter %d dBm",
3963 params
->filter_rssi
);
3964 if (nla_put_nested(match_sets
, 0, match_set_rssi
) < 0)
3965 goto nla_put_failure
;
3968 if (nla_put_nested(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
,
3970 goto nla_put_failure
;
3973 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3975 /* TODO: if we get an error here, we should fall back to normal scan */
3979 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
3980 "ret=%d (%s)", ret
, strerror(-ret
));
3981 goto nla_put_failure
;
3984 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
3985 "scan interval %d msec", ret
, interval
);
3988 nlmsg_free(match_set_ssid
);
3989 nlmsg_free(match_sets
);
3990 nlmsg_free(match_set_rssi
);
3997 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
3998 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3999 * Returns: 0 on success, -1 on failure or if not supported
4001 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
4003 struct i802_bss
*bss
= priv
;
4004 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4009 if (!drv
->capa
.sched_scan_supported
)
4010 return android_pno_stop(bss
);
4011 #endif /* ANDROID */
4013 msg
= nlmsg_alloc();
4017 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
4019 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4021 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4024 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
4025 "ret=%d (%s)", ret
, strerror(-ret
));
4026 goto nla_put_failure
;
4029 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
4037 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
4039 const u8
*end
, *pos
;
4045 end
= ies
+ ies_len
;
4047 while (pos
+ 1 < end
) {
4048 if (pos
+ 2 + pos
[1] > end
)
4059 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
4060 const u8
*ie
, size_t ie_len
)
4065 if (drv
->filter_ssids
== NULL
)
4068 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
4072 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
4073 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
4074 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
4083 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
4085 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
4086 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4087 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
4088 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
4089 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
4090 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
4091 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
4092 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
4093 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
4094 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
4095 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
4096 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
4097 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
4098 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
4099 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
4101 struct nl80211_bss_info_arg
*_arg
= arg
;
4102 struct wpa_scan_results
*res
= _arg
->res
;
4103 struct wpa_scan_res
**tmp
;
4104 struct wpa_scan_res
*r
;
4105 const u8
*ie
, *beacon_ie
;
4106 size_t ie_len
, beacon_ie_len
;
4110 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4111 genlmsg_attrlen(gnlh
, 0), NULL
);
4112 if (!tb
[NL80211_ATTR_BSS
])
4114 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
4117 if (bss
[NL80211_BSS_STATUS
]) {
4118 enum nl80211_bss_status status
;
4119 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
4120 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
4121 bss
[NL80211_BSS_FREQUENCY
]) {
4123 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
4124 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
4127 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
4128 bss
[NL80211_BSS_BSSID
]) {
4129 os_memcpy(_arg
->assoc_bssid
,
4130 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
4131 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
4132 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
4137 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
4138 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
4139 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
4144 if (bss
[NL80211_BSS_BEACON_IES
]) {
4145 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
4146 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
4152 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
4153 ie
? ie_len
: beacon_ie_len
))
4156 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
4159 if (bss
[NL80211_BSS_BSSID
])
4160 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
4162 if (bss
[NL80211_BSS_FREQUENCY
])
4163 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
4164 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
4165 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
4166 if (bss
[NL80211_BSS_CAPABILITY
])
4167 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
4168 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
4169 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
4170 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
4171 r
->level
/= 100; /* mBm to dBm */
4172 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
4173 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
4174 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
4175 r
->flags
|= WPA_SCAN_QUAL_INVALID
;
4177 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
4178 if (bss
[NL80211_BSS_TSF
])
4179 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
4180 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
4181 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
4183 pos
= (u8
*) (r
+ 1);
4185 os_memcpy(pos
, ie
, ie_len
);
4188 r
->beacon_ie_len
= beacon_ie_len
;
4190 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
4192 if (bss
[NL80211_BSS_STATUS
]) {
4193 enum nl80211_bss_status status
;
4194 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
4196 case NL80211_BSS_STATUS_AUTHENTICATED
:
4197 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
4199 case NL80211_BSS_STATUS_ASSOCIATED
:
4200 r
->flags
|= WPA_SCAN_ASSOCIATED
;
4208 * cfg80211 maintains separate BSS table entries for APs if the same
4209 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
4210 * not use frequency as a separate key in the BSS table, so filter out
4211 * duplicated entries. Prefer associated BSS entry in such a case in
4212 * order to get the correct frequency into the BSS table.
4214 for (i
= 0; i
< res
->num
; i
++) {
4216 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
4219 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
4220 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
4221 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
4222 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
4223 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
4226 /* Same BSSID,SSID was already included in scan results */
4227 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
4228 "for " MACSTR
, MAC2STR(r
->bssid
));
4230 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
4231 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
4232 os_free(res
->res
[i
]);
4239 tmp
= os_realloc_array(res
->res
, res
->num
+ 1,
4240 sizeof(struct wpa_scan_res
*));
4245 tmp
[res
->num
++] = r
;
4252 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
4255 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
4256 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
4257 "mismatch (" MACSTR
")", MAC2STR(addr
));
4258 wpa_driver_nl80211_mlme(drv
, addr
,
4259 NL80211_CMD_DEAUTHENTICATE
,
4260 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
4265 static void wpa_driver_nl80211_check_bss_status(
4266 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
4270 for (i
= 0; i
< res
->num
; i
++) {
4271 struct wpa_scan_res
*r
= res
->res
[i
];
4272 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
4273 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4274 "indicates BSS status with " MACSTR
4275 " as authenticated",
4277 if (is_sta_interface(drv
->nlmode
) &&
4278 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
4279 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
4281 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
4282 " in local state (auth=" MACSTR
4283 " assoc=" MACSTR
")",
4284 MAC2STR(drv
->auth_bssid
),
4285 MAC2STR(drv
->bssid
));
4286 clear_state_mismatch(drv
, r
->bssid
);
4290 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
4291 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4292 "indicate BSS status with " MACSTR
4295 if (is_sta_interface(drv
->nlmode
) &&
4297 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4298 "(not associated) does not match "
4300 clear_state_mismatch(drv
, r
->bssid
);
4301 } else if (is_sta_interface(drv
->nlmode
) &&
4302 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
4304 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4305 "(associated with " MACSTR
") does "
4306 "not match with BSS state",
4307 MAC2STR(drv
->bssid
));
4308 clear_state_mismatch(drv
, r
->bssid
);
4309 clear_state_mismatch(drv
, drv
->bssid
);
4316 static struct wpa_scan_results
*
4317 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
4320 struct wpa_scan_results
*res
;
4322 struct nl80211_bss_info_arg arg
;
4324 res
= os_zalloc(sizeof(*res
));
4327 msg
= nlmsg_alloc();
4329 goto nla_put_failure
;
4331 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
4332 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4336 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
4339 wpa_printf(MSG_DEBUG
, "nl80211: Received scan results (%lu "
4340 "BSSes)", (unsigned long) res
->num
);
4341 nl80211_get_noise_for_scan_results(drv
, res
);
4344 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
4345 "(%s)", ret
, strerror(-ret
));
4348 wpa_scan_results_free(res
);
4354 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
4355 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
4356 * Returns: Scan results on success, -1 on failure
4358 static struct wpa_scan_results
*
4359 wpa_driver_nl80211_get_scan_results(void *priv
)
4361 struct i802_bss
*bss
= priv
;
4362 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4363 struct wpa_scan_results
*res
;
4365 res
= nl80211_get_scan_results(drv
);
4367 wpa_driver_nl80211_check_bss_status(drv
, res
);
4372 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
4374 struct wpa_scan_results
*res
;
4377 res
= nl80211_get_scan_results(drv
);
4379 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
4383 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
4384 for (i
= 0; i
< res
->num
; i
++) {
4385 struct wpa_scan_res
*r
= res
->res
[i
];
4386 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
4387 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
4388 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
4389 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
4392 wpa_scan_results_free(res
);
4396 static int wpa_driver_nl80211_set_key(const char *ifname
, struct i802_bss
*bss
,
4397 enum wpa_alg alg
, const u8
*addr
,
4398 int key_idx
, int set_tx
,
4399 const u8
*seq
, size_t seq_len
,
4400 const u8
*key
, size_t key_len
)
4402 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4403 int ifindex
= if_nametoindex(ifname
);
4407 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d alg=%d addr=%p key_idx=%d "
4408 "set_tx=%d seq_len=%lu key_len=%lu",
4409 __func__
, ifindex
, alg
, addr
, key_idx
, set_tx
,
4410 (unsigned long) seq_len
, (unsigned long) key_len
);
4414 #endif /* CONFIG_TDLS */
4416 msg
= nlmsg_alloc();
4420 if (alg
== WPA_ALG_NONE
) {
4421 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
4423 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
4424 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
4428 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4429 WLAN_CIPHER_SUITE_WEP40
);
4431 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4432 WLAN_CIPHER_SUITE_WEP104
);
4435 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4436 WLAN_CIPHER_SUITE_TKIP
);
4439 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4440 WLAN_CIPHER_SUITE_CCMP
);
4443 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4444 WLAN_CIPHER_SUITE_GCMP
);
4447 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4448 WLAN_CIPHER_SUITE_AES_CMAC
);
4451 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4452 WLAN_CIPHER_SUITE_SMS4
);
4455 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4456 WLAN_CIPHER_SUITE_KRK
);
4459 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4460 "algorithm %d", __func__
, alg
);
4467 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
4469 if (addr
&& !is_broadcast_ether_addr(addr
)) {
4470 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
4471 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4473 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
4474 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
4475 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
4476 NL80211_KEYTYPE_GROUP
);
4478 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
4479 struct nl_msg
*types
;
4481 wpa_printf(MSG_DEBUG
, " broadcast key");
4482 types
= nlmsg_alloc();
4484 goto nla_put_failure
;
4485 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4486 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4490 goto nla_put_failure
;
4492 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4493 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4495 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4496 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
4499 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
4500 ret
, strerror(-ret
));
4503 * If we failed or don't need to set the default TX key (below),
4506 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
)
4508 if (is_ap_interface(drv
->nlmode
) && addr
&&
4509 !is_broadcast_ether_addr(addr
))
4512 msg
= nlmsg_alloc();
4516 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
4517 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4518 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4519 if (alg
== WPA_ALG_IGTK
)
4520 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
4522 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
4523 if (addr
&& is_broadcast_ether_addr(addr
)) {
4524 struct nl_msg
*types
;
4526 types
= nlmsg_alloc();
4528 goto nla_put_failure
;
4529 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4530 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4534 goto nla_put_failure
;
4536 struct nl_msg
*types
;
4538 types
= nlmsg_alloc();
4540 goto nla_put_failure
;
4541 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
4542 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4546 goto nla_put_failure
;
4549 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4553 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
4554 "err=%d %s)", ret
, strerror(-ret
));
4563 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
4564 int key_idx
, int defkey
,
4565 const u8
*seq
, size_t seq_len
,
4566 const u8
*key
, size_t key_len
)
4568 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
4572 if (defkey
&& alg
== WPA_ALG_IGTK
)
4573 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
4575 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4577 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
4582 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4583 WLAN_CIPHER_SUITE_WEP40
);
4585 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4586 WLAN_CIPHER_SUITE_WEP104
);
4589 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
4592 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
4595 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_GCMP
);
4598 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4599 WLAN_CIPHER_SUITE_AES_CMAC
);
4602 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4603 "algorithm %d", __func__
, alg
);
4608 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
4610 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
4612 nla_nest_end(msg
, key_attr
);
4620 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
4624 struct nlattr
*nl_keys
, *nl_key
;
4626 for (i
= 0; i
< 4; i
++) {
4627 if (!params
->wep_key
[i
])
4632 if (params
->wps
== WPS_MODE_PRIVACY
)
4634 if (params
->pairwise_suite
&&
4635 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
4641 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
4643 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
4645 goto nla_put_failure
;
4647 for (i
= 0; i
< 4; i
++) {
4648 if (!params
->wep_key
[i
])
4651 nl_key
= nla_nest_start(msg
, i
);
4653 goto nla_put_failure
;
4655 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
4656 params
->wep_key
[i
]);
4657 if (params
->wep_key_len
[i
] == 5)
4658 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4659 WLAN_CIPHER_SUITE_WEP40
);
4661 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4662 WLAN_CIPHER_SUITE_WEP104
);
4664 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
4666 if (i
== params
->wep_tx_keyidx
)
4667 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4669 nla_nest_end(msg
, nl_key
);
4671 nla_nest_end(msg
, nl_keys
);
4680 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
4681 const u8
*addr
, int cmd
, u16 reason_code
,
4682 int local_state_change
)
4687 msg
= nlmsg_alloc();
4691 nl80211_cmd(drv
, msg
, 0, cmd
);
4693 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4694 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
4696 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4697 if (local_state_change
)
4698 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
4700 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4703 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4704 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
4705 reason_code
, ret
, strerror(-ret
));
4706 goto nla_put_failure
;
4716 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
4719 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
4720 drv
->associated
= 0;
4721 drv
->ignore_next_local_disconnect
= 0;
4722 /* Disconnect command doesn't need BSSID - it uses cached value */
4723 return wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
4728 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
4729 const u8
*addr
, int reason_code
)
4731 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4732 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
4733 return wpa_driver_nl80211_disconnect(drv
, reason_code
);
4734 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
4735 __func__
, MAC2STR(addr
), reason_code
);
4736 drv
->associated
= 0;
4737 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
4738 return nl80211_leave_ibss(drv
);
4739 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
4744 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
4745 struct wpa_driver_auth_params
*params
)
4749 drv
->auth_freq
= params
->freq
;
4750 drv
->auth_alg
= params
->auth_alg
;
4751 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
4752 drv
->auth_local_state_change
= params
->local_state_change
;
4753 drv
->auth_p2p
= params
->p2p
;
4756 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
4758 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
4761 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
4762 drv
->auth_ssid_len
= params
->ssid_len
;
4764 drv
->auth_ssid_len
= 0;
4767 os_free(drv
->auth_ie
);
4768 drv
->auth_ie
= NULL
;
4769 drv
->auth_ie_len
= 0;
4771 drv
->auth_ie
= os_malloc(params
->ie_len
);
4773 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
4774 drv
->auth_ie_len
= params
->ie_len
;
4778 for (i
= 0; i
< 4; i
++) {
4779 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
4780 params
->wep_key_len
[i
] <= 16) {
4781 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
4782 params
->wep_key_len
[i
]);
4783 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
4785 drv
->auth_wep_key_len
[i
] = 0;
4790 static int wpa_driver_nl80211_authenticate(
4791 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
4793 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4796 enum nl80211_auth_type type
;
4797 enum nl80211_iftype nlmode
;
4801 is_retry
= drv
->retry_auth
;
4802 drv
->retry_auth
= 0;
4804 drv
->associated
= 0;
4805 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
4806 /* FIX: IBSS mode */
4807 nlmode
= params
->p2p
?
4808 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
4809 if (drv
->nlmode
!= nlmode
&&
4810 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
4814 msg
= nlmsg_alloc();
4818 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
4821 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
4823 for (i
= 0; i
< 4; i
++) {
4824 if (!params
->wep_key
[i
])
4826 wpa_driver_nl80211_set_key(bss
->ifname
, bss
, WPA_ALG_WEP
,
4828 i
== params
->wep_tx_keyidx
, NULL
, 0,
4830 params
->wep_key_len
[i
]);
4831 if (params
->wep_tx_keyidx
!= i
)
4833 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
4834 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
4840 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4841 if (params
->bssid
) {
4842 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
4843 MAC2STR(params
->bssid
));
4844 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
4847 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
4848 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
4851 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4852 params
->ssid
, params
->ssid_len
);
4853 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
4856 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
4858 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
4859 if (params
->sae_data
) {
4860 wpa_hexdump(MSG_DEBUG
, " * SAE data", params
->sae_data
,
4861 params
->sae_data_len
);
4862 NLA_PUT(msg
, NL80211_ATTR_SAE_DATA
, params
->sae_data_len
,
4865 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
4866 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
4867 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
4868 type
= NL80211_AUTHTYPE_SHARED_KEY
;
4869 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
4870 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
4871 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
4872 type
= NL80211_AUTHTYPE_FT
;
4873 else if (params
->auth_alg
& WPA_AUTH_ALG_SAE
)
4874 type
= NL80211_AUTHTYPE_SAE
;
4876 goto nla_put_failure
;
4877 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
4878 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
4879 if (params
->local_state_change
) {
4880 wpa_printf(MSG_DEBUG
, " * Local state change only");
4881 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
4884 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4887 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4888 "nl80211: MLME command failed (auth): ret=%d (%s)",
4889 ret
, strerror(-ret
));
4891 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
4892 !params
->local_state_change
) {
4894 * mac80211 does not currently accept new
4895 * authentication if we are already authenticated. As a
4896 * workaround, force deauthentication and try again.
4898 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
4899 "after forced deauthentication");
4900 wpa_driver_nl80211_deauthenticate(
4902 WLAN_REASON_PREV_AUTH_NOT_VALID
);
4907 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
4909 * cfg80211 has likely expired the BSS entry even
4910 * though it was previously available in our internal
4911 * BSS table. To recover quickly, start a single
4912 * channel scan on the specified channel.
4914 struct wpa_driver_scan_params scan
;
4917 os_memset(&scan
, 0, sizeof(scan
));
4920 scan
.ssids
[0].ssid
= params
->ssid
;
4921 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
4923 freqs
[0] = params
->freq
;
4926 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
4927 "channel scan to refresh cfg80211 BSS "
4929 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
4931 nl80211_copy_auth_params(drv
, params
);
4932 drv
->scan_for_auth
= 1;
4934 } else if (is_retry
) {
4936 * Need to indicate this with an event since the return
4937 * value from the retry is not delivered to core code.
4939 union wpa_event_data event
;
4940 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
4942 os_memset(&event
, 0, sizeof(event
));
4943 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
4945 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
4949 goto nla_put_failure
;
4952 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
4961 static int wpa_driver_nl80211_authenticate_retry(
4962 struct wpa_driver_nl80211_data
*drv
)
4964 struct wpa_driver_auth_params params
;
4965 struct i802_bss
*bss
= &drv
->first_bss
;
4968 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
4970 os_memset(¶ms
, 0, sizeof(params
));
4971 params
.freq
= drv
->auth_freq
;
4972 params
.auth_alg
= drv
->auth_alg
;
4973 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
4974 params
.local_state_change
= drv
->auth_local_state_change
;
4975 params
.p2p
= drv
->auth_p2p
;
4977 if (!is_zero_ether_addr(drv
->auth_bssid_
))
4978 params
.bssid
= drv
->auth_bssid_
;
4980 if (drv
->auth_ssid_len
) {
4981 params
.ssid
= drv
->auth_ssid
;
4982 params
.ssid_len
= drv
->auth_ssid_len
;
4985 params
.ie
= drv
->auth_ie
;
4986 params
.ie_len
= drv
->auth_ie_len
;
4988 for (i
= 0; i
< 4; i
++) {
4989 if (drv
->auth_wep_key_len
[i
]) {
4990 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
4991 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
4995 drv
->retry_auth
= 1;
4996 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
5000 struct phy_info_arg
{
5002 struct hostapd_hw_modes
*modes
;
5003 int last_mode
, last_chan_idx
;
5006 static void phy_info_ht_capa(struct hostapd_hw_modes
*mode
, struct nlattr
*capa
,
5007 struct nlattr
*ampdu_factor
,
5008 struct nlattr
*ampdu_density
,
5009 struct nlattr
*mcs_set
)
5012 mode
->ht_capab
= nla_get_u16(capa
);
5015 mode
->a_mpdu_params
|= nla_get_u8(ampdu_factor
) & 0x03;
5018 mode
->a_mpdu_params
|= nla_get_u8(ampdu_density
) << 2;
5020 if (mcs_set
&& nla_len(mcs_set
) >= 16) {
5022 mcs
= nla_data(mcs_set
);
5023 os_memcpy(mode
->mcs_set
, mcs
, 16);
5028 static void phy_info_vht_capa(struct hostapd_hw_modes
*mode
,
5029 struct nlattr
*capa
,
5030 struct nlattr
*mcs_set
)
5033 mode
->vht_capab
= nla_get_u32(capa
);
5035 if (mcs_set
&& nla_len(mcs_set
) >= 8) {
5037 mcs
= nla_data(mcs_set
);
5038 os_memcpy(mode
->vht_mcs_set
, mcs
, 8);
5043 static void phy_info_freq(struct hostapd_hw_modes
*mode
,
5044 struct hostapd_channel_data
*chan
,
5045 struct nlattr
*tb_freq
[])
5047 chan
->freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
5050 /* mode is not set */
5051 if (mode
->mode
>= NUM_HOSTAPD_MODES
) {
5052 /* crude heuristic */
5053 if (chan
->freq
< 4000)
5054 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
5055 else if (chan
->freq
> 50000)
5056 mode
->mode
= HOSTAPD_MODE_IEEE80211AD
;
5058 mode
->mode
= HOSTAPD_MODE_IEEE80211A
;
5061 switch (mode
->mode
) {
5062 case HOSTAPD_MODE_IEEE80211AD
:
5063 chan
->chan
= (chan
->freq
- 56160) / 2160;
5065 case HOSTAPD_MODE_IEEE80211A
:
5066 chan
->chan
= chan
->freq
/ 5 - 1000;
5068 case HOSTAPD_MODE_IEEE80211B
:
5069 case HOSTAPD_MODE_IEEE80211G
:
5070 if (chan
->freq
== 2484)
5073 chan
->chan
= (chan
->freq
- 2407) / 5;
5079 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
5080 chan
->flag
|= HOSTAPD_CHAN_DISABLED
;
5081 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
5082 chan
->flag
|= HOSTAPD_CHAN_PASSIVE_SCAN
;
5083 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
5084 chan
->flag
|= HOSTAPD_CHAN_NO_IBSS
;
5085 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
5086 chan
->flag
|= HOSTAPD_CHAN_RADAR
;
5088 if (tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] &&
5089 !tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
5090 chan
->max_tx_power
= nla_get_u32(
5091 tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
]) / 100;
5095 static int phy_info_freqs(struct phy_info_arg
*phy_info
,
5096 struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
5098 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
5099 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
5100 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
5101 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
5102 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
5103 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
5104 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
5106 int new_channels
= 0;
5107 struct hostapd_channel_data
*channel
;
5108 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
5109 struct nlattr
*nl_freq
;
5115 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
5116 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
5117 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
5118 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
5123 channel
= os_realloc_array(mode
->channels
,
5124 mode
->num_channels
+ new_channels
,
5125 sizeof(struct hostapd_channel_data
));
5129 mode
->channels
= channel
;
5130 mode
->num_channels
+= new_channels
;
5132 idx
= phy_info
->last_chan_idx
;
5134 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
5135 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
5136 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
5137 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
5139 phy_info_freq(mode
, &mode
->channels
[idx
], tb_freq
);
5142 phy_info
->last_chan_idx
= idx
;
5148 static int phy_info_rates(struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
5150 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
5151 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
5152 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] =
5153 { .type
= NLA_FLAG
},
5155 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
5156 struct nlattr
*nl_rate
;
5162 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
5163 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
5164 nla_data(nl_rate
), nla_len(nl_rate
),
5166 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
5171 mode
->rates
= os_calloc(mode
->num_rates
, sizeof(int));
5177 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
5178 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
5179 nla_data(nl_rate
), nla_len(nl_rate
),
5181 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
5183 mode
->rates
[idx
] = nla_get_u32(
5184 tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
5186 /* crude heuristic */
5187 if (mode
->mode
== HOSTAPD_MODE_IEEE80211B
&&
5188 mode
->rates
[idx
] > 200)
5189 mode
->mode
= HOSTAPD_MODE_IEEE80211G
;
5198 static int phy_info_band(struct phy_info_arg
*phy_info
, struct nlattr
*nl_band
)
5200 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
5201 struct hostapd_hw_modes
*mode
;
5204 if (phy_info
->last_mode
!= nl_band
->nla_type
) {
5205 mode
= os_realloc_array(phy_info
->modes
,
5206 *phy_info
->num_modes
+ 1,
5210 phy_info
->modes
= mode
;
5212 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
5213 os_memset(mode
, 0, sizeof(*mode
));
5214 mode
->mode
= NUM_HOSTAPD_MODES
;
5215 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
;
5216 *(phy_info
->num_modes
) += 1;
5217 phy_info
->last_mode
= nl_band
->nla_type
;
5218 phy_info
->last_chan_idx
= 0;
5220 mode
= &phy_info
->modes
[*(phy_info
->num_modes
) - 1];
5222 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
5223 nla_len(nl_band
), NULL
);
5225 phy_info_ht_capa(mode
, tb_band
[NL80211_BAND_ATTR_HT_CAPA
],
5226 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
],
5227 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
],
5228 tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
5229 phy_info_vht_capa(mode
, tb_band
[NL80211_BAND_ATTR_VHT_CAPA
],
5230 tb_band
[NL80211_BAND_ATTR_VHT_MCS_SET
]);
5231 ret
= phy_info_freqs(phy_info
, mode
, tb_band
[NL80211_BAND_ATTR_FREQS
]);
5234 ret
= phy_info_rates(mode
, tb_band
[NL80211_BAND_ATTR_RATES
]);
5242 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
5244 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
5245 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5246 struct phy_info_arg
*phy_info
= arg
;
5247 struct nlattr
*nl_band
;
5250 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5251 genlmsg_attrlen(gnlh
, 0), NULL
);
5253 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
5256 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
)
5258 int res
= phy_info_band(phy_info
, nl_band
);
5267 static struct hostapd_hw_modes
*
5268 wpa_driver_nl80211_add_11b(struct hostapd_hw_modes
*modes
, u16
*num_modes
)
5271 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
5272 int i
, mode11g_idx
= -1;
5274 /* If only 802.11g mode is included, use it to construct matching
5275 * 802.11b mode data. */
5277 for (m
= 0; m
< *num_modes
; m
++) {
5278 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
5279 return modes
; /* 802.11b already included */
5280 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
5284 if (mode11g_idx
< 0)
5285 return modes
; /* 2.4 GHz band not supported at all */
5287 nmodes
= os_realloc_array(modes
, *num_modes
+ 1, sizeof(*nmodes
));
5289 return modes
; /* Could not add 802.11b mode */
5291 mode
= &nmodes
[*num_modes
];
5292 os_memset(mode
, 0, sizeof(*mode
));
5296 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
5298 mode11g
= &modes
[mode11g_idx
];
5299 mode
->num_channels
= mode11g
->num_channels
;
5300 mode
->channels
= os_malloc(mode11g
->num_channels
*
5301 sizeof(struct hostapd_channel_data
));
5302 if (mode
->channels
== NULL
) {
5304 return modes
; /* Could not add 802.11b mode */
5306 os_memcpy(mode
->channels
, mode11g
->channels
,
5307 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
5309 mode
->num_rates
= 0;
5310 mode
->rates
= os_malloc(4 * sizeof(int));
5311 if (mode
->rates
== NULL
) {
5312 os_free(mode
->channels
);
5314 return modes
; /* Could not add 802.11b mode */
5317 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
5318 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
5319 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
5321 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
5323 if (mode
->num_rates
== 4)
5327 if (mode
->num_rates
== 0) {
5328 os_free(mode
->channels
);
5329 os_free(mode
->rates
);
5331 return modes
; /* No 802.11b rates */
5334 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
5341 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
5346 for (c
= 0; c
< mode
->num_channels
; c
++) {
5347 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5348 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
5349 chan
->flag
|= HOSTAPD_CHAN_HT40
;
5354 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
5359 for (c
= 0; c
< mode
->num_channels
; c
++) {
5360 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5361 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
5363 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
5364 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
5365 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
5366 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
5371 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
5372 struct phy_info_arg
*results
)
5374 u32 start
, end
, max_bw
;
5377 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
5378 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
5379 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
5382 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
5383 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
5384 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
5386 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
5387 start
, end
, max_bw
);
5391 for (m
= 0; m
< *results
->num_modes
; m
++) {
5392 if (!(results
->modes
[m
].ht_capab
&
5393 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
5395 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
5400 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
5401 struct phy_info_arg
*results
)
5403 u32 start
, end
, max_bw
;
5406 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
5407 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
5408 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
5411 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
5412 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
5413 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
5418 for (m
= 0; m
< *results
->num_modes
; m
++) {
5419 if (!(results
->modes
[m
].ht_capab
&
5420 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
5422 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
5427 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
5429 struct phy_info_arg
*results
= arg
;
5430 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
5431 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5432 struct nlattr
*nl_rule
;
5433 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
5435 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
5436 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
5437 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
5438 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
5439 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
5440 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
5441 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
5444 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5445 genlmsg_attrlen(gnlh
, 0), NULL
);
5446 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
5447 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
5448 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
5453 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
5454 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
5456 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
5458 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
5459 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
5460 nl80211_reg_rule_ht40(tb_rule
, results
);
5463 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
5465 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
5466 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
5467 nl80211_reg_rule_sec(tb_rule
, results
);
5474 static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data
*drv
,
5475 struct phy_info_arg
*results
)
5479 msg
= nlmsg_alloc();
5483 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
5484 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
5488 static struct hostapd_hw_modes
*
5489 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
5492 struct i802_bss
*bss
= priv
;
5493 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5495 struct phy_info_arg result
= {
5496 .num_modes
= num_modes
,
5504 msg
= nlmsg_alloc();
5508 feat
= get_nl80211_protocol_features(drv
);
5509 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
5510 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_WIPHY
);
5512 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
5514 NLA_PUT_FLAG(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
);
5515 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5517 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
5518 nl80211_set_ht40_flags(drv
, &result
);
5519 return wpa_driver_nl80211_add_11b(result
.modes
, num_modes
);
5528 static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data
*drv
,
5529 const void *data
, size_t len
,
5530 int encrypt
, int noack
)
5533 0x00, 0x00, /* radiotap version */
5534 0x0e, 0x00, /* radiotap length */
5535 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
5536 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
5538 0x00, 0x00, /* RX and TX flags to indicate that */
5539 0x00, 0x00, /* this is the injected frame directly */
5541 struct iovec iov
[2] = {
5543 .iov_base
= &rtap_hdr
,
5544 .iov_len
= sizeof(rtap_hdr
),
5547 .iov_base
= (void *) data
,
5551 struct msghdr msg
= {
5556 .msg_control
= NULL
,
5557 .msg_controllen
= 0,
5564 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
5566 if (drv
->monitor_sock
< 0) {
5567 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
5568 "for %s", __func__
);
5573 txflags
|= IEEE80211_RADIOTAP_F_TX_NOACK
;
5574 WPA_PUT_LE16(&rtap_hdr
[12], txflags
);
5576 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
5578 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
5585 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
5586 const void *data
, size_t len
,
5587 int encrypt
, int noack
,
5588 unsigned int freq
, int no_cck
,
5589 int offchanok
, unsigned int wait_time
)
5591 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5597 if (drv
->use_monitor
)
5598 return wpa_driver_nl80211_send_mntr(drv
, data
, len
,
5601 return nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
5602 &cookie
, no_cck
, noack
, offchanok
);
5606 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
5607 size_t data_len
, int noack
,
5608 unsigned int freq
, int no_cck
,
5610 unsigned int wait_time
)
5612 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5613 struct ieee80211_mgmt
*mgmt
;
5617 mgmt
= (struct ieee80211_mgmt
*) data
;
5618 fc
= le_to_host16(mgmt
->frame_control
);
5620 if (is_sta_interface(drv
->nlmode
) &&
5621 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5622 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
5624 * The use of last_mgmt_freq is a bit of a hack,
5625 * but it works due to the single-threaded nature
5626 * of wpa_supplicant.
5629 freq
= drv
->last_mgmt_freq
;
5630 return nl80211_send_frame_cmd(bss
, freq
, 0,
5631 data
, data_len
, NULL
, 1, noack
,
5635 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
5638 return nl80211_send_frame_cmd(bss
, freq
,
5639 (int) freq
== bss
->freq
? 0 :
5642 &drv
->send_action_cookie
,
5643 no_cck
, noack
, offchanok
);
5646 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5647 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
5649 * Only one of the authentication frame types is encrypted.
5650 * In order for static WEP encryption to work properly (i.e.,
5651 * to not encrypt the frame), we need to tell mac80211 about
5652 * the frames that must not be encrypted.
5654 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
5655 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
5656 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
5660 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
5661 noack
, freq
, no_cck
, offchanok
,
5666 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
5667 int slot
, int ht_opmode
, int ap_isolate
,
5670 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5673 msg
= nlmsg_alloc();
5677 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
5680 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
5682 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
5684 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
5686 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
5687 if (ap_isolate
>= 0)
5688 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
);
5691 u8 rates
[NL80211_MAX_SUPP_RATES
];
5695 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0;
5697 rates
[rates_len
++] = basic_rates
[i
] / 5;
5699 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
5702 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5704 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5711 static int wpa_driver_nl80211_set_ap(void *priv
,
5712 struct wpa_driver_ap_params
*params
)
5714 struct i802_bss
*bss
= priv
;
5715 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5717 u8 cmd
= NL80211_CMD_NEW_BEACON
;
5720 int ifindex
= if_nametoindex(bss
->ifname
);
5725 beacon_set
= bss
->beacon_set
;
5727 msg
= nlmsg_alloc();
5731 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
5734 cmd
= NL80211_CMD_SET_BEACON
;
5736 nl80211_cmd(drv
, msg
, 0, cmd
);
5737 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
5738 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
5739 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5740 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
5741 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
5742 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5744 if (params
->proberesp
&& params
->proberesp_len
)
5745 NLA_PUT(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
5747 switch (params
->hide_ssid
) {
5748 case NO_SSID_HIDING
:
5749 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5750 NL80211_HIDDEN_SSID_NOT_IN_USE
);
5752 case HIDDEN_SSID_ZERO_LEN
:
5753 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5754 NL80211_HIDDEN_SSID_ZERO_LEN
);
5756 case HIDDEN_SSID_ZERO_CONTENTS
:
5757 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5758 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
5761 if (params
->privacy
)
5762 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
5763 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
5764 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
5765 /* Leave out the attribute */
5766 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
5767 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
5768 NL80211_AUTHTYPE_SHARED_KEY
);
5770 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
5771 NL80211_AUTHTYPE_OPEN_SYSTEM
);
5774 if (params
->wpa_version
& WPA_PROTO_WPA
)
5775 ver
|= NL80211_WPA_VERSION_1
;
5776 if (params
->wpa_version
& WPA_PROTO_RSN
)
5777 ver
|= NL80211_WPA_VERSION_2
;
5779 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
5782 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
5783 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
5784 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
5785 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
5787 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
5788 num_suites
* sizeof(u32
), suites
);
5791 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
&&
5792 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
))
5793 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
);
5796 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
5797 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
5798 if (params
->pairwise_ciphers
& WPA_CIPHER_GCMP
)
5799 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP
;
5800 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
5801 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
5802 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
5803 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
5804 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
5805 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
5807 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
5808 num_suites
* sizeof(u32
), suites
);
5811 switch (params
->group_cipher
) {
5812 case WPA_CIPHER_CCMP
:
5813 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5814 WLAN_CIPHER_SUITE_CCMP
);
5816 case WPA_CIPHER_GCMP
:
5817 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5818 WLAN_CIPHER_SUITE_GCMP
);
5820 case WPA_CIPHER_TKIP
:
5821 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5822 WLAN_CIPHER_SUITE_TKIP
);
5824 case WPA_CIPHER_WEP104
:
5825 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5826 WLAN_CIPHER_SUITE_WEP104
);
5828 case WPA_CIPHER_WEP40
:
5829 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5830 WLAN_CIPHER_SUITE_WEP40
);
5834 if (params
->beacon_ies
) {
5835 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
5836 wpabuf_head(params
->beacon_ies
));
5838 if (params
->proberesp_ies
) {
5839 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
5840 wpabuf_len(params
->proberesp_ies
),
5841 wpabuf_head(params
->proberesp_ies
));
5843 if (params
->assocresp_ies
) {
5844 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
5845 wpabuf_len(params
->assocresp_ies
),
5846 wpabuf_head(params
->assocresp_ies
));
5849 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
5850 NLA_PUT_U16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
5851 params
->ap_max_inactivity
);
5854 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5856 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
5857 ret
, strerror(-ret
));
5859 bss
->beacon_set
= 1;
5860 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
5861 params
->short_slot_time
, params
->ht_opmode
,
5862 params
->isolate
, params
->basic_rates
);
5871 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
5872 struct hostapd_freq_params
*freq
)
5874 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5878 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d,"
5879 " bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
5880 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
5881 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
5882 msg
= nlmsg_alloc();
5886 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
5888 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5889 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
);
5890 if (freq
->vht_enabled
) {
5891 switch (freq
->bandwidth
) {
5893 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
5894 NL80211_CHAN_WIDTH_20
);
5897 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
5898 NL80211_CHAN_WIDTH_40
);
5901 if (freq
->center_freq2
)
5902 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
5903 NL80211_CHAN_WIDTH_80P80
);
5905 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
5906 NL80211_CHAN_WIDTH_80
);
5909 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
5910 NL80211_CHAN_WIDTH_160
);
5915 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ1
, freq
->center_freq1
);
5916 if (freq
->center_freq2
)
5917 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ2
,
5918 freq
->center_freq2
);
5919 } else if (freq
->ht_enabled
) {
5920 switch (freq
->sec_channel_offset
) {
5922 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5923 NL80211_CHAN_HT40MINUS
);
5926 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5927 NL80211_CHAN_HT40PLUS
);
5930 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5936 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5939 bss
->freq
= freq
->freq
;
5942 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
5943 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
5950 static u32
sta_flags_nl80211(int flags
)
5954 if (flags
& WPA_STA_AUTHORIZED
)
5955 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5956 if (flags
& WPA_STA_WMM
)
5957 f
|= BIT(NL80211_STA_FLAG_WME
);
5958 if (flags
& WPA_STA_SHORT_PREAMBLE
)
5959 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
5960 if (flags
& WPA_STA_MFP
)
5961 f
|= BIT(NL80211_STA_FLAG_MFP
);
5962 if (flags
& WPA_STA_TDLS_PEER
)
5963 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
5969 static int wpa_driver_nl80211_sta_add(void *priv
,
5970 struct hostapd_sta_add_params
*params
)
5972 struct i802_bss
*bss
= priv
;
5973 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5974 struct nl_msg
*msg
, *wme
= NULL
;
5975 struct nl80211_sta_flag_update upd
;
5978 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
5979 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
5982 msg
= nlmsg_alloc();
5986 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
5987 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
5988 nl80211_cmd(drv
, msg
, 0, params
->set
? NL80211_CMD_SET_STATION
:
5989 NL80211_CMD_NEW_STATION
);
5991 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5992 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
5993 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
5994 params
->supp_rates
);
5995 wpa_hexdump(MSG_DEBUG
, " * supported rates", params
->supp_rates
,
5996 params
->supp_rates_len
);
5998 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
5999 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
6000 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
6001 params
->listen_interval
);
6002 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
6003 params
->listen_interval
);
6005 if (params
->ht_capabilities
) {
6006 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
6007 (u8
*) params
->ht_capabilities
,
6008 sizeof(*params
->ht_capabilities
));
6009 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
6010 sizeof(*params
->ht_capabilities
),
6011 params
->ht_capabilities
);
6014 if (params
->vht_capabilities
) {
6015 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
6016 (u8
*) params
->vht_capabilities
,
6017 sizeof(*params
->vht_capabilities
));
6018 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
,
6019 sizeof(*params
->vht_capabilities
),
6020 params
->vht_capabilities
);
6023 wpa_printf(MSG_DEBUG
, " * capability=0x%x", params
->capability
);
6024 NLA_PUT_U16(msg
, NL80211_ATTR_STA_CAPABILITY
, params
->capability
);
6026 if (params
->ext_capab
) {
6027 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
6028 params
->ext_capab
, params
->ext_capab_len
);
6029 NLA_PUT(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
6030 params
->ext_capab_len
, params
->ext_capab
);
6033 os_memset(&upd
, 0, sizeof(upd
));
6034 upd
.mask
= sta_flags_nl80211(params
->flags
);
6036 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
6038 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6040 if (params
->flags
& WPA_STA_WMM
) {
6041 wme
= nlmsg_alloc();
6043 goto nla_put_failure
;
6045 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
6046 NLA_PUT_U8(wme
, NL80211_STA_WME_UAPSD_QUEUES
,
6047 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
);
6048 NLA_PUT_U8(wme
, NL80211_STA_WME_MAX_SP
,
6049 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
6050 WMM_QOSINFO_STA_SP_MASK
);
6051 if (nla_put_nested(msg
, NL80211_ATTR_STA_WME
, wme
) < 0)
6052 goto nla_put_failure
;
6055 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6058 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
6059 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
6070 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
)
6072 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6076 msg
= nlmsg_alloc();
6080 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
6082 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6083 if_nametoindex(bss
->ifname
));
6084 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6086 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6096 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
6101 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
6103 /* stop listening for EAPOL on this interface */
6104 del_ifidx(drv
, ifidx
);
6106 msg
= nlmsg_alloc();
6108 goto nla_put_failure
;
6110 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
6111 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
6113 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
6118 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
6122 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
6125 case NL80211_IFTYPE_ADHOC
:
6127 case NL80211_IFTYPE_STATION
:
6129 case NL80211_IFTYPE_AP
:
6131 case NL80211_IFTYPE_MONITOR
:
6133 case NL80211_IFTYPE_P2P_CLIENT
:
6134 return "P2P_CLIENT";
6135 case NL80211_IFTYPE_P2P_GO
:
6143 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
6145 enum nl80211_iftype iftype
,
6146 const u8
*addr
, int wds
)
6148 struct nl_msg
*msg
, *flags
= NULL
;
6152 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
6153 iftype
, nl80211_iftype_str(iftype
));
6155 msg
= nlmsg_alloc();
6159 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
6160 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6161 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
6162 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
6164 if (iftype
== NL80211_IFTYPE_MONITOR
) {
6167 flags
= nlmsg_alloc();
6169 goto nla_put_failure
;
6171 NLA_PUT_FLAG(flags
, NL80211_MNTR_FLAG_COOK_FRAMES
);
6173 err
= nla_put_nested(msg
, NL80211_ATTR_MNTR_FLAGS
, flags
);
6178 goto nla_put_failure
;
6180 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
6183 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6188 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
6189 ifname
, ret
, strerror(-ret
));
6193 ifidx
= if_nametoindex(ifname
);
6194 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
6200 /* start listening for EAPOL on this interface */
6201 add_ifidx(drv
, ifidx
);
6203 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
6204 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
6205 nl80211_remove_iface(drv
, ifidx
);
6213 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
6214 const char *ifname
, enum nl80211_iftype iftype
,
6215 const u8
*addr
, int wds
)
6219 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
);
6221 /* if error occurred and interface exists already */
6222 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
6223 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
6225 /* Try to remove the interface that was already there. */
6226 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
6228 /* Try to create the interface again */
6229 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
6233 if (ret
>= 0 && is_p2p_interface(iftype
))
6234 nl80211_disable_11b_rates(drv
, ret
, 1);
6240 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
6242 struct ieee80211_hdr
*hdr
;
6244 union wpa_event_data event
;
6246 hdr
= (struct ieee80211_hdr
*) buf
;
6247 fc
= le_to_host16(hdr
->frame_control
);
6249 os_memset(&event
, 0, sizeof(event
));
6250 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
6251 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
6252 event
.tx_status
.dst
= hdr
->addr1
;
6253 event
.tx_status
.data
= buf
;
6254 event
.tx_status
.data_len
= len
;
6255 event
.tx_status
.ack
= ok
;
6256 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
6260 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
6261 u8
*buf
, size_t len
)
6263 struct ieee80211_hdr
*hdr
= (void *)buf
;
6265 union wpa_event_data event
;
6267 if (len
< sizeof(*hdr
))
6270 fc
= le_to_host16(hdr
->frame_control
);
6272 os_memset(&event
, 0, sizeof(event
));
6273 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
6274 event
.rx_from_unknown
.addr
= hdr
->addr2
;
6275 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
6276 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
6277 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
6281 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
6282 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
6284 struct ieee80211_hdr
*hdr
;
6286 union wpa_event_data event
;
6288 hdr
= (struct ieee80211_hdr
*) buf
;
6289 fc
= le_to_host16(hdr
->frame_control
);
6291 switch (WLAN_FC_GET_TYPE(fc
)) {
6292 case WLAN_FC_TYPE_MGMT
:
6293 os_memset(&event
, 0, sizeof(event
));
6294 event
.rx_mgmt
.frame
= buf
;
6295 event
.rx_mgmt
.frame_len
= len
;
6296 event
.rx_mgmt
.datarate
= datarate
;
6297 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
6298 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
6300 case WLAN_FC_TYPE_CTRL
:
6301 /* can only get here with PS-Poll frames */
6302 wpa_printf(MSG_DEBUG
, "CTRL");
6303 from_unknown_sta(drv
, buf
, len
);
6305 case WLAN_FC_TYPE_DATA
:
6306 from_unknown_sta(drv
, buf
, len
);
6312 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
6314 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
6316 unsigned char buf
[3000];
6317 struct ieee80211_radiotap_iterator iter
;
6319 int datarate
= 0, ssi_signal
= 0;
6320 int injected
= 0, failed
= 0, rxflags
= 0;
6322 len
= recv(sock
, buf
, sizeof(buf
), 0);
6328 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
6329 printf("received invalid radiotap frame\n");
6334 ret
= ieee80211_radiotap_iterator_next(&iter
);
6338 printf("received invalid radiotap frame (%d)\n", ret
);
6341 switch (iter
.this_arg_index
) {
6342 case IEEE80211_RADIOTAP_FLAGS
:
6343 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
6346 case IEEE80211_RADIOTAP_RX_FLAGS
:
6349 case IEEE80211_RADIOTAP_TX_FLAGS
:
6351 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
6352 IEEE80211_RADIOTAP_F_TX_FAIL
;
6354 case IEEE80211_RADIOTAP_DATA_RETRIES
:
6356 case IEEE80211_RADIOTAP_CHANNEL
:
6357 /* TODO: convert from freq/flags to channel number */
6359 case IEEE80211_RADIOTAP_RATE
:
6360 datarate
= *iter
.this_arg
* 5;
6362 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
6363 ssi_signal
= (s8
) *iter
.this_arg
;
6368 if (rxflags
&& injected
)
6372 handle_frame(drv
, buf
+ iter
.max_length
,
6373 len
- iter
.max_length
, datarate
, ssi_signal
);
6375 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
6376 len
- iter
.max_length
, !failed
);
6381 * we post-process the filter code later and rewrite
6382 * this to the offset to the last instruction
6387 static struct sock_filter msock_filter_insns
[] = {
6389 * do a little-endian load of the radiotap length field
6391 /* load lower byte into A */
6392 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
6393 /* put it into X (== index register) */
6394 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6395 /* load upper byte into A */
6396 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
6397 /* left-shift it by 8 */
6398 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
6400 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
6401 /* put result into X */
6402 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6405 * Allow management frames through, this also gives us those
6406 * management frames that we sent ourselves with status
6408 /* load the lower byte of the IEEE 802.11 frame control field */
6409 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6410 /* mask off frame type and version */
6411 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
6412 /* accept frame if it's both 0, fall through otherwise */
6413 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
6416 * TODO: add a bit to radiotap RX flags that indicates
6417 * that the sending station is not associated, then
6418 * add a filter here that filters on our DA and that flag
6419 * to allow us to deauth frames to that bad station.
6421 * For now allow all To DS data frames through.
6423 /* load the IEEE 802.11 frame control field */
6424 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
6425 /* mask off frame type, version and DS status */
6426 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
6427 /* accept frame if version 0, type 2 and To DS, fall through otherwise
6429 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
6433 * drop non-data frames
6435 /* load the lower byte of the frame control field */
6436 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6437 /* mask off QoS bit */
6438 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
6439 /* drop non-data frames */
6440 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
6442 /* load the upper byte of the frame control field */
6443 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
6444 /* mask off toDS/fromDS */
6445 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
6446 /* accept WDS frames */
6447 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
6450 * add header length to index
6452 /* load the lower byte of the frame control field */
6453 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6454 /* mask off QoS bit */
6455 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
6456 /* right shift it by 6 to give 0 or 2 */
6457 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
6458 /* add data frame header length */
6459 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
6460 /* add index, was start of 802.11 header */
6461 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
6462 /* move to index, now start of LL header */
6463 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6466 * Accept empty data frames, we use those for
6469 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
6470 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
6473 * Accept EAPOL frames
6475 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
6476 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
6477 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
6478 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
6480 /* keep these last two statements or change the code below */
6481 /* return 0 == "DROP" */
6482 BPF_STMT(BPF_RET
| BPF_K
, 0),
6483 /* return ~0 == "keep all" */
6484 BPF_STMT(BPF_RET
| BPF_K
, ~0),
6487 static struct sock_fprog msock_filter
= {
6488 .len
= sizeof(msock_filter_insns
)/sizeof(msock_filter_insns
[0]),
6489 .filter
= msock_filter_insns
,
6493 static int add_monitor_filter(int s
)
6497 /* rewrite all PASS/FAIL jump offsets */
6498 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
6499 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
6501 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
6502 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
6503 if (insn
->k
== PASS
)
6504 insn
->k
= msock_filter
.len
- idx
- 2;
6505 else if (insn
->k
== FAIL
)
6506 insn
->k
= msock_filter
.len
- idx
- 3;
6509 if (insn
->jt
== PASS
)
6510 insn
->jt
= msock_filter
.len
- idx
- 2;
6511 else if (insn
->jt
== FAIL
)
6512 insn
->jt
= msock_filter
.len
- idx
- 3;
6514 if (insn
->jf
== PASS
)
6515 insn
->jf
= msock_filter
.len
- idx
- 2;
6516 else if (insn
->jf
== FAIL
)
6517 insn
->jf
= msock_filter
.len
- idx
- 3;
6521 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
6522 &msock_filter
, sizeof(msock_filter
))) {
6523 perror("SO_ATTACH_FILTER");
6531 static void nl80211_remove_monitor_interface(
6532 struct wpa_driver_nl80211_data
*drv
)
6534 drv
->monitor_refcount
--;
6535 if (drv
->monitor_refcount
> 0)
6538 if (drv
->monitor_ifidx
>= 0) {
6539 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
6540 drv
->monitor_ifidx
= -1;
6542 if (drv
->monitor_sock
>= 0) {
6543 eloop_unregister_read_sock(drv
->monitor_sock
);
6544 close(drv
->monitor_sock
);
6545 drv
->monitor_sock
= -1;
6551 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
6554 struct sockaddr_ll ll
;
6558 if (drv
->monitor_ifidx
>= 0) {
6559 drv
->monitor_refcount
++;
6563 if (os_strncmp(drv
->first_bss
.ifname
, "p2p-", 4) == 0) {
6565 * P2P interface name is of the format p2p-%s-%d. For monitor
6566 * interface name corresponding to P2P GO, replace "p2p-" with
6567 * "mon-" to retain the same interface name length and to
6568 * indicate that it is a monitor interface.
6570 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
.ifname
+ 4);
6572 /* Non-P2P interface with AP functionality. */
6573 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
.ifname
);
6576 buf
[IFNAMSIZ
- 1] = '\0';
6578 drv
->monitor_ifidx
=
6579 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
6582 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
6584 * This is backward compatibility for a few versions of
6585 * the kernel only that didn't advertise the right
6586 * attributes for the only driver that then supported
6587 * AP mode w/o monitor -- ath6kl.
6589 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
6590 "monitor interface type - try to run without it");
6591 drv
->device_ap_sme
= 1;
6594 if (drv
->monitor_ifidx
< 0)
6597 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
6600 memset(&ll
, 0, sizeof(ll
));
6601 ll
.sll_family
= AF_PACKET
;
6602 ll
.sll_ifindex
= drv
->monitor_ifidx
;
6603 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
6604 if (drv
->monitor_sock
< 0) {
6605 perror("socket[PF_PACKET,SOCK_RAW]");
6609 if (add_monitor_filter(drv
->monitor_sock
)) {
6610 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
6611 "interface; do filtering in user space");
6612 /* This works, but will cost in performance. */
6615 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
6616 perror("monitor socket bind");
6620 optlen
= sizeof(optval
);
6623 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
6624 perror("Failed to set socket priority");
6628 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
6630 printf("Could not register monitor read socket\n");
6636 nl80211_remove_monitor_interface(drv
);
6641 static int nl80211_setup_ap(struct i802_bss
*bss
)
6643 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6645 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP - device_ap_sme=%d "
6646 "use_monitor=%d", drv
->device_ap_sme
, drv
->use_monitor
);
6649 * Disable Probe Request reporting unless we need it in this way for
6650 * devices that include the AP SME, in the other case (unless using
6651 * monitor iface) we'll get it through the nl_mgmt socket instead.
6653 if (!drv
->device_ap_sme
)
6654 wpa_driver_nl80211_probe_req_report(bss
, 0);
6656 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
6657 if (nl80211_mgmt_subscribe_ap(bss
))
6660 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
6661 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
6664 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
6665 nl80211_create_monitor_interface(drv
) &&
6666 !drv
->device_ap_sme
)
6669 if (drv
->device_ap_sme
&&
6670 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
6671 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
6672 "Probe Request frame reporting in AP mode");
6673 /* Try to survive without this */
6680 static void nl80211_teardown_ap(struct i802_bss
*bss
)
6682 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6684 if (drv
->device_ap_sme
) {
6685 wpa_driver_nl80211_probe_req_report(bss
, 0);
6686 if (!drv
->use_monitor
)
6687 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
6688 } else if (drv
->use_monitor
)
6689 nl80211_remove_monitor_interface(drv
);
6691 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
6693 bss
->beacon_set
= 0;
6697 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
6698 const u8
*addr
, const u8
*data
,
6701 struct sockaddr_ll ll
;
6704 if (bss
->drv
->eapol_tx_sock
< 0) {
6705 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
6709 os_memset(&ll
, 0, sizeof(ll
));
6710 ll
.sll_family
= AF_PACKET
;
6711 ll
.sll_ifindex
= bss
->ifindex
;
6712 ll
.sll_protocol
= htons(ETH_P_PAE
);
6713 ll
.sll_halen
= ETH_ALEN
;
6714 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
6715 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
6716 (struct sockaddr
*) &ll
, sizeof(ll
));
6718 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
6725 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
6727 static int wpa_driver_nl80211_hapd_send_eapol(
6728 void *priv
, const u8
*addr
, const u8
*data
,
6729 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
6731 struct i802_bss
*bss
= priv
;
6732 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6733 struct ieee80211_hdr
*hdr
;
6737 int qos
= flags
& WPA_STA_WMM
;
6739 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
6740 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
6742 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
6744 hdr
= os_zalloc(len
);
6746 printf("malloc() failed for i802_send_data(len=%lu)\n",
6747 (unsigned long) len
);
6751 hdr
->frame_control
=
6752 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
6753 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
6755 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
6757 hdr
->frame_control
|=
6758 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
6761 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
6762 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
6763 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
6764 pos
= (u8
*) (hdr
+ 1);
6767 /* Set highest priority in QoS header */
6773 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
6774 pos
+= sizeof(rfc1042_header
);
6775 WPA_PUT_BE16(pos
, ETH_P_PAE
);
6777 memcpy(pos
, data
, data_len
);
6779 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
6782 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
6784 (unsigned long) len
, errno
, strerror(errno
));
6792 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
6794 int flags_or
, int flags_and
)
6796 struct i802_bss
*bss
= priv
;
6797 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6798 struct nl_msg
*msg
, *flags
= NULL
;
6799 struct nl80211_sta_flag_update upd
;
6801 msg
= nlmsg_alloc();
6805 flags
= nlmsg_alloc();
6811 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
6813 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6814 if_nametoindex(bss
->ifname
));
6815 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6818 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
6819 * can be removed eventually.
6821 if (total_flags
& WPA_STA_AUTHORIZED
)
6822 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_AUTHORIZED
);
6824 if (total_flags
& WPA_STA_WMM
)
6825 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_WME
);
6827 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
6828 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
6830 if (total_flags
& WPA_STA_MFP
)
6831 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_MFP
);
6833 if (total_flags
& WPA_STA_TDLS_PEER
)
6834 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_TDLS_PEER
);
6836 if (nla_put_nested(msg
, NL80211_ATTR_STA_FLAGS
, flags
))
6837 goto nla_put_failure
;
6839 os_memset(&upd
, 0, sizeof(upd
));
6840 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
6841 upd
.set
= sta_flags_nl80211(flags_or
);
6842 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6846 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6854 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
6855 struct wpa_driver_associate_params
*params
)
6857 enum nl80211_iftype nlmode
, old_mode
;
6858 struct hostapd_freq_params freq
= {
6859 .freq
= params
->freq
,
6863 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
6865 nlmode
= NL80211_IFTYPE_P2P_GO
;
6867 nlmode
= NL80211_IFTYPE_AP
;
6869 old_mode
= drv
->nlmode
;
6870 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
, nlmode
)) {
6871 nl80211_remove_monitor_interface(drv
);
6875 if (wpa_driver_nl80211_set_freq(&drv
->first_bss
, &freq
)) {
6876 if (old_mode
!= nlmode
)
6877 wpa_driver_nl80211_set_mode(&drv
->first_bss
, old_mode
);
6878 nl80211_remove_monitor_interface(drv
);
6886 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
6891 msg
= nlmsg_alloc();
6895 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
6896 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6897 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6900 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
6901 "(%s)", ret
, strerror(-ret
));
6902 goto nla_put_failure
;
6906 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
6914 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
6915 struct wpa_driver_associate_params
*params
)
6921 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
6923 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
6924 NL80211_IFTYPE_ADHOC
)) {
6925 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
6931 msg
= nlmsg_alloc();
6935 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
6936 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6938 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
6939 goto nla_put_failure
;
6941 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6942 params
->ssid
, params
->ssid_len
);
6943 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6945 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6946 drv
->ssid_len
= params
->ssid_len
;
6948 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6949 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6951 ret
= nl80211_set_conn_keys(params
, msg
);
6953 goto nla_put_failure
;
6955 if (params
->bssid
&& params
->fixed_bssid
) {
6956 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
6957 MAC2STR(params
->bssid
));
6958 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
6961 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
6962 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
6963 params
->key_mgmt_suite
== KEY_MGMT_802_1X_SHA256
||
6964 params
->key_mgmt_suite
== KEY_MGMT_PSK_SHA256
) {
6965 wpa_printf(MSG_DEBUG
, " * control port");
6966 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
6969 if (params
->wpa_ie
) {
6970 wpa_hexdump(MSG_DEBUG
,
6971 " * Extra IEs for Beacon/Probe Response frames",
6972 params
->wpa_ie
, params
->wpa_ie_len
);
6973 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6977 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6980 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
6981 ret
, strerror(-ret
));
6983 if (ret
== -EALREADY
&& count
== 1) {
6984 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
6986 nl80211_leave_ibss(drv
);
6991 goto nla_put_failure
;
6994 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
7002 static int wpa_driver_nl80211_try_connect(
7003 struct wpa_driver_nl80211_data
*drv
,
7004 struct wpa_driver_associate_params
*params
)
7007 enum nl80211_auth_type type
;
7011 msg
= nlmsg_alloc();
7015 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
7016 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
7018 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7019 if (params
->bssid
) {
7020 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
7021 MAC2STR(params
->bssid
));
7022 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7025 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7026 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7028 if (params
->bg_scan_period
>= 0) {
7029 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
7030 params
->bg_scan_period
);
7031 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
7032 params
->bg_scan_period
);
7035 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7036 params
->ssid
, params
->ssid_len
);
7037 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7039 if (params
->ssid_len
> sizeof(drv
->ssid
))
7040 goto nla_put_failure
;
7041 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7042 drv
->ssid_len
= params
->ssid_len
;
7044 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
7046 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7050 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
7052 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
7054 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
7057 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
7059 goto skip_auth_type
;
7062 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
7063 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
7064 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
7065 type
= NL80211_AUTHTYPE_SHARED_KEY
;
7066 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
7067 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
7068 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
7069 type
= NL80211_AUTHTYPE_FT
;
7071 goto nla_put_failure
;
7073 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
7074 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
7077 if (params
->wpa_proto
) {
7078 enum nl80211_wpa_versions ver
= 0;
7080 if (params
->wpa_proto
& WPA_PROTO_WPA
)
7081 ver
|= NL80211_WPA_VERSION_1
;
7082 if (params
->wpa_proto
& WPA_PROTO_RSN
)
7083 ver
|= NL80211_WPA_VERSION_2
;
7085 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
7086 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
7089 if (params
->pairwise_suite
!= CIPHER_NONE
) {
7092 switch (params
->pairwise_suite
) {
7094 cipher
= WLAN_CIPHER_SUITE_SMS4
;
7097 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7100 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7103 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7106 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7110 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7113 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
7116 if (params
->group_suite
!= CIPHER_NONE
) {
7119 switch (params
->group_suite
) {
7121 cipher
= WLAN_CIPHER_SUITE_SMS4
;
7124 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7127 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7130 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7133 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7137 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7140 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
7143 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
7144 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
7145 params
->key_mgmt_suite
== KEY_MGMT_CCKM
) {
7146 int mgmt
= WLAN_AKM_SUITE_PSK
;
7148 switch (params
->key_mgmt_suite
) {
7150 mgmt
= WLAN_AKM_SUITE_CCKM
;
7152 case KEY_MGMT_802_1X
:
7153 mgmt
= WLAN_AKM_SUITE_8021X
;
7157 mgmt
= WLAN_AKM_SUITE_PSK
;
7160 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
7163 #ifdef CONFIG_IEEE80211W
7164 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
7165 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
7166 #endif /* CONFIG_IEEE80211W */
7168 if (params
->disable_ht
)
7169 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
7171 if (params
->htcaps
&& params
->htcaps_mask
) {
7172 int sz
= sizeof(struct ieee80211_ht_capabilities
);
7173 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
7174 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
7175 params
->htcaps_mask
);
7178 #ifdef CONFIG_VHT_OVERRIDES
7179 if (params
->disable_vht
) {
7180 wpa_printf(MSG_DEBUG
, " * VHT disabled");
7181 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_VHT
);
7184 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
7185 int sz
= sizeof(struct ieee80211_vht_capabilities
);
7186 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
, params
->vhtcaps
);
7187 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
7188 params
->vhtcaps_mask
);
7190 #endif /* CONFIG_VHT_OVERRIDES */
7192 ret
= nl80211_set_conn_keys(params
, msg
);
7194 goto nla_put_failure
;
7196 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7199 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
7200 "(%s)", ret
, strerror(-ret
));
7201 goto nla_put_failure
;
7204 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
7213 static int wpa_driver_nl80211_connect(
7214 struct wpa_driver_nl80211_data
*drv
,
7215 struct wpa_driver_associate_params
*params
)
7217 int ret
= wpa_driver_nl80211_try_connect(drv
, params
);
7218 if (ret
== -EALREADY
) {
7220 * cfg80211 does not currently accept new connections if
7221 * we are already connected. As a workaround, force
7222 * disconnection and try again.
7224 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
7225 "disconnecting before reassociation "
7227 if (wpa_driver_nl80211_disconnect(
7228 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
))
7230 /* Ignore the next local disconnect message. */
7231 drv
->ignore_next_local_disconnect
= 1;
7232 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
7238 static int wpa_driver_nl80211_associate(
7239 void *priv
, struct wpa_driver_associate_params
*params
)
7241 struct i802_bss
*bss
= priv
;
7242 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7246 if (params
->mode
== IEEE80211_MODE_AP
)
7247 return wpa_driver_nl80211_ap(drv
, params
);
7249 if (params
->mode
== IEEE80211_MODE_IBSS
)
7250 return wpa_driver_nl80211_ibss(drv
, params
);
7252 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
7253 enum nl80211_iftype nlmode
= params
->p2p
?
7254 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
7256 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
7258 return wpa_driver_nl80211_connect(drv
, params
);
7261 drv
->associated
= 0;
7263 msg
= nlmsg_alloc();
7267 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
7269 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
7271 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7272 if (params
->bssid
) {
7273 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
7274 MAC2STR(params
->bssid
));
7275 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7278 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7279 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7280 drv
->assoc_freq
= params
->freq
;
7282 drv
->assoc_freq
= 0;
7283 if (params
->bg_scan_period
>= 0) {
7284 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
7285 params
->bg_scan_period
);
7286 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
7287 params
->bg_scan_period
);
7290 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7291 params
->ssid
, params
->ssid_len
);
7292 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7294 if (params
->ssid_len
> sizeof(drv
->ssid
))
7295 goto nla_put_failure
;
7296 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7297 drv
->ssid_len
= params
->ssid_len
;
7299 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
7301 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7304 if (params
->pairwise_suite
!= CIPHER_NONE
) {
7307 switch (params
->pairwise_suite
) {
7309 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7312 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7315 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7318 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7322 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7325 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
7326 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
7329 if (params
->group_suite
!= CIPHER_NONE
) {
7332 switch (params
->group_suite
) {
7334 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7337 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7340 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7343 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7347 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7350 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
7351 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
7354 #ifdef CONFIG_IEEE80211W
7355 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
7356 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
7357 #endif /* CONFIG_IEEE80211W */
7359 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
7361 if (params
->prev_bssid
) {
7362 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
7363 MAC2STR(params
->prev_bssid
));
7364 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
7365 params
->prev_bssid
);
7368 if (params
->disable_ht
)
7369 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
7371 if (params
->htcaps
&& params
->htcaps_mask
) {
7372 int sz
= sizeof(struct ieee80211_ht_capabilities
);
7373 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
7374 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
7375 params
->htcaps_mask
);
7378 #ifdef CONFIG_VHT_OVERRIDES
7379 if (params
->disable_vht
) {
7380 wpa_printf(MSG_DEBUG
, " * VHT disabled");
7381 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_VHT
);
7384 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
7385 int sz
= sizeof(struct ieee80211_vht_capabilities
);
7386 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
, params
->vhtcaps
);
7387 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
7388 params
->vhtcaps_mask
);
7390 #endif /* CONFIG_VHT_OVERRIDES */
7393 wpa_printf(MSG_DEBUG
, " * P2P group");
7395 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7398 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
7399 "nl80211: MLME command failed (assoc): ret=%d (%s)",
7400 ret
, strerror(-ret
));
7401 nl80211_dump_scan(drv
);
7402 goto nla_put_failure
;
7405 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
7414 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
7415 int ifindex
, enum nl80211_iftype mode
)
7420 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
7421 ifindex
, mode
, nl80211_iftype_str(mode
));
7423 msg
= nlmsg_alloc();
7427 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
7428 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
7429 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
7431 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7437 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
7438 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
7443 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
7444 enum nl80211_iftype nlmode
)
7446 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7449 int was_ap
= is_ap_interface(drv
->nlmode
);
7452 res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
7454 drv
->nlmode
= nlmode
;
7462 if (nlmode
== drv
->nlmode
) {
7463 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
7464 "requested mode - ignore error");
7466 goto done
; /* Already in the requested mode */
7469 /* mac80211 doesn't allow mode changes while the device is up, so
7470 * take the device down, try to set the mode again, and bring the
7473 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
7475 for (i
= 0; i
< 10; i
++) {
7476 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
7478 if (res
== -EACCES
|| res
== -ENODEV
)
7481 /* Try to set the mode again while the interface is
7483 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
7486 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
7490 else if (ret
!= -EBUSY
)
7493 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
7495 os_sleep(0, 100000);
7499 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
7500 "interface is down");
7501 drv
->nlmode
= nlmode
;
7502 drv
->ignore_if_down_event
= 1;
7507 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
7508 "from %d failed", nlmode
, drv
->nlmode
);
7512 if (is_p2p_interface(nlmode
))
7513 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
7514 else if (drv
->disabled_11b_rates
)
7515 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
7517 if (is_ap_interface(nlmode
)) {
7518 nl80211_mgmt_unsubscribe(bss
, "start AP");
7519 /* Setup additional AP mode functionality if needed */
7520 if (nl80211_setup_ap(bss
))
7522 } else if (was_ap
) {
7523 /* Remove additional AP mode functionality */
7524 nl80211_teardown_ap(bss
);
7526 nl80211_mgmt_unsubscribe(bss
, "mode change");
7529 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
7530 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
7531 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
7532 "frame processing - ignore for now");
7538 static int wpa_driver_nl80211_get_capa(void *priv
,
7539 struct wpa_driver_capa
*capa
)
7541 struct i802_bss
*bss
= priv
;
7542 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7543 if (!drv
->has_capability
)
7545 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
7550 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
7552 struct i802_bss
*bss
= priv
;
7553 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7555 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
7556 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
7557 drv
->operstate
= state
;
7558 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
7559 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
7563 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
7565 struct i802_bss
*bss
= priv
;
7566 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7568 struct nl80211_sta_flag_update upd
;
7570 msg
= nlmsg_alloc();
7574 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7576 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7577 if_nametoindex(bss
->ifname
));
7578 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
7580 os_memset(&upd
, 0, sizeof(upd
));
7581 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
7583 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
7584 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
7586 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7593 /* Set kernel driver on given frequency (MHz) */
7594 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
7596 struct i802_bss
*bss
= priv
;
7597 return wpa_driver_nl80211_set_freq(bss
, freq
);
7601 #if defined(HOSTAPD) || defined(CONFIG_AP)
7603 static inline int min_int(int a
, int b
)
7611 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
7613 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7614 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7616 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7617 genlmsg_attrlen(gnlh
, 0), NULL
);
7620 * TODO: validate the key index and mac address!
7621 * Otherwise, there's a race condition as soon as
7622 * the kernel starts sending key notifications.
7625 if (tb
[NL80211_ATTR_KEY_SEQ
])
7626 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
7627 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
7632 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
7635 struct i802_bss
*bss
= priv
;
7636 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7639 msg
= nlmsg_alloc();
7643 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
7646 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7647 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
7648 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
7652 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
7659 static int i802_set_rts(void *priv
, int rts
)
7661 struct i802_bss
*bss
= priv
;
7662 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7667 msg
= nlmsg_alloc();
7676 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7677 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7678 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
7680 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7686 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
7687 "%d (%s)", rts
, ret
, strerror(-ret
));
7692 static int i802_set_frag(void *priv
, int frag
)
7694 struct i802_bss
*bss
= priv
;
7695 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7700 msg
= nlmsg_alloc();
7709 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7710 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7711 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
7713 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7719 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
7720 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
7725 static int i802_flush(void *priv
)
7727 struct i802_bss
*bss
= priv
;
7728 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7732 msg
= nlmsg_alloc();
7736 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
7739 * XXX: FIX! this needs to flush all VLANs too
7741 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7742 if_nametoindex(bss
->ifname
));
7744 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7746 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
7747 "(%s)", res
, strerror(-res
));
7755 #endif /* HOSTAPD || CONFIG_AP */
7758 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
7760 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7761 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7762 struct hostap_sta_driver_data
*data
= arg
;
7763 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
7764 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
7765 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
7766 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
7767 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
7768 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
7769 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
7770 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
7773 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7774 genlmsg_attrlen(gnlh
, 0), NULL
);
7777 * TODO: validate the interface and mac address!
7778 * Otherwise, there's a race condition as soon as
7779 * the kernel starts sending station notifications.
7782 if (!tb
[NL80211_ATTR_STA_INFO
]) {
7783 wpa_printf(MSG_DEBUG
, "sta stats missing!");
7786 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
7787 tb
[NL80211_ATTR_STA_INFO
],
7789 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
7793 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
7794 data
->inactive_msec
=
7795 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
7796 if (stats
[NL80211_STA_INFO_RX_BYTES
])
7797 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
7798 if (stats
[NL80211_STA_INFO_TX_BYTES
])
7799 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
7800 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
7802 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
7803 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
7805 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
7806 if (stats
[NL80211_STA_INFO_TX_FAILED
])
7807 data
->tx_retry_failed
=
7808 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
7813 static int i802_read_sta_data(struct i802_bss
*bss
,
7814 struct hostap_sta_driver_data
*data
,
7817 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7820 os_memset(data
, 0, sizeof(*data
));
7821 msg
= nlmsg_alloc();
7825 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
7827 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7828 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7830 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
7837 #if defined(HOSTAPD) || defined(CONFIG_AP)
7839 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
7840 int cw_min
, int cw_max
, int burst_time
)
7842 struct i802_bss
*bss
= priv
;
7843 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7845 struct nlattr
*txq
, *params
;
7847 msg
= nlmsg_alloc();
7851 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7853 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7855 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
7857 goto nla_put_failure
;
7859 /* We are only sending parameters for a single TXQ at a time */
7860 params
= nla_nest_start(msg
, 1);
7862 goto nla_put_failure
;
7866 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
7869 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
7872 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
7875 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
7878 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
7879 * 32 usec, so need to convert the value here. */
7880 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
7881 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
7882 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
7883 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
7885 nla_nest_end(msg
, params
);
7887 nla_nest_end(msg
, txq
);
7889 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
7898 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
7899 const char *ifname
, int vlan_id
)
7901 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7905 msg
= nlmsg_alloc();
7909 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7911 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7912 if_nametoindex(bss
->ifname
));
7913 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7914 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
7915 if_nametoindex(ifname
));
7917 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7920 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
7921 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
7922 MAC2STR(addr
), ifname
, vlan_id
, ret
,
7931 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
7933 struct hostap_sta_driver_data data
;
7936 data
.inactive_msec
= (unsigned long) -1;
7937 ret
= i802_read_sta_data(priv
, &data
, addr
);
7938 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
7940 return data
.inactive_msec
/ 1000;
7944 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
7953 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
7956 struct i802_bss
*bss
= priv
;
7957 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7958 struct ieee80211_mgmt mgmt
;
7960 if (drv
->device_ap_sme
)
7961 return wpa_driver_nl80211_sta_remove(bss
, addr
);
7963 memset(&mgmt
, 0, sizeof(mgmt
));
7964 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
7965 WLAN_FC_STYPE_DEAUTH
);
7966 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
7967 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
7968 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
7969 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
7970 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
7972 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
7977 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
7980 struct i802_bss
*bss
= priv
;
7981 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7982 struct ieee80211_mgmt mgmt
;
7984 if (drv
->device_ap_sme
)
7985 return wpa_driver_nl80211_sta_remove(bss
, addr
);
7987 memset(&mgmt
, 0, sizeof(mgmt
));
7988 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
7989 WLAN_FC_STYPE_DISASSOC
);
7990 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
7991 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
7992 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
7993 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
7994 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
7996 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
8000 #endif /* HOSTAPD || CONFIG_AP */
8004 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8009 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
8011 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
8012 if (drv
->if_indices
[i
] == 0) {
8013 drv
->if_indices
[i
] = ifidx
;
8018 if (drv
->if_indices
!= drv
->default_if_indices
)
8019 old
= drv
->if_indices
;
8023 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
8025 if (!drv
->if_indices
) {
8027 drv
->if_indices
= drv
->default_if_indices
;
8029 drv
->if_indices
= old
;
8030 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
8032 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
8035 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
8036 sizeof(drv
->default_if_indices
));
8037 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
8038 drv
->num_if_indices
++;
8042 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8046 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
8047 if (drv
->if_indices
[i
] == ifidx
) {
8048 drv
->if_indices
[i
] = 0;
8055 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8059 for (i
= 0; i
< drv
->num_if_indices
; i
++)
8060 if (drv
->if_indices
[i
] == ifidx
)
8067 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
8068 const char *bridge_ifname
)
8070 struct i802_bss
*bss
= priv
;
8071 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8072 char name
[IFNAMSIZ
+ 1];
8074 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
8075 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
8076 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
8078 if (!if_nametoindex(name
)) {
8079 if (nl80211_create_iface(drv
, name
,
8080 NL80211_IFTYPE_AP_VLAN
,
8083 if (bridge_ifname
&&
8084 linux_br_add_if(drv
->global
->ioctl_sock
,
8085 bridge_ifname
, name
) < 0)
8088 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
8089 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
8090 "interface %s up", name
);
8092 return i802_set_sta_vlan(priv
, addr
, name
, 0);
8095 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
8098 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
8099 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
8105 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
8107 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
8108 struct sockaddr_ll lladdr
;
8109 unsigned char buf
[3000];
8111 socklen_t fromlen
= sizeof(lladdr
);
8113 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
8114 (struct sockaddr
*)&lladdr
, &fromlen
);
8120 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
8121 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
8125 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
8126 struct i802_bss
*bss
,
8127 const char *brname
, const char *ifname
)
8130 char in_br
[IFNAMSIZ
];
8132 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
8133 ifindex
= if_nametoindex(brname
);
8136 * Bridge was configured, but the bridge device does
8137 * not exist. Try to add it now.
8139 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
8140 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
8141 "bridge interface %s: %s",
8142 brname
, strerror(errno
));
8145 bss
->added_bridge
= 1;
8146 add_ifidx(drv
, if_nametoindex(brname
));
8149 if (linux_br_get(in_br
, ifname
) == 0) {
8150 if (os_strcmp(in_br
, brname
) == 0)
8151 return 0; /* already in the bridge */
8153 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
8154 "bridge %s", ifname
, in_br
);
8155 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
8157 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
8158 "remove interface %s from bridge "
8160 ifname
, brname
, strerror(errno
));
8165 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
8167 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
8168 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
8169 "into bridge %s: %s",
8170 ifname
, brname
, strerror(errno
));
8173 bss
->added_if_into_bridge
= 1;
8179 static void *i802_init(struct hostapd_data
*hapd
,
8180 struct wpa_init_params
*params
)
8182 struct wpa_driver_nl80211_data
*drv
;
8183 struct i802_bss
*bss
;
8185 char brname
[IFNAMSIZ
];
8186 int ifindex
, br_ifindex
;
8189 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
8190 params
->global_priv
);
8195 drv
->nlmode
= NL80211_IFTYPE_AP
;
8196 drv
->eapol_sock
= -1;
8198 if (linux_br_get(brname
, params
->ifname
) == 0) {
8199 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
8200 params
->ifname
, brname
);
8201 br_ifindex
= if_nametoindex(brname
);
8207 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
8208 drv
->if_indices
= drv
->default_if_indices
;
8209 for (i
= 0; i
< params
->num_bridge
; i
++) {
8210 if (params
->bridge
[i
]) {
8211 ifindex
= if_nametoindex(params
->bridge
[i
]);
8213 add_ifidx(drv
, ifindex
);
8214 if (ifindex
== br_ifindex
)
8218 if (!br_added
&& br_ifindex
&&
8219 (params
->num_bridge
== 0 || !params
->bridge
[0]))
8220 add_ifidx(drv
, br_ifindex
);
8222 /* start listening for EAPOL on the default AP interface */
8223 add_ifidx(drv
, drv
->ifindex
);
8225 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
8228 if (params
->bssid
) {
8229 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
8234 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
8235 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
8236 "into AP mode", bss
->ifname
);
8240 if (params
->num_bridge
&& params
->bridge
[0] &&
8241 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
8244 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
8247 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
8248 if (drv
->eapol_sock
< 0) {
8249 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
8253 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
8255 printf("Could not register read socket for eapol\n");
8259 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
8263 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
8268 wpa_driver_nl80211_deinit(bss
);
8273 static void i802_deinit(void *priv
)
8275 struct i802_bss
*bss
= priv
;
8276 wpa_driver_nl80211_deinit(bss
);
8279 #endif /* HOSTAPD */
8282 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
8283 enum wpa_driver_if_type type
)
8286 case WPA_IF_STATION
:
8287 return NL80211_IFTYPE_STATION
;
8288 case WPA_IF_P2P_CLIENT
:
8289 case WPA_IF_P2P_GROUP
:
8290 return NL80211_IFTYPE_P2P_CLIENT
;
8291 case WPA_IF_AP_VLAN
:
8292 return NL80211_IFTYPE_AP_VLAN
;
8294 return NL80211_IFTYPE_AP
;
8296 return NL80211_IFTYPE_P2P_GO
;
8304 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
8306 struct wpa_driver_nl80211_data
*drv
;
8307 dl_list_for_each(drv
, &global
->interfaces
,
8308 struct wpa_driver_nl80211_data
, list
) {
8309 if (os_memcmp(addr
, drv
->first_bss
.addr
, ETH_ALEN
) == 0)
8316 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
8324 os_memcpy(new_addr
, drv
->first_bss
.addr
, ETH_ALEN
);
8325 for (idx
= 0; idx
< 64; idx
++) {
8326 new_addr
[0] = drv
->first_bss
.addr
[0] | 0x02;
8327 new_addr
[0] ^= idx
<< 2;
8328 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
8334 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
8335 MACSTR
, MAC2STR(new_addr
));
8340 #endif /* CONFIG_P2P */
8343 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
8344 const char *ifname
, const u8
*addr
,
8345 void *bss_ctx
, void **drv_priv
,
8346 char *force_ifname
, u8
*if_addr
,
8349 struct i802_bss
*bss
= priv
;
8350 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8353 struct i802_bss
*new_bss
= NULL
;
8355 if (type
== WPA_IF_AP_BSS
) {
8356 new_bss
= os_zalloc(sizeof(*new_bss
));
8357 if (new_bss
== NULL
)
8360 #endif /* HOSTAPD */
8363 os_memcpy(if_addr
, addr
, ETH_ALEN
);
8364 ifidx
= nl80211_create_iface(drv
, ifname
,
8365 wpa_driver_nl80211_if_type(type
), addr
,
8370 #endif /* HOSTAPD */
8375 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
8377 nl80211_remove_iface(drv
, ifidx
);
8383 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
8384 type
== WPA_IF_P2P_GO
)) {
8385 /* Enforce unique P2P Interface Address */
8386 u8 new_addr
[ETH_ALEN
], own_addr
[ETH_ALEN
];
8388 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
8390 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
8392 nl80211_remove_iface(drv
, ifidx
);
8395 if (os_memcmp(own_addr
, new_addr
, ETH_ALEN
) == 0) {
8396 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
8397 "for P2P group interface");
8398 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
8399 nl80211_remove_iface(drv
, ifidx
);
8402 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
8404 nl80211_remove_iface(drv
, ifidx
);
8408 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
8410 #endif /* CONFIG_P2P */
8414 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
8415 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
8416 "interface %s to a bridge %s", ifname
, bridge
);
8417 nl80211_remove_iface(drv
, ifidx
);
8422 if (type
== WPA_IF_AP_BSS
) {
8423 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
8425 nl80211_remove_iface(drv
, ifidx
);
8429 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
8430 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
8431 new_bss
->ifindex
= ifidx
;
8433 new_bss
->next
= drv
->first_bss
.next
;
8434 new_bss
->freq
= drv
->first_bss
.freq
;
8435 new_bss
->ctx
= bss_ctx
;
8436 drv
->first_bss
.next
= new_bss
;
8438 *drv_priv
= new_bss
;
8439 nl80211_init_bss(new_bss
);
8441 /* Subscribe management frames for this WPA_IF_AP_BSS */
8442 if (nl80211_setup_ap(new_bss
))
8445 #endif /* HOSTAPD */
8448 drv
->global
->if_add_ifindex
= ifidx
;
8454 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
8455 enum wpa_driver_if_type type
,
8458 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8459 int ifindex
= if_nametoindex(ifname
);
8461 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d",
8462 __func__
, type
, ifname
, ifindex
);
8466 nl80211_remove_iface(drv
, ifindex
);
8469 if (type
!= WPA_IF_AP_BSS
)
8472 if (bss
->added_if_into_bridge
) {
8473 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
8475 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
8476 "interface %s from bridge %s: %s",
8477 bss
->ifname
, bss
->brname
, strerror(errno
));
8479 if (bss
->added_bridge
) {
8480 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
8481 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
8483 bss
->brname
, strerror(errno
));
8486 if (bss
!= &drv
->first_bss
) {
8487 struct i802_bss
*tbss
;
8489 for (tbss
= &drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
8490 if (tbss
->next
== bss
) {
8491 tbss
->next
= bss
->next
;
8492 /* Unsubscribe management frames */
8493 nl80211_teardown_ap(bss
);
8494 nl80211_destroy_bss(bss
);
8501 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
8502 "BSS %p in the list", __func__
, bss
);
8504 #endif /* HOSTAPD */
8510 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
8512 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8513 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8515 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8516 genlmsg_attrlen(gnlh
, 0), NULL
);
8517 if (tb
[NL80211_ATTR_COOKIE
])
8518 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
8523 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
8524 unsigned int freq
, unsigned int wait
,
8525 const u8
*buf
, size_t buf_len
,
8526 u64
*cookie_out
, int no_cck
, int no_ack
,
8529 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8534 msg
= nlmsg_alloc();
8538 wpa_printf(MSG_DEBUG
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
8539 "no_ack=%d offchanok=%d",
8540 freq
, wait
, no_cck
, no_ack
, offchanok
);
8541 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
8543 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8544 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
8546 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
8547 if (offchanok
&& (drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
))
8548 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
8550 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
8552 NLA_PUT_FLAG(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
);
8554 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
8557 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
8560 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
8561 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
8563 goto nla_put_failure
;
8565 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX command accepted%s; "
8566 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
8567 (long long unsigned int) cookie
);
8570 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
8578 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
8580 unsigned int wait_time
,
8581 const u8
*dst
, const u8
*src
,
8583 const u8
*data
, size_t data_len
,
8586 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8589 struct ieee80211_hdr
*hdr
;
8591 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
8592 "freq=%u MHz wait=%d ms no_cck=%d)",
8593 drv
->ifindex
, freq
, wait_time
, no_cck
);
8595 buf
= os_zalloc(24 + data_len
);
8598 os_memcpy(buf
+ 24, data
, data_len
);
8599 hdr
= (struct ieee80211_hdr
*) buf
;
8600 hdr
->frame_control
=
8601 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
8602 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
8603 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
8604 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
8606 if (is_ap_interface(drv
->nlmode
))
8607 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
8611 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
8613 &drv
->send_action_cookie
,
8621 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
8623 struct i802_bss
*bss
= priv
;
8624 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8628 msg
= nlmsg_alloc();
8632 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
8633 (long long unsigned int) drv
->send_action_cookie
);
8634 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
8636 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8637 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
8639 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8642 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
8643 "(%s)", ret
, strerror(-ret
));
8650 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
8651 unsigned int duration
)
8653 struct i802_bss
*bss
= priv
;
8654 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8659 msg
= nlmsg_alloc();
8663 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
8665 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8666 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
8667 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
8670 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
8673 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
8674 "0x%llx for freq=%u MHz duration=%u",
8675 (long long unsigned int) cookie
, freq
, duration
);
8676 drv
->remain_on_chan_cookie
= cookie
;
8677 drv
->pending_remain_on_chan
= 1;
8680 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
8681 "(freq=%d duration=%u): %d (%s)",
8682 freq
, duration
, ret
, strerror(-ret
));
8689 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
8691 struct i802_bss
*bss
= priv
;
8692 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8696 if (!drv
->pending_remain_on_chan
) {
8697 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
8702 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
8704 (long long unsigned int) drv
->remain_on_chan_cookie
);
8706 msg
= nlmsg_alloc();
8710 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
8712 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8713 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
8715 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8719 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
8720 "%d (%s)", ret
, strerror(-ret
));
8727 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
8729 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8732 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
8733 is_ap_interface(drv
->nlmode
)) {
8735 * Do not disable Probe Request reporting that was
8736 * enabled in nl80211_setup_ap().
8738 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
8739 "Probe Request reporting nl_preq=%p while "
8740 "in AP mode", bss
->nl_preq
);
8741 } else if (bss
->nl_preq
) {
8742 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
8743 "reporting nl_preq=%p", bss
->nl_preq
);
8744 eloop_unregister_read_sock(
8745 nl_socket_get_fd(bss
->nl_preq
));
8746 nl_destroy_handles(&bss
->nl_preq
);
8752 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
8753 "already on! nl_preq=%p", bss
->nl_preq
);
8757 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
8758 if (bss
->nl_preq
== NULL
)
8760 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
8761 "reporting nl_preq=%p", bss
->nl_preq
);
8763 if (nl80211_register_frame(bss
, bss
->nl_preq
,
8764 (WLAN_FC_TYPE_MGMT
<< 2) |
8765 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
8769 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_preq
),
8770 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
8776 nl_destroy_handles(&bss
->nl_preq
);
8781 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
8782 int ifindex
, int disabled
)
8785 struct nlattr
*bands
, *band
;
8788 msg
= nlmsg_alloc();
8792 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
8793 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
8795 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
8797 goto nla_put_failure
;
8800 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
8801 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
8802 * rates. All 5 GHz rates are left enabled.
8804 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
8806 goto nla_put_failure
;
8808 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
8809 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
8811 nla_nest_end(msg
, band
);
8813 nla_nest_end(msg
, bands
);
8815 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8818 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
8819 "(%s)", ret
, strerror(-ret
));
8821 drv
->disabled_11b_rates
= disabled
;
8831 static int wpa_driver_nl80211_deinit_ap(void *priv
)
8833 struct i802_bss
*bss
= priv
;
8834 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8835 if (!is_ap_interface(drv
->nlmode
))
8837 wpa_driver_nl80211_del_beacon(drv
);
8838 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
8842 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
8844 struct i802_bss
*bss
= priv
;
8845 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8846 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
8848 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
8852 static void wpa_driver_nl80211_resume(void *priv
)
8854 struct i802_bss
*bss
= priv
;
8855 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8856 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
8857 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on "
8863 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
8864 const u8
*ies
, size_t ies_len
)
8866 struct i802_bss
*bss
= priv
;
8867 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8871 const u8
*own_addr
= bss
->addr
;
8874 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
8875 "action %d", action
);
8880 * Action frame payload:
8881 * Category[1] = 6 (Fast BSS Transition)
8882 * Action[1] = 1 (Fast BSS Transition Request)
8888 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
8889 data
= os_malloc(data_len
);
8893 *pos
++ = 0x06; /* FT Action category */
8895 os_memcpy(pos
, own_addr
, ETH_ALEN
);
8897 os_memcpy(pos
, target_ap
, ETH_ALEN
);
8899 os_memcpy(pos
, ies
, ies_len
);
8901 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
8902 drv
->bssid
, own_addr
, drv
->bssid
,
8910 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
8912 struct i802_bss
*bss
= priv
;
8913 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8914 struct nl_msg
*msg
, *cqm
= NULL
;
8917 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
8918 "hysteresis=%d", threshold
, hysteresis
);
8920 msg
= nlmsg_alloc();
8924 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
8926 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8928 cqm
= nlmsg_alloc();
8930 goto nla_put_failure
;
8932 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
8933 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
8934 if (nla_put_nested(msg
, NL80211_ATTR_CQM
, cqm
) < 0)
8935 goto nla_put_failure
;
8937 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8947 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
8949 struct i802_bss
*bss
= priv
;
8950 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8953 os_memset(si
, 0, sizeof(*si
));
8954 res
= nl80211_get_link_signal(drv
, si
);
8958 return nl80211_get_link_noise(drv
, si
);
8962 static int wpa_driver_nl80211_shared_freq(void *priv
)
8964 struct i802_bss
*bss
= priv
;
8965 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8966 struct wpa_driver_nl80211_data
*driver
;
8970 * If the same PHY is in connected state with some other interface,
8971 * then retrieve the assoc freq.
8973 wpa_printf(MSG_DEBUG
, "nl80211: Get shared freq for PHY %s",
8976 dl_list_for_each(driver
, &drv
->global
->interfaces
,
8977 struct wpa_driver_nl80211_data
, list
) {
8978 if (drv
== driver
||
8979 os_strcmp(drv
->phyname
, driver
->phyname
) != 0 ||
8980 !driver
->associated
)
8983 wpa_printf(MSG_DEBUG
, "nl80211: Found a match for PHY %s - %s "
8985 driver
->phyname
, driver
->first_bss
.ifname
,
8986 MAC2STR(driver
->first_bss
.addr
));
8987 if (is_ap_interface(driver
->nlmode
))
8988 freq
= driver
->first_bss
.freq
;
8990 freq
= nl80211_get_assoc_freq(driver
);
8991 wpa_printf(MSG_DEBUG
, "nl80211: Shared freq for PHY %s: %d",
8992 drv
->phyname
, freq
);
8996 wpa_printf(MSG_DEBUG
, "nl80211: No shared interface for "
8997 "PHY (%s) in associated state", drv
->phyname
);
9003 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
9006 struct i802_bss
*bss
= priv
;
9007 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
9012 static int nl80211_set_param(void *priv
, const char *param
)
9014 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
9019 if (os_strstr(param
, "use_p2p_group_interface=1")) {
9020 struct i802_bss
*bss
= priv
;
9021 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9023 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
9025 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
9026 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
9028 #endif /* CONFIG_P2P */
9034 static void * nl80211_global_init(void)
9036 struct nl80211_global
*global
;
9037 struct netlink_config
*cfg
;
9039 global
= os_zalloc(sizeof(*global
));
9042 global
->ioctl_sock
= -1;
9043 dl_list_init(&global
->interfaces
);
9044 global
->if_add_ifindex
= -1;
9046 cfg
= os_zalloc(sizeof(*cfg
));
9051 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
9052 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
9053 global
->netlink
= netlink_init(cfg
);
9054 if (global
->netlink
== NULL
) {
9059 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
9062 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
9063 if (global
->ioctl_sock
< 0) {
9064 perror("socket(PF_INET,SOCK_DGRAM)");
9071 nl80211_global_deinit(global
);
9076 static void nl80211_global_deinit(void *priv
)
9078 struct nl80211_global
*global
= priv
;
9081 if (!dl_list_empty(&global
->interfaces
)) {
9082 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
9083 "nl80211_global_deinit",
9084 dl_list_len(&global
->interfaces
));
9087 if (global
->netlink
)
9088 netlink_deinit(global
->netlink
);
9090 nl_destroy_handles(&global
->nl
);
9092 if (global
->nl_event
) {
9093 eloop_unregister_read_sock(
9094 nl_socket_get_fd(global
->nl_event
));
9095 nl_destroy_handles(&global
->nl_event
);
9098 nl_cb_put(global
->nl_cb
);
9100 if (global
->ioctl_sock
>= 0)
9101 close(global
->ioctl_sock
);
9107 static const char * nl80211_get_radio_name(void *priv
)
9109 struct i802_bss
*bss
= priv
;
9110 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9111 return drv
->phyname
;
9115 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
9120 msg
= nlmsg_alloc();
9124 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
9126 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
9128 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
9130 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
9132 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
9139 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
9141 struct i802_bss
*bss
= priv
;
9142 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
9143 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
9147 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
9149 struct i802_bss
*bss
= priv
;
9150 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
9152 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
9156 static int nl80211_flush_pmkid(void *priv
)
9158 struct i802_bss
*bss
= priv
;
9159 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
9160 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
9164 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
9165 const u8
*replay_ctr
)
9167 struct i802_bss
*bss
= priv
;
9168 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9169 struct nlattr
*replay_nested
;
9172 msg
= nlmsg_alloc();
9176 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
9178 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9180 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
9182 goto nla_put_failure
;
9184 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
9185 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
9186 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
9189 nla_nest_end(msg
, replay_nested
);
9191 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9198 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
9199 const u8
*addr
, int qos
)
9201 /* send data frame to poll STA and check whether
9202 * this frame is ACKed */
9204 struct ieee80211_hdr hdr
;
9206 } STRUCT_PACKED nulldata
;
9209 /* Send data frame to poll STA and check whether this frame is ACKed */
9211 os_memset(&nulldata
, 0, sizeof(nulldata
));
9214 nulldata
.hdr
.frame_control
=
9215 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
9216 WLAN_FC_STYPE_QOS_NULL
);
9217 size
= sizeof(nulldata
);
9219 nulldata
.hdr
.frame_control
=
9220 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
9221 WLAN_FC_STYPE_NULLFUNC
);
9222 size
= sizeof(struct ieee80211_hdr
);
9225 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
9226 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
9227 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
9228 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
9230 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
9232 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
9236 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
9239 struct i802_bss
*bss
= priv
;
9240 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9243 if (!drv
->poll_command_supported
) {
9244 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
9248 msg
= nlmsg_alloc();
9252 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_PROBE_CLIENT
);
9254 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9255 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
9257 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9264 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
9268 msg
= nlmsg_alloc();
9272 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_SET_POWER_SAVE
);
9273 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9274 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
,
9275 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
);
9276 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
9283 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
9286 struct i802_bss
*bss
= priv
;
9288 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
9289 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
9291 if (opp_ps
!= -1 || ctwindow
!= -1)
9292 return -1; /* Not yet supported */
9294 if (legacy_ps
== -1)
9296 if (legacy_ps
!= 0 && legacy_ps
!= 1)
9297 return -1; /* Not yet supported */
9299 return nl80211_set_power_save(bss
, legacy_ps
);
9305 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
9306 u8 dialog_token
, u16 status_code
,
9307 const u8
*buf
, size_t len
)
9309 struct i802_bss
*bss
= priv
;
9310 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9313 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
9319 msg
= nlmsg_alloc();
9323 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_MGMT
);
9324 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
9325 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
9326 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
);
9327 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
);
9328 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
);
9329 NLA_PUT(msg
, NL80211_ATTR_IE
, len
, buf
);
9331 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9339 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
9341 struct i802_bss
*bss
= priv
;
9342 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9344 enum nl80211_tdls_operation nl80211_oper
;
9346 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
9350 case TDLS_DISCOVERY_REQ
:
9351 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
9354 nl80211_oper
= NL80211_TDLS_SETUP
;
9357 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
9359 case TDLS_ENABLE_LINK
:
9360 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
9362 case TDLS_DISABLE_LINK
:
9363 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
9373 msg
= nlmsg_alloc();
9377 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_OPER
);
9378 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
);
9379 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
9380 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
9382 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9389 #endif /* CONFIG TDLS */
9394 typedef struct android_wifi_priv_cmd
{
9398 } android_wifi_priv_cmd
;
9400 static int drv_errors
= 0;
9402 static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data
*drv
)
9405 if (drv_errors
> DRV_NUMBER_SEQUENTIAL_ERRORS
) {
9407 wpa_msg(drv
->ctx
, MSG_INFO
, WPA_EVENT_DRIVER_STATE
"HANGED");
9412 static int android_priv_cmd(struct i802_bss
*bss
, const char *cmd
)
9414 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9416 android_wifi_priv_cmd priv_cmd
;
9417 char buf
[MAX_DRV_CMD_SIZE
];
9420 os_memset(&ifr
, 0, sizeof(ifr
));
9421 os_memset(&priv_cmd
, 0, sizeof(priv_cmd
));
9422 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
9424 os_memset(buf
, 0, sizeof(buf
));
9425 os_strlcpy(buf
, cmd
, sizeof(buf
));
9428 priv_cmd
.used_len
= sizeof(buf
);
9429 priv_cmd
.total_len
= sizeof(buf
);
9430 ifr
.ifr_data
= &priv_cmd
;
9432 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
9434 wpa_printf(MSG_ERROR
, "%s: failed to issue private commands",
9436 wpa_driver_send_hang_msg(drv
);
9445 static int android_pno_start(struct i802_bss
*bss
,
9446 struct wpa_driver_scan_params
*params
)
9448 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9450 android_wifi_priv_cmd priv_cmd
;
9451 int ret
= 0, i
= 0, bp
;
9452 char buf
[WEXT_PNO_MAX_COMMAND_SIZE
];
9454 bp
= WEXT_PNOSETUP_HEADER_SIZE
;
9455 os_memcpy(buf
, WEXT_PNOSETUP_HEADER
, bp
);
9456 buf
[bp
++] = WEXT_PNO_TLV_PREFIX
;
9457 buf
[bp
++] = WEXT_PNO_TLV_VERSION
;
9458 buf
[bp
++] = WEXT_PNO_TLV_SUBVERSION
;
9459 buf
[bp
++] = WEXT_PNO_TLV_RESERVED
;
9461 while (i
< WEXT_PNO_AMOUNT
&& (size_t) i
< params
->num_ssids
) {
9462 /* Check that there is enough space needed for 1 more SSID, the
9463 * other sections and null termination */
9464 if ((bp
+ WEXT_PNO_SSID_HEADER_SIZE
+ MAX_SSID_LEN
+
9465 WEXT_PNO_NONSSID_SECTIONS_SIZE
+ 1) >= (int) sizeof(buf
))
9467 wpa_hexdump_ascii(MSG_DEBUG
, "For PNO Scan",
9468 params
->ssids
[i
].ssid
,
9469 params
->ssids
[i
].ssid_len
);
9470 buf
[bp
++] = WEXT_PNO_SSID_SECTION
;
9471 buf
[bp
++] = params
->ssids
[i
].ssid_len
;
9472 os_memcpy(&buf
[bp
], params
->ssids
[i
].ssid
,
9473 params
->ssids
[i
].ssid_len
);
9474 bp
+= params
->ssids
[i
].ssid_len
;
9478 buf
[bp
++] = WEXT_PNO_SCAN_INTERVAL_SECTION
;
9479 os_snprintf(&buf
[bp
], WEXT_PNO_SCAN_INTERVAL_LENGTH
+ 1, "%x",
9480 WEXT_PNO_SCAN_INTERVAL
);
9481 bp
+= WEXT_PNO_SCAN_INTERVAL_LENGTH
;
9483 buf
[bp
++] = WEXT_PNO_REPEAT_SECTION
;
9484 os_snprintf(&buf
[bp
], WEXT_PNO_REPEAT_LENGTH
+ 1, "%x",
9486 bp
+= WEXT_PNO_REPEAT_LENGTH
;
9488 buf
[bp
++] = WEXT_PNO_MAX_REPEAT_SECTION
;
9489 os_snprintf(&buf
[bp
], WEXT_PNO_MAX_REPEAT_LENGTH
+ 1, "%x",
9490 WEXT_PNO_MAX_REPEAT
);
9491 bp
+= WEXT_PNO_MAX_REPEAT_LENGTH
+ 1;
9493 memset(&ifr
, 0, sizeof(ifr
));
9494 memset(&priv_cmd
, 0, sizeof(priv_cmd
));
9495 os_strncpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
9498 priv_cmd
.used_len
= bp
;
9499 priv_cmd
.total_len
= bp
;
9500 ifr
.ifr_data
= &priv_cmd
;
9502 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
9505 wpa_printf(MSG_ERROR
, "ioctl[SIOCSIWPRIV] (pnosetup): %d",
9507 wpa_driver_send_hang_msg(drv
);
9513 return android_priv_cmd(bss
, "PNOFORCE 1");
9517 static int android_pno_stop(struct i802_bss
*bss
)
9519 return android_priv_cmd(bss
, "PNOFORCE 0");
9522 #endif /* ANDROID */
9525 static int driver_nl80211_set_key(const char *ifname
, void *priv
,
9526 enum wpa_alg alg
, const u8
*addr
,
9527 int key_idx
, int set_tx
,
9528 const u8
*seq
, size_t seq_len
,
9529 const u8
*key
, size_t key_len
)
9531 struct i802_bss
*bss
= priv
;
9532 return wpa_driver_nl80211_set_key(ifname
, bss
, alg
, addr
, key_idx
,
9533 set_tx
, seq
, seq_len
, key
, key_len
);
9537 static int driver_nl80211_scan2(void *priv
,
9538 struct wpa_driver_scan_params
*params
)
9540 struct i802_bss
*bss
= priv
;
9541 return wpa_driver_nl80211_scan(bss
, params
);
9545 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
9548 struct i802_bss
*bss
= priv
;
9549 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
9553 static int driver_nl80211_authenticate(void *priv
,
9554 struct wpa_driver_auth_params
*params
)
9556 struct i802_bss
*bss
= priv
;
9557 return wpa_driver_nl80211_authenticate(bss
, params
);
9561 static void driver_nl80211_deinit(void *priv
)
9563 struct i802_bss
*bss
= priv
;
9564 wpa_driver_nl80211_deinit(bss
);
9568 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
9571 struct i802_bss
*bss
= priv
;
9572 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
9576 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
9577 size_t data_len
, int noack
)
9579 struct i802_bss
*bss
= priv
;
9580 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
9585 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
9587 struct i802_bss
*bss
= priv
;
9588 return wpa_driver_nl80211_sta_remove(bss
, addr
);
9592 #if defined(HOSTAPD) || defined(CONFIG_AP)
9593 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
9594 const char *ifname
, int vlan_id
)
9596 struct i802_bss
*bss
= priv
;
9597 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
9599 #endif /* HOSTAPD || CONFIG_AP */
9602 static int driver_nl80211_read_sta_data(void *priv
,
9603 struct hostap_sta_driver_data
*data
,
9606 struct i802_bss
*bss
= priv
;
9607 return i802_read_sta_data(bss
, data
, addr
);
9611 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
9612 unsigned int wait_time
,
9613 const u8
*dst
, const u8
*src
,
9615 const u8
*data
, size_t data_len
,
9618 struct i802_bss
*bss
= priv
;
9619 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
9620 bssid
, data
, data_len
, no_cck
);
9624 static int driver_nl80211_probe_req_report(void *priv
, int report
)
9626 struct i802_bss
*bss
= priv
;
9627 return wpa_driver_nl80211_probe_req_report(bss
, report
);
9631 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
9633 .desc
= "Linux nl80211/cfg80211",
9634 .get_bssid
= wpa_driver_nl80211_get_bssid
,
9635 .get_ssid
= wpa_driver_nl80211_get_ssid
,
9636 .set_key
= driver_nl80211_set_key
,
9637 .scan2
= driver_nl80211_scan2
,
9638 .sched_scan
= wpa_driver_nl80211_sched_scan
,
9639 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
9640 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
9641 .deauthenticate
= driver_nl80211_deauthenticate
,
9642 .authenticate
= driver_nl80211_authenticate
,
9643 .associate
= wpa_driver_nl80211_associate
,
9644 .global_init
= nl80211_global_init
,
9645 .global_deinit
= nl80211_global_deinit
,
9646 .init2
= wpa_driver_nl80211_init
,
9647 .deinit
= driver_nl80211_deinit
,
9648 .get_capa
= wpa_driver_nl80211_get_capa
,
9649 .set_operstate
= wpa_driver_nl80211_set_operstate
,
9650 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
9651 .set_country
= wpa_driver_nl80211_set_country
,
9652 .set_ap
= wpa_driver_nl80211_set_ap
,
9653 .if_add
= wpa_driver_nl80211_if_add
,
9654 .if_remove
= driver_nl80211_if_remove
,
9655 .send_mlme
= driver_nl80211_send_mlme
,
9656 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
9657 .sta_add
= wpa_driver_nl80211_sta_add
,
9658 .sta_remove
= driver_nl80211_sta_remove
,
9659 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
9660 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
9662 .hapd_init
= i802_init
,
9663 .hapd_deinit
= i802_deinit
,
9664 .set_wds_sta
= i802_set_wds_sta
,
9665 #endif /* HOSTAPD */
9666 #if defined(HOSTAPD) || defined(CONFIG_AP)
9667 .get_seqnum
= i802_get_seqnum
,
9668 .flush
= i802_flush
,
9669 .get_inact_sec
= i802_get_inact_sec
,
9670 .sta_clear_stats
= i802_sta_clear_stats
,
9671 .set_rts
= i802_set_rts
,
9672 .set_frag
= i802_set_frag
,
9673 .set_tx_queue_params
= i802_set_tx_queue_params
,
9674 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
9675 .sta_deauth
= i802_sta_deauth
,
9676 .sta_disassoc
= i802_sta_disassoc
,
9677 #endif /* HOSTAPD || CONFIG_AP */
9678 .read_sta_data
= driver_nl80211_read_sta_data
,
9679 .set_freq
= i802_set_freq
,
9680 .send_action
= driver_nl80211_send_action
,
9681 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
9682 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
9683 .cancel_remain_on_channel
=
9684 wpa_driver_nl80211_cancel_remain_on_channel
,
9685 .probe_req_report
= driver_nl80211_probe_req_report
,
9686 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
9687 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
9688 .resume
= wpa_driver_nl80211_resume
,
9689 .send_ft_action
= nl80211_send_ft_action
,
9690 .signal_monitor
= nl80211_signal_monitor
,
9691 .signal_poll
= nl80211_signal_poll
,
9692 .send_frame
= nl80211_send_frame
,
9693 .shared_freq
= wpa_driver_nl80211_shared_freq
,
9694 .set_param
= nl80211_set_param
,
9695 .get_radio_name
= nl80211_get_radio_name
,
9696 .add_pmkid
= nl80211_add_pmkid
,
9697 .remove_pmkid
= nl80211_remove_pmkid
,
9698 .flush_pmkid
= nl80211_flush_pmkid
,
9699 .set_rekey_info
= nl80211_set_rekey_info
,
9700 .poll_client
= nl80211_poll_client
,
9701 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
9703 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
9704 .tdls_oper
= nl80211_tdls_oper
,
9705 #endif /* CONFIG_TDLS */