2 * Driver interaction with Linux nl80211/cfg80211
3 * Copyright (c) 2002-2010, 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 program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * Alternatively, this software may be distributed under the terms of BSD
16 * See README and COPYING for more details.
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
25 #include <netlink/genl/genl.h>
26 #include <netlink/genl/family.h>
27 #include <netlink/genl/ctrl.h>
28 #include <linux/rtnetlink.h>
29 #include <netpacket/packet.h>
30 #include <linux/filter.h>
31 #include <linux/errqueue.h>
32 #include "nl80211_copy.h"
36 #include "utils/list.h"
37 #include "common/ieee802_11_defs.h"
38 #include "common/ieee802_11_common.h"
39 #include "l2_packet/l2_packet.h"
41 #include "linux_ioctl.h"
43 #include "radiotap_iter.h"
47 #ifndef SO_WIFI_STATUS
48 # if defined(__sparc__)
49 # define SO_WIFI_STATUS 0x0025
50 # elif defined(__parisc__)
51 # define SO_WIFI_STATUS 0x4022
53 # define SO_WIFI_STATUS 41
56 # define SCM_WIFI_STATUS SO_WIFI_STATUS
59 #ifndef SO_EE_ORIGIN_TXSTATUS
60 #define SO_EE_ORIGIN_TXSTATUS 4
63 #ifndef PACKET_TX_TIMESTAMP
64 #define PACKET_TX_TIMESTAMP 16
68 #include "android_drv.h"
71 /* libnl 2.0 compatibility code */
72 #define nl_handle nl_sock
73 #define nl80211_handle_alloc nl_socket_alloc_cb
74 #define nl80211_handle_destroy nl_socket_free
77 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
78 * but when you free a socket again it will mess up its bitmap and
79 * and use the wrong number the next time it needs a socket ID.
80 * Therefore, we wrap the handle alloc/destroy and add our own pid
83 static uint32_t port_bitmap
[32] = { 0 };
85 static struct nl_handle
*nl80211_handle_alloc(void *cb
)
87 struct nl_handle
*handle
;
88 uint32_t pid
= getpid() & 0x3FFFFF;
91 handle
= nl_handle_alloc_cb(cb
);
93 for (i
= 0; i
< 1024; i
++) {
94 if (port_bitmap
[i
/ 32] & (1 << (i
% 32)))
96 port_bitmap
[i
/ 32] |= 1 << (i
% 32);
101 nl_socket_set_local_port(handle
, pid
);
106 static void nl80211_handle_destroy(struct nl_handle
*handle
)
108 uint32_t port
= nl_socket_get_local_port(handle
);
111 port_bitmap
[port
/ 32] &= ~(1 << (port
% 32));
113 nl_handle_destroy(handle
);
115 #endif /* CONFIG_LIBNL20 */
118 static struct nl_handle
* nl_create_handle(struct nl_cb
*cb
, const char *dbg
)
120 struct nl_handle
*handle
;
122 handle
= nl80211_handle_alloc(cb
);
123 if (handle
== NULL
) {
124 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
125 "callbacks (%s)", dbg
);
129 if (genl_connect(handle
)) {
130 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect to generic "
131 "netlink (%s)", dbg
);
132 nl80211_handle_destroy(handle
);
140 static void nl_destroy_handles(struct nl_handle
**handle
)
144 nl80211_handle_destroy(*handle
);
150 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
153 #define IFF_DORMANT 0x20000 /* driver signals dormant */
156 #ifndef IF_OPER_DORMANT
157 #define IF_OPER_DORMANT 5
163 struct nl80211_global
{
164 struct dl_list interfaces
;
166 struct netlink_data
*netlink
;
168 struct nl_handle
*nl
;
170 int ioctl_sock
; /* socket for ioctl() use */
172 struct nl_handle
*nl_event
;
175 struct nl80211_wiphy_data
{
180 struct nl_handle
*nl_beacons
;
186 static void nl80211_global_deinit(void *priv
);
187 static void wpa_driver_nl80211_deinit(void *priv
);
190 struct wpa_driver_nl80211_data
*drv
;
191 struct i802_bss
*next
;
193 char ifname
[IFNAMSIZ
+ 1];
194 char brname
[IFNAMSIZ
];
195 unsigned int beacon_set
:1;
196 unsigned int added_if_into_bridge
:1;
197 unsigned int added_bridge
:1;
203 struct nl_handle
*nl_preq
, *nl_mgmt
;
206 struct nl80211_wiphy_data
*wiphy_data
;
207 struct dl_list wiphy_list
;
210 struct wpa_driver_nl80211_data
{
211 struct nl80211_global
*global
;
213 struct dl_list wiphy_list
;
219 int ignore_if_down_event
;
220 struct rfkill_data
*rfkill
;
221 struct wpa_driver_capa capa
;
226 int scan_complete_events
;
230 u8 auth_bssid
[ETH_ALEN
];
235 enum nl80211_iftype nlmode
;
236 enum nl80211_iftype ap_scan_as_station
;
237 unsigned int assoc_freq
;
241 int monitor_refcount
;
243 unsigned int disabled_11b_rates
:1;
244 unsigned int pending_remain_on_chan
:1;
245 unsigned int in_interface_list
:1;
246 unsigned int device_ap_sme
:1;
247 unsigned int poll_command_supported
:1;
248 unsigned int data_tx_status
:1;
249 unsigned int scan_for_auth
:1;
250 unsigned int retry_auth
:1;
251 unsigned int use_monitor
:1;
253 u64 remain_on_chan_cookie
;
254 u64 send_action_cookie
;
256 unsigned int last_mgmt_freq
;
258 struct wpa_driver_scan_filter
*filter_ssids
;
259 size_t num_filter_ssids
;
261 struct i802_bss first_bss
;
266 int eapol_sock
; /* socket for EAPOL frames */
268 int default_if_indices
[16];
276 /* From failed authentication command */
278 u8 auth_bssid_
[ETH_ALEN
];
280 size_t auth_ssid_len
;
284 u8 auth_wep_key
[4][16];
285 size_t auth_wep_key_len
[4];
286 int auth_wep_tx_keyidx
;
287 int auth_local_state_change
;
292 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
,
294 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
295 enum nl80211_iftype nlmode
);
297 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
);
298 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
299 const u8
*addr
, int cmd
, u16 reason_code
,
300 int local_state_change
);
301 static void nl80211_remove_monitor_interface(
302 struct wpa_driver_nl80211_data
*drv
);
303 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
304 unsigned int freq
, unsigned int wait
,
305 const u8
*buf
, size_t buf_len
, u64
*cookie
,
306 int no_cck
, int no_ack
, int offchanok
);
307 static int wpa_driver_nl80211_probe_req_report(void *priv
, int report
);
309 static int android_pno_start(struct i802_bss
*bss
,
310 struct wpa_driver_scan_params
*params
);
311 static int android_pno_stop(struct i802_bss
*bss
);
315 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
316 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
317 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
318 static int wpa_driver_nl80211_if_remove(void *priv
,
319 enum wpa_driver_if_type type
,
322 static inline void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
326 static inline void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
330 static inline int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
336 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
);
337 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
338 int ifindex
, int disabled
);
340 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
);
341 static int wpa_driver_nl80211_authenticate_retry(
342 struct wpa_driver_nl80211_data
*drv
);
345 static int is_ap_interface(enum nl80211_iftype nlmode
)
347 return (nlmode
== NL80211_IFTYPE_AP
||
348 nlmode
== NL80211_IFTYPE_P2P_GO
);
352 static int is_sta_interface(enum nl80211_iftype nlmode
)
354 return (nlmode
== NL80211_IFTYPE_STATION
||
355 nlmode
== NL80211_IFTYPE_P2P_CLIENT
);
359 static int is_p2p_interface(enum nl80211_iftype nlmode
)
361 return (nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
362 nlmode
== NL80211_IFTYPE_P2P_GO
);
366 struct nl80211_bss_info_arg
{
367 struct wpa_driver_nl80211_data
*drv
;
368 struct wpa_scan_results
*res
;
369 unsigned int assoc_freq
;
370 u8 assoc_bssid
[ETH_ALEN
];
373 static int bss_info_handler(struct nl_msg
*msg
, void *arg
);
377 static int ack_handler(struct nl_msg
*msg
, void *arg
)
384 static int finish_handler(struct nl_msg
*msg
, void *arg
)
391 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
400 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
406 static int send_and_recv(struct nl80211_global
*global
,
407 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
408 int (*valid_handler
)(struct nl_msg
*, void *),
414 cb
= nl_cb_clone(global
->nl_cb
);
418 err
= nl_send_auto_complete(nl_handle
, msg
);
424 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
425 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
426 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
429 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
430 valid_handler
, valid_data
);
433 nl_recvmsgs(nl_handle
, cb
);
441 static int send_and_recv_msgs_global(struct nl80211_global
*global
,
443 int (*valid_handler
)(struct nl_msg
*, void *),
446 return send_and_recv(global
, global
->nl
, msg
, valid_handler
,
451 static int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
453 int (*valid_handler
)(struct nl_msg
*, void *),
456 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
457 valid_handler
, valid_data
);
467 static int family_handler(struct nl_msg
*msg
, void *arg
)
469 struct family_data
*res
= arg
;
470 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
471 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
472 struct nlattr
*mcgrp
;
475 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
476 genlmsg_attrlen(gnlh
, 0), NULL
);
477 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
480 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
481 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
482 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
483 nla_len(mcgrp
), NULL
);
484 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
485 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
486 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
488 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
490 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
498 static int nl_get_multicast_id(struct nl80211_global
*global
,
499 const char *family
, const char *group
)
503 struct family_data res
= { group
, -ENOENT
};
508 genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
509 0, 0, CTRL_CMD_GETFAMILY
, 0);
510 NLA_PUT_STRING(msg
, CTRL_ATTR_FAMILY_NAME
, family
);
512 ret
= send_and_recv_msgs_global(global
, msg
, family_handler
, &res
);
523 static void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
524 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
526 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
531 struct wiphy_idx_data
{
536 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
538 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
539 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
540 struct wiphy_idx_data
*info
= arg
;
542 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
543 genlmsg_attrlen(gnlh
, 0), NULL
);
545 if (tb
[NL80211_ATTR_WIPHY
])
546 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
552 static int nl80211_get_wiphy_index(struct i802_bss
*bss
)
555 struct wiphy_idx_data data
= {
563 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
565 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
567 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
568 return data
.wiphy_idx
;
576 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
577 struct nl80211_wiphy_data
*w
)
586 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
);
588 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
);
590 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
593 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
594 "failed: ret=%d (%s)",
595 ret
, strerror(-ret
));
596 goto nla_put_failure
;
605 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
607 struct nl80211_wiphy_data
*w
= eloop_ctx
;
609 wpa_printf(MSG_DEBUG
, "nl80211: Beacon event message available");
611 nl_recvmsgs(handle
, w
->nl_cb
);
615 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
617 struct nl80211_wiphy_data
*w
= arg
;
618 struct wpa_driver_nl80211_data
*drv
;
619 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
620 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
621 union wpa_event_data event
;
623 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
624 genlmsg_attrlen(gnlh
, 0), NULL
);
626 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
627 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
632 if (!tb
[NL80211_ATTR_FRAME
])
635 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
637 os_memset(&event
, 0, sizeof(event
));
638 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
639 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
640 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
647 static struct nl80211_wiphy_data
*
648 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
650 static DEFINE_DL_LIST(nl80211_wiphys
);
651 struct nl80211_wiphy_data
*w
;
652 int wiphy_idx
, found
= 0;
653 struct i802_bss
*tmp_bss
;
655 if (bss
->wiphy_data
!= NULL
)
656 return bss
->wiphy_data
;
658 wiphy_idx
= nl80211_get_wiphy_index(bss
);
660 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
661 if (w
->wiphy_idx
== wiphy_idx
)
666 w
= os_zalloc(sizeof(*w
));
669 w
->wiphy_idx
= wiphy_idx
;
670 dl_list_init(&w
->bsss
);
671 dl_list_init(&w
->drvs
);
673 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
678 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
679 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
682 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
684 if (w
->nl_beacons
== NULL
) {
689 if (nl80211_register_beacons(bss
->drv
, w
)) {
690 nl_destroy_handles(&w
->nl_beacons
);
695 eloop_register_read_sock(nl_socket_get_fd(w
->nl_beacons
),
696 nl80211_recv_beacons
, w
, w
->nl_beacons
);
698 dl_list_add(&nl80211_wiphys
, &w
->list
);
701 /* drv entry for this bss already there? */
702 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
703 if (tmp_bss
->drv
== bss
->drv
) {
710 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
712 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
718 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
720 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
721 struct i802_bss
*tmp_bss
;
726 bss
->wiphy_data
= NULL
;
727 dl_list_del(&bss
->wiphy_list
);
729 /* still any for this drv present? */
730 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
731 if (tmp_bss
->drv
== bss
->drv
) {
736 /* if not remove it */
738 dl_list_del(&bss
->drv
->wiphy_list
);
740 if (!dl_list_empty(&w
->bsss
))
743 eloop_unregister_read_sock(nl_socket_get_fd(w
->nl_beacons
));
746 nl_destroy_handles(&w
->nl_beacons
);
747 dl_list_del(&w
->list
);
752 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
754 struct i802_bss
*bss
= priv
;
755 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
756 if (!drv
->associated
)
758 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
763 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
765 struct i802_bss
*bss
= priv
;
766 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
767 if (!drv
->associated
)
769 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
770 return drv
->ssid_len
;
774 static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data
*drv
,
775 char *buf
, size_t len
, int del
)
777 union wpa_event_data event
;
779 os_memset(&event
, 0, sizeof(event
));
780 if (len
> sizeof(event
.interface_status
.ifname
))
781 len
= sizeof(event
.interface_status
.ifname
) - 1;
782 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
783 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
784 EVENT_INTERFACE_ADDED
;
786 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
788 event
.interface_status
.ifname
,
789 del
? "removed" : "added");
791 if (os_strcmp(drv
->first_bss
.ifname
, event
.interface_status
.ifname
) == 0) {
798 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
802 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
805 int attrlen
, rta_len
;
809 attr
= (struct rtattr
*) buf
;
811 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
812 while (RTA_OK(attr
, attrlen
)) {
813 if (attr
->rta_type
== IFLA_IFNAME
) {
814 if (os_strcmp(((char *) attr
) + rta_len
, drv
->first_bss
.ifname
)
820 attr
= RTA_NEXT(attr
, attrlen
);
827 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
828 int ifindex
, u8
*buf
, size_t len
)
830 if (drv
->ifindex
== ifindex
)
833 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
834 drv
->first_bss
.ifindex
= if_nametoindex(drv
->first_bss
.ifname
);
835 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
837 wpa_driver_nl80211_finish_drv_init(drv
);
845 static struct wpa_driver_nl80211_data
*
846 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
848 struct wpa_driver_nl80211_data
*drv
;
849 dl_list_for_each(drv
, &global
->interfaces
,
850 struct wpa_driver_nl80211_data
, list
) {
851 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
852 have_ifidx(drv
, idx
))
859 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
860 struct ifinfomsg
*ifi
,
863 struct nl80211_global
*global
= ctx
;
864 struct wpa_driver_nl80211_data
*drv
;
865 int attrlen
, rta_len
;
868 char namebuf
[IFNAMSIZ
];
870 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
872 wpa_printf(MSG_DEBUG
, "nl80211: Ignore event for foreign "
873 "ifindex %d", ifi
->ifi_index
);
877 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
879 drv
->operstate
, ifi
->ifi_flags
,
880 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
881 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
882 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
883 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
885 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
886 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
887 linux_iface_up(drv
->global
->ioctl_sock
,
888 drv
->first_bss
.ifname
) > 0) {
889 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
890 "event since interface %s is up", namebuf
);
893 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
894 if (drv
->ignore_if_down_event
) {
895 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
896 "event generated by mode change");
897 drv
->ignore_if_down_event
= 0;
899 drv
->if_disabled
= 1;
900 wpa_supplicant_event(drv
->ctx
,
901 EVENT_INTERFACE_DISABLED
, NULL
);
905 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
906 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
907 linux_iface_up(drv
->global
->ioctl_sock
,
908 drv
->first_bss
.ifname
) == 0) {
909 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
910 "event since interface %s is down",
913 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
914 drv
->if_disabled
= 0;
915 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
921 * Some drivers send the association event before the operup event--in
922 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
923 * fails. This will hit us when wpa_supplicant does not need to do
924 * IEEE 802.1X authentication
926 if (drv
->operstate
== 1 &&
927 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
928 !(ifi
->ifi_flags
& IFF_RUNNING
))
929 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
933 attr
= (struct rtattr
*) buf
;
934 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
935 while (RTA_OK(attr
, attrlen
)) {
936 if (attr
->rta_type
== IFLA_IFNAME
) {
937 wpa_driver_nl80211_event_link(
939 ((char *) attr
) + rta_len
,
940 attr
->rta_len
- rta_len
, 0);
941 } else if (attr
->rta_type
== IFLA_MASTER
)
942 brid
= nla_get_u32((struct nlattr
*) attr
);
943 attr
= RTA_NEXT(attr
, attrlen
);
946 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
947 /* device has been added to bridge */
948 if_indextoname(brid
, namebuf
);
949 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
951 add_ifidx(drv
, brid
);
956 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
957 struct ifinfomsg
*ifi
,
960 struct nl80211_global
*global
= ctx
;
961 struct wpa_driver_nl80211_data
*drv
;
962 int attrlen
, rta_len
;
966 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
968 wpa_printf(MSG_DEBUG
, "nl80211: Ignore dellink event for "
969 "foreign ifindex %d", ifi
->ifi_index
);
974 attr
= (struct rtattr
*) buf
;
976 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
977 while (RTA_OK(attr
, attrlen
)) {
978 if (attr
->rta_type
== IFLA_IFNAME
) {
979 wpa_driver_nl80211_event_link(
981 ((char *) attr
) + rta_len
,
982 attr
->rta_len
- rta_len
, 1);
983 } else if (attr
->rta_type
== IFLA_MASTER
)
984 brid
= nla_get_u32((struct nlattr
*) attr
);
985 attr
= RTA_NEXT(attr
, attrlen
);
988 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
989 /* device has been removed from bridge */
990 char namebuf
[IFNAMSIZ
];
991 if_indextoname(brid
, namebuf
);
992 wpa_printf(MSG_DEBUG
, "nl80211: Remove ifindex %u for bridge "
993 "%s", brid
, namebuf
);
994 del_ifidx(drv
, brid
);
999 static void mlme_event_auth(struct wpa_driver_nl80211_data
*drv
,
1000 const u8
*frame
, size_t len
)
1002 const struct ieee80211_mgmt
*mgmt
;
1003 union wpa_event_data event
;
1005 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1006 if (len
< 24 + sizeof(mgmt
->u
.auth
)) {
1007 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1012 os_memcpy(drv
->auth_bssid
, mgmt
->sa
, ETH_ALEN
);
1013 os_memset(&event
, 0, sizeof(event
));
1014 os_memcpy(event
.auth
.peer
, mgmt
->sa
, ETH_ALEN
);
1015 event
.auth
.auth_type
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
1016 event
.auth
.status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
1017 if (len
> 24 + sizeof(mgmt
->u
.auth
)) {
1018 event
.auth
.ies
= mgmt
->u
.auth
.variable
;
1019 event
.auth
.ies_len
= len
- 24 - sizeof(mgmt
->u
.auth
);
1022 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH
, &event
);
1026 static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1030 struct nl80211_bss_info_arg arg
;
1032 os_memset(&arg
, 0, sizeof(arg
));
1033 msg
= nlmsg_alloc();
1035 goto nla_put_failure
;
1037 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1038 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1041 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
1044 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1045 "associated BSS from scan results: %u MHz",
1047 return arg
.assoc_freq
? arg
.assoc_freq
: drv
->assoc_freq
;
1049 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1050 "(%s)", ret
, strerror(-ret
));
1053 return drv
->assoc_freq
;
1057 static void mlme_event_assoc(struct wpa_driver_nl80211_data
*drv
,
1058 const u8
*frame
, size_t len
)
1060 const struct ieee80211_mgmt
*mgmt
;
1061 union wpa_event_data event
;
1064 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1065 if (len
< 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1066 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1071 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
1072 if (status
!= WLAN_STATUS_SUCCESS
) {
1073 os_memset(&event
, 0, sizeof(event
));
1074 event
.assoc_reject
.bssid
= mgmt
->bssid
;
1075 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1076 event
.assoc_reject
.resp_ies
=
1077 (u8
*) mgmt
->u
.assoc_resp
.variable
;
1078 event
.assoc_reject
.resp_ies_len
=
1079 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1081 event
.assoc_reject
.status_code
= status
;
1083 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1087 drv
->associated
= 1;
1088 os_memcpy(drv
->bssid
, mgmt
->sa
, ETH_ALEN
);
1090 os_memset(&event
, 0, sizeof(event
));
1091 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1092 event
.assoc_info
.resp_ies
= (u8
*) mgmt
->u
.assoc_resp
.variable
;
1093 event
.assoc_info
.resp_ies_len
=
1094 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1097 event
.assoc_info
.freq
= drv
->assoc_freq
;
1099 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1103 static void mlme_event_connect(struct wpa_driver_nl80211_data
*drv
,
1104 enum nl80211_commands cmd
, struct nlattr
*status
,
1105 struct nlattr
*addr
, struct nlattr
*req_ie
,
1106 struct nlattr
*resp_ie
)
1108 union wpa_event_data event
;
1110 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1112 * Avoid reporting two association events that would confuse
1115 wpa_printf(MSG_DEBUG
, "nl80211: Ignore connect event (cmd=%d) "
1116 "when using userspace SME", cmd
);
1120 os_memset(&event
, 0, sizeof(event
));
1121 if (cmd
== NL80211_CMD_CONNECT
&&
1122 nla_get_u16(status
) != WLAN_STATUS_SUCCESS
) {
1124 event
.assoc_reject
.bssid
= nla_data(addr
);
1126 event
.assoc_reject
.resp_ies
= nla_data(resp_ie
);
1127 event
.assoc_reject
.resp_ies_len
= nla_len(resp_ie
);
1129 event
.assoc_reject
.status_code
= nla_get_u16(status
);
1130 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1134 drv
->associated
= 1;
1136 os_memcpy(drv
->bssid
, nla_data(addr
), ETH_ALEN
);
1139 event
.assoc_info
.req_ies
= nla_data(req_ie
);
1140 event
.assoc_info
.req_ies_len
= nla_len(req_ie
);
1143 event
.assoc_info
.resp_ies
= nla_data(resp_ie
);
1144 event
.assoc_info
.resp_ies_len
= nla_len(resp_ie
);
1147 event
.assoc_info
.freq
= nl80211_get_assoc_freq(drv
);
1149 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1153 static void mlme_event_disconnect(struct wpa_driver_nl80211_data
*drv
,
1154 struct nlattr
*reason
, struct nlattr
*addr
)
1156 union wpa_event_data data
;
1158 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1160 * Avoid reporting two disassociation events that could
1161 * confuse the core code.
1163 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1164 "event when using userspace SME");
1168 drv
->associated
= 0;
1169 os_memset(&data
, 0, sizeof(data
));
1171 data
.disassoc_info
.reason_code
= nla_get_u16(reason
);
1172 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, &data
);
1176 static void mlme_timeout_event(struct wpa_driver_nl80211_data
*drv
,
1177 enum nl80211_commands cmd
, struct nlattr
*addr
)
1179 union wpa_event_data event
;
1180 enum wpa_event_type ev
;
1182 if (nla_len(addr
) != ETH_ALEN
)
1185 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d; timeout with " MACSTR
,
1186 cmd
, MAC2STR((u8
*) nla_data(addr
)));
1188 if (cmd
== NL80211_CMD_AUTHENTICATE
)
1189 ev
= EVENT_AUTH_TIMED_OUT
;
1190 else if (cmd
== NL80211_CMD_ASSOCIATE
)
1191 ev
= EVENT_ASSOC_TIMED_OUT
;
1195 os_memset(&event
, 0, sizeof(event
));
1196 os_memcpy(event
.timeout_event
.addr
, nla_data(addr
), ETH_ALEN
);
1197 wpa_supplicant_event(drv
->ctx
, ev
, &event
);
1201 static void mlme_event_mgmt(struct wpa_driver_nl80211_data
*drv
,
1202 struct nlattr
*freq
, const u8
*frame
, size_t len
)
1204 const struct ieee80211_mgmt
*mgmt
;
1205 union wpa_event_data event
;
1208 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1210 wpa_printf(MSG_DEBUG
, "nl80211: Too short action frame");
1214 fc
= le_to_host16(mgmt
->frame_control
);
1215 stype
= WLAN_FC_GET_STYPE(fc
);
1217 os_memset(&event
, 0, sizeof(event
));
1219 event
.rx_action
.freq
= nla_get_u32(freq
);
1220 drv
->last_mgmt_freq
= event
.rx_action
.freq
;
1222 if (stype
== WLAN_FC_STYPE_ACTION
) {
1223 event
.rx_action
.da
= mgmt
->da
;
1224 event
.rx_action
.sa
= mgmt
->sa
;
1225 event
.rx_action
.bssid
= mgmt
->bssid
;
1226 event
.rx_action
.category
= mgmt
->u
.action
.category
;
1227 event
.rx_action
.data
= &mgmt
->u
.action
.category
+ 1;
1228 event
.rx_action
.len
= frame
+ len
- event
.rx_action
.data
;
1229 wpa_supplicant_event(drv
->ctx
, EVENT_RX_ACTION
, &event
);
1231 event
.rx_mgmt
.frame
= frame
;
1232 event
.rx_mgmt
.frame_len
= len
;
1233 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
1238 static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data
*drv
,
1239 struct nlattr
*cookie
, const u8
*frame
,
1240 size_t len
, struct nlattr
*ack
)
1242 union wpa_event_data event
;
1243 const struct ieee80211_hdr
*hdr
;
1246 if (!is_ap_interface(drv
->nlmode
)) {
1252 cookie_val
= nla_get_u64(cookie
);
1253 wpa_printf(MSG_DEBUG
, "nl80211: Action TX status:"
1254 " cookie=0%llx%s (ack=%d)",
1255 (long long unsigned int) cookie_val
,
1256 cookie_val
== drv
->send_action_cookie
?
1257 " (match)" : " (unknown)", ack
!= NULL
);
1258 if (cookie_val
!= drv
->send_action_cookie
)
1262 hdr
= (const struct ieee80211_hdr
*) frame
;
1263 fc
= le_to_host16(hdr
->frame_control
);
1265 os_memset(&event
, 0, sizeof(event
));
1266 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
1267 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
1268 event
.tx_status
.dst
= hdr
->addr1
;
1269 event
.tx_status
.data
= frame
;
1270 event
.tx_status
.data_len
= len
;
1271 event
.tx_status
.ack
= ack
!= NULL
;
1272 wpa_supplicant_event(drv
->ctx
, EVENT_TX_STATUS
, &event
);
1276 static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data
*drv
,
1277 enum wpa_event_type type
,
1278 const u8
*frame
, size_t len
)
1280 const struct ieee80211_mgmt
*mgmt
;
1281 union wpa_event_data event
;
1282 const u8
*bssid
= NULL
;
1283 u16 reason_code
= 0;
1285 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1287 bssid
= mgmt
->bssid
;
1289 if (drv
->associated
!= 0 &&
1290 os_memcmp(bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
1291 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0) {
1293 * We have presumably received this deauth as a
1294 * response to a clear_state_mismatch() outgoing
1295 * deauth. Don't let it take us offline!
1297 wpa_printf(MSG_DEBUG
, "nl80211: Deauth received "
1298 "from Unknown BSSID " MACSTR
" -- ignoring",
1304 drv
->associated
= 0;
1305 os_memset(&event
, 0, sizeof(event
));
1307 /* Note: Same offset for Reason Code in both frame subtypes */
1308 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1309 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1311 if (type
== EVENT_DISASSOC
) {
1312 event
.disassoc_info
.addr
= bssid
;
1313 event
.disassoc_info
.reason_code
= reason_code
;
1314 if (frame
+ len
> mgmt
->u
.disassoc
.variable
) {
1315 event
.disassoc_info
.ie
= mgmt
->u
.disassoc
.variable
;
1316 event
.disassoc_info
.ie_len
= frame
+ len
-
1317 mgmt
->u
.disassoc
.variable
;
1320 event
.deauth_info
.addr
= bssid
;
1321 event
.deauth_info
.reason_code
= reason_code
;
1322 if (frame
+ len
> mgmt
->u
.deauth
.variable
) {
1323 event
.deauth_info
.ie
= mgmt
->u
.deauth
.variable
;
1324 event
.deauth_info
.ie_len
= frame
+ len
-
1325 mgmt
->u
.deauth
.variable
;
1329 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1333 static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data
*drv
,
1334 enum wpa_event_type type
,
1335 const u8
*frame
, size_t len
)
1337 const struct ieee80211_mgmt
*mgmt
;
1338 union wpa_event_data event
;
1339 u16 reason_code
= 0;
1344 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1346 os_memset(&event
, 0, sizeof(event
));
1347 /* Note: Same offset for Reason Code in both frame subtypes */
1348 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1349 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1351 if (type
== EVENT_UNPROT_DISASSOC
) {
1352 event
.unprot_disassoc
.sa
= mgmt
->sa
;
1353 event
.unprot_disassoc
.da
= mgmt
->da
;
1354 event
.unprot_disassoc
.reason_code
= reason_code
;
1356 event
.unprot_deauth
.sa
= mgmt
->sa
;
1357 event
.unprot_deauth
.da
= mgmt
->da
;
1358 event
.unprot_deauth
.reason_code
= reason_code
;
1361 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1365 static void mlme_event(struct wpa_driver_nl80211_data
*drv
,
1366 enum nl80211_commands cmd
, struct nlattr
*frame
,
1367 struct nlattr
*addr
, struct nlattr
*timed_out
,
1368 struct nlattr
*freq
, struct nlattr
*ack
,
1369 struct nlattr
*cookie
)
1371 if (timed_out
&& addr
) {
1372 mlme_timeout_event(drv
, cmd
, addr
);
1376 if (frame
== NULL
) {
1377 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d without frame "
1382 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d", cmd
);
1383 wpa_hexdump(MSG_MSGDUMP
, "nl80211: MLME event frame",
1384 nla_data(frame
), nla_len(frame
));
1387 case NL80211_CMD_AUTHENTICATE
:
1388 mlme_event_auth(drv
, nla_data(frame
), nla_len(frame
));
1390 case NL80211_CMD_ASSOCIATE
:
1391 mlme_event_assoc(drv
, nla_data(frame
), nla_len(frame
));
1393 case NL80211_CMD_DEAUTHENTICATE
:
1394 mlme_event_deauth_disassoc(drv
, EVENT_DEAUTH
,
1395 nla_data(frame
), nla_len(frame
));
1397 case NL80211_CMD_DISASSOCIATE
:
1398 mlme_event_deauth_disassoc(drv
, EVENT_DISASSOC
,
1399 nla_data(frame
), nla_len(frame
));
1401 case NL80211_CMD_FRAME
:
1402 mlme_event_mgmt(drv
, freq
, nla_data(frame
), nla_len(frame
));
1404 case NL80211_CMD_FRAME_TX_STATUS
:
1405 mlme_event_mgmt_tx_status(drv
, cookie
, nla_data(frame
),
1406 nla_len(frame
), ack
);
1408 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1409 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DEAUTH
,
1410 nla_data(frame
), nla_len(frame
));
1412 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1413 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DISASSOC
,
1414 nla_data(frame
), nla_len(frame
));
1422 static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data
*drv
,
1423 struct nlattr
*tb
[])
1425 union wpa_event_data data
;
1427 wpa_printf(MSG_DEBUG
, "nl80211: MLME event Michael MIC failure");
1428 os_memset(&data
, 0, sizeof(data
));
1429 if (tb
[NL80211_ATTR_MAC
]) {
1430 wpa_hexdump(MSG_DEBUG
, "nl80211: Source MAC address",
1431 nla_data(tb
[NL80211_ATTR_MAC
]),
1432 nla_len(tb
[NL80211_ATTR_MAC
]));
1433 data
.michael_mic_failure
.src
= nla_data(tb
[NL80211_ATTR_MAC
]);
1435 if (tb
[NL80211_ATTR_KEY_SEQ
]) {
1436 wpa_hexdump(MSG_DEBUG
, "nl80211: TSC",
1437 nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
1438 nla_len(tb
[NL80211_ATTR_KEY_SEQ
]));
1440 if (tb
[NL80211_ATTR_KEY_TYPE
]) {
1441 enum nl80211_key_type key_type
=
1442 nla_get_u32(tb
[NL80211_ATTR_KEY_TYPE
]);
1443 wpa_printf(MSG_DEBUG
, "nl80211: Key Type %d", key_type
);
1444 if (key_type
== NL80211_KEYTYPE_PAIRWISE
)
1445 data
.michael_mic_failure
.unicast
= 1;
1447 data
.michael_mic_failure
.unicast
= 1;
1449 if (tb
[NL80211_ATTR_KEY_IDX
]) {
1450 u8 key_id
= nla_get_u8(tb
[NL80211_ATTR_KEY_IDX
]);
1451 wpa_printf(MSG_DEBUG
, "nl80211: Key Id %d", key_id
);
1454 wpa_supplicant_event(drv
->ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
1458 static void mlme_event_join_ibss(struct wpa_driver_nl80211_data
*drv
,
1459 struct nlattr
*tb
[])
1461 if (tb
[NL80211_ATTR_MAC
] == NULL
) {
1462 wpa_printf(MSG_DEBUG
, "nl80211: No address in IBSS joined "
1466 os_memcpy(drv
->bssid
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1467 drv
->associated
= 1;
1468 wpa_printf(MSG_DEBUG
, "nl80211: IBSS " MACSTR
" joined",
1469 MAC2STR(drv
->bssid
));
1471 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1475 static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data
*drv
,
1476 int cancel_event
, struct nlattr
*tb
[])
1478 unsigned int freq
, chan_type
, duration
;
1479 union wpa_event_data data
;
1482 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1483 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1487 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1488 chan_type
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1492 if (tb
[NL80211_ATTR_DURATION
])
1493 duration
= nla_get_u32(tb
[NL80211_ATTR_DURATION
]);
1497 if (tb
[NL80211_ATTR_COOKIE
])
1498 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
1502 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel event (cancel=%d "
1503 "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
1504 cancel_event
, freq
, chan_type
, duration
,
1505 (long long unsigned int) cookie
,
1506 cookie
== drv
->remain_on_chan_cookie
? "match" : "unknown");
1508 if (cookie
!= drv
->remain_on_chan_cookie
)
1509 return; /* not for us */
1512 drv
->pending_remain_on_chan
= 0;
1514 os_memset(&data
, 0, sizeof(data
));
1515 data
.remain_on_channel
.freq
= freq
;
1516 data
.remain_on_channel
.duration
= duration
;
1517 wpa_supplicant_event(drv
->ctx
, cancel_event
?
1518 EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1519 EVENT_REMAIN_ON_CHANNEL
, &data
);
1523 static void send_scan_event(struct wpa_driver_nl80211_data
*drv
, int aborted
,
1524 struct nlattr
*tb
[])
1526 union wpa_event_data event
;
1529 struct scan_info
*info
;
1530 #define MAX_REPORT_FREQS 50
1531 int freqs
[MAX_REPORT_FREQS
];
1534 if (drv
->scan_for_auth
) {
1535 drv
->scan_for_auth
= 0;
1536 wpa_printf(MSG_DEBUG
, "nl80211: Scan results for missing "
1537 "cfg80211 BSS entry");
1538 wpa_driver_nl80211_authenticate_retry(drv
);
1542 os_memset(&event
, 0, sizeof(event
));
1543 info
= &event
.scan_info
;
1544 info
->aborted
= aborted
;
1546 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
1547 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem
) {
1548 struct wpa_driver_scan_ssid
*s
=
1549 &info
->ssids
[info
->num_ssids
];
1550 s
->ssid
= nla_data(nl
);
1551 s
->ssid_len
= nla_len(nl
);
1553 if (info
->num_ssids
== WPAS_MAX_SCAN_SSIDS
)
1557 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
1558 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem
)
1560 freqs
[num_freqs
] = nla_get_u32(nl
);
1562 if (num_freqs
== MAX_REPORT_FREQS
- 1)
1565 info
->freqs
= freqs
;
1566 info
->num_freqs
= num_freqs
;
1568 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
, &event
);
1572 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1574 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1575 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1576 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1577 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1578 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1580 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1581 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1582 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1583 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1584 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1585 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1587 struct wpa_signal_info
*sig_change
= arg
;
1589 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1590 genlmsg_attrlen(gnlh
, 0), NULL
);
1591 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1592 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1593 tb
[NL80211_ATTR_STA_INFO
], policy
))
1595 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1598 sig_change
->current_signal
=
1599 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1601 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1602 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1603 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1605 sig_change
->current_txrate
= 0;
1607 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1608 sig_change
->current_txrate
=
1610 NL80211_RATE_INFO_BITRATE
]) * 100;
1619 static int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1620 struct wpa_signal_info
*sig
)
1624 sig
->current_signal
= -9999;
1625 sig
->current_txrate
= 0;
1627 msg
= nlmsg_alloc();
1631 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
1633 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1634 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
1636 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1643 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1645 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1646 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1647 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1648 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1649 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1650 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1652 struct wpa_signal_info
*sig_change
= arg
;
1654 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1655 genlmsg_attrlen(gnlh
, 0), NULL
);
1657 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1658 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1662 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1663 tb
[NL80211_ATTR_SURVEY_INFO
],
1665 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1670 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1673 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1674 sig_change
->frequency
)
1677 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1680 sig_change
->current_noise
=
1681 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1687 static int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1688 struct wpa_signal_info
*sig_change
)
1692 sig_change
->current_noise
= 9999;
1693 sig_change
->frequency
= drv
->assoc_freq
;
1695 msg
= nlmsg_alloc();
1699 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1701 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1703 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1710 static int get_noise_for_scan_results(struct nl_msg
*msg
, void *arg
)
1712 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1713 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1714 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1715 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1716 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1717 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1719 struct wpa_scan_results
*scan_results
= arg
;
1720 struct wpa_scan_res
*scan_res
;
1723 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1724 genlmsg_attrlen(gnlh
, 0), NULL
);
1726 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1727 wpa_printf(MSG_DEBUG
, "nl80211: Survey data missing");
1731 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1732 tb
[NL80211_ATTR_SURVEY_INFO
],
1734 wpa_printf(MSG_DEBUG
, "nl80211: Failed to parse nested "
1739 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1742 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1745 for (i
= 0; i
< scan_results
->num
; ++i
) {
1746 scan_res
= scan_results
->res
[i
];
1749 if ((int) nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1752 if (!(scan_res
->flags
& WPA_SCAN_NOISE_INVALID
))
1754 scan_res
->noise
= (s8
)
1755 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1756 scan_res
->flags
&= ~WPA_SCAN_NOISE_INVALID
;
1763 static int nl80211_get_noise_for_scan_results(
1764 struct wpa_driver_nl80211_data
*drv
,
1765 struct wpa_scan_results
*scan_res
)
1769 msg
= nlmsg_alloc();
1773 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1775 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1777 return send_and_recv_msgs(drv
, msg
, get_noise_for_scan_results
,
1785 static void nl80211_cqm_event(struct wpa_driver_nl80211_data
*drv
,
1786 struct nlattr
*tb
[])
1788 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
1789 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
1790 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U8
},
1791 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
1792 [NL80211_ATTR_CQM_PKT_LOSS_EVENT
] = { .type
= NLA_U32
},
1794 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
1795 enum nl80211_cqm_rssi_threshold_event event
;
1796 union wpa_event_data ed
;
1797 struct wpa_signal_info sig
;
1800 if (tb
[NL80211_ATTR_CQM
] == NULL
||
1801 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, tb
[NL80211_ATTR_CQM
],
1803 wpa_printf(MSG_DEBUG
, "nl80211: Ignore invalid CQM event");
1807 os_memset(&ed
, 0, sizeof(ed
));
1809 if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
1810 if (!tb
[NL80211_ATTR_MAC
])
1812 os_memcpy(ed
.low_ack
.addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
1814 wpa_supplicant_event(drv
->ctx
, EVENT_STATION_LOW_ACK
, &ed
);
1818 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] == NULL
)
1820 event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
1822 if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
) {
1823 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1824 "event: RSSI high");
1825 ed
.signal_change
.above_threshold
= 1;
1826 } else if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
) {
1827 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1829 ed
.signal_change
.above_threshold
= 0;
1833 res
= nl80211_get_link_signal(drv
, &sig
);
1835 ed
.signal_change
.current_signal
= sig
.current_signal
;
1836 ed
.signal_change
.current_txrate
= sig
.current_txrate
;
1837 wpa_printf(MSG_DEBUG
, "nl80211: Signal: %d dBm txrate: %d",
1838 sig
.current_signal
, sig
.current_txrate
);
1841 res
= nl80211_get_link_noise(drv
, &sig
);
1843 ed
.signal_change
.current_noise
= sig
.current_noise
;
1844 wpa_printf(MSG_DEBUG
, "nl80211: Noise: %d dBm",
1848 wpa_supplicant_event(drv
->ctx
, EVENT_SIGNAL_CHANGE
, &ed
);
1852 static void nl80211_new_station_event(struct wpa_driver_nl80211_data
*drv
,
1856 union wpa_event_data data
;
1858 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1860 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1861 wpa_printf(MSG_DEBUG
, "nl80211: New station " MACSTR
, MAC2STR(addr
));
1863 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
1866 if (tb
[NL80211_ATTR_IE
]) {
1867 ies
= nla_data(tb
[NL80211_ATTR_IE
]);
1868 ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
1870 wpa_hexdump(MSG_DEBUG
, "nl80211: Assoc Req IEs", ies
, ies_len
);
1871 drv_event_assoc(drv
->ctx
, addr
, ies
, ies_len
, 0);
1875 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1878 os_memset(&data
, 0, sizeof(data
));
1879 os_memcpy(data
.ibss_rsn_start
.peer
, addr
, ETH_ALEN
);
1880 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_RSN_START
, &data
);
1884 static void nl80211_del_station_event(struct wpa_driver_nl80211_data
*drv
,
1888 union wpa_event_data data
;
1890 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1892 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1893 wpa_printf(MSG_DEBUG
, "nl80211: Delete station " MACSTR
,
1896 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
1897 drv_event_disassoc(drv
->ctx
, addr
);
1901 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1904 os_memset(&data
, 0, sizeof(data
));
1905 os_memcpy(data
.ibss_peer_lost
.peer
, addr
, ETH_ALEN
);
1906 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_PEER_LOST
, &data
);
1910 static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data
*drv
,
1913 struct nlattr
*rekey_info
[NUM_NL80211_REKEY_DATA
];
1914 static struct nla_policy rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
1915 [NL80211_REKEY_DATA_KEK
] = {
1916 .minlen
= NL80211_KEK_LEN
,
1917 .maxlen
= NL80211_KEK_LEN
,
1919 [NL80211_REKEY_DATA_KCK
] = {
1920 .minlen
= NL80211_KCK_LEN
,
1921 .maxlen
= NL80211_KCK_LEN
,
1923 [NL80211_REKEY_DATA_REPLAY_CTR
] = {
1924 .minlen
= NL80211_REPLAY_CTR_LEN
,
1925 .maxlen
= NL80211_REPLAY_CTR_LEN
,
1928 union wpa_event_data data
;
1930 if (!tb
[NL80211_ATTR_MAC
])
1932 if (!tb
[NL80211_ATTR_REKEY_DATA
])
1934 if (nla_parse_nested(rekey_info
, MAX_NL80211_REKEY_DATA
,
1935 tb
[NL80211_ATTR_REKEY_DATA
], rekey_policy
))
1937 if (!rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
])
1940 os_memset(&data
, 0, sizeof(data
));
1941 data
.driver_gtk_rekey
.bssid
= nla_data(tb
[NL80211_ATTR_MAC
]);
1942 wpa_printf(MSG_DEBUG
, "nl80211: Rekey offload event for BSSID " MACSTR
,
1943 MAC2STR(data
.driver_gtk_rekey
.bssid
));
1944 data
.driver_gtk_rekey
.replay_ctr
=
1945 nla_data(rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
]);
1946 wpa_hexdump(MSG_DEBUG
, "nl80211: Rekey offload - Replay Counter",
1947 data
.driver_gtk_rekey
.replay_ctr
, NL80211_REPLAY_CTR_LEN
);
1948 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_GTK_REKEY
, &data
);
1952 static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data
*drv
,
1955 struct nlattr
*cand
[NUM_NL80211_PMKSA_CANDIDATE
];
1956 static struct nla_policy cand_policy
[NUM_NL80211_PMKSA_CANDIDATE
] = {
1957 [NL80211_PMKSA_CANDIDATE_INDEX
] = { .type
= NLA_U32
},
1958 [NL80211_PMKSA_CANDIDATE_BSSID
] = {
1962 [NL80211_PMKSA_CANDIDATE_PREAUTH
] = { .type
= NLA_FLAG
},
1964 union wpa_event_data data
;
1966 if (!tb
[NL80211_ATTR_PMKSA_CANDIDATE
])
1968 if (nla_parse_nested(cand
, MAX_NL80211_PMKSA_CANDIDATE
,
1969 tb
[NL80211_ATTR_PMKSA_CANDIDATE
], cand_policy
))
1971 if (!cand
[NL80211_PMKSA_CANDIDATE_INDEX
] ||
1972 !cand
[NL80211_PMKSA_CANDIDATE_BSSID
])
1975 os_memset(&data
, 0, sizeof(data
));
1976 os_memcpy(data
.pmkid_candidate
.bssid
,
1977 nla_data(cand
[NL80211_PMKSA_CANDIDATE_BSSID
]), ETH_ALEN
);
1978 data
.pmkid_candidate
.index
=
1979 nla_get_u32(cand
[NL80211_PMKSA_CANDIDATE_INDEX
]);
1980 data
.pmkid_candidate
.preauth
=
1981 cand
[NL80211_PMKSA_CANDIDATE_PREAUTH
] != NULL
;
1982 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
1986 static void nl80211_client_probe_event(struct wpa_driver_nl80211_data
*drv
,
1989 union wpa_event_data data
;
1991 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_ACK
])
1994 os_memset(&data
, 0, sizeof(data
));
1995 os_memcpy(data
.client_poll
.addr
,
1996 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1998 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_CLIENT_POLL_OK
, &data
);
2002 static void nl80211_spurious_frame(struct i802_bss
*bss
, struct nlattr
**tb
,
2005 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2006 union wpa_event_data event
;
2008 if (!tb
[NL80211_ATTR_MAC
])
2011 os_memset(&event
, 0, sizeof(event
));
2012 event
.rx_from_unknown
.bssid
= bss
->addr
;
2013 event
.rx_from_unknown
.addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2014 event
.rx_from_unknown
.wds
= wds
;
2016 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
2020 static void do_process_drv_event(struct wpa_driver_nl80211_data
*drv
,
2021 int cmd
, struct nlattr
**tb
)
2023 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
&&
2024 (cmd
== NL80211_CMD_NEW_SCAN_RESULTS
||
2025 cmd
== NL80211_CMD_SCAN_ABORTED
)) {
2026 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
2027 drv
->ap_scan_as_station
);
2028 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2032 case NL80211_CMD_TRIGGER_SCAN
:
2033 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger");
2035 case NL80211_CMD_START_SCHED_SCAN
:
2036 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan started");
2038 case NL80211_CMD_SCHED_SCAN_STOPPED
:
2039 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stopped");
2040 wpa_supplicant_event(drv
->ctx
, EVENT_SCHED_SCAN_STOPPED
, NULL
);
2042 case NL80211_CMD_NEW_SCAN_RESULTS
:
2043 wpa_printf(MSG_DEBUG
, "nl80211: New scan results available");
2044 drv
->scan_complete_events
= 1;
2045 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2047 send_scan_event(drv
, 0, tb
);
2049 case NL80211_CMD_SCHED_SCAN_RESULTS
:
2050 wpa_printf(MSG_DEBUG
,
2051 "nl80211: New sched scan results available");
2052 send_scan_event(drv
, 0, tb
);
2054 case NL80211_CMD_SCAN_ABORTED
:
2055 wpa_printf(MSG_DEBUG
, "nl80211: Scan aborted");
2057 * Need to indicate that scan results are available in order
2058 * not to make wpa_supplicant stop its scanning.
2060 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2062 send_scan_event(drv
, 1, tb
);
2064 case NL80211_CMD_AUTHENTICATE
:
2065 case NL80211_CMD_ASSOCIATE
:
2066 case NL80211_CMD_DEAUTHENTICATE
:
2067 case NL80211_CMD_DISASSOCIATE
:
2068 case NL80211_CMD_FRAME_TX_STATUS
:
2069 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
2070 case NL80211_CMD_UNPROT_DISASSOCIATE
:
2071 mlme_event(drv
, cmd
, tb
[NL80211_ATTR_FRAME
],
2072 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2073 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2074 tb
[NL80211_ATTR_COOKIE
]);
2076 case NL80211_CMD_CONNECT
:
2077 case NL80211_CMD_ROAM
:
2078 mlme_event_connect(drv
, cmd
,
2079 tb
[NL80211_ATTR_STATUS_CODE
],
2080 tb
[NL80211_ATTR_MAC
],
2081 tb
[NL80211_ATTR_REQ_IE
],
2082 tb
[NL80211_ATTR_RESP_IE
]);
2084 case NL80211_CMD_DISCONNECT
:
2085 mlme_event_disconnect(drv
, tb
[NL80211_ATTR_REASON_CODE
],
2086 tb
[NL80211_ATTR_MAC
]);
2088 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
2089 mlme_event_michael_mic_failure(drv
, tb
);
2091 case NL80211_CMD_JOIN_IBSS
:
2092 mlme_event_join_ibss(drv
, tb
);
2094 case NL80211_CMD_REMAIN_ON_CHANNEL
:
2095 mlme_event_remain_on_channel(drv
, 0, tb
);
2097 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
2098 mlme_event_remain_on_channel(drv
, 1, tb
);
2100 case NL80211_CMD_NOTIFY_CQM
:
2101 nl80211_cqm_event(drv
, tb
);
2103 case NL80211_CMD_REG_CHANGE
:
2104 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory domain change");
2105 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2108 case NL80211_CMD_REG_BEACON_HINT
:
2109 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory beacon hint");
2110 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2113 case NL80211_CMD_NEW_STATION
:
2114 nl80211_new_station_event(drv
, tb
);
2116 case NL80211_CMD_DEL_STATION
:
2117 nl80211_del_station_event(drv
, tb
);
2119 case NL80211_CMD_SET_REKEY_OFFLOAD
:
2120 nl80211_rekey_offload_event(drv
, tb
);
2122 case NL80211_CMD_PMKSA_CANDIDATE
:
2123 nl80211_pmksa_candidate_event(drv
, tb
);
2125 case NL80211_CMD_PROBE_CLIENT
:
2126 nl80211_client_probe_event(drv
, tb
);
2129 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2136 static int process_drv_event(struct nl_msg
*msg
, void *arg
)
2138 struct wpa_driver_nl80211_data
*drv
= arg
;
2139 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2140 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2142 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2143 genlmsg_attrlen(gnlh
, 0), NULL
);
2145 if (tb
[NL80211_ATTR_IFINDEX
]) {
2146 int ifindex
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2147 if (ifindex
!= drv
->ifindex
&& !have_ifidx(drv
, ifindex
)) {
2148 wpa_printf(MSG_DEBUG
, "nl80211: Ignored event (cmd=%d)"
2149 " for foreign interface (ifindex %d)",
2150 gnlh
->cmd
, ifindex
);
2155 do_process_drv_event(drv
, gnlh
->cmd
, tb
);
2160 static int process_global_event(struct nl_msg
*msg
, void *arg
)
2162 struct nl80211_global
*global
= arg
;
2163 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2164 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2165 struct wpa_driver_nl80211_data
*drv
;
2168 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2169 genlmsg_attrlen(gnlh
, 0), NULL
);
2171 if (tb
[NL80211_ATTR_IFINDEX
])
2172 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2174 dl_list_for_each(drv
, &global
->interfaces
,
2175 struct wpa_driver_nl80211_data
, list
) {
2176 if (ifidx
== -1 || ifidx
== drv
->ifindex
||
2177 have_ifidx(drv
, ifidx
))
2178 do_process_drv_event(drv
, gnlh
->cmd
, tb
);
2185 static int process_bss_event(struct nl_msg
*msg
, void *arg
)
2187 struct i802_bss
*bss
= arg
;
2188 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2189 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2191 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2192 genlmsg_attrlen(gnlh
, 0), NULL
);
2194 switch (gnlh
->cmd
) {
2195 case NL80211_CMD_FRAME
:
2196 case NL80211_CMD_FRAME_TX_STATUS
:
2197 mlme_event(bss
->drv
, gnlh
->cmd
, tb
[NL80211_ATTR_FRAME
],
2198 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2199 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2200 tb
[NL80211_ATTR_COOKIE
]);
2202 case NL80211_CMD_UNEXPECTED_FRAME
:
2203 nl80211_spurious_frame(bss
, tb
, 0);
2205 case NL80211_CMD_UNEXPECTED_4ADDR_FRAME
:
2206 nl80211_spurious_frame(bss
, tb
, 1);
2209 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2210 "(cmd=%d)", gnlh
->cmd
);
2218 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
2221 struct nl_cb
*cb
= eloop_ctx
;
2223 wpa_printf(MSG_DEBUG
, "nl80211: Event message available");
2225 nl_recvmsgs(handle
, cb
);
2230 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
2231 * @priv: driver_nl80211 private data
2232 * @alpha2_arg: country to which to switch to
2233 * Returns: 0 on success, -1 on failure
2235 * This asks nl80211 to set the regulatory domain for given
2236 * country ISO / IEC alpha2.
2238 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
2240 struct i802_bss
*bss
= priv
;
2241 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2245 msg
= nlmsg_alloc();
2249 alpha2
[0] = alpha2_arg
[0];
2250 alpha2
[1] = alpha2_arg
[1];
2253 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
);
2255 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
);
2256 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
2265 struct wiphy_info_data
{
2266 struct wpa_driver_capa
*capa
;
2268 unsigned int error
:1;
2269 unsigned int device_ap_sme
:1;
2270 unsigned int poll_command_supported
:1;
2271 unsigned int data_tx_status
:1;
2272 unsigned int monitor_supported
:1;
2276 static unsigned int probe_resp_offload_support(int supp_protocols
)
2278 unsigned int prot
= 0;
2280 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
)
2281 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
;
2282 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
)
2283 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
;
2284 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
)
2285 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
;
2286 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
)
2287 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
;
2293 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
2295 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2296 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2297 struct wiphy_info_data
*info
= arg
;
2298 int p2p_go_supported
= 0, p2p_client_supported
= 0;
2299 int p2p_concurrent
= 0;
2300 int auth_supported
= 0, connect_supported
= 0;
2301 struct wpa_driver_capa
*capa
= info
->capa
;
2302 static struct nla_policy
2303 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
2304 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
2305 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
2306 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
2307 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
2309 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
2310 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
2311 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
2314 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2315 genlmsg_attrlen(gnlh
, 0), NULL
);
2317 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
2318 capa
->max_scan_ssids
=
2319 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
2321 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
2322 capa
->max_sched_scan_ssids
=
2323 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
2325 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
2326 capa
->max_match_sets
=
2327 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
2329 if (tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]) {
2330 struct nlattr
*nl_mode
;
2332 nla_for_each_nested(nl_mode
,
2333 tb
[NL80211_ATTR_SUPPORTED_IFTYPES
], i
) {
2334 switch (nla_type(nl_mode
)) {
2335 case NL80211_IFTYPE_AP
:
2336 capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
2338 case NL80211_IFTYPE_P2P_GO
:
2339 p2p_go_supported
= 1;
2341 case NL80211_IFTYPE_P2P_CLIENT
:
2342 p2p_client_supported
= 1;
2344 case NL80211_IFTYPE_MONITOR
:
2345 info
->monitor_supported
= 1;
2351 if (tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]) {
2352 struct nlattr
*nl_combi
;
2355 nla_for_each_nested(nl_combi
,
2356 tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
],
2358 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
2359 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
2360 struct nlattr
*nl_limit
, *nl_mode
;
2361 int err
, rem_limit
, rem_mode
;
2362 int combination_has_p2p
= 0, combination_has_mgd
= 0;
2364 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
2366 iface_combination_policy
);
2367 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
2368 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
2369 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
2370 goto broken_combination
;
2372 nla_for_each_nested(nl_limit
,
2373 tb_comb
[NL80211_IFACE_COMB_LIMITS
],
2375 err
= nla_parse_nested(tb_limit
,
2376 MAX_NL80211_IFACE_LIMIT
,
2378 iface_limit_policy
);
2380 !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
2381 goto broken_combination
;
2383 nla_for_each_nested(
2385 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
2387 int ift
= nla_type(nl_mode
);
2388 if (ift
== NL80211_IFTYPE_P2P_GO
||
2389 ift
== NL80211_IFTYPE_P2P_CLIENT
)
2390 combination_has_p2p
= 1;
2391 if (ift
== NL80211_IFTYPE_STATION
)
2392 combination_has_mgd
= 1;
2394 if (combination_has_p2p
&& combination_has_mgd
)
2398 if (combination_has_p2p
&& combination_has_mgd
) {
2408 if (tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]) {
2409 struct nlattr
*nl_cmd
;
2412 nla_for_each_nested(nl_cmd
,
2413 tb
[NL80211_ATTR_SUPPORTED_COMMANDS
], i
) {
2414 switch (nla_get_u32(nl_cmd
)) {
2415 case NL80211_CMD_AUTHENTICATE
:
2418 case NL80211_CMD_CONNECT
:
2419 connect_supported
= 1;
2421 case NL80211_CMD_START_SCHED_SCAN
:
2422 capa
->sched_scan_supported
= 1;
2424 case NL80211_CMD_PROBE_CLIENT
:
2425 info
->poll_command_supported
= 1;
2431 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
2432 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
2434 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
2437 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
2438 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
2439 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
2442 /* default to 5000 since early versions of mac80211 don't set it */
2443 capa
->max_remain_on_chan
= 5000;
2445 if (tb
[NL80211_ATTR_SUPPORT_AP_UAPSD
])
2446 capa
->flags
|= WPA_DRIVER_FLAGS_AP_UAPSD
;
2448 if (tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
])
2449 capa
->max_remain_on_chan
=
2450 nla_get_u32(tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
2453 capa
->flags
|= WPA_DRIVER_FLAGS_SME
;
2454 else if (!connect_supported
) {
2455 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
2456 "authentication/association or connect commands");
2460 if (p2p_go_supported
&& p2p_client_supported
)
2461 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
2462 if (p2p_concurrent
) {
2463 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
2464 "interface (driver advertised support)");
2465 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
2466 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
2469 if (tb
[NL80211_ATTR_TDLS_SUPPORT
]) {
2470 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
2471 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
2473 if (tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]) {
2474 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
2476 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
2480 if (tb
[NL80211_ATTR_DEVICE_AP_SME
])
2481 info
->device_ap_sme
= 1;
2483 if (tb
[NL80211_ATTR_FEATURE_FLAGS
]) {
2484 u32 flags
= nla_get_u32(tb
[NL80211_ATTR_FEATURE_FLAGS
]);
2486 if (flags
& NL80211_FEATURE_SK_TX_STATUS
)
2487 info
->data_tx_status
= 1;
2490 if (tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]) {
2492 nla_get_u32(tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]);
2493 wpa_printf(MSG_DEBUG
, "nl80211: Supports Probe Response "
2494 "offload in AP mode");
2495 capa
->flags
|= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
;
2496 capa
->probe_resp_offloads
=
2497 probe_resp_offload_support(protocols
);
2504 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
2505 struct wiphy_info_data
*info
)
2509 os_memset(info
, 0, sizeof(*info
));
2510 info
->capa
= &drv
->capa
;
2512 msg
= nlmsg_alloc();
2516 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
2518 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->first_bss
.ifindex
);
2520 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
) == 0)
2529 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
2531 struct wiphy_info_data info
;
2532 if (wpa_driver_nl80211_get_info(drv
, &info
))
2538 drv
->has_capability
= 1;
2539 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
2540 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2541 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2542 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2543 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
2544 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
2545 WPA_DRIVER_CAPA_ENC_WEP104
|
2546 WPA_DRIVER_CAPA_ENC_TKIP
|
2547 WPA_DRIVER_CAPA_ENC_CCMP
;
2548 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
2549 WPA_DRIVER_AUTH_SHARED
|
2550 WPA_DRIVER_AUTH_LEAP
;
2552 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
2553 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
2554 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2555 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
2557 drv
->device_ap_sme
= info
.device_ap_sme
;
2558 drv
->poll_command_supported
= info
.poll_command_supported
;
2559 drv
->data_tx_status
= info
.data_tx_status
;
2562 * If poll command is supported mac80211 is new enough to
2563 * have everything we need to not need monitor interfaces.
2565 drv
->use_monitor
= !info
.poll_command_supported
;
2567 if (drv
->device_ap_sme
&& drv
->use_monitor
) {
2569 * Non-mac80211 drivers may not support monitor interface.
2570 * Make sure we do not get stuck with incorrect capability here
2571 * by explicitly testing this.
2573 if (!info
.monitor_supported
) {
2574 wpa_printf(MSG_DEBUG
, "nl80211: Disable use_monitor "
2575 "with device_ap_sme since no monitor mode "
2576 "support detected");
2577 drv
->use_monitor
= 0;
2582 * If we aren't going to use monitor interfaces, but the
2583 * driver doesn't support data TX status, we won't get TX
2584 * status for EAPOL frames.
2586 if (!drv
->use_monitor
&& !info
.data_tx_status
)
2587 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2594 static int android_genl_ctrl_resolve(struct nl_handle
*handle
,
2598 * Android ICS has very minimal genl_ctrl_resolve() implementation, so
2599 * need to work around that.
2601 struct nl_cache
*cache
= NULL
;
2602 struct genl_family
*nl80211
= NULL
;
2605 if (genl_ctrl_alloc_cache(handle
, &cache
) < 0) {
2606 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate generic "
2611 nl80211
= genl_ctrl_search_by_name(cache
, name
);
2612 if (nl80211
== NULL
)
2615 id
= genl_family_get_id(nl80211
);
2619 genl_family_put(nl80211
);
2621 nl_cache_free(cache
);
2625 #define genl_ctrl_resolve android_genl_ctrl_resolve
2626 #endif /* ANDROID */
2629 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
2633 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2634 if (global
->nl_cb
== NULL
) {
2635 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
2640 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
2641 if (global
->nl
== NULL
)
2644 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
2645 if (global
->nl80211_id
< 0) {
2646 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
2651 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
2652 if (global
->nl_event
== NULL
)
2655 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
2657 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2659 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2660 "membership for scan events: %d (%s)",
2661 ret
, strerror(-ret
));
2665 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
2667 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2669 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2670 "membership for mlme events: %d (%s)",
2671 ret
, strerror(-ret
));
2675 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
2677 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2679 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
2680 "membership for regulatory events: %d (%s)",
2681 ret
, strerror(-ret
));
2682 /* Continue without regulatory events */
2685 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2686 no_seq_check
, NULL
);
2687 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2688 process_global_event
, global
);
2690 eloop_register_read_sock(nl_socket_get_fd(global
->nl_event
),
2691 wpa_driver_nl80211_event_receive
,
2692 global
->nl_cb
, global
->nl_event
);
2697 nl_destroy_handles(&global
->nl_event
);
2698 nl_destroy_handles(&global
->nl
);
2699 nl_cb_put(global
->nl_cb
);
2700 global
->nl_cb
= NULL
;
2705 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
2707 drv
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2709 wpa_printf(MSG_ERROR
, "nl80211: Failed to alloc cb struct");
2713 nl_cb_set(drv
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2714 no_seq_check
, NULL
);
2715 nl_cb_set(drv
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2716 process_drv_event
, drv
);
2722 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
2724 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
2726 * This may be for any interface; use ifdown event to disable
2732 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
2734 struct wpa_driver_nl80211_data
*drv
= ctx
;
2735 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
2736 if (linux_set_iface_flags(drv
->global
->ioctl_sock
,
2737 drv
->first_bss
.ifname
, 1)) {
2738 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
2739 "after rfkill unblock");
2742 /* rtnetlink ifup handler will report interface as enabled */
2746 static void nl80211_get_phy_name(struct wpa_driver_nl80211_data
*drv
)
2748 /* Find phy (radio) to which this interface belongs */
2752 drv
->phyname
[0] = '\0';
2753 snprintf(buf
, sizeof(buf
) - 1, "/sys/class/net/%s/phy80211/name",
2754 drv
->first_bss
.ifname
);
2755 f
= open(buf
, O_RDONLY
);
2757 wpa_printf(MSG_DEBUG
, "Could not open file %s: %s",
2758 buf
, strerror(errno
));
2762 rv
= read(f
, drv
->phyname
, sizeof(drv
->phyname
) - 1);
2765 wpa_printf(MSG_DEBUG
, "Could not read file %s: %s",
2766 buf
, strerror(errno
));
2770 drv
->phyname
[rv
] = '\0';
2771 pos
= os_strchr(drv
->phyname
, '\n');
2774 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2775 drv
->first_bss
.ifname
, drv
->phyname
);
2779 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
2783 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
2791 struct cmsghdr
*cmsg
;
2792 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
2793 union wpa_event_data event
;
2795 memset(&msg
, 0, sizeof(msg
));
2796 msg
.msg_iov
= &entry
;
2798 entry
.iov_base
= data
;
2799 entry
.iov_len
= sizeof(data
);
2800 msg
.msg_control
= &control
;
2801 msg
.msg_controllen
= sizeof(control
);
2803 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
2804 /* if error or not fitting 802.3 header, return */
2808 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
2810 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
2811 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
2815 ack
= (void *)CMSG_DATA(cmsg
);
2819 if (cmsg
->cmsg_level
== SOL_PACKET
&&
2820 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
2821 struct sock_extended_err
*err
=
2822 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
2824 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
2829 if (!found_ee
|| !found_wifi
)
2832 memset(&event
, 0, sizeof(event
));
2833 event
.eapol_tx_status
.dst
= data
;
2834 event
.eapol_tx_status
.data
= data
+ 14;
2835 event
.eapol_tx_status
.data_len
= res
- 14;
2836 event
.eapol_tx_status
.ack
= acked
;
2837 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
2841 static int nl80211_init_bss(struct i802_bss
*bss
)
2843 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2847 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2848 no_seq_check
, NULL
);
2849 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2850 process_bss_event
, bss
);
2856 static void nl80211_destroy_bss(struct i802_bss
*bss
)
2858 nl_cb_put(bss
->nl_cb
);
2864 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2865 * @ctx: context to be used when calling wpa_supplicant functions,
2866 * e.g., wpa_supplicant_event()
2867 * @ifname: interface name, e.g., wlan0
2868 * @global_priv: private driver global data from global_init()
2869 * Returns: Pointer to private data, %NULL on failure
2871 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
2874 struct wpa_driver_nl80211_data
*drv
;
2875 struct rfkill_config
*rcfg
;
2876 struct i802_bss
*bss
;
2878 if (global_priv
== NULL
)
2880 drv
= os_zalloc(sizeof(*drv
));
2883 drv
->global
= global_priv
;
2885 bss
= &drv
->first_bss
;
2887 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
2888 drv
->monitor_ifidx
= -1;
2889 drv
->monitor_sock
= -1;
2890 drv
->eapol_tx_sock
= -1;
2891 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2893 if (wpa_driver_nl80211_init_nl(drv
)) {
2898 if (nl80211_init_bss(bss
))
2901 nl80211_get_phy_name(drv
);
2903 rcfg
= os_zalloc(sizeof(*rcfg
));
2907 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
2908 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
2909 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
2910 drv
->rfkill
= rfkill_init(rcfg
);
2911 if (drv
->rfkill
== NULL
) {
2912 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
2916 if (wpa_driver_nl80211_finish_drv_init(drv
))
2919 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
2920 if (drv
->eapol_tx_sock
< 0)
2923 if (drv
->data_tx_status
) {
2926 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
2927 &enabled
, sizeof(enabled
)) < 0) {
2928 wpa_printf(MSG_DEBUG
,
2929 "nl80211: wifi status sockopt failed\n");
2930 drv
->data_tx_status
= 0;
2931 if (!drv
->use_monitor
)
2933 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2935 eloop_register_read_sock(drv
->eapol_tx_sock
,
2936 wpa_driver_nl80211_handle_eapol_tx_status
,
2942 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
2943 drv
->in_interface_list
= 1;
2949 wpa_driver_nl80211_deinit(bss
);
2954 static int nl80211_register_frame(struct i802_bss
*bss
,
2955 struct nl_handle
*nl_handle
,
2956 u16 type
, const u8
*match
, size_t match_len
)
2958 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2962 msg
= nlmsg_alloc();
2966 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x nl_handle=%p",
2968 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
2971 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
2973 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
2974 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
2975 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
2977 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
2980 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
2981 "failed (type=%u): ret=%d (%s)",
2982 type
, ret
, strerror(-ret
));
2983 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
2985 goto nla_put_failure
;
2994 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
2996 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2999 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
3000 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
3004 bss
->nl_mgmt
= nl_create_handle(drv
->nl_cb
, "mgmt");
3005 if (bss
->nl_mgmt
== NULL
)
3008 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_mgmt
),
3009 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
3016 static int nl80211_register_action_frame(struct i802_bss
*bss
,
3017 const u8
*match
, size_t match_len
)
3019 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
3020 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
3021 type
, match
, match_len
);
3025 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
3027 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3029 if (nl80211_alloc_mgmt_handle(bss
))
3031 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
3032 "handle %p", bss
->nl_mgmt
);
3034 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
3035 /* GAS Initial Request */
3036 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
3038 /* GAS Initial Response */
3039 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
3041 /* GAS Comeback Request */
3042 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
3044 /* GAS Comeback Response */
3045 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
3047 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
3049 /* P2P Public Action */
3050 if (nl80211_register_action_frame(bss
,
3051 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
3055 if (nl80211_register_action_frame(bss
,
3056 (u8
*) "\x7f\x50\x6f\x9a\x09",
3059 #endif /* CONFIG_P2P */
3060 #ifdef CONFIG_IEEE80211W
3061 /* SA Query Response */
3062 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
3064 #endif /* CONFIG_IEEE80211W */
3066 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
3067 /* TDLS Discovery Response */
3068 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
3072 #endif /* CONFIG_TDLS */
3074 /* FT Action frames */
3075 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
3078 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
3079 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
3081 /* WNM - BSS Transition Management Request */
3082 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
3089 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
3091 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3095 msg
= nlmsg_alloc();
3099 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
3101 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3103 ret
= send_and_recv(drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
3106 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
3107 "failed: ret=%d (%s)",
3108 ret
, strerror(-ret
));
3109 goto nla_put_failure
;
3118 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
3120 static const int stypes
[] = {
3122 WLAN_FC_STYPE_ASSOC_REQ
,
3123 WLAN_FC_STYPE_REASSOC_REQ
,
3124 WLAN_FC_STYPE_DISASSOC
,
3125 WLAN_FC_STYPE_DEAUTH
,
3126 WLAN_FC_STYPE_ACTION
,
3127 WLAN_FC_STYPE_PROBE_REQ
,
3128 /* Beacon doesn't work as mac80211 doesn't currently allow
3129 * it, but it wouldn't really be the right thing anyway as
3130 * it isn't per interface ... maybe just dump the scan
3131 * results periodically for OLBC?
3133 // WLAN_FC_STYPE_BEACON,
3137 if (nl80211_alloc_mgmt_handle(bss
))
3139 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3140 "handle %p", bss
->nl_mgmt
);
3142 for (i
= 0; i
< sizeof(stypes
) / sizeof(stypes
[0]); i
++) {
3143 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3144 (WLAN_FC_TYPE_MGMT
<< 2) |
3151 if (nl80211_register_spurious_class3(bss
))
3154 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
3160 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3161 nl_destroy_handles(&bss
->nl_mgmt
);
3166 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
3168 if (bss
->nl_mgmt
== NULL
)
3170 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
3171 "(%s)", bss
->nl_mgmt
, reason
);
3172 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3173 nl_destroy_handles(&bss
->nl_mgmt
);
3175 nl80211_put_wiphy_data_ap(bss
);
3179 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
3181 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
3186 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
3188 struct i802_bss
*bss
= &drv
->first_bss
;
3189 int send_rfkill_event
= 0;
3191 drv
->ifindex
= if_nametoindex(bss
->ifname
);
3192 drv
->first_bss
.ifindex
= drv
->ifindex
;
3196 * Make sure the interface starts up in station mode unless this is a
3197 * dynamically added interface (e.g., P2P) that was already configured
3198 * with proper iftype.
3200 if (drv
->ifindex
!= drv
->global
->if_add_ifindex
&&
3201 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
) < 0) {
3202 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to "
3203 "use managed mode");
3207 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
3208 if (rfkill_is_blocked(drv
->rfkill
)) {
3209 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
3210 "interface '%s' due to rfkill",
3212 drv
->if_disabled
= 1;
3213 send_rfkill_event
= 1;
3215 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
3216 "interface '%s' UP", bss
->ifname
);
3221 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
3222 1, IF_OPER_DORMANT
);
3223 #endif /* HOSTAPD */
3225 if (wpa_driver_nl80211_capa(drv
))
3228 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
3232 if (send_rfkill_event
) {
3233 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
3241 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
3245 msg
= nlmsg_alloc();
3249 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
3250 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3252 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3260 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
3261 * @priv: Pointer to private nl80211 data from wpa_driver_nl80211_init()
3263 * Shut down driver interface and processing of driver events. Free
3264 * private data buffer if one was allocated in wpa_driver_nl80211_init().
3266 static void wpa_driver_nl80211_deinit(void *priv
)
3268 struct i802_bss
*bss
= priv
;
3269 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3271 if (drv
->data_tx_status
)
3272 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
3273 if (drv
->eapol_tx_sock
>= 0)
3274 close(drv
->eapol_tx_sock
);
3277 wpa_driver_nl80211_probe_req_report(bss
, 0);
3278 if (bss
->added_if_into_bridge
) {
3279 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
3281 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
3282 "interface %s from bridge %s: %s",
3283 bss
->ifname
, bss
->brname
, strerror(errno
));
3285 if (bss
->added_bridge
) {
3286 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
3287 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
3289 bss
->brname
, strerror(errno
));
3292 nl80211_remove_monitor_interface(drv
);
3294 if (is_ap_interface(drv
->nlmode
))
3295 wpa_driver_nl80211_del_beacon(drv
);
3298 if (drv
->last_freq_ht
) {
3299 /* Clear HT flags from the driver */
3300 struct hostapd_freq_params freq
;
3301 os_memset(&freq
, 0, sizeof(freq
));
3302 freq
.freq
= drv
->last_freq
;
3303 i802_set_freq(priv
, &freq
);
3306 if (drv
->eapol_sock
>= 0) {
3307 eloop_unregister_read_sock(drv
->eapol_sock
);
3308 close(drv
->eapol_sock
);
3311 if (drv
->if_indices
!= drv
->default_if_indices
)
3312 os_free(drv
->if_indices
);
3313 #endif /* HOSTAPD */
3315 if (drv
->disabled_11b_rates
)
3316 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
3318 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
3320 rfkill_deinit(drv
->rfkill
);
3322 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
3324 (void) linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0);
3325 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
3326 nl80211_mgmt_unsubscribe(bss
, "deinit");
3328 nl_cb_put(drv
->nl_cb
);
3330 nl80211_destroy_bss(&drv
->first_bss
);
3332 os_free(drv
->filter_ssids
);
3334 os_free(drv
->auth_ie
);
3336 if (drv
->in_interface_list
)
3337 dl_list_del(&drv
->list
);
3344 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
3345 * @eloop_ctx: Driver private data
3346 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
3348 * This function can be used as registered timeout when starting a scan to
3349 * generate a scan completed event if the driver does not report this.
3351 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
3353 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
3354 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
3355 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
3356 drv
->ap_scan_as_station
);
3357 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
3359 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
3360 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
3365 * wpa_driver_nl80211_scan - Request the driver to initiate scan
3366 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3367 * @params: Scan parameters
3368 * Returns: 0 on success, -1 on failure
3370 static int wpa_driver_nl80211_scan(void *priv
,
3371 struct wpa_driver_scan_params
*params
)
3373 struct i802_bss
*bss
= priv
;
3374 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3375 int ret
= 0, timeout
;
3376 struct nl_msg
*msg
, *ssids
, *freqs
, *rates
;
3379 drv
->scan_for_auth
= 0;
3381 msg
= nlmsg_alloc();
3382 ssids
= nlmsg_alloc();
3383 freqs
= nlmsg_alloc();
3384 rates
= nlmsg_alloc();
3385 if (!msg
|| !ssids
|| !freqs
|| !rates
) {
3393 os_free(drv
->filter_ssids
);
3394 drv
->filter_ssids
= params
->filter_ssids
;
3395 params
->filter_ssids
= NULL
;
3396 drv
->num_filter_ssids
= params
->num_filter_ssids
;
3398 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TRIGGER_SCAN
);
3400 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3402 for (i
= 0; i
< params
->num_ssids
; i
++) {
3403 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
3404 params
->ssids
[i
].ssid
,
3405 params
->ssids
[i
].ssid_len
);
3406 NLA_PUT(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
3407 params
->ssids
[i
].ssid
);
3409 if (params
->num_ssids
)
3410 nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
3412 if (params
->extra_ies
) {
3413 wpa_hexdump(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
3414 params
->extra_ies
, params
->extra_ies_len
);
3415 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
3419 if (params
->freqs
) {
3420 for (i
= 0; params
->freqs
[i
]; i
++) {
3421 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
3422 "MHz", params
->freqs
[i
]);
3423 NLA_PUT_U32(freqs
, i
+ 1, params
->freqs
[i
]);
3425 nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
, freqs
);
3428 if (params
->p2p_probe
) {
3430 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
3431 * by masking out everything else apart from the OFDM rates 6,
3432 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
3433 * rates are left enabled.
3435 NLA_PUT(rates
, NL80211_BAND_2GHZ
, 8,
3436 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
3437 nla_put_nested(msg
, NL80211_ATTR_SCAN_SUPP_RATES
, rates
);
3439 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
3442 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3445 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
3446 "(%s)", ret
, strerror(-ret
));
3448 if (is_ap_interface(drv
->nlmode
)) {
3450 * mac80211 does not allow scan requests in AP mode, so
3451 * try to do this in station mode.
3453 if (wpa_driver_nl80211_set_mode(
3454 bss
, NL80211_IFTYPE_STATION
))
3455 goto nla_put_failure
;
3457 if (wpa_driver_nl80211_scan(drv
, params
)) {
3458 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
3459 goto nla_put_failure
;
3462 /* Restore AP mode when processing scan results */
3463 drv
->ap_scan_as_station
= drv
->nlmode
;
3466 goto nla_put_failure
;
3468 goto nla_put_failure
;
3469 #endif /* HOSTAPD */
3472 /* Not all drivers generate "scan completed" wireless event, so try to
3473 * read results after a timeout. */
3475 if (drv
->scan_complete_events
) {
3477 * The driver seems to deliver events to notify when scan is
3478 * complete, so use longer timeout to avoid race conditions
3479 * with scanning and following association request.
3483 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
3484 "seconds", ret
, timeout
);
3485 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
3486 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
3499 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
3500 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3501 * @params: Scan parameters
3502 * @interval: Interval between scan cycles in milliseconds
3503 * Returns: 0 on success, -1 on failure or if not supported
3505 static int wpa_driver_nl80211_sched_scan(void *priv
,
3506 struct wpa_driver_scan_params
*params
,
3509 struct i802_bss
*bss
= priv
;
3510 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3512 struct nl_msg
*msg
, *ssids
, *freqs
, *match_set_ssid
, *match_sets
;
3516 if (!drv
->capa
.sched_scan_supported
)
3517 return android_pno_start(bss
, params
);
3518 #endif /* ANDROID */
3520 msg
= nlmsg_alloc();
3521 ssids
= nlmsg_alloc();
3522 freqs
= nlmsg_alloc();
3523 if (!msg
|| !ssids
|| !freqs
) {
3530 os_free(drv
->filter_ssids
);
3531 drv
->filter_ssids
= params
->filter_ssids
;
3532 params
->filter_ssids
= NULL
;
3533 drv
->num_filter_ssids
= params
->num_filter_ssids
;
3535 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_START_SCHED_SCAN
);
3537 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3539 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
3541 if (drv
->num_filter_ssids
&&
3542 (int) drv
->num_filter_ssids
<= drv
->capa
.max_match_sets
) {
3543 match_sets
= nlmsg_alloc();
3545 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
3546 wpa_hexdump_ascii(MSG_MSGDUMP
,
3547 "nl80211: Sched scan filter SSID",
3548 drv
->filter_ssids
[i
].ssid
,
3549 drv
->filter_ssids
[i
].ssid_len
);
3551 match_set_ssid
= nlmsg_alloc();
3552 nla_put(match_set_ssid
,
3553 NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
3554 drv
->filter_ssids
[i
].ssid_len
,
3555 drv
->filter_ssids
[i
].ssid
);
3557 nla_put_nested(match_sets
, i
+ 1, match_set_ssid
);
3559 nlmsg_free(match_set_ssid
);
3562 nla_put_nested(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
,
3564 nlmsg_free(match_sets
);
3567 for (i
= 0; i
< params
->num_ssids
; i
++) {
3568 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Sched scan SSID",
3569 params
->ssids
[i
].ssid
,
3570 params
->ssids
[i
].ssid_len
);
3571 NLA_PUT(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
3572 params
->ssids
[i
].ssid
);
3574 if (params
->num_ssids
)
3575 nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
3577 if (params
->extra_ies
) {
3578 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Sched scan extra IEs",
3579 params
->extra_ies
, params
->extra_ies_len
);
3580 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
3584 if (params
->freqs
) {
3585 for (i
= 0; params
->freqs
[i
]; i
++) {
3586 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
3587 "MHz", params
->freqs
[i
]);
3588 NLA_PUT_U32(freqs
, i
+ 1, params
->freqs
[i
]);
3590 nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
, freqs
);
3593 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3595 /* TODO: if we get an error here, we should fall back to normal scan */
3599 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
3600 "ret=%d (%s)", ret
, strerror(-ret
));
3601 goto nla_put_failure
;
3604 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
3605 "scan interval %d msec", ret
, interval
);
3616 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
3617 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3618 * Returns: 0 on success, -1 on failure or if not supported
3620 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
3622 struct i802_bss
*bss
= priv
;
3623 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3628 if (!drv
->capa
.sched_scan_supported
)
3629 return android_pno_stop(bss
);
3630 #endif /* ANDROID */
3632 msg
= nlmsg_alloc();
3636 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
3638 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3640 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3643 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
3644 "ret=%d (%s)", ret
, strerror(-ret
));
3645 goto nla_put_failure
;
3648 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
3656 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
3658 const u8
*end
, *pos
;
3664 end
= ies
+ ies_len
;
3666 while (pos
+ 1 < end
) {
3667 if (pos
+ 2 + pos
[1] > end
)
3678 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
3679 const u8
*ie
, size_t ie_len
)
3684 if (drv
->filter_ssids
== NULL
)
3687 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
3691 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
3692 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
3693 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
3702 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
3704 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
3705 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3706 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
3707 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
3708 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
3709 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
3710 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
3711 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
3712 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
3713 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
3714 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
3715 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
3716 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
3717 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
3718 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
3720 struct nl80211_bss_info_arg
*_arg
= arg
;
3721 struct wpa_scan_results
*res
= _arg
->res
;
3722 struct wpa_scan_res
**tmp
;
3723 struct wpa_scan_res
*r
;
3724 const u8
*ie
, *beacon_ie
;
3725 size_t ie_len
, beacon_ie_len
;
3729 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3730 genlmsg_attrlen(gnlh
, 0), NULL
);
3731 if (!tb
[NL80211_ATTR_BSS
])
3733 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
3736 if (bss
[NL80211_BSS_STATUS
]) {
3737 enum nl80211_bss_status status
;
3738 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
3739 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
3740 bss
[NL80211_BSS_FREQUENCY
]) {
3742 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
3743 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
3746 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
3747 bss
[NL80211_BSS_BSSID
]) {
3748 os_memcpy(_arg
->assoc_bssid
,
3749 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
3750 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
3751 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
3756 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
3757 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
3758 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
3763 if (bss
[NL80211_BSS_BEACON_IES
]) {
3764 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
3765 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
3771 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
3772 ie
? ie_len
: beacon_ie_len
))
3775 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
3778 if (bss
[NL80211_BSS_BSSID
])
3779 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
3781 if (bss
[NL80211_BSS_FREQUENCY
])
3782 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
3783 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
3784 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
3785 if (bss
[NL80211_BSS_CAPABILITY
])
3786 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
3787 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
3788 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
3789 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
3790 r
->level
/= 100; /* mBm to dBm */
3791 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
3792 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
3793 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
3794 r
->flags
|= WPA_SCAN_QUAL_INVALID
;
3796 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
3797 if (bss
[NL80211_BSS_TSF
])
3798 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
3799 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
3800 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
3802 pos
= (u8
*) (r
+ 1);
3804 os_memcpy(pos
, ie
, ie_len
);
3807 r
->beacon_ie_len
= beacon_ie_len
;
3809 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
3811 if (bss
[NL80211_BSS_STATUS
]) {
3812 enum nl80211_bss_status status
;
3813 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
3815 case NL80211_BSS_STATUS_AUTHENTICATED
:
3816 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
3818 case NL80211_BSS_STATUS_ASSOCIATED
:
3819 r
->flags
|= WPA_SCAN_ASSOCIATED
;
3827 * cfg80211 maintains separate BSS table entries for APs if the same
3828 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
3829 * not use frequency as a separate key in the BSS table, so filter out
3830 * duplicated entries. Prefer associated BSS entry in such a case in
3831 * order to get the correct frequency into the BSS table.
3833 for (i
= 0; i
< res
->num
; i
++) {
3835 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
3838 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
3839 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
3840 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
3841 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
3842 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
3845 /* Same BSSID,SSID was already included in scan results */
3846 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
3847 "for " MACSTR
, MAC2STR(r
->bssid
));
3849 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
3850 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
3851 os_free(res
->res
[i
]);
3858 tmp
= os_realloc(res
->res
,
3859 (res
->num
+ 1) * sizeof(struct wpa_scan_res
*));
3864 tmp
[res
->num
++] = r
;
3871 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
3874 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
3875 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
3876 "mismatch (" MACSTR
")", MAC2STR(addr
));
3877 wpa_driver_nl80211_mlme(drv
, addr
,
3878 NL80211_CMD_DEAUTHENTICATE
,
3879 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
3884 static void wpa_driver_nl80211_check_bss_status(
3885 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
3889 for (i
= 0; i
< res
->num
; i
++) {
3890 struct wpa_scan_res
*r
= res
->res
[i
];
3891 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
3892 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
3893 "indicates BSS status with " MACSTR
3894 " as authenticated",
3896 if (is_sta_interface(drv
->nlmode
) &&
3897 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
3898 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
3900 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
3901 " in local state (auth=" MACSTR
3902 " assoc=" MACSTR
")",
3903 MAC2STR(drv
->auth_bssid
),
3904 MAC2STR(drv
->bssid
));
3905 clear_state_mismatch(drv
, r
->bssid
);
3909 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
3910 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
3911 "indicate BSS status with " MACSTR
3914 if (is_sta_interface(drv
->nlmode
) &&
3916 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
3917 "(not associated) does not match "
3919 clear_state_mismatch(drv
, r
->bssid
);
3920 } else if (is_sta_interface(drv
->nlmode
) &&
3921 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
3923 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
3924 "(associated with " MACSTR
") does "
3925 "not match with BSS state",
3926 MAC2STR(drv
->bssid
));
3927 clear_state_mismatch(drv
, r
->bssid
);
3928 clear_state_mismatch(drv
, drv
->bssid
);
3935 static struct wpa_scan_results
*
3936 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
3939 struct wpa_scan_results
*res
;
3941 struct nl80211_bss_info_arg arg
;
3943 res
= os_zalloc(sizeof(*res
));
3946 msg
= nlmsg_alloc();
3948 goto nla_put_failure
;
3950 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
3951 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3955 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
3958 wpa_printf(MSG_DEBUG
, "nl80211: Received scan results (%lu "
3959 "BSSes)", (unsigned long) res
->num
);
3960 nl80211_get_noise_for_scan_results(drv
, res
);
3963 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
3964 "(%s)", ret
, strerror(-ret
));
3967 wpa_scan_results_free(res
);
3973 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
3974 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
3975 * Returns: Scan results on success, -1 on failure
3977 static struct wpa_scan_results
*
3978 wpa_driver_nl80211_get_scan_results(void *priv
)
3980 struct i802_bss
*bss
= priv
;
3981 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3982 struct wpa_scan_results
*res
;
3984 res
= nl80211_get_scan_results(drv
);
3986 wpa_driver_nl80211_check_bss_status(drv
, res
);
3991 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
3993 struct wpa_scan_results
*res
;
3996 res
= nl80211_get_scan_results(drv
);
3998 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
4002 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
4003 for (i
= 0; i
< res
->num
; i
++) {
4004 struct wpa_scan_res
*r
= res
->res
[i
];
4005 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
4006 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
4007 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
4008 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
4011 wpa_scan_results_free(res
);
4015 static int wpa_driver_nl80211_set_key(const char *ifname
, void *priv
,
4016 enum wpa_alg alg
, const u8
*addr
,
4017 int key_idx
, int set_tx
,
4018 const u8
*seq
, size_t seq_len
,
4019 const u8
*key
, size_t key_len
)
4021 struct i802_bss
*bss
= priv
;
4022 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4023 int ifindex
= if_nametoindex(ifname
);
4027 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d alg=%d addr=%p key_idx=%d "
4028 "set_tx=%d seq_len=%lu key_len=%lu",
4029 __func__
, ifindex
, alg
, addr
, key_idx
, set_tx
,
4030 (unsigned long) seq_len
, (unsigned long) key_len
);
4034 #endif /* CONFIG_TDLS */
4036 msg
= nlmsg_alloc();
4040 if (alg
== WPA_ALG_NONE
) {
4041 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
4043 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
4044 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
4048 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4049 WLAN_CIPHER_SUITE_WEP40
);
4051 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4052 WLAN_CIPHER_SUITE_WEP104
);
4055 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4056 WLAN_CIPHER_SUITE_TKIP
);
4059 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4060 WLAN_CIPHER_SUITE_CCMP
);
4063 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4064 WLAN_CIPHER_SUITE_AES_CMAC
);
4067 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4068 "algorithm %d", __func__
, alg
);
4075 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
4077 if (addr
&& !is_broadcast_ether_addr(addr
)) {
4078 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
4079 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4081 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
4082 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
4083 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
4084 NL80211_KEYTYPE_GROUP
);
4086 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
4087 struct nl_msg
*types
;
4089 wpa_printf(MSG_DEBUG
, " broadcast key");
4090 types
= nlmsg_alloc();
4092 goto nla_put_failure
;
4093 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4094 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4098 goto nla_put_failure
;
4100 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4101 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4103 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4104 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
4107 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
4108 ret
, strerror(-ret
));
4111 * If we failed or don't need to set the default TX key (below),
4114 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
)
4116 if (is_ap_interface(drv
->nlmode
) && addr
&&
4117 !is_broadcast_ether_addr(addr
))
4120 msg
= nlmsg_alloc();
4124 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
4125 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4126 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4127 if (alg
== WPA_ALG_IGTK
)
4128 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
4130 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
4131 if (addr
&& is_broadcast_ether_addr(addr
)) {
4132 struct nl_msg
*types
;
4134 types
= nlmsg_alloc();
4136 goto nla_put_failure
;
4137 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4138 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4142 goto nla_put_failure
;
4144 struct nl_msg
*types
;
4146 types
= nlmsg_alloc();
4148 goto nla_put_failure
;
4149 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
4150 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4154 goto nla_put_failure
;
4157 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4161 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
4162 "err=%d %s)", ret
, strerror(-ret
));
4171 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
4172 int key_idx
, int defkey
,
4173 const u8
*seq
, size_t seq_len
,
4174 const u8
*key
, size_t key_len
)
4176 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
4180 if (defkey
&& alg
== WPA_ALG_IGTK
)
4181 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
4183 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4185 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
4190 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4191 WLAN_CIPHER_SUITE_WEP40
);
4193 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4194 WLAN_CIPHER_SUITE_WEP104
);
4197 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
4200 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
4203 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4204 WLAN_CIPHER_SUITE_AES_CMAC
);
4207 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4208 "algorithm %d", __func__
, alg
);
4213 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
4215 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
4217 nla_nest_end(msg
, key_attr
);
4225 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
4229 struct nlattr
*nl_keys
, *nl_key
;
4231 for (i
= 0; i
< 4; i
++) {
4232 if (!params
->wep_key
[i
])
4237 if (params
->wps
== WPS_MODE_PRIVACY
)
4239 if (params
->pairwise_suite
&&
4240 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
4246 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
4248 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
4250 goto nla_put_failure
;
4252 for (i
= 0; i
< 4; i
++) {
4253 if (!params
->wep_key
[i
])
4256 nl_key
= nla_nest_start(msg
, i
);
4258 goto nla_put_failure
;
4260 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
4261 params
->wep_key
[i
]);
4262 if (params
->wep_key_len
[i
] == 5)
4263 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4264 WLAN_CIPHER_SUITE_WEP40
);
4266 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4267 WLAN_CIPHER_SUITE_WEP104
);
4269 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
4271 if (i
== params
->wep_tx_keyidx
)
4272 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4274 nla_nest_end(msg
, nl_key
);
4276 nla_nest_end(msg
, nl_keys
);
4285 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
4286 const u8
*addr
, int cmd
, u16 reason_code
,
4287 int local_state_change
)
4292 msg
= nlmsg_alloc();
4296 nl80211_cmd(drv
, msg
, 0, cmd
);
4298 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4299 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
4300 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4301 if (local_state_change
)
4302 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
4304 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4307 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4308 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
4309 reason_code
, ret
, strerror(-ret
));
4310 goto nla_put_failure
;
4320 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
4321 const u8
*addr
, int reason_code
)
4323 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
4324 __func__
, MAC2STR(addr
), reason_code
);
4325 drv
->associated
= 0;
4326 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISCONNECT
,
4331 static int wpa_driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
4334 struct i802_bss
*bss
= priv
;
4335 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4336 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
4337 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
4338 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
4339 __func__
, MAC2STR(addr
), reason_code
);
4340 drv
->associated
= 0;
4341 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
4342 return nl80211_leave_ibss(drv
);
4343 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
4348 static int wpa_driver_nl80211_disassociate(void *priv
, const u8
*addr
,
4351 struct i802_bss
*bss
= priv
;
4352 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4353 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
4354 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
4355 wpa_printf(MSG_DEBUG
, "%s", __func__
);
4356 drv
->associated
= 0;
4357 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISASSOCIATE
,
4362 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
4363 struct wpa_driver_auth_params
*params
)
4367 drv
->auth_freq
= params
->freq
;
4368 drv
->auth_alg
= params
->auth_alg
;
4369 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
4370 drv
->auth_local_state_change
= params
->local_state_change
;
4371 drv
->auth_p2p
= params
->p2p
;
4374 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
4376 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
4379 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
4380 drv
->auth_ssid_len
= params
->ssid_len
;
4382 drv
->auth_ssid_len
= 0;
4385 os_free(drv
->auth_ie
);
4386 drv
->auth_ie
= NULL
;
4387 drv
->auth_ie_len
= 0;
4389 drv
->auth_ie
= os_malloc(params
->ie_len
);
4391 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
4392 drv
->auth_ie_len
= params
->ie_len
;
4396 for (i
= 0; i
< 4; i
++) {
4397 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
4398 params
->wep_key_len
[i
] <= 16) {
4399 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
4400 params
->wep_key_len
[i
]);
4401 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
4403 drv
->auth_wep_key_len
[i
] = 0;
4408 static int wpa_driver_nl80211_authenticate(
4409 void *priv
, struct wpa_driver_auth_params
*params
)
4411 struct i802_bss
*bss
= priv
;
4412 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4415 enum nl80211_auth_type type
;
4416 enum nl80211_iftype nlmode
;
4420 is_retry
= drv
->retry_auth
;
4421 drv
->retry_auth
= 0;
4423 drv
->associated
= 0;
4424 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
4425 /* FIX: IBSS mode */
4426 nlmode
= params
->p2p
?
4427 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
4428 if (drv
->nlmode
!= nlmode
&&
4429 wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
4433 msg
= nlmsg_alloc();
4437 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
4440 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
4442 for (i
= 0; i
< 4; i
++) {
4443 if (!params
->wep_key
[i
])
4445 wpa_driver_nl80211_set_key(bss
->ifname
, priv
, WPA_ALG_WEP
,
4447 i
== params
->wep_tx_keyidx
, NULL
, 0,
4449 params
->wep_key_len
[i
]);
4450 if (params
->wep_tx_keyidx
!= i
)
4452 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
4453 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
4459 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4460 if (params
->bssid
) {
4461 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
4462 MAC2STR(params
->bssid
));
4463 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
4466 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
4467 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
4470 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4471 params
->ssid
, params
->ssid_len
);
4472 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
4475 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
4477 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
4478 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
4479 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
4480 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
4481 type
= NL80211_AUTHTYPE_SHARED_KEY
;
4482 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
4483 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
4484 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
4485 type
= NL80211_AUTHTYPE_FT
;
4487 goto nla_put_failure
;
4488 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
4489 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
4490 if (params
->local_state_change
) {
4491 wpa_printf(MSG_DEBUG
, " * Local state change only");
4492 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
4495 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4498 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4499 "nl80211: MLME command failed (auth): ret=%d (%s)",
4500 ret
, strerror(-ret
));
4502 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
4503 !params
->local_state_change
) {
4505 * mac80211 does not currently accept new
4506 * authentication if we are already authenticated. As a
4507 * workaround, force deauthentication and try again.
4509 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
4510 "after forced deauthentication");
4511 wpa_driver_nl80211_deauthenticate(
4513 WLAN_REASON_PREV_AUTH_NOT_VALID
);
4518 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
4520 * cfg80211 has likely expired the BSS entry even
4521 * though it was previously available in our internal
4522 * BSS table. To recover quickly, start a single
4523 * channel scan on the specified channel.
4525 struct wpa_driver_scan_params scan
;
4528 os_memset(&scan
, 0, sizeof(scan
));
4531 scan
.ssids
[0].ssid
= params
->ssid
;
4532 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
4534 freqs
[0] = params
->freq
;
4537 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
4538 "channel scan to refresh cfg80211 BSS "
4540 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
4542 nl80211_copy_auth_params(drv
, params
);
4543 drv
->scan_for_auth
= 1;
4545 } else if (is_retry
) {
4547 * Need to indicate this with an event since the return
4548 * value from the retry is not delivered to core code.
4550 union wpa_event_data event
;
4551 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
4553 os_memset(&event
, 0, sizeof(event
));
4554 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
4556 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
4560 goto nla_put_failure
;
4563 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
4572 static int wpa_driver_nl80211_authenticate_retry(
4573 struct wpa_driver_nl80211_data
*drv
)
4575 struct wpa_driver_auth_params params
;
4576 struct i802_bss
*bss
= &drv
->first_bss
;
4579 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
4581 os_memset(¶ms
, 0, sizeof(params
));
4582 params
.freq
= drv
->auth_freq
;
4583 params
.auth_alg
= drv
->auth_alg
;
4584 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
4585 params
.local_state_change
= drv
->auth_local_state_change
;
4586 params
.p2p
= drv
->auth_p2p
;
4588 if (!is_zero_ether_addr(drv
->auth_bssid_
))
4589 params
.bssid
= drv
->auth_bssid_
;
4591 if (drv
->auth_ssid_len
) {
4592 params
.ssid
= drv
->auth_ssid
;
4593 params
.ssid_len
= drv
->auth_ssid_len
;
4596 params
.ie
= drv
->auth_ie
;
4597 params
.ie_len
= drv
->auth_ie_len
;
4599 for (i
= 0; i
< 4; i
++) {
4600 if (drv
->auth_wep_key_len
[i
]) {
4601 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
4602 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
4606 drv
->retry_auth
= 1;
4607 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
4611 struct phy_info_arg
{
4613 struct hostapd_hw_modes
*modes
;
4616 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
4618 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
4619 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4620 struct phy_info_arg
*phy_info
= arg
;
4622 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
4624 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
4625 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
4626 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
4627 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
4628 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
4629 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
4630 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
4631 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
4634 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
4635 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
4636 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
4637 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] = { .type
= NLA_FLAG
},
4640 struct nlattr
*nl_band
;
4641 struct nlattr
*nl_freq
;
4642 struct nlattr
*nl_rate
;
4643 int rem_band
, rem_freq
, rem_rate
;
4644 struct hostapd_hw_modes
*mode
;
4645 int idx
, mode_is_set
;
4647 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4648 genlmsg_attrlen(gnlh
, 0), NULL
);
4650 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
4653 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
) {
4654 mode
= os_realloc(phy_info
->modes
, (*phy_info
->num_modes
+ 1) * sizeof(*mode
));
4657 phy_info
->modes
= mode
;
4661 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
4662 memset(mode
, 0, sizeof(*mode
));
4663 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
;
4664 *(phy_info
->num_modes
) += 1;
4666 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
4667 nla_len(nl_band
), NULL
);
4669 if (tb_band
[NL80211_BAND_ATTR_HT_CAPA
]) {
4670 mode
->ht_capab
= nla_get_u16(
4671 tb_band
[NL80211_BAND_ATTR_HT_CAPA
]);
4674 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) {
4675 mode
->a_mpdu_params
|= nla_get_u8(
4676 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) &
4680 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) {
4681 mode
->a_mpdu_params
|= nla_get_u8(
4682 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) <<
4686 if (tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
] &&
4687 nla_len(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
])) {
4689 mcs
= nla_data(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
4690 os_memcpy(mode
->mcs_set
, mcs
, 16);
4693 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
4694 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
4695 nla_len(nl_freq
), freq_policy
);
4696 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
4698 mode
->num_channels
++;
4701 mode
->channels
= os_zalloc(mode
->num_channels
* sizeof(struct hostapd_channel_data
));
4702 if (!mode
->channels
)
4707 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
4708 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
4709 nla_len(nl_freq
), freq_policy
);
4710 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
4713 mode
->channels
[idx
].freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
4714 mode
->channels
[idx
].flag
= 0;
4717 /* crude heuristic */
4718 if (mode
->channels
[idx
].freq
< 4000)
4719 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
4721 mode
->mode
= HOSTAPD_MODE_IEEE80211A
;
4725 /* crude heuristic */
4726 if (mode
->channels
[idx
].freq
< 4000)
4727 if (mode
->channels
[idx
].freq
== 2484)
4728 mode
->channels
[idx
].chan
= 14;
4730 mode
->channels
[idx
].chan
= (mode
->channels
[idx
].freq
- 2407) / 5;
4732 mode
->channels
[idx
].chan
= mode
->channels
[idx
].freq
/5 - 1000;
4734 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
4735 mode
->channels
[idx
].flag
|=
4736 HOSTAPD_CHAN_DISABLED
;
4737 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
4738 mode
->channels
[idx
].flag
|=
4739 HOSTAPD_CHAN_PASSIVE_SCAN
;
4740 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
4741 mode
->channels
[idx
].flag
|=
4742 HOSTAPD_CHAN_NO_IBSS
;
4743 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
4744 mode
->channels
[idx
].flag
|=
4747 if (tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] &&
4748 !tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
4749 mode
->channels
[idx
].max_tx_power
=
4750 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
]) / 100;
4755 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
4756 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
4757 nla_len(nl_rate
), rate_policy
);
4758 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
4763 mode
->rates
= os_zalloc(mode
->num_rates
* sizeof(int));
4769 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
4770 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
4771 nla_len(nl_rate
), rate_policy
);
4772 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
4774 mode
->rates
[idx
] = nla_get_u32(tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
4776 /* crude heuristic */
4777 if (mode
->mode
== HOSTAPD_MODE_IEEE80211B
&&
4778 mode
->rates
[idx
] > 200)
4779 mode
->mode
= HOSTAPD_MODE_IEEE80211G
;
4788 static struct hostapd_hw_modes
*
4789 wpa_driver_nl80211_add_11b(struct hostapd_hw_modes
*modes
, u16
*num_modes
)
4792 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
4793 int i
, mode11g_idx
= -1;
4795 /* If only 802.11g mode is included, use it to construct matching
4796 * 802.11b mode data. */
4798 for (m
= 0; m
< *num_modes
; m
++) {
4799 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
4800 return modes
; /* 802.11b already included */
4801 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
4805 if (mode11g_idx
< 0)
4806 return modes
; /* 2.4 GHz band not supported at all */
4808 nmodes
= os_realloc(modes
, (*num_modes
+ 1) * sizeof(*nmodes
));
4810 return modes
; /* Could not add 802.11b mode */
4812 mode
= &nmodes
[*num_modes
];
4813 os_memset(mode
, 0, sizeof(*mode
));
4817 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
4819 mode11g
= &modes
[mode11g_idx
];
4820 mode
->num_channels
= mode11g
->num_channels
;
4821 mode
->channels
= os_malloc(mode11g
->num_channels
*
4822 sizeof(struct hostapd_channel_data
));
4823 if (mode
->channels
== NULL
) {
4825 return modes
; /* Could not add 802.11b mode */
4827 os_memcpy(mode
->channels
, mode11g
->channels
,
4828 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
4830 mode
->num_rates
= 0;
4831 mode
->rates
= os_malloc(4 * sizeof(int));
4832 if (mode
->rates
== NULL
) {
4833 os_free(mode
->channels
);
4835 return modes
; /* Could not add 802.11b mode */
4838 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
4839 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
4840 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
4842 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
4844 if (mode
->num_rates
== 4)
4848 if (mode
->num_rates
== 0) {
4849 os_free(mode
->channels
);
4850 os_free(mode
->rates
);
4852 return modes
; /* No 802.11b rates */
4855 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
4862 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
4867 for (c
= 0; c
< mode
->num_channels
; c
++) {
4868 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
4869 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
4870 chan
->flag
|= HOSTAPD_CHAN_HT40
;
4875 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
4880 for (c
= 0; c
< mode
->num_channels
; c
++) {
4881 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
4882 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
4884 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
4885 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
4886 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
4887 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
4892 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
4893 struct phy_info_arg
*results
)
4895 u32 start
, end
, max_bw
;
4898 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
4899 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
4900 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
4903 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
4904 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
4905 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
4907 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
4908 start
, end
, max_bw
);
4912 for (m
= 0; m
< *results
->num_modes
; m
++) {
4913 if (!(results
->modes
[m
].ht_capab
&
4914 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
4916 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
4921 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
4922 struct phy_info_arg
*results
)
4924 u32 start
, end
, max_bw
;
4927 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
4928 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
4929 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
4932 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
4933 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
4934 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
4939 for (m
= 0; m
< *results
->num_modes
; m
++) {
4940 if (!(results
->modes
[m
].ht_capab
&
4941 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
4943 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
4948 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
4950 struct phy_info_arg
*results
= arg
;
4951 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
4952 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4953 struct nlattr
*nl_rule
;
4954 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
4956 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
4957 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4958 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4959 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4960 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4961 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4962 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4965 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4966 genlmsg_attrlen(gnlh
, 0), NULL
);
4967 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
4968 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
4969 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
4974 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
4975 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
4977 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
4979 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
4980 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
4981 nl80211_reg_rule_ht40(tb_rule
, results
);
4984 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
4986 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
4987 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
4988 nl80211_reg_rule_sec(tb_rule
, results
);
4995 static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data
*drv
,
4996 struct phy_info_arg
*results
)
5000 msg
= nlmsg_alloc();
5004 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
5005 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
5009 static struct hostapd_hw_modes
*
5010 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
5012 struct i802_bss
*bss
= priv
;
5013 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5015 struct phy_info_arg result
= {
5016 .num_modes
= num_modes
,
5023 msg
= nlmsg_alloc();
5027 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
5029 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5031 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
5032 nl80211_set_ht40_flags(drv
, &result
);
5033 return wpa_driver_nl80211_add_11b(result
.modes
, num_modes
);
5042 static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data
*drv
,
5043 const void *data
, size_t len
,
5044 int encrypt
, int noack
)
5047 0x00, 0x00, /* radiotap version */
5048 0x0e, 0x00, /* radiotap length */
5049 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
5050 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
5052 0x00, 0x00, /* RX and TX flags to indicate that */
5053 0x00, 0x00, /* this is the injected frame directly */
5055 struct iovec iov
[2] = {
5057 .iov_base
= &rtap_hdr
,
5058 .iov_len
= sizeof(rtap_hdr
),
5061 .iov_base
= (void *) data
,
5065 struct msghdr msg
= {
5070 .msg_control
= NULL
,
5071 .msg_controllen
= 0,
5078 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
5080 if (drv
->monitor_sock
< 0) {
5081 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
5082 "for %s", __func__
);
5087 txflags
|= IEEE80211_RADIOTAP_F_TX_NOACK
;
5088 *(le16
*) &rtap_hdr
[12] = host_to_le16(txflags
);
5090 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
5092 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
5099 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
5100 const void *data
, size_t len
,
5101 int encrypt
, int noack
)
5103 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5106 if (drv
->use_monitor
)
5107 return wpa_driver_nl80211_send_mntr(drv
, data
, len
,
5110 return nl80211_send_frame_cmd(bss
, bss
->freq
, 0, data
, len
,
5111 &cookie
, 0, noack
, 0);
5115 static int wpa_driver_nl80211_send_mlme(void *priv
, const u8
*data
,
5116 size_t data_len
, int noack
)
5118 struct i802_bss
*bss
= priv
;
5119 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5120 struct ieee80211_mgmt
*mgmt
;
5124 mgmt
= (struct ieee80211_mgmt
*) data
;
5125 fc
= le_to_host16(mgmt
->frame_control
);
5127 if (is_sta_interface(drv
->nlmode
) &&
5128 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5129 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
5131 * The use of last_mgmt_freq is a bit of a hack,
5132 * but it works due to the single-threaded nature
5133 * of wpa_supplicant.
5135 return nl80211_send_frame_cmd(bss
, drv
->last_mgmt_freq
, 0,
5136 data
, data_len
, NULL
, 1, noack
,
5140 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
5141 return nl80211_send_frame_cmd(bss
, bss
->freq
, 0,
5142 data
, data_len
, NULL
,
5146 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5147 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
5149 * Only one of the authentication frame types is encrypted.
5150 * In order for static WEP encryption to work properly (i.e.,
5151 * to not encrypt the frame), we need to tell mac80211 about
5152 * the frames that must not be encrypted.
5154 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
5155 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
5156 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
5160 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
5165 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
5166 int slot
, int ht_opmode
, int ap_isolate
,
5169 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5172 msg
= nlmsg_alloc();
5176 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
5179 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
5181 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
5183 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
5185 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
5186 if (ap_isolate
>= 0)
5187 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
);
5190 u8 rates
[NL80211_MAX_SUPP_RATES
];
5194 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0;
5196 rates
[rates_len
++] = basic_rates
[i
] / 5;
5198 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
5201 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5203 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5210 static int wpa_driver_nl80211_set_ap(void *priv
,
5211 struct wpa_driver_ap_params
*params
)
5213 struct i802_bss
*bss
= priv
;
5214 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5216 u8 cmd
= NL80211_CMD_NEW_BEACON
;
5219 int ifindex
= if_nametoindex(bss
->ifname
);
5224 beacon_set
= bss
->beacon_set
;
5226 msg
= nlmsg_alloc();
5230 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
5233 cmd
= NL80211_CMD_SET_BEACON
;
5235 nl80211_cmd(drv
, msg
, 0, cmd
);
5236 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
5237 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
5238 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5239 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
5240 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
5241 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5243 if (params
->proberesp
&& params
->proberesp_len
)
5244 NLA_PUT(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
5246 switch (params
->hide_ssid
) {
5247 case NO_SSID_HIDING
:
5248 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5249 NL80211_HIDDEN_SSID_NOT_IN_USE
);
5251 case HIDDEN_SSID_ZERO_LEN
:
5252 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5253 NL80211_HIDDEN_SSID_ZERO_LEN
);
5255 case HIDDEN_SSID_ZERO_CONTENTS
:
5256 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5257 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
5260 if (params
->privacy
)
5261 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
5262 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
5263 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
5264 /* Leave out the attribute */
5265 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
5266 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
5267 NL80211_AUTHTYPE_SHARED_KEY
);
5269 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
5270 NL80211_AUTHTYPE_OPEN_SYSTEM
);
5273 if (params
->wpa_version
& WPA_PROTO_WPA
)
5274 ver
|= NL80211_WPA_VERSION_1
;
5275 if (params
->wpa_version
& WPA_PROTO_RSN
)
5276 ver
|= NL80211_WPA_VERSION_2
;
5278 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
5281 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
5282 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
5283 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
5284 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
5286 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
5287 num_suites
* sizeof(u32
), suites
);
5290 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
&&
5291 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
))
5292 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
);
5295 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
5296 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
5297 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
5298 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
5299 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
5300 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
5301 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
5302 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
5304 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
5305 num_suites
* sizeof(u32
), suites
);
5308 switch (params
->group_cipher
) {
5309 case WPA_CIPHER_CCMP
:
5310 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5311 WLAN_CIPHER_SUITE_CCMP
);
5313 case WPA_CIPHER_TKIP
:
5314 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5315 WLAN_CIPHER_SUITE_TKIP
);
5317 case WPA_CIPHER_WEP104
:
5318 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5319 WLAN_CIPHER_SUITE_WEP104
);
5321 case WPA_CIPHER_WEP40
:
5322 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5323 WLAN_CIPHER_SUITE_WEP40
);
5327 if (params
->beacon_ies
) {
5328 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
5329 wpabuf_head(params
->beacon_ies
));
5331 if (params
->proberesp_ies
) {
5332 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
5333 wpabuf_len(params
->proberesp_ies
),
5334 wpabuf_head(params
->proberesp_ies
));
5336 if (params
->assocresp_ies
) {
5337 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
5338 wpabuf_len(params
->assocresp_ies
),
5339 wpabuf_head(params
->assocresp_ies
));
5342 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5344 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
5345 ret
, strerror(-ret
));
5347 bss
->beacon_set
= 1;
5348 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
5349 params
->short_slot_time
, params
->ht_opmode
,
5350 params
->isolate
, params
->basic_rates
);
5359 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
5360 int freq
, int ht_enabled
,
5361 int sec_channel_offset
)
5363 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5367 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d "
5368 "sec_channel_offset=%d)",
5369 freq
, ht_enabled
, sec_channel_offset
);
5370 msg
= nlmsg_alloc();
5374 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
5376 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5377 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5379 switch (sec_channel_offset
) {
5381 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5382 NL80211_CHAN_HT40MINUS
);
5385 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5386 NL80211_CHAN_HT40PLUS
);
5389 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5395 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5401 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
5402 "%d (%s)", freq
, ret
, strerror(-ret
));
5409 static u32
sta_flags_nl80211(int flags
)
5413 if (flags
& WPA_STA_AUTHORIZED
)
5414 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5415 if (flags
& WPA_STA_WMM
)
5416 f
|= BIT(NL80211_STA_FLAG_WME
);
5417 if (flags
& WPA_STA_SHORT_PREAMBLE
)
5418 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
5419 if (flags
& WPA_STA_MFP
)
5420 f
|= BIT(NL80211_STA_FLAG_MFP
);
5421 if (flags
& WPA_STA_TDLS_PEER
)
5422 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
5428 static int wpa_driver_nl80211_sta_add(void *priv
,
5429 struct hostapd_sta_add_params
*params
)
5431 struct i802_bss
*bss
= priv
;
5432 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5433 struct nl_msg
*msg
, *wme
= NULL
;
5434 struct nl80211_sta_flag_update upd
;
5437 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
5438 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
5441 msg
= nlmsg_alloc();
5445 nl80211_cmd(drv
, msg
, 0, params
->set
? NL80211_CMD_SET_STATION
:
5446 NL80211_CMD_NEW_STATION
);
5448 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5449 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
5450 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
5451 params
->supp_rates
);
5453 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
5454 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
5455 params
->listen_interval
);
5457 if (params
->ht_capabilities
) {
5458 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
5459 sizeof(*params
->ht_capabilities
),
5460 params
->ht_capabilities
);
5463 os_memset(&upd
, 0, sizeof(upd
));
5464 upd
.mask
= sta_flags_nl80211(params
->flags
);
5466 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
5468 if (params
->flags
& WPA_STA_WMM
) {
5469 wme
= nlmsg_alloc();
5471 goto nla_put_failure
;
5473 NLA_PUT_U8(wme
, NL80211_STA_WME_UAPSD_QUEUES
,
5474 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
);
5475 NLA_PUT_U8(wme
, NL80211_STA_WME_MAX_SP
,
5476 (params
->qosinfo
> WMM_QOSINFO_STA_SP_SHIFT
) &
5477 WMM_QOSINFO_STA_SP_MASK
);
5478 nla_put_nested(msg
, NL80211_ATTR_STA_WME
, wme
);
5481 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5484 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
5485 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
5496 static int wpa_driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
5498 struct i802_bss
*bss
= priv
;
5499 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5503 msg
= nlmsg_alloc();
5507 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
5509 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5510 if_nametoindex(bss
->ifname
));
5511 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5513 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5523 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
5528 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
5530 /* stop listening for EAPOL on this interface */
5531 del_ifidx(drv
, ifidx
);
5533 msg
= nlmsg_alloc();
5535 goto nla_put_failure
;
5537 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
5538 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
5540 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
5545 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
5549 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
5552 case NL80211_IFTYPE_ADHOC
:
5554 case NL80211_IFTYPE_STATION
:
5556 case NL80211_IFTYPE_AP
:
5558 case NL80211_IFTYPE_MONITOR
:
5560 case NL80211_IFTYPE_P2P_CLIENT
:
5561 return "P2P_CLIENT";
5562 case NL80211_IFTYPE_P2P_GO
:
5570 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
5572 enum nl80211_iftype iftype
,
5573 const u8
*addr
, int wds
)
5575 struct nl_msg
*msg
, *flags
= NULL
;
5579 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
5580 iftype
, nl80211_iftype_str(iftype
));
5582 msg
= nlmsg_alloc();
5586 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
5587 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5588 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
5589 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
5591 if (iftype
== NL80211_IFTYPE_MONITOR
) {
5594 flags
= nlmsg_alloc();
5596 goto nla_put_failure
;
5598 NLA_PUT_FLAG(flags
, NL80211_MNTR_FLAG_COOK_FRAMES
);
5600 err
= nla_put_nested(msg
, NL80211_ATTR_MNTR_FLAGS
, flags
);
5605 goto nla_put_failure
;
5607 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
5610 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5615 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
5616 ifname
, ret
, strerror(-ret
));
5620 ifidx
= if_nametoindex(ifname
);
5621 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
5627 /* start listening for EAPOL on this interface */
5628 add_ifidx(drv
, ifidx
);
5630 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
5631 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
5632 nl80211_remove_iface(drv
, ifidx
);
5640 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
5641 const char *ifname
, enum nl80211_iftype iftype
,
5642 const u8
*addr
, int wds
)
5646 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
);
5648 /* if error occurred and interface exists already */
5649 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
5650 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
5652 /* Try to remove the interface that was already there. */
5653 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
5655 /* Try to create the interface again */
5656 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
5660 if (ret
>= 0 && is_p2p_interface(iftype
))
5661 nl80211_disable_11b_rates(drv
, ret
, 1);
5667 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
5669 struct ieee80211_hdr
*hdr
;
5671 union wpa_event_data event
;
5673 hdr
= (struct ieee80211_hdr
*) buf
;
5674 fc
= le_to_host16(hdr
->frame_control
);
5676 os_memset(&event
, 0, sizeof(event
));
5677 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
5678 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
5679 event
.tx_status
.dst
= hdr
->addr1
;
5680 event
.tx_status
.data
= buf
;
5681 event
.tx_status
.data_len
= len
;
5682 event
.tx_status
.ack
= ok
;
5683 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
5687 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
5688 u8
*buf
, size_t len
)
5690 struct ieee80211_hdr
*hdr
= (void *)buf
;
5692 union wpa_event_data event
;
5694 if (len
< sizeof(*hdr
))
5697 fc
= le_to_host16(hdr
->frame_control
);
5699 os_memset(&event
, 0, sizeof(event
));
5700 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
5701 event
.rx_from_unknown
.addr
= hdr
->addr2
;
5702 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
5703 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
5704 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
5708 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
5709 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
5711 struct ieee80211_hdr
*hdr
;
5713 union wpa_event_data event
;
5715 hdr
= (struct ieee80211_hdr
*) buf
;
5716 fc
= le_to_host16(hdr
->frame_control
);
5718 switch (WLAN_FC_GET_TYPE(fc
)) {
5719 case WLAN_FC_TYPE_MGMT
:
5720 os_memset(&event
, 0, sizeof(event
));
5721 event
.rx_mgmt
.frame
= buf
;
5722 event
.rx_mgmt
.frame_len
= len
;
5723 event
.rx_mgmt
.datarate
= datarate
;
5724 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
5725 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
5727 case WLAN_FC_TYPE_CTRL
:
5728 /* can only get here with PS-Poll frames */
5729 wpa_printf(MSG_DEBUG
, "CTRL");
5730 from_unknown_sta(drv
, buf
, len
);
5732 case WLAN_FC_TYPE_DATA
:
5733 from_unknown_sta(drv
, buf
, len
);
5739 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
5741 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
5743 unsigned char buf
[3000];
5744 struct ieee80211_radiotap_iterator iter
;
5746 int datarate
= 0, ssi_signal
= 0;
5747 int injected
= 0, failed
= 0, rxflags
= 0;
5749 len
= recv(sock
, buf
, sizeof(buf
), 0);
5755 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
5756 printf("received invalid radiotap frame\n");
5761 ret
= ieee80211_radiotap_iterator_next(&iter
);
5765 printf("received invalid radiotap frame (%d)\n", ret
);
5768 switch (iter
.this_arg_index
) {
5769 case IEEE80211_RADIOTAP_FLAGS
:
5770 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
5773 case IEEE80211_RADIOTAP_RX_FLAGS
:
5776 case IEEE80211_RADIOTAP_TX_FLAGS
:
5778 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
5779 IEEE80211_RADIOTAP_F_TX_FAIL
;
5781 case IEEE80211_RADIOTAP_DATA_RETRIES
:
5783 case IEEE80211_RADIOTAP_CHANNEL
:
5784 /* TODO: convert from freq/flags to channel number */
5786 case IEEE80211_RADIOTAP_RATE
:
5787 datarate
= *iter
.this_arg
* 5;
5789 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
5790 ssi_signal
= *iter
.this_arg
;
5795 if (rxflags
&& injected
)
5799 handle_frame(drv
, buf
+ iter
.max_length
,
5800 len
- iter
.max_length
, datarate
, ssi_signal
);
5802 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
5803 len
- iter
.max_length
, !failed
);
5808 * we post-process the filter code later and rewrite
5809 * this to the offset to the last instruction
5814 static struct sock_filter msock_filter_insns
[] = {
5816 * do a little-endian load of the radiotap length field
5818 /* load lower byte into A */
5819 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
5820 /* put it into X (== index register) */
5821 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
5822 /* load upper byte into A */
5823 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
5824 /* left-shift it by 8 */
5825 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
5827 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
5828 /* put result into X */
5829 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
5832 * Allow management frames through, this also gives us those
5833 * management frames that we sent ourselves with status
5835 /* load the lower byte of the IEEE 802.11 frame control field */
5836 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
5837 /* mask off frame type and version */
5838 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
5839 /* accept frame if it's both 0, fall through otherwise */
5840 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
5843 * TODO: add a bit to radiotap RX flags that indicates
5844 * that the sending station is not associated, then
5845 * add a filter here that filters on our DA and that flag
5846 * to allow us to deauth frames to that bad station.
5848 * For now allow all To DS data frames through.
5850 /* load the IEEE 802.11 frame control field */
5851 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
5852 /* mask off frame type, version and DS status */
5853 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
5854 /* accept frame if version 0, type 2 and To DS, fall through otherwise
5856 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
5860 * drop non-data frames
5862 /* load the lower byte of the frame control field */
5863 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
5864 /* mask off QoS bit */
5865 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
5866 /* drop non-data frames */
5867 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
5869 /* load the upper byte of the frame control field */
5870 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
5871 /* mask off toDS/fromDS */
5872 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
5873 /* accept WDS frames */
5874 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
5877 * add header length to index
5879 /* load the lower byte of the frame control field */
5880 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
5881 /* mask off QoS bit */
5882 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
5883 /* right shift it by 6 to give 0 or 2 */
5884 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
5885 /* add data frame header length */
5886 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
5887 /* add index, was start of 802.11 header */
5888 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
5889 /* move to index, now start of LL header */
5890 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
5893 * Accept empty data frames, we use those for
5896 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
5897 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
5900 * Accept EAPOL frames
5902 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
5903 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
5904 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
5905 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
5907 /* keep these last two statements or change the code below */
5908 /* return 0 == "DROP" */
5909 BPF_STMT(BPF_RET
| BPF_K
, 0),
5910 /* return ~0 == "keep all" */
5911 BPF_STMT(BPF_RET
| BPF_K
, ~0),
5914 static struct sock_fprog msock_filter
= {
5915 .len
= sizeof(msock_filter_insns
)/sizeof(msock_filter_insns
[0]),
5916 .filter
= msock_filter_insns
,
5920 static int add_monitor_filter(int s
)
5924 /* rewrite all PASS/FAIL jump offsets */
5925 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
5926 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
5928 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
5929 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
5930 if (insn
->k
== PASS
)
5931 insn
->k
= msock_filter
.len
- idx
- 2;
5932 else if (insn
->k
== FAIL
)
5933 insn
->k
= msock_filter
.len
- idx
- 3;
5936 if (insn
->jt
== PASS
)
5937 insn
->jt
= msock_filter
.len
- idx
- 2;
5938 else if (insn
->jt
== FAIL
)
5939 insn
->jt
= msock_filter
.len
- idx
- 3;
5941 if (insn
->jf
== PASS
)
5942 insn
->jf
= msock_filter
.len
- idx
- 2;
5943 else if (insn
->jf
== FAIL
)
5944 insn
->jf
= msock_filter
.len
- idx
- 3;
5948 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
5949 &msock_filter
, sizeof(msock_filter
))) {
5950 perror("SO_ATTACH_FILTER");
5958 static void nl80211_remove_monitor_interface(
5959 struct wpa_driver_nl80211_data
*drv
)
5961 drv
->monitor_refcount
--;
5962 if (drv
->monitor_refcount
> 0)
5965 if (drv
->monitor_ifidx
>= 0) {
5966 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
5967 drv
->monitor_ifidx
= -1;
5969 if (drv
->monitor_sock
>= 0) {
5970 eloop_unregister_read_sock(drv
->monitor_sock
);
5971 close(drv
->monitor_sock
);
5972 drv
->monitor_sock
= -1;
5978 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
5981 struct sockaddr_ll ll
;
5985 if (drv
->monitor_ifidx
>= 0) {
5986 drv
->monitor_refcount
++;
5990 if (os_strncmp(drv
->first_bss
.ifname
, "p2p-", 4) == 0) {
5992 * P2P interface name is of the format p2p-%s-%d. For monitor
5993 * interface name corresponding to P2P GO, replace "p2p-" with
5994 * "mon-" to retain the same interface name length and to
5995 * indicate that it is a monitor interface.
5997 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
.ifname
+ 4);
5999 /* Non-P2P interface with AP functionality. */
6000 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
.ifname
);
6003 buf
[IFNAMSIZ
- 1] = '\0';
6005 drv
->monitor_ifidx
=
6006 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
6009 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
6011 * This is backward compatibility for a few versions of
6012 * the kernel only that didn't advertise the right
6013 * attributes for the only driver that then supported
6014 * AP mode w/o monitor -- ath6kl.
6016 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
6017 "monitor interface type - try to run without it");
6018 drv
->device_ap_sme
= 1;
6021 if (drv
->monitor_ifidx
< 0)
6024 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
6027 memset(&ll
, 0, sizeof(ll
));
6028 ll
.sll_family
= AF_PACKET
;
6029 ll
.sll_ifindex
= drv
->monitor_ifidx
;
6030 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
6031 if (drv
->monitor_sock
< 0) {
6032 perror("socket[PF_PACKET,SOCK_RAW]");
6036 if (add_monitor_filter(drv
->monitor_sock
)) {
6037 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
6038 "interface; do filtering in user space");
6039 /* This works, but will cost in performance. */
6042 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
6043 perror("monitor socket bind");
6047 optlen
= sizeof(optval
);
6050 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
6051 perror("Failed to set socket priority");
6055 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
6057 printf("Could not register monitor read socket\n");
6063 nl80211_remove_monitor_interface(drv
);
6068 static int nl80211_setup_ap(struct i802_bss
*bss
)
6070 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6072 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP - device_ap_sme=%d "
6073 "use_monitor=%d", drv
->device_ap_sme
, drv
->use_monitor
);
6076 * Disable Probe Request reporting unless we need it in this way for
6077 * devices that include the AP SME, in the other case (unless using
6078 * monitor iface) we'll get it through the nl_mgmt socket instead.
6080 if (!drv
->device_ap_sme
)
6081 wpa_driver_nl80211_probe_req_report(bss
, 0);
6083 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
6084 if (nl80211_mgmt_subscribe_ap(bss
))
6087 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
6088 nl80211_create_monitor_interface(drv
) &&
6089 !drv
->device_ap_sme
)
6092 if (drv
->device_ap_sme
&&
6093 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
6094 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
6095 "Probe Request frame reporting in AP mode");
6096 /* Try to survive without this */
6103 static void nl80211_teardown_ap(struct i802_bss
*bss
)
6105 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6107 if (drv
->device_ap_sme
)
6108 wpa_driver_nl80211_probe_req_report(bss
, 0);
6109 else if (drv
->use_monitor
)
6110 nl80211_remove_monitor_interface(drv
);
6112 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
6114 bss
->beacon_set
= 0;
6118 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
6119 const u8
*addr
, const u8
*data
,
6122 struct sockaddr_ll ll
;
6125 if (bss
->drv
->eapol_tx_sock
< 0) {
6126 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
6130 os_memset(&ll
, 0, sizeof(ll
));
6131 ll
.sll_family
= AF_PACKET
;
6132 ll
.sll_ifindex
= bss
->ifindex
;
6133 ll
.sll_protocol
= htons(ETH_P_PAE
);
6134 ll
.sll_halen
= ETH_ALEN
;
6135 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
6136 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
6137 (struct sockaddr
*) &ll
, sizeof(ll
));
6139 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
6146 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
6148 static int wpa_driver_nl80211_hapd_send_eapol(
6149 void *priv
, const u8
*addr
, const u8
*data
,
6150 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
6152 struct i802_bss
*bss
= priv
;
6153 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6154 struct ieee80211_hdr
*hdr
;
6158 int qos
= flags
& WPA_STA_WMM
;
6160 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
6161 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
6163 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
6165 hdr
= os_zalloc(len
);
6167 printf("malloc() failed for i802_send_data(len=%lu)\n",
6168 (unsigned long) len
);
6172 hdr
->frame_control
=
6173 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
6174 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
6176 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
6178 hdr
->frame_control
|=
6179 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
6182 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
6183 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
6184 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
6185 pos
= (u8
*) (hdr
+ 1);
6188 /* add an empty QoS header if needed */
6194 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
6195 pos
+= sizeof(rfc1042_header
);
6196 WPA_PUT_BE16(pos
, ETH_P_PAE
);
6198 memcpy(pos
, data
, data_len
);
6200 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0);
6202 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
6204 (unsigned long) len
, errno
, strerror(errno
));
6212 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
6214 int flags_or
, int flags_and
)
6216 struct i802_bss
*bss
= priv
;
6217 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6218 struct nl_msg
*msg
, *flags
= NULL
;
6219 struct nl80211_sta_flag_update upd
;
6221 msg
= nlmsg_alloc();
6225 flags
= nlmsg_alloc();
6231 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
6233 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6234 if_nametoindex(bss
->ifname
));
6235 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6238 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
6239 * can be removed eventually.
6241 if (total_flags
& WPA_STA_AUTHORIZED
)
6242 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_AUTHORIZED
);
6244 if (total_flags
& WPA_STA_WMM
)
6245 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_WME
);
6247 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
6248 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
6250 if (total_flags
& WPA_STA_MFP
)
6251 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_MFP
);
6253 if (total_flags
& WPA_STA_TDLS_PEER
)
6254 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_TDLS_PEER
);
6256 if (nla_put_nested(msg
, NL80211_ATTR_STA_FLAGS
, flags
))
6257 goto nla_put_failure
;
6259 os_memset(&upd
, 0, sizeof(upd
));
6260 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
6261 upd
.set
= sta_flags_nl80211(flags_or
);
6262 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6266 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6274 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
6275 struct wpa_driver_associate_params
*params
)
6277 enum nl80211_iftype nlmode
;
6280 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
6282 nlmode
= NL80211_IFTYPE_P2P_GO
;
6284 nlmode
= NL80211_IFTYPE_AP
;
6286 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
, nlmode
) ||
6287 wpa_driver_nl80211_set_freq(&drv
->first_bss
, params
->freq
, 0, 0)) {
6288 nl80211_remove_monitor_interface(drv
);
6296 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
6301 msg
= nlmsg_alloc();
6305 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
6306 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6307 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6310 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
6311 "(%s)", ret
, strerror(-ret
));
6312 goto nla_put_failure
;
6316 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
6324 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
6325 struct wpa_driver_associate_params
*params
)
6331 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
6333 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
6334 NL80211_IFTYPE_ADHOC
)) {
6335 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
6341 msg
= nlmsg_alloc();
6345 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
6346 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6348 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
6349 goto nla_put_failure
;
6351 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6352 params
->ssid
, params
->ssid_len
);
6353 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6355 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6356 drv
->ssid_len
= params
->ssid_len
;
6358 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6359 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6361 ret
= nl80211_set_conn_keys(params
, msg
);
6363 goto nla_put_failure
;
6365 if (params
->wpa_ie
) {
6366 wpa_hexdump(MSG_DEBUG
,
6367 " * Extra IEs for Beacon/Probe Response frames",
6368 params
->wpa_ie
, params
->wpa_ie_len
);
6369 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6373 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6376 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
6377 ret
, strerror(-ret
));
6379 if (ret
== -EALREADY
&& count
== 1) {
6380 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
6382 nl80211_leave_ibss(drv
);
6387 goto nla_put_failure
;
6390 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
6398 static unsigned int nl80211_get_assoc_bssid(struct wpa_driver_nl80211_data
*drv
,
6403 struct nl80211_bss_info_arg arg
;
6405 os_memset(&arg
, 0, sizeof(arg
));
6406 msg
= nlmsg_alloc();
6408 goto nla_put_failure
;
6410 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
6411 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6414 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
6417 if (is_zero_ether_addr(arg
.assoc_bssid
))
6419 os_memcpy(bssid
, arg
.assoc_bssid
, ETH_ALEN
);
6422 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
6423 "(%s)", ret
, strerror(-ret
));
6426 return drv
->assoc_freq
;
6430 static int nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
6435 if (bssid
== NULL
) {
6436 int res
= nl80211_get_assoc_bssid(drv
, addr
);
6442 return wpa_driver_nl80211_disconnect(drv
, bssid
,
6443 WLAN_REASON_PREV_AUTH_NOT_VALID
);
6447 static int wpa_driver_nl80211_connect(
6448 struct wpa_driver_nl80211_data
*drv
,
6449 struct wpa_driver_associate_params
*params
)
6452 enum nl80211_auth_type type
;
6456 msg
= nlmsg_alloc();
6460 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
6461 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
6463 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6464 if (params
->bssid
) {
6465 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
6466 MAC2STR(params
->bssid
));
6467 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
6470 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6471 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6474 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6475 params
->ssid
, params
->ssid_len
);
6476 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6478 if (params
->ssid_len
> sizeof(drv
->ssid
))
6479 goto nla_put_failure
;
6480 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6481 drv
->ssid_len
= params
->ssid_len
;
6483 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
6485 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6489 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
6491 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
6493 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
6496 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
6498 goto skip_auth_type
;
6501 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
6502 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
6503 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
6504 type
= NL80211_AUTHTYPE_SHARED_KEY
;
6505 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
6506 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
6507 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
6508 type
= NL80211_AUTHTYPE_FT
;
6510 goto nla_put_failure
;
6512 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
6513 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
6516 if (params
->wpa_proto
) {
6517 enum nl80211_wpa_versions ver
= 0;
6519 if (params
->wpa_proto
& WPA_PROTO_WPA
)
6520 ver
|= NL80211_WPA_VERSION_1
;
6521 if (params
->wpa_proto
& WPA_PROTO_RSN
)
6522 ver
|= NL80211_WPA_VERSION_2
;
6524 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
6525 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
6528 if (params
->pairwise_suite
!= CIPHER_NONE
) {
6531 switch (params
->pairwise_suite
) {
6533 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6536 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6539 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6543 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6546 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
6549 if (params
->group_suite
!= CIPHER_NONE
) {
6552 switch (params
->group_suite
) {
6554 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6557 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6560 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6564 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6567 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
6570 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
6571 params
->key_mgmt_suite
== KEY_MGMT_PSK
) {
6572 int mgmt
= WLAN_AKM_SUITE_PSK
;
6574 switch (params
->key_mgmt_suite
) {
6575 case KEY_MGMT_802_1X
:
6576 mgmt
= WLAN_AKM_SUITE_8021X
;
6580 mgmt
= WLAN_AKM_SUITE_PSK
;
6583 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
6586 ret
= nl80211_set_conn_keys(params
, msg
);
6588 goto nla_put_failure
;
6590 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6593 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
6594 "(%s)", ret
, strerror(-ret
));
6596 * cfg80211 does not currently accept new connection if we are
6597 * already connected. As a workaround, force disconnection and
6598 * try again once the driver indicates it completed
6601 if (ret
== -EALREADY
)
6602 nl80211_disconnect(drv
, params
->bssid
);
6603 goto nla_put_failure
;
6606 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
6615 static int wpa_driver_nl80211_associate(
6616 void *priv
, struct wpa_driver_associate_params
*params
)
6618 struct i802_bss
*bss
= priv
;
6619 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6623 if (params
->mode
== IEEE80211_MODE_AP
)
6624 return wpa_driver_nl80211_ap(drv
, params
);
6626 if (params
->mode
== IEEE80211_MODE_IBSS
)
6627 return wpa_driver_nl80211_ibss(drv
, params
);
6629 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
6630 enum nl80211_iftype nlmode
= params
->p2p
?
6631 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
6633 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
6635 return wpa_driver_nl80211_connect(drv
, params
);
6638 drv
->associated
= 0;
6640 msg
= nlmsg_alloc();
6644 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
6646 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
6648 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6649 if (params
->bssid
) {
6650 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
6651 MAC2STR(params
->bssid
));
6652 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
6655 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6656 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6657 drv
->assoc_freq
= params
->freq
;
6659 drv
->assoc_freq
= 0;
6661 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6662 params
->ssid
, params
->ssid_len
);
6663 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6665 if (params
->ssid_len
> sizeof(drv
->ssid
))
6666 goto nla_put_failure
;
6667 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6668 drv
->ssid_len
= params
->ssid_len
;
6670 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
6672 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6675 if (params
->pairwise_suite
!= CIPHER_NONE
) {
6678 switch (params
->pairwise_suite
) {
6680 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6683 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6686 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6690 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6693 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
6694 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
6697 if (params
->group_suite
!= CIPHER_NONE
) {
6700 switch (params
->group_suite
) {
6702 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6705 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6708 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6712 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6715 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
6716 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
6719 #ifdef CONFIG_IEEE80211W
6720 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
6721 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
6722 #endif /* CONFIG_IEEE80211W */
6724 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
6726 if (params
->prev_bssid
) {
6727 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
6728 MAC2STR(params
->prev_bssid
));
6729 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
6730 params
->prev_bssid
);
6734 wpa_printf(MSG_DEBUG
, " * P2P group");
6736 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6739 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
6740 "nl80211: MLME command failed (assoc): ret=%d (%s)",
6741 ret
, strerror(-ret
));
6742 nl80211_dump_scan(drv
);
6743 goto nla_put_failure
;
6746 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
6755 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
6756 int ifindex
, enum nl80211_iftype mode
)
6761 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
6762 ifindex
, mode
, nl80211_iftype_str(mode
));
6764 msg
= nlmsg_alloc();
6768 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
6769 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
6770 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
6772 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6778 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
6779 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
6784 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
6785 enum nl80211_iftype nlmode
)
6787 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6790 int was_ap
= is_ap_interface(drv
->nlmode
);
6793 res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
6795 drv
->nlmode
= nlmode
;
6803 if (nlmode
== drv
->nlmode
) {
6804 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
6805 "requested mode - ignore error");
6807 goto done
; /* Already in the requested mode */
6810 /* mac80211 doesn't allow mode changes while the device is up, so
6811 * take the device down, try to set the mode again, and bring the
6814 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
6816 for (i
= 0; i
< 10; i
++) {
6817 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
6819 if (res
== -EACCES
|| res
== -ENODEV
)
6822 /* Try to set the mode again while the interface is
6824 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
6827 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
6831 else if (ret
!= -EBUSY
)
6834 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
6836 os_sleep(0, 100000);
6840 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
6841 "interface is down");
6842 drv
->nlmode
= nlmode
;
6843 drv
->ignore_if_down_event
= 1;
6848 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
6849 "from %d failed", nlmode
, drv
->nlmode
);
6853 if (is_ap_interface(nlmode
)) {
6854 nl80211_mgmt_unsubscribe(bss
, "start AP");
6855 /* Setup additional AP mode functionality if needed */
6856 if (nl80211_setup_ap(bss
))
6858 } else if (was_ap
) {
6859 /* Remove additional AP mode functionality */
6860 nl80211_teardown_ap(bss
);
6862 nl80211_mgmt_unsubscribe(bss
, "mode change");
6865 if (!is_ap_interface(nlmode
) &&
6866 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
6867 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
6868 "frame processing - ignore for now");
6874 static int wpa_driver_nl80211_get_capa(void *priv
,
6875 struct wpa_driver_capa
*capa
)
6877 struct i802_bss
*bss
= priv
;
6878 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6879 if (!drv
->has_capability
)
6881 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
6886 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
6888 struct i802_bss
*bss
= priv
;
6889 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6891 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
6892 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
6893 drv
->operstate
= state
;
6894 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
6895 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
6899 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
6901 struct i802_bss
*bss
= priv
;
6902 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6904 struct nl80211_sta_flag_update upd
;
6906 msg
= nlmsg_alloc();
6910 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
6912 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6913 if_nametoindex(bss
->ifname
));
6914 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
6916 os_memset(&upd
, 0, sizeof(upd
));
6917 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6919 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6920 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6922 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6929 /* Set kernel driver on given frequency (MHz) */
6930 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
6932 struct i802_bss
*bss
= priv
;
6933 return wpa_driver_nl80211_set_freq(bss
, freq
->freq
, freq
->ht_enabled
,
6934 freq
->sec_channel_offset
);
6938 #if defined(HOSTAPD) || defined(CONFIG_AP)
6940 static inline int min_int(int a
, int b
)
6948 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
6950 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6951 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6953 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6954 genlmsg_attrlen(gnlh
, 0), NULL
);
6957 * TODO: validate the key index and mac address!
6958 * Otherwise, there's a race condition as soon as
6959 * the kernel starts sending key notifications.
6962 if (tb
[NL80211_ATTR_KEY_SEQ
])
6963 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
6964 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
6969 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
6972 struct i802_bss
*bss
= priv
;
6973 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6976 msg
= nlmsg_alloc();
6980 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
6983 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6984 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
6985 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
6989 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
6996 static int i802_set_rts(void *priv
, int rts
)
6998 struct i802_bss
*bss
= priv
;
6999 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7004 msg
= nlmsg_alloc();
7013 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7014 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7015 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
7017 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7023 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
7024 "%d (%s)", rts
, ret
, strerror(-ret
));
7029 static int i802_set_frag(void *priv
, int frag
)
7031 struct i802_bss
*bss
= priv
;
7032 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7037 msg
= nlmsg_alloc();
7046 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7047 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7048 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
7050 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7056 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
7057 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
7062 static int i802_flush(void *priv
)
7064 struct i802_bss
*bss
= priv
;
7065 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7069 msg
= nlmsg_alloc();
7073 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
7076 * XXX: FIX! this needs to flush all VLANs too
7078 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7079 if_nametoindex(bss
->ifname
));
7081 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7083 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
7084 "(%s)", res
, strerror(-res
));
7093 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
7095 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7096 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7097 struct hostap_sta_driver_data
*data
= arg
;
7098 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
7099 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
7100 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
7101 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
7102 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
7103 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
7104 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
7107 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7108 genlmsg_attrlen(gnlh
, 0), NULL
);
7111 * TODO: validate the interface and mac address!
7112 * Otherwise, there's a race condition as soon as
7113 * the kernel starts sending station notifications.
7116 if (!tb
[NL80211_ATTR_STA_INFO
]) {
7117 wpa_printf(MSG_DEBUG
, "sta stats missing!");
7120 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
7121 tb
[NL80211_ATTR_STA_INFO
],
7123 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
7127 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
7128 data
->inactive_msec
=
7129 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
7130 if (stats
[NL80211_STA_INFO_RX_BYTES
])
7131 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
7132 if (stats
[NL80211_STA_INFO_TX_BYTES
])
7133 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
7134 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
7136 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
7137 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
7139 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
7144 static int i802_read_sta_data(void *priv
, struct hostap_sta_driver_data
*data
,
7147 struct i802_bss
*bss
= priv
;
7148 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7151 os_memset(data
, 0, sizeof(*data
));
7152 msg
= nlmsg_alloc();
7156 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
7158 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7159 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7161 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
7168 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
7169 int cw_min
, int cw_max
, int burst_time
)
7171 struct i802_bss
*bss
= priv
;
7172 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7174 struct nlattr
*txq
, *params
;
7176 msg
= nlmsg_alloc();
7180 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7182 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7184 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
7186 goto nla_put_failure
;
7188 /* We are only sending parameters for a single TXQ at a time */
7189 params
= nla_nest_start(msg
, 1);
7191 goto nla_put_failure
;
7195 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
7198 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
7201 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
7204 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
7207 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
7208 * 32 usec, so need to convert the value here. */
7209 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
7210 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
7211 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
7212 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
7214 nla_nest_end(msg
, params
);
7216 nla_nest_end(msg
, txq
);
7218 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
7227 static int i802_set_sta_vlan(void *priv
, const u8
*addr
,
7228 const char *ifname
, int vlan_id
)
7230 struct i802_bss
*bss
= priv
;
7231 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7235 msg
= nlmsg_alloc();
7239 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7241 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7242 if_nametoindex(bss
->ifname
));
7243 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7244 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
7245 if_nametoindex(ifname
));
7247 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7250 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
7251 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
7252 MAC2STR(addr
), ifname
, vlan_id
, ret
,
7261 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
7263 struct hostap_sta_driver_data data
;
7266 data
.inactive_msec
= (unsigned long) -1;
7267 ret
= i802_read_sta_data(priv
, &data
, addr
);
7268 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
7270 return data
.inactive_msec
/ 1000;
7274 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
7283 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
7286 struct i802_bss
*bss
= priv
;
7287 struct ieee80211_mgmt mgmt
;
7289 memset(&mgmt
, 0, sizeof(mgmt
));
7290 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
7291 WLAN_FC_STYPE_DEAUTH
);
7292 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
7293 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
7294 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
7295 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
7296 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
7298 sizeof(mgmt
.u
.deauth
), 0);
7302 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
7305 struct i802_bss
*bss
= priv
;
7306 struct ieee80211_mgmt mgmt
;
7308 memset(&mgmt
, 0, sizeof(mgmt
));
7309 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
7310 WLAN_FC_STYPE_DISASSOC
);
7311 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
7312 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
7313 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
7314 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
7315 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
7317 sizeof(mgmt
.u
.disassoc
), 0);
7320 #endif /* HOSTAPD || CONFIG_AP */
7324 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7329 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
7331 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
7332 if (drv
->if_indices
[i
] == 0) {
7333 drv
->if_indices
[i
] = ifidx
;
7338 if (drv
->if_indices
!= drv
->default_if_indices
)
7339 old
= drv
->if_indices
;
7343 drv
->if_indices
= os_realloc(old
,
7344 sizeof(int) * (drv
->num_if_indices
+ 1));
7345 if (!drv
->if_indices
) {
7347 drv
->if_indices
= drv
->default_if_indices
;
7349 drv
->if_indices
= old
;
7350 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
7352 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
7355 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
7356 sizeof(drv
->default_if_indices
));
7357 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
7358 drv
->num_if_indices
++;
7362 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7366 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
7367 if (drv
->if_indices
[i
] == ifidx
) {
7368 drv
->if_indices
[i
] = 0;
7375 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7379 for (i
= 0; i
< drv
->num_if_indices
; i
++)
7380 if (drv
->if_indices
[i
] == ifidx
)
7387 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
7388 const char *bridge_ifname
)
7390 struct i802_bss
*bss
= priv
;
7391 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7392 char name
[IFNAMSIZ
+ 1];
7394 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
7395 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
7396 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
7398 if (!if_nametoindex(name
)) {
7399 if (nl80211_create_iface(drv
, name
,
7400 NL80211_IFTYPE_AP_VLAN
,
7403 if (bridge_ifname
&&
7404 linux_br_add_if(drv
->global
->ioctl_sock
,
7405 bridge_ifname
, name
) < 0)
7408 linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1);
7409 return i802_set_sta_vlan(priv
, addr
, name
, 0);
7411 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
7412 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
7418 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
7420 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
7421 struct sockaddr_ll lladdr
;
7422 unsigned char buf
[3000];
7424 socklen_t fromlen
= sizeof(lladdr
);
7426 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
7427 (struct sockaddr
*)&lladdr
, &fromlen
);
7433 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
7434 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
7438 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
7439 struct i802_bss
*bss
,
7440 const char *brname
, const char *ifname
)
7443 char in_br
[IFNAMSIZ
];
7445 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
7446 ifindex
= if_nametoindex(brname
);
7449 * Bridge was configured, but the bridge device does
7450 * not exist. Try to add it now.
7452 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
7453 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
7454 "bridge interface %s: %s",
7455 brname
, strerror(errno
));
7458 bss
->added_bridge
= 1;
7459 add_ifidx(drv
, if_nametoindex(brname
));
7462 if (linux_br_get(in_br
, ifname
) == 0) {
7463 if (os_strcmp(in_br
, brname
) == 0)
7464 return 0; /* already in the bridge */
7466 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
7467 "bridge %s", ifname
, in_br
);
7468 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
7470 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
7471 "remove interface %s from bridge "
7473 ifname
, brname
, strerror(errno
));
7478 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
7480 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
7481 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
7482 "into bridge %s: %s",
7483 ifname
, brname
, strerror(errno
));
7486 bss
->added_if_into_bridge
= 1;
7492 static void *i802_init(struct hostapd_data
*hapd
,
7493 struct wpa_init_params
*params
)
7495 struct wpa_driver_nl80211_data
*drv
;
7496 struct i802_bss
*bss
;
7498 char brname
[IFNAMSIZ
];
7499 int ifindex
, br_ifindex
;
7502 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
7503 params
->global_priv
);
7508 drv
->nlmode
= NL80211_IFTYPE_AP
;
7509 drv
->eapol_sock
= -1;
7511 if (linux_br_get(brname
, params
->ifname
) == 0) {
7512 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
7513 params
->ifname
, brname
);
7514 br_ifindex
= if_nametoindex(brname
);
7520 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
7521 drv
->if_indices
= drv
->default_if_indices
;
7522 for (i
= 0; i
< params
->num_bridge
; i
++) {
7523 if (params
->bridge
[i
]) {
7524 ifindex
= if_nametoindex(params
->bridge
[i
]);
7526 add_ifidx(drv
, ifindex
);
7527 if (ifindex
== br_ifindex
)
7531 if (!br_added
&& br_ifindex
&&
7532 (params
->num_bridge
== 0 || !params
->bridge
[0]))
7533 add_ifidx(drv
, br_ifindex
);
7535 /* start listening for EAPOL on the default AP interface */
7536 add_ifidx(drv
, drv
->ifindex
);
7538 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
7541 if (params
->bssid
) {
7542 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7547 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
7548 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
7549 "into AP mode", bss
->ifname
);
7553 if (params
->num_bridge
&& params
->bridge
[0] &&
7554 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
7557 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
7560 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
7561 if (drv
->eapol_sock
< 0) {
7562 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
7566 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
7568 printf("Could not register read socket for eapol\n");
7572 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7576 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
7581 wpa_driver_nl80211_deinit(bss
);
7586 static void i802_deinit(void *priv
)
7588 wpa_driver_nl80211_deinit(priv
);
7591 #endif /* HOSTAPD */
7594 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
7595 enum wpa_driver_if_type type
)
7598 case WPA_IF_STATION
:
7599 return NL80211_IFTYPE_STATION
;
7600 case WPA_IF_P2P_CLIENT
:
7601 case WPA_IF_P2P_GROUP
:
7602 return NL80211_IFTYPE_P2P_CLIENT
;
7603 case WPA_IF_AP_VLAN
:
7604 return NL80211_IFTYPE_AP_VLAN
;
7606 return NL80211_IFTYPE_AP
;
7608 return NL80211_IFTYPE_P2P_GO
;
7616 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
7618 struct wpa_driver_nl80211_data
*drv
;
7619 dl_list_for_each(drv
, &global
->interfaces
,
7620 struct wpa_driver_nl80211_data
, list
) {
7621 if (os_memcmp(addr
, drv
->first_bss
.addr
, ETH_ALEN
) == 0)
7628 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
7636 os_memcpy(new_addr
, drv
->first_bss
.addr
, ETH_ALEN
);
7637 for (idx
= 0; idx
< 64; idx
++) {
7638 new_addr
[0] = drv
->first_bss
.addr
[0] | 0x02;
7639 new_addr
[0] ^= idx
<< 2;
7640 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
7646 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
7647 MACSTR
, MAC2STR(new_addr
));
7652 #endif /* CONFIG_P2P */
7655 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
7656 const char *ifname
, const u8
*addr
,
7657 void *bss_ctx
, void **drv_priv
,
7658 char *force_ifname
, u8
*if_addr
,
7661 struct i802_bss
*bss
= priv
;
7662 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7665 struct i802_bss
*new_bss
= NULL
;
7667 if (type
== WPA_IF_AP_BSS
) {
7668 new_bss
= os_zalloc(sizeof(*new_bss
));
7669 if (new_bss
== NULL
)
7672 #endif /* HOSTAPD */
7675 os_memcpy(if_addr
, addr
, ETH_ALEN
);
7676 ifidx
= nl80211_create_iface(drv
, ifname
,
7677 wpa_driver_nl80211_if_type(type
), addr
,
7682 #endif /* HOSTAPD */
7687 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7689 nl80211_remove_iface(drv
, ifidx
);
7695 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
7696 type
== WPA_IF_P2P_GO
)) {
7697 /* Enforce unique P2P Interface Address */
7698 u8 new_addr
[ETH_ALEN
], own_addr
[ETH_ALEN
];
7700 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7702 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
7704 nl80211_remove_iface(drv
, ifidx
);
7707 if (os_memcmp(own_addr
, new_addr
, ETH_ALEN
) == 0) {
7708 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
7709 "for P2P group interface");
7710 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
7711 nl80211_remove_iface(drv
, ifidx
);
7714 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
7716 nl80211_remove_iface(drv
, ifidx
);
7720 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
7722 #endif /* CONFIG_P2P */
7726 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
7727 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
7728 "interface %s to a bridge %s", ifname
, bridge
);
7729 nl80211_remove_iface(drv
, ifidx
);
7734 if (type
== WPA_IF_AP_BSS
) {
7735 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
7737 nl80211_remove_iface(drv
, ifidx
);
7741 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
7742 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
7743 new_bss
->ifindex
= ifidx
;
7745 new_bss
->next
= drv
->first_bss
.next
;
7746 drv
->first_bss
.next
= new_bss
;
7748 *drv_priv
= new_bss
;
7749 nl80211_init_bss(new_bss
);
7751 #endif /* HOSTAPD */
7754 drv
->global
->if_add_ifindex
= ifidx
;
7760 static int wpa_driver_nl80211_if_remove(void *priv
,
7761 enum wpa_driver_if_type type
,
7764 struct i802_bss
*bss
= priv
;
7765 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7766 int ifindex
= if_nametoindex(ifname
);
7768 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d",
7769 __func__
, type
, ifname
, ifindex
);
7774 if (bss
->added_if_into_bridge
) {
7775 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
7777 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
7778 "interface %s from bridge %s: %s",
7779 bss
->ifname
, bss
->brname
, strerror(errno
));
7781 if (bss
->added_bridge
) {
7782 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
7783 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
7785 bss
->brname
, strerror(errno
));
7787 #endif /* HOSTAPD */
7789 nl80211_remove_iface(drv
, ifindex
);
7792 if (type
!= WPA_IF_AP_BSS
)
7795 if (bss
!= &drv
->first_bss
) {
7796 struct i802_bss
*tbss
;
7798 for (tbss
= &drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
7799 if (tbss
->next
== bss
) {
7800 tbss
->next
= bss
->next
;
7801 nl80211_destroy_bss(bss
);
7808 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
7809 "BSS %p in the list", __func__
, bss
);
7811 #endif /* HOSTAPD */
7817 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
7819 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7820 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7822 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7823 genlmsg_attrlen(gnlh
, 0), NULL
);
7824 if (tb
[NL80211_ATTR_COOKIE
])
7825 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
7830 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
7831 unsigned int freq
, unsigned int wait
,
7832 const u8
*buf
, size_t buf_len
,
7833 u64
*cookie_out
, int no_cck
, int no_ack
,
7836 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7841 msg
= nlmsg_alloc();
7845 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
7847 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
7848 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7850 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
7852 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
7854 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
7856 NLA_PUT_FLAG(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
);
7858 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
7861 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
7864 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
7865 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
7867 goto nla_put_failure
;
7869 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX command accepted%s; "
7870 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
7871 (long long unsigned int) cookie
);
7874 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
7882 static int wpa_driver_nl80211_send_action(void *priv
, unsigned int freq
,
7883 unsigned int wait_time
,
7884 const u8
*dst
, const u8
*src
,
7886 const u8
*data
, size_t data_len
,
7889 struct i802_bss
*bss
= priv
;
7890 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7893 struct ieee80211_hdr
*hdr
;
7895 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
7896 "wait=%d ms no_cck=%d)", drv
->ifindex
, wait_time
, no_cck
);
7898 buf
= os_zalloc(24 + data_len
);
7901 os_memcpy(buf
+ 24, data
, data_len
);
7902 hdr
= (struct ieee80211_hdr
*) buf
;
7903 hdr
->frame_control
=
7904 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
7905 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
7906 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
7907 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
7909 if (is_ap_interface(drv
->nlmode
))
7910 ret
= wpa_driver_nl80211_send_mlme(priv
, buf
, 24 + data_len
,
7913 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
7915 &drv
->send_action_cookie
,
7923 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
7925 struct i802_bss
*bss
= priv
;
7926 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7930 msg
= nlmsg_alloc();
7934 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
7936 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7937 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
7939 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7942 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
7943 "(%s)", ret
, strerror(-ret
));
7950 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
7951 unsigned int duration
)
7953 struct i802_bss
*bss
= priv
;
7954 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7959 msg
= nlmsg_alloc();
7963 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
7965 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7966 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7967 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
7970 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
7973 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
7974 "0x%llx for freq=%u MHz duration=%u",
7975 (long long unsigned int) cookie
, freq
, duration
);
7976 drv
->remain_on_chan_cookie
= cookie
;
7977 drv
->pending_remain_on_chan
= 1;
7980 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
7981 "(freq=%d duration=%u): %d (%s)",
7982 freq
, duration
, ret
, strerror(-ret
));
7989 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
7991 struct i802_bss
*bss
= priv
;
7992 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7996 if (!drv
->pending_remain_on_chan
) {
7997 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
8002 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
8004 (long long unsigned int) drv
->remain_on_chan_cookie
);
8006 msg
= nlmsg_alloc();
8010 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
8012 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8013 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
8015 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8019 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
8020 "%d (%s)", ret
, strerror(-ret
));
8027 static int wpa_driver_nl80211_probe_req_report(void *priv
, int report
)
8029 struct i802_bss
*bss
= priv
;
8030 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8034 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
8035 "reporting nl_preq=%p", bss
->nl_preq
);
8036 eloop_unregister_read_sock(
8037 nl_socket_get_fd(bss
->nl_preq
));
8038 nl_destroy_handles(&bss
->nl_preq
);
8044 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
8045 "already on! nl_preq=%p", bss
->nl_preq
);
8049 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
8050 if (bss
->nl_preq
== NULL
)
8052 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
8053 "reporting nl_preq=%p", bss
->nl_preq
);
8055 if (nl80211_register_frame(bss
, bss
->nl_preq
,
8056 (WLAN_FC_TYPE_MGMT
<< 2) |
8057 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
8061 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_preq
),
8062 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
8068 nl_destroy_handles(&bss
->nl_preq
);
8073 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
8074 int ifindex
, int disabled
)
8077 struct nlattr
*bands
, *band
;
8080 msg
= nlmsg_alloc();
8084 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
8085 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
8087 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
8089 goto nla_put_failure
;
8092 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
8093 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
8094 * rates. All 5 GHz rates are left enabled.
8096 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
8098 goto nla_put_failure
;
8100 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
8101 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
8103 nla_nest_end(msg
, band
);
8105 nla_nest_end(msg
, bands
);
8107 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8110 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
8111 "(%s)", ret
, strerror(-ret
));
8122 static int wpa_driver_nl80211_deinit_ap(void *priv
)
8124 struct i802_bss
*bss
= priv
;
8125 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8126 if (!is_ap_interface(drv
->nlmode
))
8128 wpa_driver_nl80211_del_beacon(drv
);
8129 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
8133 static void wpa_driver_nl80211_resume(void *priv
)
8135 struct i802_bss
*bss
= priv
;
8136 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8137 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
8138 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on "
8144 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
8145 const u8
*ies
, size_t ies_len
)
8147 struct i802_bss
*bss
= priv
;
8148 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8152 const u8
*own_addr
= bss
->addr
;
8155 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
8156 "action %d", action
);
8161 * Action frame payload:
8162 * Category[1] = 6 (Fast BSS Transition)
8163 * Action[1] = 1 (Fast BSS Transition Request)
8169 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
8170 data
= os_malloc(data_len
);
8174 *pos
++ = 0x06; /* FT Action category */
8176 os_memcpy(pos
, own_addr
, ETH_ALEN
);
8178 os_memcpy(pos
, target_ap
, ETH_ALEN
);
8180 os_memcpy(pos
, ies
, ies_len
);
8182 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
8183 drv
->bssid
, own_addr
, drv
->bssid
,
8191 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
8193 struct i802_bss
*bss
= priv
;
8194 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8195 struct nl_msg
*msg
, *cqm
= NULL
;
8197 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
8198 "hysteresis=%d", threshold
, hysteresis
);
8200 msg
= nlmsg_alloc();
8204 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
8206 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8208 cqm
= nlmsg_alloc();
8212 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
8213 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
8214 nla_put_nested(msg
, NL80211_ATTR_CQM
, cqm
);
8216 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
8227 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
8229 struct i802_bss
*bss
= priv
;
8230 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8233 os_memset(si
, 0, sizeof(*si
));
8234 res
= nl80211_get_link_signal(drv
, si
);
8238 return nl80211_get_link_noise(drv
, si
);
8242 static int wpa_driver_nl80211_shared_freq(void *priv
)
8244 struct i802_bss
*bss
= priv
;
8245 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8246 struct wpa_driver_nl80211_data
*driver
;
8250 * If the same PHY is in connected state with some other interface,
8251 * then retrieve the assoc freq.
8253 wpa_printf(MSG_DEBUG
, "nl80211: Get shared freq for PHY %s",
8256 dl_list_for_each(driver
, &drv
->global
->interfaces
,
8257 struct wpa_driver_nl80211_data
, list
) {
8258 if (drv
== driver
||
8259 os_strcmp(drv
->phyname
, driver
->phyname
) != 0 ||
8260 !driver
->associated
)
8263 wpa_printf(MSG_DEBUG
, "nl80211: Found a match for PHY %s - %s "
8265 driver
->phyname
, driver
->first_bss
.ifname
,
8266 MAC2STR(driver
->first_bss
.addr
));
8267 freq
= nl80211_get_assoc_freq(driver
);
8268 wpa_printf(MSG_DEBUG
, "nl80211: Shared freq for PHY %s: %d",
8269 drv
->phyname
, freq
);
8273 wpa_printf(MSG_DEBUG
, "nl80211: No shared interface for "
8274 "PHY (%s) in associated state", drv
->phyname
);
8280 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
8283 struct i802_bss
*bss
= priv
;
8284 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0);
8288 static int nl80211_set_param(void *priv
, const char *param
)
8290 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
8295 if (os_strstr(param
, "use_p2p_group_interface=1")) {
8296 struct i802_bss
*bss
= priv
;
8297 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8299 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
8301 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
8302 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
8304 #endif /* CONFIG_P2P */
8310 static void * nl80211_global_init(void)
8312 struct nl80211_global
*global
;
8313 struct netlink_config
*cfg
;
8315 global
= os_zalloc(sizeof(*global
));
8318 global
->ioctl_sock
= -1;
8319 dl_list_init(&global
->interfaces
);
8320 global
->if_add_ifindex
= -1;
8322 cfg
= os_zalloc(sizeof(*cfg
));
8327 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
8328 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
8329 global
->netlink
= netlink_init(cfg
);
8330 if (global
->netlink
== NULL
) {
8335 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
8338 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
8339 if (global
->ioctl_sock
< 0) {
8340 perror("socket(PF_INET,SOCK_DGRAM)");
8347 nl80211_global_deinit(global
);
8352 static void nl80211_global_deinit(void *priv
)
8354 struct nl80211_global
*global
= priv
;
8357 if (!dl_list_empty(&global
->interfaces
)) {
8358 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
8359 "nl80211_global_deinit",
8360 dl_list_len(&global
->interfaces
));
8363 if (global
->netlink
)
8364 netlink_deinit(global
->netlink
);
8366 nl_destroy_handles(&global
->nl
);
8368 if (global
->nl_event
) {
8369 eloop_unregister_read_sock(
8370 nl_socket_get_fd(global
->nl_event
));
8371 nl_destroy_handles(&global
->nl_event
);
8374 nl_cb_put(global
->nl_cb
);
8376 if (global
->ioctl_sock
>= 0)
8377 close(global
->ioctl_sock
);
8383 static const char * nl80211_get_radio_name(void *priv
)
8385 struct i802_bss
*bss
= priv
;
8386 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8387 return drv
->phyname
;
8391 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
8396 msg
= nlmsg_alloc();
8400 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
8402 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8404 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
8406 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
8408 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8415 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
8417 struct i802_bss
*bss
= priv
;
8418 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
8419 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
8423 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
8425 struct i802_bss
*bss
= priv
;
8426 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
8428 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
8432 static int nl80211_flush_pmkid(void *priv
)
8434 struct i802_bss
*bss
= priv
;
8435 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
8436 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
8440 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
8441 const u8
*replay_ctr
)
8443 struct i802_bss
*bss
= priv
;
8444 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8445 struct nlattr
*replay_nested
;
8448 msg
= nlmsg_alloc();
8452 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8454 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8456 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8458 goto nla_put_failure
;
8460 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
8461 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
8462 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
8465 nla_nest_end(msg
, replay_nested
);
8467 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8474 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
8475 const u8
*addr
, int qos
)
8477 /* send data frame to poll STA and check whether
8478 * this frame is ACKed */
8480 struct ieee80211_hdr hdr
;
8482 } STRUCT_PACKED nulldata
;
8485 /* Send data frame to poll STA and check whether this frame is ACKed */
8487 os_memset(&nulldata
, 0, sizeof(nulldata
));
8490 nulldata
.hdr
.frame_control
=
8491 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
8492 WLAN_FC_STYPE_QOS_NULL
);
8493 size
= sizeof(nulldata
);
8495 nulldata
.hdr
.frame_control
=
8496 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
8497 WLAN_FC_STYPE_NULLFUNC
);
8498 size
= sizeof(struct ieee80211_hdr
);
8501 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
8502 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
8503 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
8504 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
8506 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0) < 0)
8507 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
8511 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
8514 struct i802_bss
*bss
= priv
;
8515 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8518 if (!drv
->poll_command_supported
) {
8519 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
8523 msg
= nlmsg_alloc();
8527 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_PROBE_CLIENT
);
8529 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8530 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8532 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8539 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
8543 msg
= nlmsg_alloc();
8547 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_SET_POWER_SAVE
);
8548 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8549 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
,
8550 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
);
8551 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8558 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
8561 struct i802_bss
*bss
= priv
;
8563 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
8564 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
8566 if (opp_ps
!= -1 || ctwindow
!= -1)
8567 return -1; /* Not yet supported */
8569 if (legacy_ps
== -1)
8571 if (legacy_ps
!= 0 && legacy_ps
!= 1)
8572 return -1; /* Not yet supported */
8574 return nl80211_set_power_save(bss
, legacy_ps
);
8580 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
8581 u8 dialog_token
, u16 status_code
,
8582 const u8
*buf
, size_t len
)
8584 struct i802_bss
*bss
= priv
;
8585 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8588 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8594 msg
= nlmsg_alloc();
8598 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_MGMT
);
8599 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8600 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
8601 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
);
8602 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
);
8603 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
);
8604 NLA_PUT(msg
, NL80211_ATTR_IE
, len
, buf
);
8606 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8614 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
8616 struct i802_bss
*bss
= priv
;
8617 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8619 enum nl80211_tdls_operation nl80211_oper
;
8621 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8625 case TDLS_DISCOVERY_REQ
:
8626 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
8629 nl80211_oper
= NL80211_TDLS_SETUP
;
8632 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
8634 case TDLS_ENABLE_LINK
:
8635 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
8637 case TDLS_DISABLE_LINK
:
8638 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
8648 msg
= nlmsg_alloc();
8652 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_OPER
);
8653 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
);
8654 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8655 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
8657 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8664 #endif /* CONFIG TDLS */
8669 typedef struct android_wifi_priv_cmd
{
8673 } android_wifi_priv_cmd
;
8675 static int drv_errors
= 0;
8677 static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data
*drv
)
8680 if (drv_errors
> DRV_NUMBER_SEQUENTIAL_ERRORS
) {
8682 wpa_msg(drv
->ctx
, MSG_INFO
, WPA_EVENT_DRIVER_STATE
"HANGED");
8687 static int android_priv_cmd(struct i802_bss
*bss
, const char *cmd
)
8689 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8691 android_wifi_priv_cmd priv_cmd
;
8692 char buf
[MAX_DRV_CMD_SIZE
];
8695 os_memset(&ifr
, 0, sizeof(ifr
));
8696 os_memset(&priv_cmd
, 0, sizeof(priv_cmd
));
8697 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
8699 os_memset(buf
, 0, sizeof(buf
));
8700 os_strlcpy(buf
, cmd
, sizeof(buf
));
8703 priv_cmd
.used_len
= sizeof(buf
);
8704 priv_cmd
.total_len
= sizeof(buf
);
8705 ifr
.ifr_data
= &priv_cmd
;
8707 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
8709 wpa_printf(MSG_ERROR
, "%s: failed to issue private commands",
8711 wpa_driver_send_hang_msg(drv
);
8720 static int android_pno_start(struct i802_bss
*bss
,
8721 struct wpa_driver_scan_params
*params
)
8723 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8725 android_wifi_priv_cmd priv_cmd
;
8726 int ret
= 0, i
= 0, bp
;
8727 char buf
[WEXT_PNO_MAX_COMMAND_SIZE
];
8729 bp
= WEXT_PNOSETUP_HEADER_SIZE
;
8730 os_memcpy(buf
, WEXT_PNOSETUP_HEADER
, bp
);
8731 buf
[bp
++] = WEXT_PNO_TLV_PREFIX
;
8732 buf
[bp
++] = WEXT_PNO_TLV_VERSION
;
8733 buf
[bp
++] = WEXT_PNO_TLV_SUBVERSION
;
8734 buf
[bp
++] = WEXT_PNO_TLV_RESERVED
;
8736 while (i
< WEXT_PNO_AMOUNT
&& (size_t) i
< params
->num_ssids
) {
8737 /* Check that there is enough space needed for 1 more SSID, the
8738 * other sections and null termination */
8739 if ((bp
+ WEXT_PNO_SSID_HEADER_SIZE
+ MAX_SSID_LEN
+
8740 WEXT_PNO_NONSSID_SECTIONS_SIZE
+ 1) >= (int) sizeof(buf
))
8742 wpa_hexdump_ascii(MSG_DEBUG
, "For PNO Scan",
8743 params
->ssids
[i
].ssid
,
8744 params
->ssids
[i
].ssid_len
);
8745 buf
[bp
++] = WEXT_PNO_SSID_SECTION
;
8746 buf
[bp
++] = params
->ssids
[i
].ssid_len
;
8747 os_memcpy(&buf
[bp
], params
->ssids
[i
].ssid
,
8748 params
->ssids
[i
].ssid_len
);
8749 bp
+= params
->ssids
[i
].ssid_len
;
8753 buf
[bp
++] = WEXT_PNO_SCAN_INTERVAL_SECTION
;
8754 os_snprintf(&buf
[bp
], WEXT_PNO_SCAN_INTERVAL_LENGTH
+ 1, "%x",
8755 WEXT_PNO_SCAN_INTERVAL
);
8756 bp
+= WEXT_PNO_SCAN_INTERVAL_LENGTH
;
8758 buf
[bp
++] = WEXT_PNO_REPEAT_SECTION
;
8759 os_snprintf(&buf
[bp
], WEXT_PNO_REPEAT_LENGTH
+ 1, "%x",
8761 bp
+= WEXT_PNO_REPEAT_LENGTH
;
8763 buf
[bp
++] = WEXT_PNO_MAX_REPEAT_SECTION
;
8764 os_snprintf(&buf
[bp
], WEXT_PNO_MAX_REPEAT_LENGTH
+ 1, "%x",
8765 WEXT_PNO_MAX_REPEAT
);
8766 bp
+= WEXT_PNO_MAX_REPEAT_LENGTH
+ 1;
8768 memset(&ifr
, 0, sizeof(ifr
));
8769 memset(&priv_cmd
, 0, sizeof(priv_cmd
));
8770 os_strncpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
8773 priv_cmd
.used_len
= bp
;
8774 priv_cmd
.total_len
= bp
;
8775 ifr
.ifr_data
= &priv_cmd
;
8777 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
8780 wpa_printf(MSG_ERROR
, "ioctl[SIOCSIWPRIV] (pnosetup): %d",
8782 wpa_driver_send_hang_msg(drv
);
8788 return android_priv_cmd(bss
, "PNOFORCE 1");
8792 static int android_pno_stop(struct i802_bss
*bss
)
8794 return android_priv_cmd(bss
, "PNOFORCE 0");
8797 #endif /* ANDROID */
8800 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
8802 .desc
= "Linux nl80211/cfg80211",
8803 .get_bssid
= wpa_driver_nl80211_get_bssid
,
8804 .get_ssid
= wpa_driver_nl80211_get_ssid
,
8805 .set_key
= wpa_driver_nl80211_set_key
,
8806 .scan2
= wpa_driver_nl80211_scan
,
8807 .sched_scan
= wpa_driver_nl80211_sched_scan
,
8808 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
8809 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
8810 .deauthenticate
= wpa_driver_nl80211_deauthenticate
,
8811 .disassociate
= wpa_driver_nl80211_disassociate
,
8812 .authenticate
= wpa_driver_nl80211_authenticate
,
8813 .associate
= wpa_driver_nl80211_associate
,
8814 .global_init
= nl80211_global_init
,
8815 .global_deinit
= nl80211_global_deinit
,
8816 .init2
= wpa_driver_nl80211_init
,
8817 .deinit
= wpa_driver_nl80211_deinit
,
8818 .get_capa
= wpa_driver_nl80211_get_capa
,
8819 .set_operstate
= wpa_driver_nl80211_set_operstate
,
8820 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
8821 .set_country
= wpa_driver_nl80211_set_country
,
8822 .set_ap
= wpa_driver_nl80211_set_ap
,
8823 .if_add
= wpa_driver_nl80211_if_add
,
8824 .if_remove
= wpa_driver_nl80211_if_remove
,
8825 .send_mlme
= wpa_driver_nl80211_send_mlme
,
8826 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
8827 .sta_add
= wpa_driver_nl80211_sta_add
,
8828 .sta_remove
= wpa_driver_nl80211_sta_remove
,
8829 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
8830 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
8832 .hapd_init
= i802_init
,
8833 .hapd_deinit
= i802_deinit
,
8834 .set_wds_sta
= i802_set_wds_sta
,
8835 #endif /* HOSTAPD */
8836 #if defined(HOSTAPD) || defined(CONFIG_AP)
8837 .get_seqnum
= i802_get_seqnum
,
8838 .flush
= i802_flush
,
8839 .read_sta_data
= i802_read_sta_data
,
8840 .get_inact_sec
= i802_get_inact_sec
,
8841 .sta_clear_stats
= i802_sta_clear_stats
,
8842 .set_rts
= i802_set_rts
,
8843 .set_frag
= i802_set_frag
,
8844 .set_tx_queue_params
= i802_set_tx_queue_params
,
8845 .set_sta_vlan
= i802_set_sta_vlan
,
8846 .sta_deauth
= i802_sta_deauth
,
8847 .sta_disassoc
= i802_sta_disassoc
,
8848 #endif /* HOSTAPD || CONFIG_AP */
8849 .set_freq
= i802_set_freq
,
8850 .send_action
= wpa_driver_nl80211_send_action
,
8851 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
8852 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
8853 .cancel_remain_on_channel
=
8854 wpa_driver_nl80211_cancel_remain_on_channel
,
8855 .probe_req_report
= wpa_driver_nl80211_probe_req_report
,
8856 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
8857 .resume
= wpa_driver_nl80211_resume
,
8858 .send_ft_action
= nl80211_send_ft_action
,
8859 .signal_monitor
= nl80211_signal_monitor
,
8860 .signal_poll
= nl80211_signal_poll
,
8861 .send_frame
= nl80211_send_frame
,
8862 .shared_freq
= wpa_driver_nl80211_shared_freq
,
8863 .set_param
= nl80211_set_param
,
8864 .get_radio_name
= nl80211_get_radio_name
,
8865 .add_pmkid
= nl80211_add_pmkid
,
8866 .remove_pmkid
= nl80211_remove_pmkid
,
8867 .flush_pmkid
= nl80211_flush_pmkid
,
8868 .set_rekey_info
= nl80211_set_rekey_info
,
8869 .poll_client
= nl80211_poll_client
,
8870 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
8872 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
8873 .tdls_oper
= nl80211_tdls_oper
,
8874 #endif /* CONFIG_TDLS */