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;
2275 static unsigned int probe_resp_offload_support(int supp_protocols
)
2277 unsigned int prot
= 0;
2279 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
)
2280 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
;
2281 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
)
2282 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
;
2283 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
)
2284 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
;
2285 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
)
2286 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
;
2292 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
2294 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2295 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2296 struct wiphy_info_data
*info
= arg
;
2297 int p2p_go_supported
= 0, p2p_client_supported
= 0;
2298 int p2p_concurrent
= 0;
2299 int auth_supported
= 0, connect_supported
= 0;
2300 struct wpa_driver_capa
*capa
= info
->capa
;
2301 static struct nla_policy
2302 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
2303 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
2304 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
2305 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
2306 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
2308 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
2309 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
2310 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
2313 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2314 genlmsg_attrlen(gnlh
, 0), NULL
);
2316 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
2317 capa
->max_scan_ssids
=
2318 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
2320 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
2321 capa
->max_sched_scan_ssids
=
2322 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
2324 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
2325 capa
->max_match_sets
=
2326 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
2328 if (tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]) {
2329 struct nlattr
*nl_mode
;
2331 nla_for_each_nested(nl_mode
,
2332 tb
[NL80211_ATTR_SUPPORTED_IFTYPES
], i
) {
2333 switch (nla_type(nl_mode
)) {
2334 case NL80211_IFTYPE_AP
:
2335 capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
2337 case NL80211_IFTYPE_P2P_GO
:
2338 p2p_go_supported
= 1;
2340 case NL80211_IFTYPE_P2P_CLIENT
:
2341 p2p_client_supported
= 1;
2347 if (tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]) {
2348 struct nlattr
*nl_combi
;
2351 nla_for_each_nested(nl_combi
,
2352 tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
],
2354 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
2355 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
2356 struct nlattr
*nl_limit
, *nl_mode
;
2357 int err
, rem_limit
, rem_mode
;
2358 int combination_has_p2p
= 0, combination_has_mgd
= 0;
2360 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
2362 iface_combination_policy
);
2363 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
2364 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
2365 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
2366 goto broken_combination
;
2368 nla_for_each_nested(nl_limit
,
2369 tb_comb
[NL80211_IFACE_COMB_LIMITS
],
2371 err
= nla_parse_nested(tb_limit
,
2372 MAX_NL80211_IFACE_LIMIT
,
2374 iface_limit_policy
);
2376 !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
2377 goto broken_combination
;
2379 nla_for_each_nested(
2381 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
2383 int ift
= nla_type(nl_mode
);
2384 if (ift
== NL80211_IFTYPE_P2P_GO
||
2385 ift
== NL80211_IFTYPE_P2P_CLIENT
)
2386 combination_has_p2p
= 1;
2387 if (ift
== NL80211_IFTYPE_STATION
)
2388 combination_has_mgd
= 1;
2390 if (combination_has_p2p
&& combination_has_mgd
)
2394 if (combination_has_p2p
&& combination_has_mgd
) {
2404 if (tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]) {
2405 struct nlattr
*nl_cmd
;
2408 nla_for_each_nested(nl_cmd
,
2409 tb
[NL80211_ATTR_SUPPORTED_COMMANDS
], i
) {
2410 switch (nla_get_u32(nl_cmd
)) {
2411 case NL80211_CMD_AUTHENTICATE
:
2414 case NL80211_CMD_CONNECT
:
2415 connect_supported
= 1;
2417 case NL80211_CMD_START_SCHED_SCAN
:
2418 capa
->sched_scan_supported
= 1;
2420 case NL80211_CMD_PROBE_CLIENT
:
2421 info
->poll_command_supported
= 1;
2427 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
2428 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
2430 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
2433 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
2434 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
2435 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
2438 /* default to 5000 since early versions of mac80211 don't set it */
2439 capa
->max_remain_on_chan
= 5000;
2441 if (tb
[NL80211_ATTR_SUPPORT_AP_UAPSD
])
2442 capa
->flags
|= WPA_DRIVER_FLAGS_AP_UAPSD
;
2444 if (tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
])
2445 capa
->max_remain_on_chan
=
2446 nla_get_u32(tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
2449 capa
->flags
|= WPA_DRIVER_FLAGS_SME
;
2450 else if (!connect_supported
) {
2451 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
2452 "authentication/association or connect commands");
2456 if (p2p_go_supported
&& p2p_client_supported
)
2457 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
2458 if (p2p_concurrent
) {
2459 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
2460 "interface (driver advertised support)");
2461 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
2462 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
2465 if (tb
[NL80211_ATTR_TDLS_SUPPORT
]) {
2466 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
2467 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
2469 if (tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]) {
2470 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
2472 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
2476 if (tb
[NL80211_ATTR_DEVICE_AP_SME
])
2477 info
->device_ap_sme
= 1;
2479 if (tb
[NL80211_ATTR_FEATURE_FLAGS
]) {
2480 u32 flags
= nla_get_u32(tb
[NL80211_ATTR_FEATURE_FLAGS
]);
2482 if (flags
& NL80211_FEATURE_SK_TX_STATUS
)
2483 info
->data_tx_status
= 1;
2486 if (tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]) {
2488 nla_get_u32(tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]);
2489 wpa_printf(MSG_DEBUG
, "nl80211: Supports Probe Response "
2490 "offload in AP mode");
2491 capa
->flags
|= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
;
2492 capa
->probe_resp_offloads
=
2493 probe_resp_offload_support(protocols
);
2500 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
2501 struct wiphy_info_data
*info
)
2505 os_memset(info
, 0, sizeof(*info
));
2506 info
->capa
= &drv
->capa
;
2508 msg
= nlmsg_alloc();
2512 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
2514 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->first_bss
.ifindex
);
2516 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
) == 0)
2525 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
2527 struct wiphy_info_data info
;
2528 if (wpa_driver_nl80211_get_info(drv
, &info
))
2534 drv
->has_capability
= 1;
2535 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
2536 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2537 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2538 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2539 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
2540 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
2541 WPA_DRIVER_CAPA_ENC_WEP104
|
2542 WPA_DRIVER_CAPA_ENC_TKIP
|
2543 WPA_DRIVER_CAPA_ENC_CCMP
;
2544 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
2545 WPA_DRIVER_AUTH_SHARED
|
2546 WPA_DRIVER_AUTH_LEAP
;
2548 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
2549 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
2550 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2551 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
2553 drv
->device_ap_sme
= info
.device_ap_sme
;
2554 drv
->poll_command_supported
= info
.poll_command_supported
;
2555 drv
->data_tx_status
= info
.data_tx_status
;
2558 * If poll command is supported mac80211 is new enough to
2559 * have everything we need to not need monitor interfaces.
2561 drv
->use_monitor
= !info
.poll_command_supported
;
2564 * If we aren't going to use monitor interfaces, but the
2565 * driver doesn't support data TX status, we won't get TX
2566 * status for EAPOL frames.
2568 if (!drv
->use_monitor
&& !info
.data_tx_status
)
2569 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2576 static int android_genl_ctrl_resolve(struct nl_handle
*handle
,
2580 * Android ICS has very minimal genl_ctrl_resolve() implementation, so
2581 * need to work around that.
2583 struct nl_cache
*cache
= NULL
;
2584 struct genl_family
*nl80211
= NULL
;
2587 if (genl_ctrl_alloc_cache(handle
, &cache
) < 0) {
2588 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate generic "
2593 nl80211
= genl_ctrl_search_by_name(cache
, name
);
2594 if (nl80211
== NULL
)
2597 id
= genl_family_get_id(nl80211
);
2601 genl_family_put(nl80211
);
2603 nl_cache_free(cache
);
2607 #define genl_ctrl_resolve android_genl_ctrl_resolve
2608 #endif /* ANDROID */
2611 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
2615 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2616 if (global
->nl_cb
== NULL
) {
2617 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
2622 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
2623 if (global
->nl
== NULL
)
2626 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
2627 if (global
->nl80211_id
< 0) {
2628 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
2633 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
2634 if (global
->nl_event
== NULL
)
2637 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
2639 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2641 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2642 "membership for scan events: %d (%s)",
2643 ret
, strerror(-ret
));
2647 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
2649 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2651 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2652 "membership for mlme events: %d (%s)",
2653 ret
, strerror(-ret
));
2657 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
2659 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
2661 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
2662 "membership for regulatory events: %d (%s)",
2663 ret
, strerror(-ret
));
2664 /* Continue without regulatory events */
2667 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2668 no_seq_check
, NULL
);
2669 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2670 process_global_event
, global
);
2672 eloop_register_read_sock(nl_socket_get_fd(global
->nl_event
),
2673 wpa_driver_nl80211_event_receive
,
2674 global
->nl_cb
, global
->nl_event
);
2679 nl_destroy_handles(&global
->nl_event
);
2680 nl_destroy_handles(&global
->nl
);
2681 nl_cb_put(global
->nl_cb
);
2682 global
->nl_cb
= NULL
;
2687 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
2689 drv
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2691 wpa_printf(MSG_ERROR
, "nl80211: Failed to alloc cb struct");
2695 nl_cb_set(drv
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2696 no_seq_check
, NULL
);
2697 nl_cb_set(drv
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2698 process_drv_event
, drv
);
2704 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
2706 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
2708 * This may be for any interface; use ifdown event to disable
2714 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
2716 struct wpa_driver_nl80211_data
*drv
= ctx
;
2717 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
2718 if (linux_set_iface_flags(drv
->global
->ioctl_sock
,
2719 drv
->first_bss
.ifname
, 1)) {
2720 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
2721 "after rfkill unblock");
2724 /* rtnetlink ifup handler will report interface as enabled */
2728 static void nl80211_get_phy_name(struct wpa_driver_nl80211_data
*drv
)
2730 /* Find phy (radio) to which this interface belongs */
2734 drv
->phyname
[0] = '\0';
2735 snprintf(buf
, sizeof(buf
) - 1, "/sys/class/net/%s/phy80211/name",
2736 drv
->first_bss
.ifname
);
2737 f
= open(buf
, O_RDONLY
);
2739 wpa_printf(MSG_DEBUG
, "Could not open file %s: %s",
2740 buf
, strerror(errno
));
2744 rv
= read(f
, drv
->phyname
, sizeof(drv
->phyname
) - 1);
2747 wpa_printf(MSG_DEBUG
, "Could not read file %s: %s",
2748 buf
, strerror(errno
));
2752 drv
->phyname
[rv
] = '\0';
2753 pos
= os_strchr(drv
->phyname
, '\n');
2756 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2757 drv
->first_bss
.ifname
, drv
->phyname
);
2761 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
2765 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
2773 struct cmsghdr
*cmsg
;
2774 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
2775 union wpa_event_data event
;
2777 memset(&msg
, 0, sizeof(msg
));
2778 msg
.msg_iov
= &entry
;
2780 entry
.iov_base
= data
;
2781 entry
.iov_len
= sizeof(data
);
2782 msg
.msg_control
= &control
;
2783 msg
.msg_controllen
= sizeof(control
);
2785 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
2786 /* if error or not fitting 802.3 header, return */
2790 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
2792 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
2793 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
2797 ack
= (void *)CMSG_DATA(cmsg
);
2801 if (cmsg
->cmsg_level
== SOL_PACKET
&&
2802 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
2803 struct sock_extended_err
*err
=
2804 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
2806 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
2811 if (!found_ee
|| !found_wifi
)
2814 memset(&event
, 0, sizeof(event
));
2815 event
.eapol_tx_status
.dst
= data
;
2816 event
.eapol_tx_status
.data
= data
+ 14;
2817 event
.eapol_tx_status
.data_len
= res
- 14;
2818 event
.eapol_tx_status
.ack
= acked
;
2819 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
2823 static int nl80211_init_bss(struct i802_bss
*bss
)
2825 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2829 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
2830 no_seq_check
, NULL
);
2831 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
2832 process_bss_event
, bss
);
2838 static void nl80211_destroy_bss(struct i802_bss
*bss
)
2840 nl_cb_put(bss
->nl_cb
);
2846 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2847 * @ctx: context to be used when calling wpa_supplicant functions,
2848 * e.g., wpa_supplicant_event()
2849 * @ifname: interface name, e.g., wlan0
2850 * @global_priv: private driver global data from global_init()
2851 * Returns: Pointer to private data, %NULL on failure
2853 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
2856 struct wpa_driver_nl80211_data
*drv
;
2857 struct rfkill_config
*rcfg
;
2858 struct i802_bss
*bss
;
2860 if (global_priv
== NULL
)
2862 drv
= os_zalloc(sizeof(*drv
));
2865 drv
->global
= global_priv
;
2867 bss
= &drv
->first_bss
;
2869 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
2870 drv
->monitor_ifidx
= -1;
2871 drv
->monitor_sock
= -1;
2872 drv
->eapol_tx_sock
= -1;
2873 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2875 if (wpa_driver_nl80211_init_nl(drv
)) {
2880 if (nl80211_init_bss(bss
))
2883 nl80211_get_phy_name(drv
);
2885 rcfg
= os_zalloc(sizeof(*rcfg
));
2889 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
2890 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
2891 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
2892 drv
->rfkill
= rfkill_init(rcfg
);
2893 if (drv
->rfkill
== NULL
) {
2894 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
2898 if (wpa_driver_nl80211_finish_drv_init(drv
))
2901 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
2902 if (drv
->eapol_tx_sock
< 0)
2905 if (drv
->data_tx_status
) {
2908 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
2909 &enabled
, sizeof(enabled
)) < 0) {
2910 wpa_printf(MSG_DEBUG
,
2911 "nl80211: wifi status sockopt failed\n");
2912 drv
->data_tx_status
= 0;
2913 if (!drv
->use_monitor
)
2915 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2917 eloop_register_read_sock(drv
->eapol_tx_sock
,
2918 wpa_driver_nl80211_handle_eapol_tx_status
,
2924 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
2925 drv
->in_interface_list
= 1;
2931 wpa_driver_nl80211_deinit(bss
);
2936 static int nl80211_register_frame(struct i802_bss
*bss
,
2937 struct nl_handle
*nl_handle
,
2938 u16 type
, const u8
*match
, size_t match_len
)
2940 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2944 msg
= nlmsg_alloc();
2948 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x nl_handle=%p",
2950 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
2953 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
2955 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
2956 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
2957 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
2959 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
2962 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
2963 "failed (type=%u): ret=%d (%s)",
2964 type
, ret
, strerror(-ret
));
2965 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
2967 goto nla_put_failure
;
2976 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
2978 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2981 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
2982 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
2986 bss
->nl_mgmt
= nl_create_handle(drv
->nl_cb
, "mgmt");
2987 if (bss
->nl_mgmt
== NULL
)
2990 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_mgmt
),
2991 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
2998 static int nl80211_register_action_frame(struct i802_bss
*bss
,
2999 const u8
*match
, size_t match_len
)
3001 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
3002 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
3003 type
, match
, match_len
);
3007 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
3009 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3011 if (nl80211_alloc_mgmt_handle(bss
))
3013 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
3014 "handle %p", bss
->nl_mgmt
);
3016 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
3017 /* GAS Initial Request */
3018 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
3020 /* GAS Initial Response */
3021 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
3023 /* GAS Comeback Request */
3024 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
3026 /* GAS Comeback Response */
3027 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
3029 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
3031 /* P2P Public Action */
3032 if (nl80211_register_action_frame(bss
,
3033 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
3037 if (nl80211_register_action_frame(bss
,
3038 (u8
*) "\x7f\x50\x6f\x9a\x09",
3041 #endif /* CONFIG_P2P */
3042 #ifdef CONFIG_IEEE80211W
3043 /* SA Query Response */
3044 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
3046 #endif /* CONFIG_IEEE80211W */
3048 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
3049 /* TDLS Discovery Response */
3050 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
3054 #endif /* CONFIG_TDLS */
3056 /* FT Action frames */
3057 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
3060 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
3061 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
3063 /* WNM - BSS Transition Management Request */
3064 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
3071 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
3073 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3077 msg
= nlmsg_alloc();
3081 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
3083 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3085 ret
= send_and_recv(drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
3088 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
3089 "failed: ret=%d (%s)",
3090 ret
, strerror(-ret
));
3091 goto nla_put_failure
;
3100 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
3102 static const int stypes
[] = {
3104 WLAN_FC_STYPE_ASSOC_REQ
,
3105 WLAN_FC_STYPE_REASSOC_REQ
,
3106 WLAN_FC_STYPE_DISASSOC
,
3107 WLAN_FC_STYPE_DEAUTH
,
3108 WLAN_FC_STYPE_ACTION
,
3109 WLAN_FC_STYPE_PROBE_REQ
,
3110 /* Beacon doesn't work as mac80211 doesn't currently allow
3111 * it, but it wouldn't really be the right thing anyway as
3112 * it isn't per interface ... maybe just dump the scan
3113 * results periodically for OLBC?
3115 // WLAN_FC_STYPE_BEACON,
3119 if (nl80211_alloc_mgmt_handle(bss
))
3121 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3122 "handle %p", bss
->nl_mgmt
);
3124 for (i
= 0; i
< sizeof(stypes
) / sizeof(stypes
[0]); i
++) {
3125 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3126 (WLAN_FC_TYPE_MGMT
<< 2) |
3133 if (nl80211_register_spurious_class3(bss
))
3136 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
3142 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3143 nl_destroy_handles(&bss
->nl_mgmt
);
3148 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
3150 if (bss
->nl_mgmt
== NULL
)
3152 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
3153 "(%s)", bss
->nl_mgmt
, reason
);
3154 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3155 nl_destroy_handles(&bss
->nl_mgmt
);
3157 nl80211_put_wiphy_data_ap(bss
);
3161 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
3163 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
3168 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
3170 struct i802_bss
*bss
= &drv
->first_bss
;
3171 int send_rfkill_event
= 0;
3173 drv
->ifindex
= if_nametoindex(bss
->ifname
);
3174 drv
->first_bss
.ifindex
= drv
->ifindex
;
3178 * Make sure the interface starts up in station mode unless this is a
3179 * dynamically added interface (e.g., P2P) that was already configured
3180 * with proper iftype.
3182 if (drv
->ifindex
!= drv
->global
->if_add_ifindex
&&
3183 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
) < 0) {
3184 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to "
3185 "use managed mode");
3189 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
3190 if (rfkill_is_blocked(drv
->rfkill
)) {
3191 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
3192 "interface '%s' due to rfkill",
3194 drv
->if_disabled
= 1;
3195 send_rfkill_event
= 1;
3197 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
3198 "interface '%s' UP", bss
->ifname
);
3203 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
3204 1, IF_OPER_DORMANT
);
3205 #endif /* HOSTAPD */
3207 if (wpa_driver_nl80211_capa(drv
))
3210 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
3214 if (send_rfkill_event
) {
3215 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
3223 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
3227 msg
= nlmsg_alloc();
3231 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
3232 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3234 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3242 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
3243 * @priv: Pointer to private nl80211 data from wpa_driver_nl80211_init()
3245 * Shut down driver interface and processing of driver events. Free
3246 * private data buffer if one was allocated in wpa_driver_nl80211_init().
3248 static void wpa_driver_nl80211_deinit(void *priv
)
3250 struct i802_bss
*bss
= priv
;
3251 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3253 if (drv
->data_tx_status
)
3254 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
3255 if (drv
->eapol_tx_sock
>= 0)
3256 close(drv
->eapol_tx_sock
);
3259 wpa_driver_nl80211_probe_req_report(bss
, 0);
3260 if (bss
->added_if_into_bridge
) {
3261 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
3263 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
3264 "interface %s from bridge %s: %s",
3265 bss
->ifname
, bss
->brname
, strerror(errno
));
3267 if (bss
->added_bridge
) {
3268 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
3269 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
3271 bss
->brname
, strerror(errno
));
3274 nl80211_remove_monitor_interface(drv
);
3276 if (is_ap_interface(drv
->nlmode
))
3277 wpa_driver_nl80211_del_beacon(drv
);
3280 if (drv
->last_freq_ht
) {
3281 /* Clear HT flags from the driver */
3282 struct hostapd_freq_params freq
;
3283 os_memset(&freq
, 0, sizeof(freq
));
3284 freq
.freq
= drv
->last_freq
;
3285 i802_set_freq(priv
, &freq
);
3288 if (drv
->eapol_sock
>= 0) {
3289 eloop_unregister_read_sock(drv
->eapol_sock
);
3290 close(drv
->eapol_sock
);
3293 if (drv
->if_indices
!= drv
->default_if_indices
)
3294 os_free(drv
->if_indices
);
3295 #endif /* HOSTAPD */
3297 if (drv
->disabled_11b_rates
)
3298 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
3300 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
3302 rfkill_deinit(drv
->rfkill
);
3304 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
3306 (void) linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0);
3307 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
3308 nl80211_mgmt_unsubscribe(bss
, "deinit");
3310 nl_cb_put(drv
->nl_cb
);
3312 nl80211_destroy_bss(&drv
->first_bss
);
3314 os_free(drv
->filter_ssids
);
3316 os_free(drv
->auth_ie
);
3318 if (drv
->in_interface_list
)
3319 dl_list_del(&drv
->list
);
3326 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
3327 * @eloop_ctx: Driver private data
3328 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
3330 * This function can be used as registered timeout when starting a scan to
3331 * generate a scan completed event if the driver does not report this.
3333 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
3335 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
3336 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
3337 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
3338 drv
->ap_scan_as_station
);
3339 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
3341 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
3342 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
3347 * wpa_driver_nl80211_scan - Request the driver to initiate scan
3348 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3349 * @params: Scan parameters
3350 * Returns: 0 on success, -1 on failure
3352 static int wpa_driver_nl80211_scan(void *priv
,
3353 struct wpa_driver_scan_params
*params
)
3355 struct i802_bss
*bss
= priv
;
3356 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3357 int ret
= 0, timeout
;
3358 struct nl_msg
*msg
, *ssids
, *freqs
, *rates
;
3361 drv
->scan_for_auth
= 0;
3363 msg
= nlmsg_alloc();
3364 ssids
= nlmsg_alloc();
3365 freqs
= nlmsg_alloc();
3366 rates
= nlmsg_alloc();
3367 if (!msg
|| !ssids
|| !freqs
|| !rates
) {
3375 os_free(drv
->filter_ssids
);
3376 drv
->filter_ssids
= params
->filter_ssids
;
3377 params
->filter_ssids
= NULL
;
3378 drv
->num_filter_ssids
= params
->num_filter_ssids
;
3380 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TRIGGER_SCAN
);
3382 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3384 for (i
= 0; i
< params
->num_ssids
; i
++) {
3385 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
3386 params
->ssids
[i
].ssid
,
3387 params
->ssids
[i
].ssid_len
);
3388 NLA_PUT(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
3389 params
->ssids
[i
].ssid
);
3391 if (params
->num_ssids
)
3392 nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
3394 if (params
->extra_ies
) {
3395 wpa_hexdump(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
3396 params
->extra_ies
, params
->extra_ies_len
);
3397 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
3401 if (params
->freqs
) {
3402 for (i
= 0; params
->freqs
[i
]; i
++) {
3403 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
3404 "MHz", params
->freqs
[i
]);
3405 NLA_PUT_U32(freqs
, i
+ 1, params
->freqs
[i
]);
3407 nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
, freqs
);
3410 if (params
->p2p_probe
) {
3412 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
3413 * by masking out everything else apart from the OFDM rates 6,
3414 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
3415 * rates are left enabled.
3417 NLA_PUT(rates
, NL80211_BAND_2GHZ
, 8,
3418 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
3419 nla_put_nested(msg
, NL80211_ATTR_SCAN_SUPP_RATES
, rates
);
3421 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
3424 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3427 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
3428 "(%s)", ret
, strerror(-ret
));
3430 if (is_ap_interface(drv
->nlmode
)) {
3432 * mac80211 does not allow scan requests in AP mode, so
3433 * try to do this in station mode.
3435 if (wpa_driver_nl80211_set_mode(
3436 bss
, NL80211_IFTYPE_STATION
))
3437 goto nla_put_failure
;
3439 if (wpa_driver_nl80211_scan(drv
, params
)) {
3440 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
3441 goto nla_put_failure
;
3444 /* Restore AP mode when processing scan results */
3445 drv
->ap_scan_as_station
= drv
->nlmode
;
3448 goto nla_put_failure
;
3450 goto nla_put_failure
;
3451 #endif /* HOSTAPD */
3454 /* Not all drivers generate "scan completed" wireless event, so try to
3455 * read results after a timeout. */
3457 if (drv
->scan_complete_events
) {
3459 * The driver seems to deliver events to notify when scan is
3460 * complete, so use longer timeout to avoid race conditions
3461 * with scanning and following association request.
3465 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
3466 "seconds", ret
, timeout
);
3467 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
3468 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
3481 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
3482 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3483 * @params: Scan parameters
3484 * @interval: Interval between scan cycles in milliseconds
3485 * Returns: 0 on success, -1 on failure or if not supported
3487 static int wpa_driver_nl80211_sched_scan(void *priv
,
3488 struct wpa_driver_scan_params
*params
,
3491 struct i802_bss
*bss
= priv
;
3492 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3494 struct nl_msg
*msg
, *ssids
, *freqs
, *match_set_ssid
, *match_sets
;
3498 if (!drv
->capa
.sched_scan_supported
)
3499 return android_pno_start(bss
, params
);
3500 #endif /* ANDROID */
3502 msg
= nlmsg_alloc();
3503 ssids
= nlmsg_alloc();
3504 freqs
= nlmsg_alloc();
3505 if (!msg
|| !ssids
|| !freqs
) {
3512 os_free(drv
->filter_ssids
);
3513 drv
->filter_ssids
= params
->filter_ssids
;
3514 params
->filter_ssids
= NULL
;
3515 drv
->num_filter_ssids
= params
->num_filter_ssids
;
3517 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_START_SCHED_SCAN
);
3519 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3521 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
3523 if (drv
->num_filter_ssids
&&
3524 (int) drv
->num_filter_ssids
<= drv
->capa
.max_match_sets
) {
3525 match_sets
= nlmsg_alloc();
3527 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
3528 wpa_hexdump_ascii(MSG_MSGDUMP
,
3529 "nl80211: Sched scan filter SSID",
3530 drv
->filter_ssids
[i
].ssid
,
3531 drv
->filter_ssids
[i
].ssid_len
);
3533 match_set_ssid
= nlmsg_alloc();
3534 nla_put(match_set_ssid
,
3535 NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
3536 drv
->filter_ssids
[i
].ssid_len
,
3537 drv
->filter_ssids
[i
].ssid
);
3539 nla_put_nested(match_sets
, i
+ 1, match_set_ssid
);
3541 nlmsg_free(match_set_ssid
);
3544 nla_put_nested(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
,
3546 nlmsg_free(match_sets
);
3549 for (i
= 0; i
< params
->num_ssids
; i
++) {
3550 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Sched scan SSID",
3551 params
->ssids
[i
].ssid
,
3552 params
->ssids
[i
].ssid_len
);
3553 NLA_PUT(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
3554 params
->ssids
[i
].ssid
);
3556 if (params
->num_ssids
)
3557 nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
3559 if (params
->extra_ies
) {
3560 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Sched scan extra IEs",
3561 params
->extra_ies
, params
->extra_ies_len
);
3562 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
3566 if (params
->freqs
) {
3567 for (i
= 0; params
->freqs
[i
]; i
++) {
3568 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
3569 "MHz", params
->freqs
[i
]);
3570 NLA_PUT_U32(freqs
, i
+ 1, params
->freqs
[i
]);
3572 nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
, freqs
);
3575 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3577 /* TODO: if we get an error here, we should fall back to normal scan */
3581 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
3582 "ret=%d (%s)", ret
, strerror(-ret
));
3583 goto nla_put_failure
;
3586 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
3587 "scan interval %d msec", ret
, interval
);
3598 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
3599 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
3600 * Returns: 0 on success, -1 on failure or if not supported
3602 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
3604 struct i802_bss
*bss
= priv
;
3605 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3610 if (!drv
->capa
.sched_scan_supported
)
3611 return android_pno_stop(bss
);
3612 #endif /* ANDROID */
3614 msg
= nlmsg_alloc();
3618 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
3620 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3622 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3625 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
3626 "ret=%d (%s)", ret
, strerror(-ret
));
3627 goto nla_put_failure
;
3630 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
3638 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
3640 const u8
*end
, *pos
;
3646 end
= ies
+ ies_len
;
3648 while (pos
+ 1 < end
) {
3649 if (pos
+ 2 + pos
[1] > end
)
3660 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
3661 const u8
*ie
, size_t ie_len
)
3666 if (drv
->filter_ssids
== NULL
)
3669 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
3673 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
3674 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
3675 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
3684 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
3686 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
3687 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3688 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
3689 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
3690 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
3691 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
3692 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
3693 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
3694 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
3695 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
3696 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
3697 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
3698 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
3699 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
3700 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
3702 struct nl80211_bss_info_arg
*_arg
= arg
;
3703 struct wpa_scan_results
*res
= _arg
->res
;
3704 struct wpa_scan_res
**tmp
;
3705 struct wpa_scan_res
*r
;
3706 const u8
*ie
, *beacon_ie
;
3707 size_t ie_len
, beacon_ie_len
;
3711 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3712 genlmsg_attrlen(gnlh
, 0), NULL
);
3713 if (!tb
[NL80211_ATTR_BSS
])
3715 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
3718 if (bss
[NL80211_BSS_STATUS
]) {
3719 enum nl80211_bss_status status
;
3720 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
3721 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
3722 bss
[NL80211_BSS_FREQUENCY
]) {
3724 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
3725 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
3728 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
3729 bss
[NL80211_BSS_BSSID
]) {
3730 os_memcpy(_arg
->assoc_bssid
,
3731 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
3732 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
3733 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
3738 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
3739 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
3740 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
3745 if (bss
[NL80211_BSS_BEACON_IES
]) {
3746 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
3747 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
3753 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
3754 ie
? ie_len
: beacon_ie_len
))
3757 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
3760 if (bss
[NL80211_BSS_BSSID
])
3761 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
3763 if (bss
[NL80211_BSS_FREQUENCY
])
3764 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
3765 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
3766 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
3767 if (bss
[NL80211_BSS_CAPABILITY
])
3768 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
3769 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
3770 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
3771 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
3772 r
->level
/= 100; /* mBm to dBm */
3773 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
3774 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
3775 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
3776 r
->flags
|= WPA_SCAN_QUAL_INVALID
;
3778 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
3779 if (bss
[NL80211_BSS_TSF
])
3780 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
3781 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
3782 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
3784 pos
= (u8
*) (r
+ 1);
3786 os_memcpy(pos
, ie
, ie_len
);
3789 r
->beacon_ie_len
= beacon_ie_len
;
3791 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
3793 if (bss
[NL80211_BSS_STATUS
]) {
3794 enum nl80211_bss_status status
;
3795 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
3797 case NL80211_BSS_STATUS_AUTHENTICATED
:
3798 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
3800 case NL80211_BSS_STATUS_ASSOCIATED
:
3801 r
->flags
|= WPA_SCAN_ASSOCIATED
;
3809 * cfg80211 maintains separate BSS table entries for APs if the same
3810 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
3811 * not use frequency as a separate key in the BSS table, so filter out
3812 * duplicated entries. Prefer associated BSS entry in such a case in
3813 * order to get the correct frequency into the BSS table.
3815 for (i
= 0; i
< res
->num
; i
++) {
3817 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
3820 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
3821 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
3822 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
3823 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
3824 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
3827 /* Same BSSID,SSID was already included in scan results */
3828 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
3829 "for " MACSTR
, MAC2STR(r
->bssid
));
3831 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
3832 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
3833 os_free(res
->res
[i
]);
3840 tmp
= os_realloc(res
->res
,
3841 (res
->num
+ 1) * sizeof(struct wpa_scan_res
*));
3846 tmp
[res
->num
++] = r
;
3853 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
3856 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
3857 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
3858 "mismatch (" MACSTR
")", MAC2STR(addr
));
3859 wpa_driver_nl80211_mlme(drv
, addr
,
3860 NL80211_CMD_DEAUTHENTICATE
,
3861 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
3866 static void wpa_driver_nl80211_check_bss_status(
3867 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
3871 for (i
= 0; i
< res
->num
; i
++) {
3872 struct wpa_scan_res
*r
= res
->res
[i
];
3873 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
3874 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
3875 "indicates BSS status with " MACSTR
3876 " as authenticated",
3878 if (is_sta_interface(drv
->nlmode
) &&
3879 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
3880 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
3882 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
3883 " in local state (auth=" MACSTR
3884 " assoc=" MACSTR
")",
3885 MAC2STR(drv
->auth_bssid
),
3886 MAC2STR(drv
->bssid
));
3887 clear_state_mismatch(drv
, r
->bssid
);
3891 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
3892 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
3893 "indicate BSS status with " MACSTR
3896 if (is_sta_interface(drv
->nlmode
) &&
3898 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
3899 "(not associated) does not match "
3901 clear_state_mismatch(drv
, r
->bssid
);
3902 } else if (is_sta_interface(drv
->nlmode
) &&
3903 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
3905 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
3906 "(associated with " MACSTR
") does "
3907 "not match with BSS state",
3908 MAC2STR(drv
->bssid
));
3909 clear_state_mismatch(drv
, r
->bssid
);
3910 clear_state_mismatch(drv
, drv
->bssid
);
3917 static struct wpa_scan_results
*
3918 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
3921 struct wpa_scan_results
*res
;
3923 struct nl80211_bss_info_arg arg
;
3925 res
= os_zalloc(sizeof(*res
));
3928 msg
= nlmsg_alloc();
3930 goto nla_put_failure
;
3932 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
3933 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3937 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
3940 wpa_printf(MSG_DEBUG
, "nl80211: Received scan results (%lu "
3941 "BSSes)", (unsigned long) res
->num
);
3942 nl80211_get_noise_for_scan_results(drv
, res
);
3945 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
3946 "(%s)", ret
, strerror(-ret
));
3949 wpa_scan_results_free(res
);
3955 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
3956 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
3957 * Returns: Scan results on success, -1 on failure
3959 static struct wpa_scan_results
*
3960 wpa_driver_nl80211_get_scan_results(void *priv
)
3962 struct i802_bss
*bss
= priv
;
3963 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3964 struct wpa_scan_results
*res
;
3966 res
= nl80211_get_scan_results(drv
);
3968 wpa_driver_nl80211_check_bss_status(drv
, res
);
3973 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
3975 struct wpa_scan_results
*res
;
3978 res
= nl80211_get_scan_results(drv
);
3980 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
3984 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
3985 for (i
= 0; i
< res
->num
; i
++) {
3986 struct wpa_scan_res
*r
= res
->res
[i
];
3987 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
3988 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
3989 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
3990 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
3993 wpa_scan_results_free(res
);
3997 static int wpa_driver_nl80211_set_key(const char *ifname
, void *priv
,
3998 enum wpa_alg alg
, const u8
*addr
,
3999 int key_idx
, int set_tx
,
4000 const u8
*seq
, size_t seq_len
,
4001 const u8
*key
, size_t key_len
)
4003 struct i802_bss
*bss
= priv
;
4004 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4005 int ifindex
= if_nametoindex(ifname
);
4009 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d alg=%d addr=%p key_idx=%d "
4010 "set_tx=%d seq_len=%lu key_len=%lu",
4011 __func__
, ifindex
, alg
, addr
, key_idx
, set_tx
,
4012 (unsigned long) seq_len
, (unsigned long) key_len
);
4016 #endif /* CONFIG_TDLS */
4018 msg
= nlmsg_alloc();
4022 if (alg
== WPA_ALG_NONE
) {
4023 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
4025 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
4026 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
4030 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4031 WLAN_CIPHER_SUITE_WEP40
);
4033 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4034 WLAN_CIPHER_SUITE_WEP104
);
4037 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4038 WLAN_CIPHER_SUITE_TKIP
);
4041 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4042 WLAN_CIPHER_SUITE_CCMP
);
4045 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4046 WLAN_CIPHER_SUITE_AES_CMAC
);
4049 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4050 "algorithm %d", __func__
, alg
);
4057 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
4059 if (addr
&& !is_broadcast_ether_addr(addr
)) {
4060 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
4061 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4063 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
4064 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
4065 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
4066 NL80211_KEYTYPE_GROUP
);
4068 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
4069 struct nl_msg
*types
;
4071 wpa_printf(MSG_DEBUG
, " broadcast key");
4072 types
= nlmsg_alloc();
4074 goto nla_put_failure
;
4075 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4076 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4080 goto nla_put_failure
;
4082 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4083 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4085 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4086 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
4089 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
4090 ret
, strerror(-ret
));
4093 * If we failed or don't need to set the default TX key (below),
4096 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
)
4098 if (is_ap_interface(drv
->nlmode
) && addr
&&
4099 !is_broadcast_ether_addr(addr
))
4102 msg
= nlmsg_alloc();
4106 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
4107 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4108 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4109 if (alg
== WPA_ALG_IGTK
)
4110 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
4112 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
4113 if (addr
&& is_broadcast_ether_addr(addr
)) {
4114 struct nl_msg
*types
;
4116 types
= nlmsg_alloc();
4118 goto nla_put_failure
;
4119 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4120 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4124 goto nla_put_failure
;
4126 struct nl_msg
*types
;
4128 types
= nlmsg_alloc();
4130 goto nla_put_failure
;
4131 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
4132 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
4136 goto nla_put_failure
;
4139 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4143 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
4144 "err=%d %s)", ret
, strerror(-ret
));
4153 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
4154 int key_idx
, int defkey
,
4155 const u8
*seq
, size_t seq_len
,
4156 const u8
*key
, size_t key_len
)
4158 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
4162 if (defkey
&& alg
== WPA_ALG_IGTK
)
4163 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
4165 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4167 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
4172 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4173 WLAN_CIPHER_SUITE_WEP40
);
4175 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4176 WLAN_CIPHER_SUITE_WEP104
);
4179 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
4182 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
4185 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4186 WLAN_CIPHER_SUITE_AES_CMAC
);
4189 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4190 "algorithm %d", __func__
, alg
);
4195 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
4197 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
4199 nla_nest_end(msg
, key_attr
);
4207 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
4211 struct nlattr
*nl_keys
, *nl_key
;
4213 for (i
= 0; i
< 4; i
++) {
4214 if (!params
->wep_key
[i
])
4219 if (params
->wps
== WPS_MODE_PRIVACY
)
4221 if (params
->pairwise_suite
&&
4222 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
4228 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
4230 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
4232 goto nla_put_failure
;
4234 for (i
= 0; i
< 4; i
++) {
4235 if (!params
->wep_key
[i
])
4238 nl_key
= nla_nest_start(msg
, i
);
4240 goto nla_put_failure
;
4242 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
4243 params
->wep_key
[i
]);
4244 if (params
->wep_key_len
[i
] == 5)
4245 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4246 WLAN_CIPHER_SUITE_WEP40
);
4248 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4249 WLAN_CIPHER_SUITE_WEP104
);
4251 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
4253 if (i
== params
->wep_tx_keyidx
)
4254 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4256 nla_nest_end(msg
, nl_key
);
4258 nla_nest_end(msg
, nl_keys
);
4267 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
4268 const u8
*addr
, int cmd
, u16 reason_code
,
4269 int local_state_change
)
4274 msg
= nlmsg_alloc();
4278 nl80211_cmd(drv
, msg
, 0, cmd
);
4280 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4281 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
4282 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4283 if (local_state_change
)
4284 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
4286 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4289 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4290 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
4291 reason_code
, ret
, strerror(-ret
));
4292 goto nla_put_failure
;
4302 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
4303 const u8
*addr
, int reason_code
)
4305 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
4306 __func__
, MAC2STR(addr
), reason_code
);
4307 drv
->associated
= 0;
4308 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISCONNECT
,
4313 static int wpa_driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
4316 struct i802_bss
*bss
= priv
;
4317 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4318 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
4319 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
4320 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
4321 __func__
, MAC2STR(addr
), reason_code
);
4322 drv
->associated
= 0;
4323 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
4324 return nl80211_leave_ibss(drv
);
4325 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
4330 static int wpa_driver_nl80211_disassociate(void *priv
, const u8
*addr
,
4333 struct i802_bss
*bss
= priv
;
4334 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4335 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
4336 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
4337 wpa_printf(MSG_DEBUG
, "%s", __func__
);
4338 drv
->associated
= 0;
4339 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISASSOCIATE
,
4344 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
4345 struct wpa_driver_auth_params
*params
)
4349 drv
->auth_freq
= params
->freq
;
4350 drv
->auth_alg
= params
->auth_alg
;
4351 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
4352 drv
->auth_local_state_change
= params
->local_state_change
;
4353 drv
->auth_p2p
= params
->p2p
;
4356 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
4358 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
4361 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
4362 drv
->auth_ssid_len
= params
->ssid_len
;
4364 drv
->auth_ssid_len
= 0;
4367 os_free(drv
->auth_ie
);
4368 drv
->auth_ie
= NULL
;
4369 drv
->auth_ie_len
= 0;
4371 drv
->auth_ie
= os_malloc(params
->ie_len
);
4373 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
4374 drv
->auth_ie_len
= params
->ie_len
;
4378 for (i
= 0; i
< 4; i
++) {
4379 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
4380 params
->wep_key_len
[i
] <= 16) {
4381 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
4382 params
->wep_key_len
[i
]);
4383 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
4385 drv
->auth_wep_key_len
[i
] = 0;
4390 static int wpa_driver_nl80211_authenticate(
4391 void *priv
, struct wpa_driver_auth_params
*params
)
4393 struct i802_bss
*bss
= priv
;
4394 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4397 enum nl80211_auth_type type
;
4398 enum nl80211_iftype nlmode
;
4402 is_retry
= drv
->retry_auth
;
4403 drv
->retry_auth
= 0;
4405 drv
->associated
= 0;
4406 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
4407 /* FIX: IBSS mode */
4408 nlmode
= params
->p2p
?
4409 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
4410 if (drv
->nlmode
!= nlmode
&&
4411 wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
4415 msg
= nlmsg_alloc();
4419 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
4422 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
4424 for (i
= 0; i
< 4; i
++) {
4425 if (!params
->wep_key
[i
])
4427 wpa_driver_nl80211_set_key(bss
->ifname
, priv
, WPA_ALG_WEP
,
4429 i
== params
->wep_tx_keyidx
, NULL
, 0,
4431 params
->wep_key_len
[i
]);
4432 if (params
->wep_tx_keyidx
!= i
)
4434 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
4435 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
4441 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4442 if (params
->bssid
) {
4443 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
4444 MAC2STR(params
->bssid
));
4445 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
4448 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
4449 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
4452 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
4453 params
->ssid
, params
->ssid_len
);
4454 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
4457 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
4459 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
4460 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
4461 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
4462 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
4463 type
= NL80211_AUTHTYPE_SHARED_KEY
;
4464 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
4465 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
4466 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
4467 type
= NL80211_AUTHTYPE_FT
;
4469 goto nla_put_failure
;
4470 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
4471 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
4472 if (params
->local_state_change
) {
4473 wpa_printf(MSG_DEBUG
, " * Local state change only");
4474 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
4477 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4480 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
4481 "nl80211: MLME command failed (auth): ret=%d (%s)",
4482 ret
, strerror(-ret
));
4484 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
4485 !params
->local_state_change
) {
4487 * mac80211 does not currently accept new
4488 * authentication if we are already authenticated. As a
4489 * workaround, force deauthentication and try again.
4491 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
4492 "after forced deauthentication");
4493 wpa_driver_nl80211_deauthenticate(
4495 WLAN_REASON_PREV_AUTH_NOT_VALID
);
4500 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
4502 * cfg80211 has likely expired the BSS entry even
4503 * though it was previously available in our internal
4504 * BSS table. To recover quickly, start a single
4505 * channel scan on the specified channel.
4507 struct wpa_driver_scan_params scan
;
4510 os_memset(&scan
, 0, sizeof(scan
));
4513 scan
.ssids
[0].ssid
= params
->ssid
;
4514 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
4516 freqs
[0] = params
->freq
;
4519 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
4520 "channel scan to refresh cfg80211 BSS "
4522 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
4524 nl80211_copy_auth_params(drv
, params
);
4525 drv
->scan_for_auth
= 1;
4527 } else if (is_retry
) {
4529 * Need to indicate this with an event since the return
4530 * value from the retry is not delivered to core code.
4532 union wpa_event_data event
;
4533 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
4535 os_memset(&event
, 0, sizeof(event
));
4536 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
4538 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
4542 goto nla_put_failure
;
4545 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
4554 static int wpa_driver_nl80211_authenticate_retry(
4555 struct wpa_driver_nl80211_data
*drv
)
4557 struct wpa_driver_auth_params params
;
4558 struct i802_bss
*bss
= &drv
->first_bss
;
4561 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
4563 os_memset(¶ms
, 0, sizeof(params
));
4564 params
.freq
= drv
->auth_freq
;
4565 params
.auth_alg
= drv
->auth_alg
;
4566 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
4567 params
.local_state_change
= drv
->auth_local_state_change
;
4568 params
.p2p
= drv
->auth_p2p
;
4570 if (!is_zero_ether_addr(drv
->auth_bssid_
))
4571 params
.bssid
= drv
->auth_bssid_
;
4573 if (drv
->auth_ssid_len
) {
4574 params
.ssid
= drv
->auth_ssid
;
4575 params
.ssid_len
= drv
->auth_ssid_len
;
4578 params
.ie
= drv
->auth_ie
;
4579 params
.ie_len
= drv
->auth_ie_len
;
4581 for (i
= 0; i
< 4; i
++) {
4582 if (drv
->auth_wep_key_len
[i
]) {
4583 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
4584 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
4588 drv
->retry_auth
= 1;
4589 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
4593 struct phy_info_arg
{
4595 struct hostapd_hw_modes
*modes
;
4598 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
4600 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
4601 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4602 struct phy_info_arg
*phy_info
= arg
;
4604 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
4606 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
4607 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
4608 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
4609 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
4610 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
4611 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
4612 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
4613 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
4616 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
4617 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
4618 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
4619 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] = { .type
= NLA_FLAG
},
4622 struct nlattr
*nl_band
;
4623 struct nlattr
*nl_freq
;
4624 struct nlattr
*nl_rate
;
4625 int rem_band
, rem_freq
, rem_rate
;
4626 struct hostapd_hw_modes
*mode
;
4627 int idx
, mode_is_set
;
4629 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4630 genlmsg_attrlen(gnlh
, 0), NULL
);
4632 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
4635 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
) {
4636 mode
= os_realloc(phy_info
->modes
, (*phy_info
->num_modes
+ 1) * sizeof(*mode
));
4639 phy_info
->modes
= mode
;
4643 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
4644 memset(mode
, 0, sizeof(*mode
));
4645 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
;
4646 *(phy_info
->num_modes
) += 1;
4648 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
4649 nla_len(nl_band
), NULL
);
4651 if (tb_band
[NL80211_BAND_ATTR_HT_CAPA
]) {
4652 mode
->ht_capab
= nla_get_u16(
4653 tb_band
[NL80211_BAND_ATTR_HT_CAPA
]);
4656 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) {
4657 mode
->a_mpdu_params
|= nla_get_u8(
4658 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) &
4662 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) {
4663 mode
->a_mpdu_params
|= nla_get_u8(
4664 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) <<
4668 if (tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
] &&
4669 nla_len(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
])) {
4671 mcs
= nla_data(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
4672 os_memcpy(mode
->mcs_set
, mcs
, 16);
4675 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
4676 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
4677 nla_len(nl_freq
), freq_policy
);
4678 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
4680 mode
->num_channels
++;
4683 mode
->channels
= os_zalloc(mode
->num_channels
* sizeof(struct hostapd_channel_data
));
4684 if (!mode
->channels
)
4689 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
4690 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
4691 nla_len(nl_freq
), freq_policy
);
4692 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
4695 mode
->channels
[idx
].freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
4696 mode
->channels
[idx
].flag
= 0;
4699 /* crude heuristic */
4700 if (mode
->channels
[idx
].freq
< 4000)
4701 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
4703 mode
->mode
= HOSTAPD_MODE_IEEE80211A
;
4707 /* crude heuristic */
4708 if (mode
->channels
[idx
].freq
< 4000)
4709 if (mode
->channels
[idx
].freq
== 2484)
4710 mode
->channels
[idx
].chan
= 14;
4712 mode
->channels
[idx
].chan
= (mode
->channels
[idx
].freq
- 2407) / 5;
4714 mode
->channels
[idx
].chan
= mode
->channels
[idx
].freq
/5 - 1000;
4716 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
4717 mode
->channels
[idx
].flag
|=
4718 HOSTAPD_CHAN_DISABLED
;
4719 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
4720 mode
->channels
[idx
].flag
|=
4721 HOSTAPD_CHAN_PASSIVE_SCAN
;
4722 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
4723 mode
->channels
[idx
].flag
|=
4724 HOSTAPD_CHAN_NO_IBSS
;
4725 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
4726 mode
->channels
[idx
].flag
|=
4729 if (tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] &&
4730 !tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
4731 mode
->channels
[idx
].max_tx_power
=
4732 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
]) / 100;
4737 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
4738 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
4739 nla_len(nl_rate
), rate_policy
);
4740 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
4745 mode
->rates
= os_zalloc(mode
->num_rates
* sizeof(int));
4751 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
4752 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
4753 nla_len(nl_rate
), rate_policy
);
4754 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
4756 mode
->rates
[idx
] = nla_get_u32(tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
4758 /* crude heuristic */
4759 if (mode
->mode
== HOSTAPD_MODE_IEEE80211B
&&
4760 mode
->rates
[idx
] > 200)
4761 mode
->mode
= HOSTAPD_MODE_IEEE80211G
;
4770 static struct hostapd_hw_modes
*
4771 wpa_driver_nl80211_add_11b(struct hostapd_hw_modes
*modes
, u16
*num_modes
)
4774 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
4775 int i
, mode11g_idx
= -1;
4777 /* If only 802.11g mode is included, use it to construct matching
4778 * 802.11b mode data. */
4780 for (m
= 0; m
< *num_modes
; m
++) {
4781 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
4782 return modes
; /* 802.11b already included */
4783 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
4787 if (mode11g_idx
< 0)
4788 return modes
; /* 2.4 GHz band not supported at all */
4790 nmodes
= os_realloc(modes
, (*num_modes
+ 1) * sizeof(*nmodes
));
4792 return modes
; /* Could not add 802.11b mode */
4794 mode
= &nmodes
[*num_modes
];
4795 os_memset(mode
, 0, sizeof(*mode
));
4799 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
4801 mode11g
= &modes
[mode11g_idx
];
4802 mode
->num_channels
= mode11g
->num_channels
;
4803 mode
->channels
= os_malloc(mode11g
->num_channels
*
4804 sizeof(struct hostapd_channel_data
));
4805 if (mode
->channels
== NULL
) {
4807 return modes
; /* Could not add 802.11b mode */
4809 os_memcpy(mode
->channels
, mode11g
->channels
,
4810 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
4812 mode
->num_rates
= 0;
4813 mode
->rates
= os_malloc(4 * sizeof(int));
4814 if (mode
->rates
== NULL
) {
4815 os_free(mode
->channels
);
4817 return modes
; /* Could not add 802.11b mode */
4820 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
4821 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
4822 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
4824 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
4826 if (mode
->num_rates
== 4)
4830 if (mode
->num_rates
== 0) {
4831 os_free(mode
->channels
);
4832 os_free(mode
->rates
);
4834 return modes
; /* No 802.11b rates */
4837 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
4844 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
4849 for (c
= 0; c
< mode
->num_channels
; c
++) {
4850 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
4851 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
4852 chan
->flag
|= HOSTAPD_CHAN_HT40
;
4857 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
4862 for (c
= 0; c
< mode
->num_channels
; c
++) {
4863 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
4864 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
4866 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
4867 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
4868 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
4869 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
4874 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
4875 struct phy_info_arg
*results
)
4877 u32 start
, end
, max_bw
;
4880 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
4881 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
4882 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
4885 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
4886 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
4887 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
4889 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
4890 start
, end
, max_bw
);
4894 for (m
= 0; m
< *results
->num_modes
; m
++) {
4895 if (!(results
->modes
[m
].ht_capab
&
4896 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
4898 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
4903 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
4904 struct phy_info_arg
*results
)
4906 u32 start
, end
, max_bw
;
4909 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
4910 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
4911 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
4914 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
4915 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
4916 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
4921 for (m
= 0; m
< *results
->num_modes
; m
++) {
4922 if (!(results
->modes
[m
].ht_capab
&
4923 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
4925 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
4930 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
4932 struct phy_info_arg
*results
= arg
;
4933 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
4934 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4935 struct nlattr
*nl_rule
;
4936 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
4938 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
4939 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4940 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4941 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4942 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4943 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4944 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4947 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4948 genlmsg_attrlen(gnlh
, 0), NULL
);
4949 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
4950 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
4951 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
4956 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
4957 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
4959 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
4961 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
4962 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
4963 nl80211_reg_rule_ht40(tb_rule
, results
);
4966 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
4968 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
4969 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
4970 nl80211_reg_rule_sec(tb_rule
, results
);
4977 static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data
*drv
,
4978 struct phy_info_arg
*results
)
4982 msg
= nlmsg_alloc();
4986 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
4987 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
4991 static struct hostapd_hw_modes
*
4992 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
4994 struct i802_bss
*bss
= priv
;
4995 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4997 struct phy_info_arg result
= {
4998 .num_modes
= num_modes
,
5005 msg
= nlmsg_alloc();
5009 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
5011 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5013 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
5014 nl80211_set_ht40_flags(drv
, &result
);
5015 return wpa_driver_nl80211_add_11b(result
.modes
, num_modes
);
5024 static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data
*drv
,
5025 const void *data
, size_t len
,
5026 int encrypt
, int noack
)
5029 0x00, 0x00, /* radiotap version */
5030 0x0e, 0x00, /* radiotap length */
5031 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
5032 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
5034 0x00, 0x00, /* RX and TX flags to indicate that */
5035 0x00, 0x00, /* this is the injected frame directly */
5037 struct iovec iov
[2] = {
5039 .iov_base
= &rtap_hdr
,
5040 .iov_len
= sizeof(rtap_hdr
),
5043 .iov_base
= (void *) data
,
5047 struct msghdr msg
= {
5052 .msg_control
= NULL
,
5053 .msg_controllen
= 0,
5060 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
5062 if (drv
->monitor_sock
< 0) {
5063 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
5064 "for %s", __func__
);
5069 txflags
|= IEEE80211_RADIOTAP_F_TX_NOACK
;
5070 *(le16
*) &rtap_hdr
[12] = host_to_le16(txflags
);
5072 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
5074 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
5081 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
5082 const void *data
, size_t len
,
5083 int encrypt
, int noack
)
5085 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5088 if (drv
->use_monitor
)
5089 return wpa_driver_nl80211_send_mntr(drv
, data
, len
,
5092 return nl80211_send_frame_cmd(bss
, bss
->freq
, 0, data
, len
,
5093 &cookie
, 0, noack
, 0);
5097 static int wpa_driver_nl80211_send_mlme(void *priv
, const u8
*data
,
5098 size_t data_len
, int noack
)
5100 struct i802_bss
*bss
= priv
;
5101 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5102 struct ieee80211_mgmt
*mgmt
;
5106 mgmt
= (struct ieee80211_mgmt
*) data
;
5107 fc
= le_to_host16(mgmt
->frame_control
);
5109 if (is_sta_interface(drv
->nlmode
) &&
5110 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5111 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
5113 * The use of last_mgmt_freq is a bit of a hack,
5114 * but it works due to the single-threaded nature
5115 * of wpa_supplicant.
5117 return nl80211_send_frame_cmd(bss
, drv
->last_mgmt_freq
, 0,
5118 data
, data_len
, NULL
, 1, noack
,
5122 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
5123 return nl80211_send_frame_cmd(bss
, bss
->freq
, 0,
5124 data
, data_len
, NULL
,
5128 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5129 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
5131 * Only one of the authentication frame types is encrypted.
5132 * In order for static WEP encryption to work properly (i.e.,
5133 * to not encrypt the frame), we need to tell mac80211 about
5134 * the frames that must not be encrypted.
5136 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
5137 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
5138 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
5142 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
5147 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
5148 int slot
, int ht_opmode
, int ap_isolate
,
5151 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5154 msg
= nlmsg_alloc();
5158 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
5161 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
5163 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
5165 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
5167 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
5168 if (ap_isolate
>= 0)
5169 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
);
5172 u8 rates
[NL80211_MAX_SUPP_RATES
];
5176 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0;
5178 rates
[rates_len
++] = basic_rates
[i
] / 5;
5180 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
5183 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5185 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5192 static int wpa_driver_nl80211_set_ap(void *priv
,
5193 struct wpa_driver_ap_params
*params
)
5195 struct i802_bss
*bss
= priv
;
5196 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5198 u8 cmd
= NL80211_CMD_NEW_BEACON
;
5201 int ifindex
= if_nametoindex(bss
->ifname
);
5206 beacon_set
= bss
->beacon_set
;
5208 msg
= nlmsg_alloc();
5212 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
5215 cmd
= NL80211_CMD_SET_BEACON
;
5217 nl80211_cmd(drv
, msg
, 0, cmd
);
5218 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
5219 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
5220 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5221 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
5222 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
5223 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5225 if (params
->proberesp
&& params
->proberesp_len
)
5226 NLA_PUT(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
5228 switch (params
->hide_ssid
) {
5229 case NO_SSID_HIDING
:
5230 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5231 NL80211_HIDDEN_SSID_NOT_IN_USE
);
5233 case HIDDEN_SSID_ZERO_LEN
:
5234 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5235 NL80211_HIDDEN_SSID_ZERO_LEN
);
5237 case HIDDEN_SSID_ZERO_CONTENTS
:
5238 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
5239 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
5242 if (params
->privacy
)
5243 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
5244 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
5245 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
5246 /* Leave out the attribute */
5247 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
5248 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
5249 NL80211_AUTHTYPE_SHARED_KEY
);
5251 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
5252 NL80211_AUTHTYPE_OPEN_SYSTEM
);
5255 if (params
->wpa_version
& WPA_PROTO_WPA
)
5256 ver
|= NL80211_WPA_VERSION_1
;
5257 if (params
->wpa_version
& WPA_PROTO_RSN
)
5258 ver
|= NL80211_WPA_VERSION_2
;
5260 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
5263 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
5264 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
5265 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
5266 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
5268 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
5269 num_suites
* sizeof(u32
), suites
);
5272 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
&&
5273 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
))
5274 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
);
5277 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
5278 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
5279 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
5280 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
5281 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
5282 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
5283 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
5284 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
5286 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
5287 num_suites
* sizeof(u32
), suites
);
5290 switch (params
->group_cipher
) {
5291 case WPA_CIPHER_CCMP
:
5292 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5293 WLAN_CIPHER_SUITE_CCMP
);
5295 case WPA_CIPHER_TKIP
:
5296 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5297 WLAN_CIPHER_SUITE_TKIP
);
5299 case WPA_CIPHER_WEP104
:
5300 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5301 WLAN_CIPHER_SUITE_WEP104
);
5303 case WPA_CIPHER_WEP40
:
5304 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
5305 WLAN_CIPHER_SUITE_WEP40
);
5309 if (params
->beacon_ies
) {
5310 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
5311 wpabuf_head(params
->beacon_ies
));
5313 if (params
->proberesp_ies
) {
5314 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
5315 wpabuf_len(params
->proberesp_ies
),
5316 wpabuf_head(params
->proberesp_ies
));
5318 if (params
->assocresp_ies
) {
5319 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
5320 wpabuf_len(params
->assocresp_ies
),
5321 wpabuf_head(params
->assocresp_ies
));
5324 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5326 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
5327 ret
, strerror(-ret
));
5329 bss
->beacon_set
= 1;
5330 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
5331 params
->short_slot_time
, params
->ht_opmode
,
5332 params
->isolate
, params
->basic_rates
);
5341 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
5342 int freq
, int ht_enabled
,
5343 int sec_channel_offset
)
5345 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5349 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d "
5350 "sec_channel_offset=%d)",
5351 freq
, ht_enabled
, sec_channel_offset
);
5352 msg
= nlmsg_alloc();
5356 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
5358 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5359 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5361 switch (sec_channel_offset
) {
5363 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5364 NL80211_CHAN_HT40MINUS
);
5367 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5368 NL80211_CHAN_HT40PLUS
);
5371 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
5377 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5383 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
5384 "%d (%s)", freq
, ret
, strerror(-ret
));
5391 static u32
sta_flags_nl80211(int flags
)
5395 if (flags
& WPA_STA_AUTHORIZED
)
5396 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5397 if (flags
& WPA_STA_WMM
)
5398 f
|= BIT(NL80211_STA_FLAG_WME
);
5399 if (flags
& WPA_STA_SHORT_PREAMBLE
)
5400 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
5401 if (flags
& WPA_STA_MFP
)
5402 f
|= BIT(NL80211_STA_FLAG_MFP
);
5403 if (flags
& WPA_STA_TDLS_PEER
)
5404 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
5410 static int wpa_driver_nl80211_sta_add(void *priv
,
5411 struct hostapd_sta_add_params
*params
)
5413 struct i802_bss
*bss
= priv
;
5414 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5415 struct nl_msg
*msg
, *wme
= NULL
;
5416 struct nl80211_sta_flag_update upd
;
5419 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
5420 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
5423 msg
= nlmsg_alloc();
5427 nl80211_cmd(drv
, msg
, 0, params
->set
? NL80211_CMD_SET_STATION
:
5428 NL80211_CMD_NEW_STATION
);
5430 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5431 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
5432 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
5433 params
->supp_rates
);
5435 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
5436 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
5437 params
->listen_interval
);
5439 if (params
->ht_capabilities
) {
5440 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
5441 sizeof(*params
->ht_capabilities
),
5442 params
->ht_capabilities
);
5445 os_memset(&upd
, 0, sizeof(upd
));
5446 upd
.mask
= sta_flags_nl80211(params
->flags
);
5448 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
5450 if (params
->flags
& WPA_STA_WMM
) {
5451 wme
= nlmsg_alloc();
5453 goto nla_put_failure
;
5455 NLA_PUT_U8(wme
, NL80211_STA_WME_UAPSD_QUEUES
,
5456 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
);
5457 NLA_PUT_U8(wme
, NL80211_STA_WME_MAX_SP
,
5458 (params
->qosinfo
> WMM_QOSINFO_STA_SP_SHIFT
) &
5459 WMM_QOSINFO_STA_SP_MASK
);
5460 nla_put_nested(msg
, NL80211_ATTR_STA_WME
, wme
);
5463 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5466 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
5467 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
5478 static int wpa_driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
5480 struct i802_bss
*bss
= priv
;
5481 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5485 msg
= nlmsg_alloc();
5489 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
5491 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5492 if_nametoindex(bss
->ifname
));
5493 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5495 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5505 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
5510 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
5512 /* stop listening for EAPOL on this interface */
5513 del_ifidx(drv
, ifidx
);
5515 msg
= nlmsg_alloc();
5517 goto nla_put_failure
;
5519 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
5520 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
5522 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
5527 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
5531 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
5534 case NL80211_IFTYPE_ADHOC
:
5536 case NL80211_IFTYPE_STATION
:
5538 case NL80211_IFTYPE_AP
:
5540 case NL80211_IFTYPE_MONITOR
:
5542 case NL80211_IFTYPE_P2P_CLIENT
:
5543 return "P2P_CLIENT";
5544 case NL80211_IFTYPE_P2P_GO
:
5552 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
5554 enum nl80211_iftype iftype
,
5555 const u8
*addr
, int wds
)
5557 struct nl_msg
*msg
, *flags
= NULL
;
5561 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
5562 iftype
, nl80211_iftype_str(iftype
));
5564 msg
= nlmsg_alloc();
5568 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
5569 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5570 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
5571 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
5573 if (iftype
== NL80211_IFTYPE_MONITOR
) {
5576 flags
= nlmsg_alloc();
5578 goto nla_put_failure
;
5580 NLA_PUT_FLAG(flags
, NL80211_MNTR_FLAG_COOK_FRAMES
);
5582 err
= nla_put_nested(msg
, NL80211_ATTR_MNTR_FLAGS
, flags
);
5587 goto nla_put_failure
;
5589 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
5592 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5597 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
5598 ifname
, ret
, strerror(-ret
));
5602 ifidx
= if_nametoindex(ifname
);
5603 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
5609 /* start listening for EAPOL on this interface */
5610 add_ifidx(drv
, ifidx
);
5612 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
5613 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
5614 nl80211_remove_iface(drv
, ifidx
);
5622 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
5623 const char *ifname
, enum nl80211_iftype iftype
,
5624 const u8
*addr
, int wds
)
5628 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
);
5630 /* if error occurred and interface exists already */
5631 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
5632 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
5634 /* Try to remove the interface that was already there. */
5635 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
5637 /* Try to create the interface again */
5638 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
5642 if (ret
>= 0 && is_p2p_interface(iftype
))
5643 nl80211_disable_11b_rates(drv
, ret
, 1);
5649 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
5651 struct ieee80211_hdr
*hdr
;
5653 union wpa_event_data event
;
5655 hdr
= (struct ieee80211_hdr
*) buf
;
5656 fc
= le_to_host16(hdr
->frame_control
);
5658 os_memset(&event
, 0, sizeof(event
));
5659 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
5660 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
5661 event
.tx_status
.dst
= hdr
->addr1
;
5662 event
.tx_status
.data
= buf
;
5663 event
.tx_status
.data_len
= len
;
5664 event
.tx_status
.ack
= ok
;
5665 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
5669 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
5670 u8
*buf
, size_t len
)
5672 struct ieee80211_hdr
*hdr
= (void *)buf
;
5674 union wpa_event_data event
;
5676 if (len
< sizeof(*hdr
))
5679 fc
= le_to_host16(hdr
->frame_control
);
5681 os_memset(&event
, 0, sizeof(event
));
5682 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
5683 event
.rx_from_unknown
.addr
= hdr
->addr2
;
5684 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
5685 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
5686 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
5690 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
5691 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
5693 struct ieee80211_hdr
*hdr
;
5695 union wpa_event_data event
;
5697 hdr
= (struct ieee80211_hdr
*) buf
;
5698 fc
= le_to_host16(hdr
->frame_control
);
5700 switch (WLAN_FC_GET_TYPE(fc
)) {
5701 case WLAN_FC_TYPE_MGMT
:
5702 os_memset(&event
, 0, sizeof(event
));
5703 event
.rx_mgmt
.frame
= buf
;
5704 event
.rx_mgmt
.frame_len
= len
;
5705 event
.rx_mgmt
.datarate
= datarate
;
5706 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
5707 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
5709 case WLAN_FC_TYPE_CTRL
:
5710 /* can only get here with PS-Poll frames */
5711 wpa_printf(MSG_DEBUG
, "CTRL");
5712 from_unknown_sta(drv
, buf
, len
);
5714 case WLAN_FC_TYPE_DATA
:
5715 from_unknown_sta(drv
, buf
, len
);
5721 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
5723 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
5725 unsigned char buf
[3000];
5726 struct ieee80211_radiotap_iterator iter
;
5728 int datarate
= 0, ssi_signal
= 0;
5729 int injected
= 0, failed
= 0, rxflags
= 0;
5731 len
= recv(sock
, buf
, sizeof(buf
), 0);
5737 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
5738 printf("received invalid radiotap frame\n");
5743 ret
= ieee80211_radiotap_iterator_next(&iter
);
5747 printf("received invalid radiotap frame (%d)\n", ret
);
5750 switch (iter
.this_arg_index
) {
5751 case IEEE80211_RADIOTAP_FLAGS
:
5752 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
5755 case IEEE80211_RADIOTAP_RX_FLAGS
:
5758 case IEEE80211_RADIOTAP_TX_FLAGS
:
5760 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
5761 IEEE80211_RADIOTAP_F_TX_FAIL
;
5763 case IEEE80211_RADIOTAP_DATA_RETRIES
:
5765 case IEEE80211_RADIOTAP_CHANNEL
:
5766 /* TODO: convert from freq/flags to channel number */
5768 case IEEE80211_RADIOTAP_RATE
:
5769 datarate
= *iter
.this_arg
* 5;
5771 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
5772 ssi_signal
= *iter
.this_arg
;
5777 if (rxflags
&& injected
)
5781 handle_frame(drv
, buf
+ iter
.max_length
,
5782 len
- iter
.max_length
, datarate
, ssi_signal
);
5784 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
5785 len
- iter
.max_length
, !failed
);
5790 * we post-process the filter code later and rewrite
5791 * this to the offset to the last instruction
5796 static struct sock_filter msock_filter_insns
[] = {
5798 * do a little-endian load of the radiotap length field
5800 /* load lower byte into A */
5801 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
5802 /* put it into X (== index register) */
5803 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
5804 /* load upper byte into A */
5805 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
5806 /* left-shift it by 8 */
5807 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
5809 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
5810 /* put result into X */
5811 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
5814 * Allow management frames through, this also gives us those
5815 * management frames that we sent ourselves with status
5817 /* load the lower byte of the IEEE 802.11 frame control field */
5818 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
5819 /* mask off frame type and version */
5820 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
5821 /* accept frame if it's both 0, fall through otherwise */
5822 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
5825 * TODO: add a bit to radiotap RX flags that indicates
5826 * that the sending station is not associated, then
5827 * add a filter here that filters on our DA and that flag
5828 * to allow us to deauth frames to that bad station.
5830 * For now allow all To DS data frames through.
5832 /* load the IEEE 802.11 frame control field */
5833 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
5834 /* mask off frame type, version and DS status */
5835 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
5836 /* accept frame if version 0, type 2 and To DS, fall through otherwise
5838 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
5842 * drop non-data frames
5844 /* load the lower byte of the frame control field */
5845 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
5846 /* mask off QoS bit */
5847 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
5848 /* drop non-data frames */
5849 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
5851 /* load the upper byte of the frame control field */
5852 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
5853 /* mask off toDS/fromDS */
5854 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
5855 /* accept WDS frames */
5856 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
5859 * add header length to index
5861 /* load the lower byte of the frame control field */
5862 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
5863 /* mask off QoS bit */
5864 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
5865 /* right shift it by 6 to give 0 or 2 */
5866 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
5867 /* add data frame header length */
5868 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
5869 /* add index, was start of 802.11 header */
5870 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
5871 /* move to index, now start of LL header */
5872 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
5875 * Accept empty data frames, we use those for
5878 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
5879 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
5882 * Accept EAPOL frames
5884 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
5885 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
5886 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
5887 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
5889 /* keep these last two statements or change the code below */
5890 /* return 0 == "DROP" */
5891 BPF_STMT(BPF_RET
| BPF_K
, 0),
5892 /* return ~0 == "keep all" */
5893 BPF_STMT(BPF_RET
| BPF_K
, ~0),
5896 static struct sock_fprog msock_filter
= {
5897 .len
= sizeof(msock_filter_insns
)/sizeof(msock_filter_insns
[0]),
5898 .filter
= msock_filter_insns
,
5902 static int add_monitor_filter(int s
)
5906 /* rewrite all PASS/FAIL jump offsets */
5907 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
5908 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
5910 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
5911 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
5912 if (insn
->k
== PASS
)
5913 insn
->k
= msock_filter
.len
- idx
- 2;
5914 else if (insn
->k
== FAIL
)
5915 insn
->k
= msock_filter
.len
- idx
- 3;
5918 if (insn
->jt
== PASS
)
5919 insn
->jt
= msock_filter
.len
- idx
- 2;
5920 else if (insn
->jt
== FAIL
)
5921 insn
->jt
= msock_filter
.len
- idx
- 3;
5923 if (insn
->jf
== PASS
)
5924 insn
->jf
= msock_filter
.len
- idx
- 2;
5925 else if (insn
->jf
== FAIL
)
5926 insn
->jf
= msock_filter
.len
- idx
- 3;
5930 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
5931 &msock_filter
, sizeof(msock_filter
))) {
5932 perror("SO_ATTACH_FILTER");
5940 static void nl80211_remove_monitor_interface(
5941 struct wpa_driver_nl80211_data
*drv
)
5943 drv
->monitor_refcount
--;
5944 if (drv
->monitor_refcount
> 0)
5947 if (drv
->monitor_ifidx
>= 0) {
5948 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
5949 drv
->monitor_ifidx
= -1;
5951 if (drv
->monitor_sock
>= 0) {
5952 eloop_unregister_read_sock(drv
->monitor_sock
);
5953 close(drv
->monitor_sock
);
5954 drv
->monitor_sock
= -1;
5960 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
5963 struct sockaddr_ll ll
;
5967 if (drv
->monitor_ifidx
>= 0) {
5968 drv
->monitor_refcount
++;
5972 if (os_strncmp(drv
->first_bss
.ifname
, "p2p-", 4) == 0) {
5974 * P2P interface name is of the format p2p-%s-%d. For monitor
5975 * interface name corresponding to P2P GO, replace "p2p-" with
5976 * "mon-" to retain the same interface name length and to
5977 * indicate that it is a monitor interface.
5979 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
.ifname
+ 4);
5981 /* Non-P2P interface with AP functionality. */
5982 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
.ifname
);
5985 buf
[IFNAMSIZ
- 1] = '\0';
5987 drv
->monitor_ifidx
=
5988 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
5991 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
5993 * This is backward compatibility for a few versions of
5994 * the kernel only that didn't advertise the right
5995 * attributes for the only driver that then supported
5996 * AP mode w/o monitor -- ath6kl.
5998 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
5999 "monitor interface type - try to run without it");
6000 drv
->device_ap_sme
= 1;
6003 if (drv
->monitor_ifidx
< 0)
6006 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
6009 memset(&ll
, 0, sizeof(ll
));
6010 ll
.sll_family
= AF_PACKET
;
6011 ll
.sll_ifindex
= drv
->monitor_ifidx
;
6012 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
6013 if (drv
->monitor_sock
< 0) {
6014 perror("socket[PF_PACKET,SOCK_RAW]");
6018 if (add_monitor_filter(drv
->monitor_sock
)) {
6019 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
6020 "interface; do filtering in user space");
6021 /* This works, but will cost in performance. */
6024 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
6025 perror("monitor socket bind");
6029 optlen
= sizeof(optval
);
6032 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
6033 perror("Failed to set socket priority");
6037 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
6039 printf("Could not register monitor read socket\n");
6045 nl80211_remove_monitor_interface(drv
);
6050 static int nl80211_setup_ap(struct i802_bss
*bss
)
6052 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6054 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP - device_ap_sme=%d "
6055 "use_monitor=%d", drv
->device_ap_sme
, drv
->use_monitor
);
6058 * Disable Probe Request reporting unless we need it in this way for
6059 * devices that include the AP SME, in the other case (unless using
6060 * monitor iface) we'll get it through the nl_mgmt socket instead.
6062 if (!drv
->device_ap_sme
)
6063 wpa_driver_nl80211_probe_req_report(bss
, 0);
6065 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
6066 if (nl80211_mgmt_subscribe_ap(bss
))
6069 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
6070 nl80211_create_monitor_interface(drv
) &&
6071 !drv
->device_ap_sme
)
6074 if (drv
->device_ap_sme
&&
6075 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
6076 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
6077 "Probe Request frame reporting in AP mode");
6078 /* Try to survive without this */
6085 static void nl80211_teardown_ap(struct i802_bss
*bss
)
6087 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6089 if (drv
->device_ap_sme
)
6090 wpa_driver_nl80211_probe_req_report(bss
, 0);
6091 else if (drv
->use_monitor
)
6092 nl80211_remove_monitor_interface(drv
);
6094 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
6096 bss
->beacon_set
= 0;
6100 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
6101 const u8
*addr
, const u8
*data
,
6104 struct sockaddr_ll ll
;
6107 if (bss
->drv
->eapol_tx_sock
< 0) {
6108 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
6112 os_memset(&ll
, 0, sizeof(ll
));
6113 ll
.sll_family
= AF_PACKET
;
6114 ll
.sll_ifindex
= bss
->ifindex
;
6115 ll
.sll_protocol
= htons(ETH_P_PAE
);
6116 ll
.sll_halen
= ETH_ALEN
;
6117 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
6118 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
6119 (struct sockaddr
*) &ll
, sizeof(ll
));
6121 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
6128 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
6130 static int wpa_driver_nl80211_hapd_send_eapol(
6131 void *priv
, const u8
*addr
, const u8
*data
,
6132 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
6134 struct i802_bss
*bss
= priv
;
6135 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6136 struct ieee80211_hdr
*hdr
;
6140 int qos
= flags
& WPA_STA_WMM
;
6142 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
6143 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
6145 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
6147 hdr
= os_zalloc(len
);
6149 printf("malloc() failed for i802_send_data(len=%lu)\n",
6150 (unsigned long) len
);
6154 hdr
->frame_control
=
6155 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
6156 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
6158 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
6160 hdr
->frame_control
|=
6161 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
6164 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
6165 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
6166 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
6167 pos
= (u8
*) (hdr
+ 1);
6170 /* add an empty QoS header if needed */
6176 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
6177 pos
+= sizeof(rfc1042_header
);
6178 WPA_PUT_BE16(pos
, ETH_P_PAE
);
6180 memcpy(pos
, data
, data_len
);
6182 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0);
6184 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
6186 (unsigned long) len
, errno
, strerror(errno
));
6194 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
6196 int flags_or
, int flags_and
)
6198 struct i802_bss
*bss
= priv
;
6199 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6200 struct nl_msg
*msg
, *flags
= NULL
;
6201 struct nl80211_sta_flag_update upd
;
6203 msg
= nlmsg_alloc();
6207 flags
= nlmsg_alloc();
6213 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
6215 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6216 if_nametoindex(bss
->ifname
));
6217 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6220 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
6221 * can be removed eventually.
6223 if (total_flags
& WPA_STA_AUTHORIZED
)
6224 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_AUTHORIZED
);
6226 if (total_flags
& WPA_STA_WMM
)
6227 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_WME
);
6229 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
6230 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
6232 if (total_flags
& WPA_STA_MFP
)
6233 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_MFP
);
6235 if (total_flags
& WPA_STA_TDLS_PEER
)
6236 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_TDLS_PEER
);
6238 if (nla_put_nested(msg
, NL80211_ATTR_STA_FLAGS
, flags
))
6239 goto nla_put_failure
;
6241 os_memset(&upd
, 0, sizeof(upd
));
6242 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
6243 upd
.set
= sta_flags_nl80211(flags_or
);
6244 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6248 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6256 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
6257 struct wpa_driver_associate_params
*params
)
6259 enum nl80211_iftype nlmode
;
6262 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
6264 nlmode
= NL80211_IFTYPE_P2P_GO
;
6266 nlmode
= NL80211_IFTYPE_AP
;
6268 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
, nlmode
) ||
6269 wpa_driver_nl80211_set_freq(&drv
->first_bss
, params
->freq
, 0, 0)) {
6270 nl80211_remove_monitor_interface(drv
);
6278 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
6283 msg
= nlmsg_alloc();
6287 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
6288 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6289 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6292 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
6293 "(%s)", ret
, strerror(-ret
));
6294 goto nla_put_failure
;
6298 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
6306 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
6307 struct wpa_driver_associate_params
*params
)
6313 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
6315 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
6316 NL80211_IFTYPE_ADHOC
)) {
6317 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
6323 msg
= nlmsg_alloc();
6327 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
6328 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6330 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
6331 goto nla_put_failure
;
6333 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6334 params
->ssid
, params
->ssid_len
);
6335 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6337 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6338 drv
->ssid_len
= params
->ssid_len
;
6340 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6341 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6343 ret
= nl80211_set_conn_keys(params
, msg
);
6345 goto nla_put_failure
;
6347 if (params
->wpa_ie
) {
6348 wpa_hexdump(MSG_DEBUG
,
6349 " * Extra IEs for Beacon/Probe Response frames",
6350 params
->wpa_ie
, params
->wpa_ie_len
);
6351 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6355 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6358 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
6359 ret
, strerror(-ret
));
6361 if (ret
== -EALREADY
&& count
== 1) {
6362 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
6364 nl80211_leave_ibss(drv
);
6369 goto nla_put_failure
;
6372 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
6380 static unsigned int nl80211_get_assoc_bssid(struct wpa_driver_nl80211_data
*drv
,
6385 struct nl80211_bss_info_arg arg
;
6387 os_memset(&arg
, 0, sizeof(arg
));
6388 msg
= nlmsg_alloc();
6390 goto nla_put_failure
;
6392 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
6393 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6396 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
6399 if (is_zero_ether_addr(arg
.assoc_bssid
))
6401 os_memcpy(bssid
, arg
.assoc_bssid
, ETH_ALEN
);
6404 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
6405 "(%s)", ret
, strerror(-ret
));
6408 return drv
->assoc_freq
;
6412 static int nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
6417 if (bssid
== NULL
) {
6418 int res
= nl80211_get_assoc_bssid(drv
, addr
);
6424 return wpa_driver_nl80211_disconnect(drv
, bssid
,
6425 WLAN_REASON_PREV_AUTH_NOT_VALID
);
6429 static int wpa_driver_nl80211_connect(
6430 struct wpa_driver_nl80211_data
*drv
,
6431 struct wpa_driver_associate_params
*params
)
6434 enum nl80211_auth_type type
;
6438 msg
= nlmsg_alloc();
6442 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
6443 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
6445 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6446 if (params
->bssid
) {
6447 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
6448 MAC2STR(params
->bssid
));
6449 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
6452 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6453 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6456 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6457 params
->ssid
, params
->ssid_len
);
6458 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6460 if (params
->ssid_len
> sizeof(drv
->ssid
))
6461 goto nla_put_failure
;
6462 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6463 drv
->ssid_len
= params
->ssid_len
;
6465 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
6467 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6471 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
6473 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
6475 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
6478 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
6480 goto skip_auth_type
;
6483 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
6484 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
6485 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
6486 type
= NL80211_AUTHTYPE_SHARED_KEY
;
6487 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
6488 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
6489 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
6490 type
= NL80211_AUTHTYPE_FT
;
6492 goto nla_put_failure
;
6494 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
6495 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
6498 if (params
->wpa_proto
) {
6499 enum nl80211_wpa_versions ver
= 0;
6501 if (params
->wpa_proto
& WPA_PROTO_WPA
)
6502 ver
|= NL80211_WPA_VERSION_1
;
6503 if (params
->wpa_proto
& WPA_PROTO_RSN
)
6504 ver
|= NL80211_WPA_VERSION_2
;
6506 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
6507 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
6510 if (params
->pairwise_suite
!= CIPHER_NONE
) {
6513 switch (params
->pairwise_suite
) {
6515 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6518 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6521 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6525 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6528 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
6531 if (params
->group_suite
!= CIPHER_NONE
) {
6534 switch (params
->group_suite
) {
6536 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6539 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6542 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6546 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6549 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
6552 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
6553 params
->key_mgmt_suite
== KEY_MGMT_PSK
) {
6554 int mgmt
= WLAN_AKM_SUITE_PSK
;
6556 switch (params
->key_mgmt_suite
) {
6557 case KEY_MGMT_802_1X
:
6558 mgmt
= WLAN_AKM_SUITE_8021X
;
6562 mgmt
= WLAN_AKM_SUITE_PSK
;
6565 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
6568 ret
= nl80211_set_conn_keys(params
, msg
);
6570 goto nla_put_failure
;
6572 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6575 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
6576 "(%s)", ret
, strerror(-ret
));
6578 * cfg80211 does not currently accept new connection if we are
6579 * already connected. As a workaround, force disconnection and
6580 * try again once the driver indicates it completed
6583 if (ret
== -EALREADY
)
6584 nl80211_disconnect(drv
, params
->bssid
);
6585 goto nla_put_failure
;
6588 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
6597 static int wpa_driver_nl80211_associate(
6598 void *priv
, struct wpa_driver_associate_params
*params
)
6600 struct i802_bss
*bss
= priv
;
6601 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6605 if (params
->mode
== IEEE80211_MODE_AP
)
6606 return wpa_driver_nl80211_ap(drv
, params
);
6608 if (params
->mode
== IEEE80211_MODE_IBSS
)
6609 return wpa_driver_nl80211_ibss(drv
, params
);
6611 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
6612 enum nl80211_iftype nlmode
= params
->p2p
?
6613 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
6615 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
6617 return wpa_driver_nl80211_connect(drv
, params
);
6620 drv
->associated
= 0;
6622 msg
= nlmsg_alloc();
6626 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
6628 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
6630 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6631 if (params
->bssid
) {
6632 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
6633 MAC2STR(params
->bssid
));
6634 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
6637 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
6638 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
6639 drv
->assoc_freq
= params
->freq
;
6641 drv
->assoc_freq
= 0;
6643 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
6644 params
->ssid
, params
->ssid_len
);
6645 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6647 if (params
->ssid_len
> sizeof(drv
->ssid
))
6648 goto nla_put_failure
;
6649 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
6650 drv
->ssid_len
= params
->ssid_len
;
6652 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
6654 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
6657 if (params
->pairwise_suite
!= CIPHER_NONE
) {
6660 switch (params
->pairwise_suite
) {
6662 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6665 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6668 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6672 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6675 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
6676 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
6679 if (params
->group_suite
!= CIPHER_NONE
) {
6682 switch (params
->group_suite
) {
6684 cipher
= WLAN_CIPHER_SUITE_WEP40
;
6687 cipher
= WLAN_CIPHER_SUITE_WEP104
;
6690 cipher
= WLAN_CIPHER_SUITE_CCMP
;
6694 cipher
= WLAN_CIPHER_SUITE_TKIP
;
6697 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
6698 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
6701 #ifdef CONFIG_IEEE80211W
6702 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
6703 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
6704 #endif /* CONFIG_IEEE80211W */
6706 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
6708 if (params
->prev_bssid
) {
6709 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
6710 MAC2STR(params
->prev_bssid
));
6711 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
6712 params
->prev_bssid
);
6716 wpa_printf(MSG_DEBUG
, " * P2P group");
6718 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6721 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
6722 "nl80211: MLME command failed (assoc): ret=%d (%s)",
6723 ret
, strerror(-ret
));
6724 nl80211_dump_scan(drv
);
6725 goto nla_put_failure
;
6728 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
6737 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
6738 int ifindex
, enum nl80211_iftype mode
)
6743 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
6744 ifindex
, mode
, nl80211_iftype_str(mode
));
6746 msg
= nlmsg_alloc();
6750 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
6751 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
6752 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
6754 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6760 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
6761 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
6766 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
6767 enum nl80211_iftype nlmode
)
6769 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6772 int was_ap
= is_ap_interface(drv
->nlmode
);
6775 res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
6777 drv
->nlmode
= nlmode
;
6785 if (nlmode
== drv
->nlmode
) {
6786 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
6787 "requested mode - ignore error");
6789 goto done
; /* Already in the requested mode */
6792 /* mac80211 doesn't allow mode changes while the device is up, so
6793 * take the device down, try to set the mode again, and bring the
6796 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
6798 for (i
= 0; i
< 10; i
++) {
6799 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
6801 if (res
== -EACCES
|| res
== -ENODEV
)
6804 /* Try to set the mode again while the interface is
6806 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
6809 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
6813 else if (ret
!= -EBUSY
)
6816 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
6818 os_sleep(0, 100000);
6822 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
6823 "interface is down");
6824 drv
->nlmode
= nlmode
;
6825 drv
->ignore_if_down_event
= 1;
6830 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
6831 "from %d failed", nlmode
, drv
->nlmode
);
6835 if (is_ap_interface(nlmode
)) {
6836 nl80211_mgmt_unsubscribe(bss
, "start AP");
6837 /* Setup additional AP mode functionality if needed */
6838 if (nl80211_setup_ap(bss
))
6840 } else if (was_ap
) {
6841 /* Remove additional AP mode functionality */
6842 nl80211_teardown_ap(bss
);
6844 nl80211_mgmt_unsubscribe(bss
, "mode change");
6847 if (!is_ap_interface(nlmode
) &&
6848 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
6849 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
6850 "frame processing - ignore for now");
6856 static int wpa_driver_nl80211_get_capa(void *priv
,
6857 struct wpa_driver_capa
*capa
)
6859 struct i802_bss
*bss
= priv
;
6860 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6861 if (!drv
->has_capability
)
6863 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
6868 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
6870 struct i802_bss
*bss
= priv
;
6871 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6873 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
6874 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
6875 drv
->operstate
= state
;
6876 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
6877 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
6881 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
6883 struct i802_bss
*bss
= priv
;
6884 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6886 struct nl80211_sta_flag_update upd
;
6888 msg
= nlmsg_alloc();
6892 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
6894 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6895 if_nametoindex(bss
->ifname
));
6896 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
6898 os_memset(&upd
, 0, sizeof(upd
));
6899 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6901 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6902 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6904 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6911 /* Set kernel driver on given frequency (MHz) */
6912 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
6914 struct i802_bss
*bss
= priv
;
6915 return wpa_driver_nl80211_set_freq(bss
, freq
->freq
, freq
->ht_enabled
,
6916 freq
->sec_channel_offset
);
6920 #if defined(HOSTAPD) || defined(CONFIG_AP)
6922 static inline int min_int(int a
, int b
)
6930 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
6932 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6933 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6935 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6936 genlmsg_attrlen(gnlh
, 0), NULL
);
6939 * TODO: validate the key index and mac address!
6940 * Otherwise, there's a race condition as soon as
6941 * the kernel starts sending key notifications.
6944 if (tb
[NL80211_ATTR_KEY_SEQ
])
6945 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
6946 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
6951 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
6954 struct i802_bss
*bss
= priv
;
6955 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6958 msg
= nlmsg_alloc();
6962 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
6965 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6966 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
6967 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
6971 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
6978 static int i802_set_rts(void *priv
, int rts
)
6980 struct i802_bss
*bss
= priv
;
6981 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6986 msg
= nlmsg_alloc();
6995 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
6996 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6997 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
6999 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7005 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
7006 "%d (%s)", rts
, ret
, strerror(-ret
));
7011 static int i802_set_frag(void *priv
, int frag
)
7013 struct i802_bss
*bss
= priv
;
7014 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7019 msg
= nlmsg_alloc();
7028 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7029 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7030 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
7032 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7038 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
7039 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
7044 static int i802_flush(void *priv
)
7046 struct i802_bss
*bss
= priv
;
7047 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7050 msg
= nlmsg_alloc();
7054 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
7057 * XXX: FIX! this needs to flush all VLANs too
7059 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7060 if_nametoindex(bss
->ifname
));
7062 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7069 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
7071 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7072 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7073 struct hostap_sta_driver_data
*data
= arg
;
7074 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
7075 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
7076 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
7077 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
7078 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
7079 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
7080 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
7083 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7084 genlmsg_attrlen(gnlh
, 0), NULL
);
7087 * TODO: validate the interface and mac address!
7088 * Otherwise, there's a race condition as soon as
7089 * the kernel starts sending station notifications.
7092 if (!tb
[NL80211_ATTR_STA_INFO
]) {
7093 wpa_printf(MSG_DEBUG
, "sta stats missing!");
7096 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
7097 tb
[NL80211_ATTR_STA_INFO
],
7099 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
7103 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
7104 data
->inactive_msec
=
7105 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
7106 if (stats
[NL80211_STA_INFO_RX_BYTES
])
7107 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
7108 if (stats
[NL80211_STA_INFO_TX_BYTES
])
7109 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
7110 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
7112 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
7113 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
7115 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
7120 static int i802_read_sta_data(void *priv
, struct hostap_sta_driver_data
*data
,
7123 struct i802_bss
*bss
= priv
;
7124 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7127 os_memset(data
, 0, sizeof(*data
));
7128 msg
= nlmsg_alloc();
7132 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
7134 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7135 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7137 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
7144 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
7145 int cw_min
, int cw_max
, int burst_time
)
7147 struct i802_bss
*bss
= priv
;
7148 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7150 struct nlattr
*txq
, *params
;
7152 msg
= nlmsg_alloc();
7156 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
7158 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7160 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
7162 goto nla_put_failure
;
7164 /* We are only sending parameters for a single TXQ at a time */
7165 params
= nla_nest_start(msg
, 1);
7167 goto nla_put_failure
;
7171 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
7174 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
7177 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
7180 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
7183 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
7184 * 32 usec, so need to convert the value here. */
7185 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
7186 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
7187 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
7188 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
7190 nla_nest_end(msg
, params
);
7192 nla_nest_end(msg
, txq
);
7194 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
7203 static int i802_set_sta_vlan(void *priv
, const u8
*addr
,
7204 const char *ifname
, int vlan_id
)
7206 struct i802_bss
*bss
= priv
;
7207 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7211 msg
= nlmsg_alloc();
7215 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7217 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7218 if_nametoindex(bss
->ifname
));
7219 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7220 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
7221 if_nametoindex(ifname
));
7223 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7226 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
7227 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
7228 MAC2STR(addr
), ifname
, vlan_id
, ret
,
7237 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
7239 struct hostap_sta_driver_data data
;
7242 data
.inactive_msec
= (unsigned long) -1;
7243 ret
= i802_read_sta_data(priv
, &data
, addr
);
7244 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
7246 return data
.inactive_msec
/ 1000;
7250 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
7259 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
7262 struct i802_bss
*bss
= priv
;
7263 struct ieee80211_mgmt mgmt
;
7265 memset(&mgmt
, 0, sizeof(mgmt
));
7266 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
7267 WLAN_FC_STYPE_DEAUTH
);
7268 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
7269 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
7270 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
7271 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
7272 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
7274 sizeof(mgmt
.u
.deauth
), 0);
7278 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
7281 struct i802_bss
*bss
= priv
;
7282 struct ieee80211_mgmt mgmt
;
7284 memset(&mgmt
, 0, sizeof(mgmt
));
7285 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
7286 WLAN_FC_STYPE_DISASSOC
);
7287 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
7288 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
7289 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
7290 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
7291 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
7293 sizeof(mgmt
.u
.disassoc
), 0);
7296 #endif /* HOSTAPD || CONFIG_AP */
7300 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7305 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
7307 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
7308 if (drv
->if_indices
[i
] == 0) {
7309 drv
->if_indices
[i
] = ifidx
;
7314 if (drv
->if_indices
!= drv
->default_if_indices
)
7315 old
= drv
->if_indices
;
7319 drv
->if_indices
= os_realloc(old
,
7320 sizeof(int) * (drv
->num_if_indices
+ 1));
7321 if (!drv
->if_indices
) {
7323 drv
->if_indices
= drv
->default_if_indices
;
7325 drv
->if_indices
= old
;
7326 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
7328 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
7331 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
7332 sizeof(drv
->default_if_indices
));
7333 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
7334 drv
->num_if_indices
++;
7338 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7342 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
7343 if (drv
->if_indices
[i
] == ifidx
) {
7344 drv
->if_indices
[i
] = 0;
7351 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
7355 for (i
= 0; i
< drv
->num_if_indices
; i
++)
7356 if (drv
->if_indices
[i
] == ifidx
)
7363 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
7364 const char *bridge_ifname
)
7366 struct i802_bss
*bss
= priv
;
7367 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7368 char name
[IFNAMSIZ
+ 1];
7370 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
7371 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
7372 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
7374 if (!if_nametoindex(name
)) {
7375 if (nl80211_create_iface(drv
, name
,
7376 NL80211_IFTYPE_AP_VLAN
,
7379 if (bridge_ifname
&&
7380 linux_br_add_if(drv
->global
->ioctl_sock
,
7381 bridge_ifname
, name
) < 0)
7384 linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1);
7385 return i802_set_sta_vlan(priv
, addr
, name
, 0);
7387 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
7388 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
7394 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
7396 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
7397 struct sockaddr_ll lladdr
;
7398 unsigned char buf
[3000];
7400 socklen_t fromlen
= sizeof(lladdr
);
7402 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
7403 (struct sockaddr
*)&lladdr
, &fromlen
);
7409 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
7410 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
7414 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
7415 struct i802_bss
*bss
,
7416 const char *brname
, const char *ifname
)
7419 char in_br
[IFNAMSIZ
];
7421 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
7422 ifindex
= if_nametoindex(brname
);
7425 * Bridge was configured, but the bridge device does
7426 * not exist. Try to add it now.
7428 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
7429 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
7430 "bridge interface %s: %s",
7431 brname
, strerror(errno
));
7434 bss
->added_bridge
= 1;
7435 add_ifidx(drv
, if_nametoindex(brname
));
7438 if (linux_br_get(in_br
, ifname
) == 0) {
7439 if (os_strcmp(in_br
, brname
) == 0)
7440 return 0; /* already in the bridge */
7442 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
7443 "bridge %s", ifname
, in_br
);
7444 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
7446 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
7447 "remove interface %s from bridge "
7449 ifname
, brname
, strerror(errno
));
7454 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
7456 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
7457 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
7458 "into bridge %s: %s",
7459 ifname
, brname
, strerror(errno
));
7462 bss
->added_if_into_bridge
= 1;
7468 static void *i802_init(struct hostapd_data
*hapd
,
7469 struct wpa_init_params
*params
)
7471 struct wpa_driver_nl80211_data
*drv
;
7472 struct i802_bss
*bss
;
7474 char brname
[IFNAMSIZ
];
7475 int ifindex
, br_ifindex
;
7478 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
7479 params
->global_priv
);
7484 drv
->nlmode
= NL80211_IFTYPE_AP
;
7485 drv
->eapol_sock
= -1;
7487 if (linux_br_get(brname
, params
->ifname
) == 0) {
7488 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
7489 params
->ifname
, brname
);
7490 br_ifindex
= if_nametoindex(brname
);
7496 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
7497 drv
->if_indices
= drv
->default_if_indices
;
7498 for (i
= 0; i
< params
->num_bridge
; i
++) {
7499 if (params
->bridge
[i
]) {
7500 ifindex
= if_nametoindex(params
->bridge
[i
]);
7502 add_ifidx(drv
, ifindex
);
7503 if (ifindex
== br_ifindex
)
7507 if (!br_added
&& br_ifindex
&&
7508 (params
->num_bridge
== 0 || !params
->bridge
[0]))
7509 add_ifidx(drv
, br_ifindex
);
7511 /* start listening for EAPOL on the default AP interface */
7512 add_ifidx(drv
, drv
->ifindex
);
7514 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
7517 if (params
->bssid
) {
7518 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7523 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
7524 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
7525 "into AP mode", bss
->ifname
);
7529 if (params
->num_bridge
&& params
->bridge
[0] &&
7530 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
7533 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
7536 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
7537 if (drv
->eapol_sock
< 0) {
7538 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
7542 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
7544 printf("Could not register read socket for eapol\n");
7548 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7552 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
7557 wpa_driver_nl80211_deinit(bss
);
7562 static void i802_deinit(void *priv
)
7564 wpa_driver_nl80211_deinit(priv
);
7567 #endif /* HOSTAPD */
7570 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
7571 enum wpa_driver_if_type type
)
7574 case WPA_IF_STATION
:
7575 return NL80211_IFTYPE_STATION
;
7576 case WPA_IF_P2P_CLIENT
:
7577 case WPA_IF_P2P_GROUP
:
7578 return NL80211_IFTYPE_P2P_CLIENT
;
7579 case WPA_IF_AP_VLAN
:
7580 return NL80211_IFTYPE_AP_VLAN
;
7582 return NL80211_IFTYPE_AP
;
7584 return NL80211_IFTYPE_P2P_GO
;
7592 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
7594 struct wpa_driver_nl80211_data
*drv
;
7595 dl_list_for_each(drv
, &global
->interfaces
,
7596 struct wpa_driver_nl80211_data
, list
) {
7597 if (os_memcmp(addr
, drv
->first_bss
.addr
, ETH_ALEN
) == 0)
7604 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
7612 os_memcpy(new_addr
, drv
->first_bss
.addr
, ETH_ALEN
);
7613 for (idx
= 0; idx
< 64; idx
++) {
7614 new_addr
[0] = drv
->first_bss
.addr
[0] | 0x02;
7615 new_addr
[0] ^= idx
<< 2;
7616 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
7622 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
7623 MACSTR
, MAC2STR(new_addr
));
7628 #endif /* CONFIG_P2P */
7631 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
7632 const char *ifname
, const u8
*addr
,
7633 void *bss_ctx
, void **drv_priv
,
7634 char *force_ifname
, u8
*if_addr
,
7637 struct i802_bss
*bss
= priv
;
7638 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7641 struct i802_bss
*new_bss
= NULL
;
7643 if (type
== WPA_IF_AP_BSS
) {
7644 new_bss
= os_zalloc(sizeof(*new_bss
));
7645 if (new_bss
== NULL
)
7648 #endif /* HOSTAPD */
7651 os_memcpy(if_addr
, addr
, ETH_ALEN
);
7652 ifidx
= nl80211_create_iface(drv
, ifname
,
7653 wpa_driver_nl80211_if_type(type
), addr
,
7658 #endif /* HOSTAPD */
7663 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7665 nl80211_remove_iface(drv
, ifidx
);
7671 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
7672 type
== WPA_IF_P2P_GO
)) {
7673 /* Enforce unique P2P Interface Address */
7674 u8 new_addr
[ETH_ALEN
], own_addr
[ETH_ALEN
];
7676 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7678 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
7680 nl80211_remove_iface(drv
, ifidx
);
7683 if (os_memcmp(own_addr
, new_addr
, ETH_ALEN
) == 0) {
7684 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
7685 "for P2P group interface");
7686 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
7687 nl80211_remove_iface(drv
, ifidx
);
7690 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
7692 nl80211_remove_iface(drv
, ifidx
);
7696 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
7698 #endif /* CONFIG_P2P */
7702 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
7703 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
7704 "interface %s to a bridge %s", ifname
, bridge
);
7705 nl80211_remove_iface(drv
, ifidx
);
7710 if (type
== WPA_IF_AP_BSS
) {
7711 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
7713 nl80211_remove_iface(drv
, ifidx
);
7717 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
7718 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
7719 new_bss
->ifindex
= ifidx
;
7721 new_bss
->next
= drv
->first_bss
.next
;
7722 drv
->first_bss
.next
= new_bss
;
7724 *drv_priv
= new_bss
;
7725 nl80211_init_bss(new_bss
);
7727 #endif /* HOSTAPD */
7730 drv
->global
->if_add_ifindex
= ifidx
;
7736 static int wpa_driver_nl80211_if_remove(void *priv
,
7737 enum wpa_driver_if_type type
,
7740 struct i802_bss
*bss
= priv
;
7741 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7742 int ifindex
= if_nametoindex(ifname
);
7744 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d",
7745 __func__
, type
, ifname
, ifindex
);
7750 if (bss
->added_if_into_bridge
) {
7751 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
7753 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
7754 "interface %s from bridge %s: %s",
7755 bss
->ifname
, bss
->brname
, strerror(errno
));
7757 if (bss
->added_bridge
) {
7758 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
7759 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
7761 bss
->brname
, strerror(errno
));
7763 #endif /* HOSTAPD */
7765 nl80211_remove_iface(drv
, ifindex
);
7768 if (type
!= WPA_IF_AP_BSS
)
7771 if (bss
!= &drv
->first_bss
) {
7772 struct i802_bss
*tbss
;
7774 for (tbss
= &drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
7775 if (tbss
->next
== bss
) {
7776 tbss
->next
= bss
->next
;
7777 nl80211_destroy_bss(bss
);
7784 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
7785 "BSS %p in the list", __func__
, bss
);
7787 #endif /* HOSTAPD */
7793 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
7795 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7796 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7798 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7799 genlmsg_attrlen(gnlh
, 0), NULL
);
7800 if (tb
[NL80211_ATTR_COOKIE
])
7801 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
7806 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
7807 unsigned int freq
, unsigned int wait
,
7808 const u8
*buf
, size_t buf_len
,
7809 u64
*cookie_out
, int no_cck
, int no_ack
,
7812 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7817 msg
= nlmsg_alloc();
7821 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
7823 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
7824 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7826 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
7828 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
7830 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
7832 NLA_PUT_FLAG(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
);
7834 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
7837 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
7840 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
7841 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
7843 goto nla_put_failure
;
7845 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX command accepted%s; "
7846 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
7847 (long long unsigned int) cookie
);
7850 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
7858 static int wpa_driver_nl80211_send_action(void *priv
, unsigned int freq
,
7859 unsigned int wait_time
,
7860 const u8
*dst
, const u8
*src
,
7862 const u8
*data
, size_t data_len
,
7865 struct i802_bss
*bss
= priv
;
7866 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7869 struct ieee80211_hdr
*hdr
;
7871 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
7872 "wait=%d ms no_cck=%d)", drv
->ifindex
, wait_time
, no_cck
);
7874 buf
= os_zalloc(24 + data_len
);
7877 os_memcpy(buf
+ 24, data
, data_len
);
7878 hdr
= (struct ieee80211_hdr
*) buf
;
7879 hdr
->frame_control
=
7880 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
7881 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
7882 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
7883 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
7885 if (is_ap_interface(drv
->nlmode
))
7886 ret
= wpa_driver_nl80211_send_mlme(priv
, buf
, 24 + data_len
,
7889 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
7891 &drv
->send_action_cookie
,
7899 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
7901 struct i802_bss
*bss
= priv
;
7902 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7906 msg
= nlmsg_alloc();
7910 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
7912 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7913 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
7915 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7918 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
7919 "(%s)", ret
, strerror(-ret
));
7926 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
7927 unsigned int duration
)
7929 struct i802_bss
*bss
= priv
;
7930 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7935 msg
= nlmsg_alloc();
7939 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
7941 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7942 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7943 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
7946 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
7949 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
7950 "0x%llx for freq=%u MHz duration=%u",
7951 (long long unsigned int) cookie
, freq
, duration
);
7952 drv
->remain_on_chan_cookie
= cookie
;
7953 drv
->pending_remain_on_chan
= 1;
7956 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
7957 "(freq=%d duration=%u): %d (%s)",
7958 freq
, duration
, ret
, strerror(-ret
));
7965 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
7967 struct i802_bss
*bss
= priv
;
7968 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7972 if (!drv
->pending_remain_on_chan
) {
7973 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
7978 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
7980 (long long unsigned int) drv
->remain_on_chan_cookie
);
7982 msg
= nlmsg_alloc();
7986 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
7988 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7989 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
7991 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7995 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
7996 "%d (%s)", ret
, strerror(-ret
));
8003 static int wpa_driver_nl80211_probe_req_report(void *priv
, int report
)
8005 struct i802_bss
*bss
= priv
;
8006 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8010 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
8011 "reporting nl_preq=%p", bss
->nl_preq
);
8012 eloop_unregister_read_sock(
8013 nl_socket_get_fd(bss
->nl_preq
));
8014 nl_destroy_handles(&bss
->nl_preq
);
8020 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
8021 "already on! nl_preq=%p", bss
->nl_preq
);
8025 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
8026 if (bss
->nl_preq
== NULL
)
8028 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
8029 "reporting nl_preq=%p", bss
->nl_preq
);
8031 if (nl80211_register_frame(bss
, bss
->nl_preq
,
8032 (WLAN_FC_TYPE_MGMT
<< 2) |
8033 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
8037 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_preq
),
8038 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
8044 nl_destroy_handles(&bss
->nl_preq
);
8049 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
8050 int ifindex
, int disabled
)
8053 struct nlattr
*bands
, *band
;
8056 msg
= nlmsg_alloc();
8060 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
8061 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
8063 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
8065 goto nla_put_failure
;
8068 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
8069 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
8070 * rates. All 5 GHz rates are left enabled.
8072 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
8074 goto nla_put_failure
;
8076 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
8077 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
8079 nla_nest_end(msg
, band
);
8081 nla_nest_end(msg
, bands
);
8083 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8086 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
8087 "(%s)", ret
, strerror(-ret
));
8098 static int wpa_driver_nl80211_deinit_ap(void *priv
)
8100 struct i802_bss
*bss
= priv
;
8101 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8102 if (!is_ap_interface(drv
->nlmode
))
8104 wpa_driver_nl80211_del_beacon(drv
);
8105 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
8109 static void wpa_driver_nl80211_resume(void *priv
)
8111 struct i802_bss
*bss
= priv
;
8112 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8113 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
8114 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on "
8120 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
8121 const u8
*ies
, size_t ies_len
)
8123 struct i802_bss
*bss
= priv
;
8124 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8128 const u8
*own_addr
= bss
->addr
;
8131 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
8132 "action %d", action
);
8137 * Action frame payload:
8138 * Category[1] = 6 (Fast BSS Transition)
8139 * Action[1] = 1 (Fast BSS Transition Request)
8145 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
8146 data
= os_malloc(data_len
);
8150 *pos
++ = 0x06; /* FT Action category */
8152 os_memcpy(pos
, own_addr
, ETH_ALEN
);
8154 os_memcpy(pos
, target_ap
, ETH_ALEN
);
8156 os_memcpy(pos
, ies
, ies_len
);
8158 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
8159 drv
->bssid
, own_addr
, drv
->bssid
,
8167 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
8169 struct i802_bss
*bss
= priv
;
8170 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8171 struct nl_msg
*msg
, *cqm
= NULL
;
8173 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
8174 "hysteresis=%d", threshold
, hysteresis
);
8176 msg
= nlmsg_alloc();
8180 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
8182 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8184 cqm
= nlmsg_alloc();
8188 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
8189 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
8190 nla_put_nested(msg
, NL80211_ATTR_CQM
, cqm
);
8192 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
8203 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
8205 struct i802_bss
*bss
= priv
;
8206 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8209 os_memset(si
, 0, sizeof(*si
));
8210 res
= nl80211_get_link_signal(drv
, si
);
8214 return nl80211_get_link_noise(drv
, si
);
8218 static int wpa_driver_nl80211_shared_freq(void *priv
)
8220 struct i802_bss
*bss
= priv
;
8221 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8222 struct wpa_driver_nl80211_data
*driver
;
8226 * If the same PHY is in connected state with some other interface,
8227 * then retrieve the assoc freq.
8229 wpa_printf(MSG_DEBUG
, "nl80211: Get shared freq for PHY %s",
8232 dl_list_for_each(driver
, &drv
->global
->interfaces
,
8233 struct wpa_driver_nl80211_data
, list
) {
8234 if (drv
== driver
||
8235 os_strcmp(drv
->phyname
, driver
->phyname
) != 0 ||
8236 !driver
->associated
)
8239 wpa_printf(MSG_DEBUG
, "nl80211: Found a match for PHY %s - %s "
8241 driver
->phyname
, driver
->first_bss
.ifname
,
8242 MAC2STR(driver
->first_bss
.addr
));
8243 freq
= nl80211_get_assoc_freq(driver
);
8244 wpa_printf(MSG_DEBUG
, "nl80211: Shared freq for PHY %s: %d",
8245 drv
->phyname
, freq
);
8249 wpa_printf(MSG_DEBUG
, "nl80211: No shared interface for "
8250 "PHY (%s) in associated state", drv
->phyname
);
8256 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
8259 struct i802_bss
*bss
= priv
;
8260 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0);
8264 static int nl80211_set_param(void *priv
, const char *param
)
8266 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
8271 if (os_strstr(param
, "use_p2p_group_interface=1")) {
8272 struct i802_bss
*bss
= priv
;
8273 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8275 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
8277 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
8278 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
8280 #endif /* CONFIG_P2P */
8286 static void * nl80211_global_init(void)
8288 struct nl80211_global
*global
;
8289 struct netlink_config
*cfg
;
8291 global
= os_zalloc(sizeof(*global
));
8294 global
->ioctl_sock
= -1;
8295 dl_list_init(&global
->interfaces
);
8296 global
->if_add_ifindex
= -1;
8298 cfg
= os_zalloc(sizeof(*cfg
));
8303 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
8304 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
8305 global
->netlink
= netlink_init(cfg
);
8306 if (global
->netlink
== NULL
) {
8311 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
8314 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
8315 if (global
->ioctl_sock
< 0) {
8316 perror("socket(PF_INET,SOCK_DGRAM)");
8323 nl80211_global_deinit(global
);
8328 static void nl80211_global_deinit(void *priv
)
8330 struct nl80211_global
*global
= priv
;
8333 if (!dl_list_empty(&global
->interfaces
)) {
8334 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
8335 "nl80211_global_deinit",
8336 dl_list_len(&global
->interfaces
));
8339 if (global
->netlink
)
8340 netlink_deinit(global
->netlink
);
8342 nl_destroy_handles(&global
->nl
);
8344 if (global
->nl_event
) {
8345 eloop_unregister_read_sock(
8346 nl_socket_get_fd(global
->nl_event
));
8347 nl_destroy_handles(&global
->nl_event
);
8350 nl_cb_put(global
->nl_cb
);
8352 if (global
->ioctl_sock
>= 0)
8353 close(global
->ioctl_sock
);
8359 static const char * nl80211_get_radio_name(void *priv
)
8361 struct i802_bss
*bss
= priv
;
8362 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8363 return drv
->phyname
;
8367 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
8372 msg
= nlmsg_alloc();
8376 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
8378 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8380 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
8382 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
8384 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8391 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
8393 struct i802_bss
*bss
= priv
;
8394 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
8395 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
8399 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
8401 struct i802_bss
*bss
= priv
;
8402 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
8404 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
8408 static int nl80211_flush_pmkid(void *priv
)
8410 struct i802_bss
*bss
= priv
;
8411 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
8412 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
8416 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
8417 const u8
*replay_ctr
)
8419 struct i802_bss
*bss
= priv
;
8420 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8421 struct nlattr
*replay_nested
;
8424 msg
= nlmsg_alloc();
8428 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8430 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8432 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8434 goto nla_put_failure
;
8436 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
8437 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
8438 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
8441 nla_nest_end(msg
, replay_nested
);
8443 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8450 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
8451 const u8
*addr
, int qos
)
8453 /* send data frame to poll STA and check whether
8454 * this frame is ACKed */
8456 struct ieee80211_hdr hdr
;
8458 } STRUCT_PACKED nulldata
;
8461 /* Send data frame to poll STA and check whether this frame is ACKed */
8463 os_memset(&nulldata
, 0, sizeof(nulldata
));
8466 nulldata
.hdr
.frame_control
=
8467 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
8468 WLAN_FC_STYPE_QOS_NULL
);
8469 size
= sizeof(nulldata
);
8471 nulldata
.hdr
.frame_control
=
8472 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
8473 WLAN_FC_STYPE_NULLFUNC
);
8474 size
= sizeof(struct ieee80211_hdr
);
8477 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
8478 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
8479 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
8480 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
8482 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0) < 0)
8483 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
8487 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
8490 struct i802_bss
*bss
= priv
;
8491 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8494 if (!drv
->poll_command_supported
) {
8495 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
8499 msg
= nlmsg_alloc();
8503 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_PROBE_CLIENT
);
8505 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8506 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8508 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8515 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
8519 msg
= nlmsg_alloc();
8523 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_SET_POWER_SAVE
);
8524 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
8525 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
,
8526 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
);
8527 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8534 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
8537 struct i802_bss
*bss
= priv
;
8539 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
8540 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
8542 if (opp_ps
!= -1 || ctwindow
!= -1)
8543 return -1; /* Not yet supported */
8545 if (legacy_ps
== -1)
8547 if (legacy_ps
!= 0 && legacy_ps
!= 1)
8548 return -1; /* Not yet supported */
8550 return nl80211_set_power_save(bss
, legacy_ps
);
8556 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
8557 u8 dialog_token
, u16 status_code
,
8558 const u8
*buf
, size_t len
)
8560 struct i802_bss
*bss
= priv
;
8561 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8564 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8570 msg
= nlmsg_alloc();
8574 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_MGMT
);
8575 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8576 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
8577 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
);
8578 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
);
8579 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
);
8580 NLA_PUT(msg
, NL80211_ATTR_IE
, len
, buf
);
8582 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8590 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
8592 struct i802_bss
*bss
= priv
;
8593 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8595 enum nl80211_tdls_operation nl80211_oper
;
8597 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8601 case TDLS_DISCOVERY_REQ
:
8602 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
8605 nl80211_oper
= NL80211_TDLS_SETUP
;
8608 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
8610 case TDLS_ENABLE_LINK
:
8611 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
8613 case TDLS_DISABLE_LINK
:
8614 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
8624 msg
= nlmsg_alloc();
8628 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_OPER
);
8629 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
);
8630 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8631 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
8633 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8640 #endif /* CONFIG TDLS */
8645 typedef struct android_wifi_priv_cmd
{
8649 } android_wifi_priv_cmd
;
8651 static int drv_errors
= 0;
8653 static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data
*drv
)
8656 if (drv_errors
> DRV_NUMBER_SEQUENTIAL_ERRORS
) {
8658 wpa_msg(drv
->ctx
, MSG_INFO
, WPA_EVENT_DRIVER_STATE
"HANGED");
8663 static int android_priv_cmd(struct i802_bss
*bss
, const char *cmd
)
8665 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8667 android_wifi_priv_cmd priv_cmd
;
8668 char buf
[MAX_DRV_CMD_SIZE
];
8671 os_memset(&ifr
, 0, sizeof(ifr
));
8672 os_memset(&priv_cmd
, 0, sizeof(priv_cmd
));
8673 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
8675 os_memset(buf
, 0, sizeof(buf
));
8676 os_strlcpy(buf
, cmd
, sizeof(buf
));
8679 priv_cmd
.used_len
= sizeof(buf
);
8680 priv_cmd
.total_len
= sizeof(buf
);
8681 ifr
.ifr_data
= &priv_cmd
;
8683 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
8685 wpa_printf(MSG_ERROR
, "%s: failed to issue private commands",
8687 wpa_driver_send_hang_msg(drv
);
8696 static int android_pno_start(struct i802_bss
*bss
,
8697 struct wpa_driver_scan_params
*params
)
8699 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8701 android_wifi_priv_cmd priv_cmd
;
8702 int ret
= 0, i
= 0, bp
;
8703 char buf
[WEXT_PNO_MAX_COMMAND_SIZE
];
8705 bp
= WEXT_PNOSETUP_HEADER_SIZE
;
8706 os_memcpy(buf
, WEXT_PNOSETUP_HEADER
, bp
);
8707 buf
[bp
++] = WEXT_PNO_TLV_PREFIX
;
8708 buf
[bp
++] = WEXT_PNO_TLV_VERSION
;
8709 buf
[bp
++] = WEXT_PNO_TLV_SUBVERSION
;
8710 buf
[bp
++] = WEXT_PNO_TLV_RESERVED
;
8712 while (i
< WEXT_PNO_AMOUNT
&& (size_t) i
< params
->num_ssids
) {
8713 /* Check that there is enough space needed for 1 more SSID, the
8714 * other sections and null termination */
8715 if ((bp
+ WEXT_PNO_SSID_HEADER_SIZE
+ MAX_SSID_LEN
+
8716 WEXT_PNO_NONSSID_SECTIONS_SIZE
+ 1) >= (int) sizeof(buf
))
8718 wpa_hexdump_ascii(MSG_DEBUG
, "For PNO Scan",
8719 params
->ssids
[i
].ssid
,
8720 params
->ssids
[i
].ssid_len
);
8721 buf
[bp
++] = WEXT_PNO_SSID_SECTION
;
8722 buf
[bp
++] = params
->ssids
[i
].ssid_len
;
8723 os_memcpy(&buf
[bp
], params
->ssids
[i
].ssid
,
8724 params
->ssids
[i
].ssid_len
);
8725 bp
+= params
->ssids
[i
].ssid_len
;
8729 buf
[bp
++] = WEXT_PNO_SCAN_INTERVAL_SECTION
;
8730 os_snprintf(&buf
[bp
], WEXT_PNO_SCAN_INTERVAL_LENGTH
+ 1, "%x",
8731 WEXT_PNO_SCAN_INTERVAL
);
8732 bp
+= WEXT_PNO_SCAN_INTERVAL_LENGTH
;
8734 buf
[bp
++] = WEXT_PNO_REPEAT_SECTION
;
8735 os_snprintf(&buf
[bp
], WEXT_PNO_REPEAT_LENGTH
+ 1, "%x",
8737 bp
+= WEXT_PNO_REPEAT_LENGTH
;
8739 buf
[bp
++] = WEXT_PNO_MAX_REPEAT_SECTION
;
8740 os_snprintf(&buf
[bp
], WEXT_PNO_MAX_REPEAT_LENGTH
+ 1, "%x",
8741 WEXT_PNO_MAX_REPEAT
);
8742 bp
+= WEXT_PNO_MAX_REPEAT_LENGTH
+ 1;
8744 memset(&ifr
, 0, sizeof(ifr
));
8745 memset(&priv_cmd
, 0, sizeof(priv_cmd
));
8746 os_strncpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
8749 priv_cmd
.used_len
= bp
;
8750 priv_cmd
.total_len
= bp
;
8751 ifr
.ifr_data
= &priv_cmd
;
8753 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
8756 wpa_printf(MSG_ERROR
, "ioctl[SIOCSIWPRIV] (pnosetup): %d",
8758 wpa_driver_send_hang_msg(drv
);
8764 return android_priv_cmd(bss
, "PNOFORCE 1");
8768 static int android_pno_stop(struct i802_bss
*bss
)
8770 return android_priv_cmd(bss
, "PNOFORCE 0");
8773 #endif /* ANDROID */
8776 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
8778 .desc
= "Linux nl80211/cfg80211",
8779 .get_bssid
= wpa_driver_nl80211_get_bssid
,
8780 .get_ssid
= wpa_driver_nl80211_get_ssid
,
8781 .set_key
= wpa_driver_nl80211_set_key
,
8782 .scan2
= wpa_driver_nl80211_scan
,
8783 .sched_scan
= wpa_driver_nl80211_sched_scan
,
8784 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
8785 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
8786 .deauthenticate
= wpa_driver_nl80211_deauthenticate
,
8787 .disassociate
= wpa_driver_nl80211_disassociate
,
8788 .authenticate
= wpa_driver_nl80211_authenticate
,
8789 .associate
= wpa_driver_nl80211_associate
,
8790 .global_init
= nl80211_global_init
,
8791 .global_deinit
= nl80211_global_deinit
,
8792 .init2
= wpa_driver_nl80211_init
,
8793 .deinit
= wpa_driver_nl80211_deinit
,
8794 .get_capa
= wpa_driver_nl80211_get_capa
,
8795 .set_operstate
= wpa_driver_nl80211_set_operstate
,
8796 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
8797 .set_country
= wpa_driver_nl80211_set_country
,
8798 .set_ap
= wpa_driver_nl80211_set_ap
,
8799 .if_add
= wpa_driver_nl80211_if_add
,
8800 .if_remove
= wpa_driver_nl80211_if_remove
,
8801 .send_mlme
= wpa_driver_nl80211_send_mlme
,
8802 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
8803 .sta_add
= wpa_driver_nl80211_sta_add
,
8804 .sta_remove
= wpa_driver_nl80211_sta_remove
,
8805 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
8806 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
8808 .hapd_init
= i802_init
,
8809 .hapd_deinit
= i802_deinit
,
8810 .set_wds_sta
= i802_set_wds_sta
,
8811 #endif /* HOSTAPD */
8812 #if defined(HOSTAPD) || defined(CONFIG_AP)
8813 .get_seqnum
= i802_get_seqnum
,
8814 .flush
= i802_flush
,
8815 .read_sta_data
= i802_read_sta_data
,
8816 .get_inact_sec
= i802_get_inact_sec
,
8817 .sta_clear_stats
= i802_sta_clear_stats
,
8818 .set_rts
= i802_set_rts
,
8819 .set_frag
= i802_set_frag
,
8820 .set_tx_queue_params
= i802_set_tx_queue_params
,
8821 .set_sta_vlan
= i802_set_sta_vlan
,
8822 .sta_deauth
= i802_sta_deauth
,
8823 .sta_disassoc
= i802_sta_disassoc
,
8824 #endif /* HOSTAPD || CONFIG_AP */
8825 .set_freq
= i802_set_freq
,
8826 .send_action
= wpa_driver_nl80211_send_action
,
8827 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
8828 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
8829 .cancel_remain_on_channel
=
8830 wpa_driver_nl80211_cancel_remain_on_channel
,
8831 .probe_req_report
= wpa_driver_nl80211_probe_req_report
,
8832 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
8833 .resume
= wpa_driver_nl80211_resume
,
8834 .send_ft_action
= nl80211_send_ft_action
,
8835 .signal_monitor
= nl80211_signal_monitor
,
8836 .signal_poll
= nl80211_signal_poll
,
8837 .send_frame
= nl80211_send_frame
,
8838 .shared_freq
= wpa_driver_nl80211_shared_freq
,
8839 .set_param
= nl80211_set_param
,
8840 .get_radio_name
= nl80211_get_radio_name
,
8841 .add_pmkid
= nl80211_add_pmkid
,
8842 .remove_pmkid
= nl80211_remove_pmkid
,
8843 .flush_pmkid
= nl80211_flush_pmkid
,
8844 .set_rekey_info
= nl80211_set_rekey_info
,
8845 .poll_client
= nl80211_poll_client
,
8846 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
8848 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
8849 .tdls_oper
= nl80211_tdls_oper
,
8850 #endif /* CONFIG_TDLS */