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 "nl80211_copy.h"
35 #include "utils/list.h"
36 #include "common/ieee802_11_defs.h"
37 #include "common/ieee802_11_common.h"
38 #include "l2_packet/l2_packet.h"
40 #include "linux_ioctl.h"
42 #include "radiotap_iter.h"
47 /* libnl 2.0 compatibility code */
48 #define nl_handle nl_sock
49 #define nl80211_handle_alloc nl_socket_alloc_cb
50 #define nl80211_handle_destroy nl_socket_free
53 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
54 * but when you free a socket again it will mess up its bitmap and
55 * and use the wrong number the next time it needs a socket ID.
56 * Therefore, we wrap the handle alloc/destroy and add our own pid
59 static uint32_t port_bitmap
[32] = { 0 };
61 static struct nl_handle
*nl80211_handle_alloc(void *cb
)
63 struct nl_handle
*handle
;
64 uint32_t pid
= getpid() & 0x3FFFFF;
67 handle
= nl_handle_alloc_cb(cb
);
69 for (i
= 0; i
< 1024; i
++) {
70 if (port_bitmap
[i
/ 32] & (1 << (i
% 32)))
72 port_bitmap
[i
/ 32] |= 1 << (i
% 32);
77 nl_socket_set_local_port(handle
, pid
);
82 static void nl80211_handle_destroy(struct nl_handle
*handle
)
84 uint32_t port
= nl_socket_get_local_port(handle
);
87 port_bitmap
[port
/ 32] &= ~(1 << (port
% 32));
89 nl_handle_destroy(handle
);
92 static inline int __genl_ctrl_alloc_cache(struct nl_handle
*h
,
93 struct nl_cache
**cache
)
95 struct nl_cache
*tmp
= genl_ctrl_alloc_cache(h
);
101 #define genl_ctrl_alloc_cache __genl_ctrl_alloc_cache
102 #endif /* CONFIG_LIBNL20 */
105 struct nl80211_handles
{
106 struct nl_handle
*handle
;
107 struct nl_cache
*cache
;
111 static int nl_create_handles(struct nl80211_handles
*handles
, struct nl_cb
*cb
,
117 handles
->handle
= nl80211_handle_alloc(cb
);
118 if (handles
->handle
== NULL
) {
119 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
120 "callbacks (%s)", dbg
);
124 if (genl_connect(handles
->handle
)) {
125 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect to generic "
126 "netlink (%s)", dbg
);
130 if (genl_ctrl_alloc_cache(handles
->handle
, &handles
->cache
) < 0) {
131 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate generic "
132 "netlink cache (%s)", dbg
);
138 nl80211_handle_destroy(handles
->handle
);
143 static void nl_destroy_handles(struct nl80211_handles
*handles
)
145 if (handles
->handle
== NULL
)
147 nl_cache_free(handles
->cache
);
148 nl80211_handle_destroy(handles
->handle
);
149 handles
->handle
= NULL
;
154 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
157 #define IFF_DORMANT 0x20000 /* driver signals dormant */
160 #ifndef IF_OPER_DORMANT
161 #define IF_OPER_DORMANT 5
167 struct nl80211_global
{
168 struct dl_list interfaces
;
170 struct netlink_data
*netlink
;
172 struct nl80211_handles nl
;
173 struct genl_family
*nl80211
;
174 int ioctl_sock
; /* socket for ioctl() use */
177 static void nl80211_global_deinit(void *priv
);
178 static void wpa_driver_nl80211_deinit(void *priv
);
181 struct wpa_driver_nl80211_data
*drv
;
182 struct i802_bss
*next
;
184 char ifname
[IFNAMSIZ
+ 1];
185 char brname
[IFNAMSIZ
];
186 unsigned int beacon_set
:1;
187 unsigned int added_if_into_bridge
:1;
188 unsigned int added_bridge
:1;
191 struct wpa_driver_nl80211_data
{
192 struct nl80211_global
*global
;
200 int ignore_if_down_event
;
201 struct rfkill_data
*rfkill
;
202 struct wpa_driver_capa capa
;
207 int scan_complete_events
;
209 struct nl80211_handles nl_event
, nl_preq
;
211 u8 auth_bssid
[ETH_ALEN
];
216 enum nl80211_iftype nlmode
;
217 enum nl80211_iftype ap_scan_as_station
;
218 unsigned int assoc_freq
;
222 int no_monitor_iface_capab
;
223 int disable_11b_rates
;
225 unsigned int pending_remain_on_chan
:1;
226 unsigned int in_interface_list
:1;
228 u64 remain_on_chan_cookie
;
229 u64 send_action_cookie
;
231 unsigned int last_mgmt_freq
;
232 unsigned int ap_oper_freq
;
234 struct wpa_driver_scan_filter
*filter_ssids
;
235 size_t num_filter_ssids
;
237 struct i802_bss first_bss
;
240 struct l2_packet_data
*l2
;
241 #endif /* CONFIG_AP */
244 int eapol_sock
; /* socket for EAPOL frames */
246 int default_if_indices
[16];
256 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
,
258 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
259 enum nl80211_iftype nlmode
);
261 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
);
262 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
263 const u8
*addr
, int cmd
, u16 reason_code
,
264 int local_state_change
);
265 static void nl80211_remove_monitor_interface(
266 struct wpa_driver_nl80211_data
*drv
);
267 static int nl80211_send_frame_cmd(struct wpa_driver_nl80211_data
*drv
,
268 unsigned int freq
, unsigned int wait
,
269 const u8
*buf
, size_t buf_len
, u64
*cookie
);
270 static int wpa_driver_nl80211_probe_req_report(void *priv
, int report
);
273 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
274 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
275 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
276 static int wpa_driver_nl80211_if_remove(void *priv
,
277 enum wpa_driver_if_type type
,
280 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
286 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
);
287 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
288 int ifindex
, int disabled
);
290 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
);
293 static int is_ap_interface(enum nl80211_iftype nlmode
)
295 return (nlmode
== NL80211_IFTYPE_AP
||
296 nlmode
== NL80211_IFTYPE_P2P_GO
);
300 static int is_sta_interface(enum nl80211_iftype nlmode
)
302 return (nlmode
== NL80211_IFTYPE_STATION
||
303 nlmode
== NL80211_IFTYPE_P2P_CLIENT
);
307 struct nl80211_bss_info_arg
{
308 struct wpa_driver_nl80211_data
*drv
;
309 struct wpa_scan_results
*res
;
310 unsigned int assoc_freq
;
311 u8 assoc_bssid
[ETH_ALEN
];
314 static int bss_info_handler(struct nl_msg
*msg
, void *arg
);
318 static int ack_handler(struct nl_msg
*msg
, void *arg
)
325 static int finish_handler(struct nl_msg
*msg
, void *arg
)
332 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
341 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
347 static int send_and_recv(struct wpa_driver_nl80211_data
*drv
,
348 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
349 int (*valid_handler
)(struct nl_msg
*, void *),
355 cb
= nl_cb_clone(drv
->global
->nl_cb
);
359 err
= nl_send_auto_complete(nl_handle
, msg
);
365 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
366 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
367 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
370 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
371 valid_handler
, valid_data
);
374 nl_recvmsgs(nl_handle
, cb
);
382 static int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
384 int (*valid_handler
)(struct nl_msg
*, void *),
387 return send_and_recv(drv
, drv
->global
->nl
.handle
, msg
, valid_handler
,
398 static int family_handler(struct nl_msg
*msg
, void *arg
)
400 struct family_data
*res
= arg
;
401 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
402 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
403 struct nlattr
*mcgrp
;
406 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
407 genlmsg_attrlen(gnlh
, 0), NULL
);
408 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
411 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
412 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
413 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
414 nla_len(mcgrp
), NULL
);
415 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
416 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
417 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
419 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
421 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
429 static int nl_get_multicast_id(struct wpa_driver_nl80211_data
*drv
,
430 const char *family
, const char *group
)
434 struct family_data res
= { group
, -ENOENT
};
439 genlmsg_put(msg
, 0, 0,
440 genl_ctrl_resolve(drv
->global
->nl
.handle
, "nlctrl"),
441 0, 0, CTRL_CMD_GETFAMILY
, 0);
442 NLA_PUT_STRING(msg
, CTRL_ATTR_FAMILY_NAME
, family
);
444 ret
= send_and_recv_msgs(drv
, msg
, family_handler
, &res
);
455 static void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
456 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
458 return genlmsg_put(msg
, 0, 0, genl_family_get_id(drv
->global
->nl80211
),
463 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
465 struct i802_bss
*bss
= priv
;
466 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
467 if (!drv
->associated
)
469 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
474 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
476 struct i802_bss
*bss
= priv
;
477 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
478 if (!drv
->associated
)
480 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
481 return drv
->ssid_len
;
485 static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data
*drv
,
486 char *buf
, size_t len
, int del
)
488 union wpa_event_data event
;
490 os_memset(&event
, 0, sizeof(event
));
491 if (len
> sizeof(event
.interface_status
.ifname
))
492 len
= sizeof(event
.interface_status
.ifname
) - 1;
493 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
494 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
495 EVENT_INTERFACE_ADDED
;
497 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
499 event
.interface_status
.ifname
,
500 del
? "removed" : "added");
502 if (os_strcmp(drv
->first_bss
.ifname
, event
.interface_status
.ifname
) == 0) {
509 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
513 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
516 int attrlen
, rta_len
;
520 attr
= (struct rtattr
*) buf
;
522 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
523 while (RTA_OK(attr
, attrlen
)) {
524 if (attr
->rta_type
== IFLA_IFNAME
) {
525 if (os_strcmp(((char *) attr
) + rta_len
, drv
->first_bss
.ifname
)
531 attr
= RTA_NEXT(attr
, attrlen
);
538 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
539 int ifindex
, u8
*buf
, size_t len
)
541 if (drv
->ifindex
== ifindex
)
544 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
545 drv
->first_bss
.ifindex
= if_nametoindex(drv
->first_bss
.ifname
);
546 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
548 wpa_driver_nl80211_finish_drv_init(drv
);
556 static struct wpa_driver_nl80211_data
*
557 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
559 struct wpa_driver_nl80211_data
*drv
;
560 dl_list_for_each(drv
, &global
->interfaces
,
561 struct wpa_driver_nl80211_data
, list
) {
562 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
563 have_ifidx(drv
, idx
))
570 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
571 struct ifinfomsg
*ifi
,
574 struct nl80211_global
*global
= ctx
;
575 struct wpa_driver_nl80211_data
*drv
;
576 int attrlen
, rta_len
;
580 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
582 wpa_printf(MSG_DEBUG
, "nl80211: Ignore event for foreign "
583 "ifindex %d", ifi
->ifi_index
);
587 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
589 drv
->operstate
, ifi
->ifi_flags
,
590 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
591 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
592 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
593 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
595 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
596 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
597 if (drv
->ignore_if_down_event
) {
598 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
599 "event generated by mode change");
600 drv
->ignore_if_down_event
= 0;
602 drv
->if_disabled
= 1;
603 wpa_supplicant_event(drv
->ctx
,
604 EVENT_INTERFACE_DISABLED
, NULL
);
608 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
609 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
610 drv
->if_disabled
= 0;
611 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
, NULL
);
615 * Some drivers send the association event before the operup event--in
616 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
617 * fails. This will hit us when wpa_supplicant does not need to do
618 * IEEE 802.1X authentication
620 if (drv
->operstate
== 1 &&
621 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
622 !(ifi
->ifi_flags
& IFF_RUNNING
))
623 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
627 attr
= (struct rtattr
*) buf
;
628 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
629 while (RTA_OK(attr
, attrlen
)) {
630 if (attr
->rta_type
== IFLA_IFNAME
) {
631 wpa_driver_nl80211_event_link(
633 ((char *) attr
) + rta_len
,
634 attr
->rta_len
- rta_len
, 0);
635 } else if (attr
->rta_type
== IFLA_MASTER
)
636 brid
= nla_get_u32((struct nlattr
*) attr
);
637 attr
= RTA_NEXT(attr
, attrlen
);
641 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
642 /* device has been added to bridge */
643 char namebuf
[IFNAMSIZ
];
644 if_indextoname(brid
, namebuf
);
645 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
647 add_ifidx(drv
, brid
);
653 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
654 struct ifinfomsg
*ifi
,
657 struct nl80211_global
*global
= ctx
;
658 struct wpa_driver_nl80211_data
*drv
;
659 int attrlen
, rta_len
;
663 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
665 wpa_printf(MSG_DEBUG
, "nl80211: Ignore dellink event for "
666 "foreign ifindex %d", ifi
->ifi_index
);
671 attr
= (struct rtattr
*) buf
;
673 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
674 while (RTA_OK(attr
, attrlen
)) {
675 if (attr
->rta_type
== IFLA_IFNAME
) {
676 wpa_driver_nl80211_event_link(
678 ((char *) attr
) + rta_len
,
679 attr
->rta_len
- rta_len
, 1);
680 } else if (attr
->rta_type
== IFLA_MASTER
)
681 brid
= nla_get_u32((struct nlattr
*) attr
);
682 attr
= RTA_NEXT(attr
, attrlen
);
686 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
687 /* device has been removed from bridge */
688 char namebuf
[IFNAMSIZ
];
689 if_indextoname(brid
, namebuf
);
690 wpa_printf(MSG_DEBUG
, "nl80211: Remove ifindex %u for bridge "
691 "%s", brid
, namebuf
);
692 del_ifidx(drv
, brid
);
698 static void mlme_event_auth(struct wpa_driver_nl80211_data
*drv
,
699 const u8
*frame
, size_t len
)
701 const struct ieee80211_mgmt
*mgmt
;
702 union wpa_event_data event
;
704 mgmt
= (const struct ieee80211_mgmt
*) frame
;
705 if (len
< 24 + sizeof(mgmt
->u
.auth
)) {
706 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
711 os_memcpy(drv
->auth_bssid
, mgmt
->sa
, ETH_ALEN
);
712 os_memset(&event
, 0, sizeof(event
));
713 os_memcpy(event
.auth
.peer
, mgmt
->sa
, ETH_ALEN
);
714 event
.auth
.auth_type
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
715 event
.auth
.status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
716 if (len
> 24 + sizeof(mgmt
->u
.auth
)) {
717 event
.auth
.ies
= mgmt
->u
.auth
.variable
;
718 event
.auth
.ies_len
= len
- 24 - sizeof(mgmt
->u
.auth
);
721 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH
, &event
);
725 static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
729 struct nl80211_bss_info_arg arg
;
731 os_memset(&arg
, 0, sizeof(arg
));
734 goto nla_put_failure
;
736 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
737 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
740 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
743 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
744 "associated BSS from scan results: %u MHz",
746 return arg
.assoc_freq
? arg
.assoc_freq
: drv
->assoc_freq
;
748 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
749 "(%s)", ret
, strerror(-ret
));
752 return drv
->assoc_freq
;
756 static void mlme_event_assoc(struct wpa_driver_nl80211_data
*drv
,
757 const u8
*frame
, size_t len
)
759 const struct ieee80211_mgmt
*mgmt
;
760 union wpa_event_data event
;
763 mgmt
= (const struct ieee80211_mgmt
*) frame
;
764 if (len
< 24 + sizeof(mgmt
->u
.assoc_resp
)) {
765 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
770 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
771 if (status
!= WLAN_STATUS_SUCCESS
) {
772 os_memset(&event
, 0, sizeof(event
));
773 event
.assoc_reject
.bssid
= mgmt
->bssid
;
774 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
775 event
.assoc_reject
.resp_ies
=
776 (u8
*) mgmt
->u
.assoc_resp
.variable
;
777 event
.assoc_reject
.resp_ies_len
=
778 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
780 event
.assoc_reject
.status_code
= status
;
782 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
787 os_memcpy(drv
->bssid
, mgmt
->sa
, ETH_ALEN
);
789 os_memset(&event
, 0, sizeof(event
));
790 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
791 event
.assoc_info
.resp_ies
= (u8
*) mgmt
->u
.assoc_resp
.variable
;
792 event
.assoc_info
.resp_ies_len
=
793 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
796 event
.assoc_info
.freq
= drv
->assoc_freq
;
798 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
802 static void mlme_event_connect(struct wpa_driver_nl80211_data
*drv
,
803 enum nl80211_commands cmd
, struct nlattr
*status
,
804 struct nlattr
*addr
, struct nlattr
*req_ie
,
805 struct nlattr
*resp_ie
)
807 union wpa_event_data event
;
809 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
811 * Avoid reporting two association events that would confuse
814 wpa_printf(MSG_DEBUG
, "nl80211: Ignore connect event (cmd=%d) "
815 "when using userspace SME", cmd
);
819 os_memset(&event
, 0, sizeof(event
));
820 if (cmd
== NL80211_CMD_CONNECT
&&
821 nla_get_u16(status
) != WLAN_STATUS_SUCCESS
) {
823 event
.assoc_reject
.bssid
= nla_data(addr
);
825 event
.assoc_reject
.resp_ies
= nla_data(resp_ie
);
826 event
.assoc_reject
.resp_ies_len
= nla_len(resp_ie
);
828 event
.assoc_reject
.status_code
= nla_get_u16(status
);
829 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
835 os_memcpy(drv
->bssid
, nla_data(addr
), ETH_ALEN
);
838 event
.assoc_info
.req_ies
= nla_data(req_ie
);
839 event
.assoc_info
.req_ies_len
= nla_len(req_ie
);
842 event
.assoc_info
.resp_ies
= nla_data(resp_ie
);
843 event
.assoc_info
.resp_ies_len
= nla_len(resp_ie
);
846 event
.assoc_info
.freq
= nl80211_get_assoc_freq(drv
);
848 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
852 static void mlme_event_disconnect(struct wpa_driver_nl80211_data
*drv
,
853 struct nlattr
*reason
, struct nlattr
*addr
)
855 union wpa_event_data data
;
857 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
859 * Avoid reporting two disassociation events that could
860 * confuse the core code.
862 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
863 "event when using userspace SME");
868 os_memset(&data
, 0, sizeof(data
));
870 data
.disassoc_info
.reason_code
= nla_get_u16(reason
);
871 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, &data
);
875 static void mlme_timeout_event(struct wpa_driver_nl80211_data
*drv
,
876 enum nl80211_commands cmd
, struct nlattr
*addr
)
878 union wpa_event_data event
;
879 enum wpa_event_type ev
;
881 if (nla_len(addr
) != ETH_ALEN
)
884 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d; timeout with " MACSTR
,
885 cmd
, MAC2STR((u8
*) nla_data(addr
)));
887 if (cmd
== NL80211_CMD_AUTHENTICATE
)
888 ev
= EVENT_AUTH_TIMED_OUT
;
889 else if (cmd
== NL80211_CMD_ASSOCIATE
)
890 ev
= EVENT_ASSOC_TIMED_OUT
;
894 os_memset(&event
, 0, sizeof(event
));
895 os_memcpy(event
.timeout_event
.addr
, nla_data(addr
), ETH_ALEN
);
896 wpa_supplicant_event(drv
->ctx
, ev
, &event
);
900 static void mlme_event_mgmt(struct wpa_driver_nl80211_data
*drv
,
901 struct nlattr
*freq
, const u8
*frame
, size_t len
)
903 const struct ieee80211_mgmt
*mgmt
;
904 union wpa_event_data event
;
907 mgmt
= (const struct ieee80211_mgmt
*) frame
;
909 wpa_printf(MSG_DEBUG
, "nl80211: Too short action frame");
913 fc
= le_to_host16(mgmt
->frame_control
);
914 stype
= WLAN_FC_GET_STYPE(fc
);
916 os_memset(&event
, 0, sizeof(event
));
918 event
.rx_action
.freq
= nla_get_u32(freq
);
919 drv
->last_mgmt_freq
= event
.rx_action
.freq
;
921 if (stype
== WLAN_FC_STYPE_ACTION
) {
922 event
.rx_action
.da
= mgmt
->da
;
923 event
.rx_action
.sa
= mgmt
->sa
;
924 event
.rx_action
.bssid
= mgmt
->bssid
;
925 event
.rx_action
.category
= mgmt
->u
.action
.category
;
926 event
.rx_action
.data
= &mgmt
->u
.action
.category
+ 1;
927 event
.rx_action
.len
= frame
+ len
- event
.rx_action
.data
;
928 wpa_supplicant_event(drv
->ctx
, EVENT_RX_ACTION
, &event
);
930 event
.rx_mgmt
.frame
= frame
;
931 event
.rx_mgmt
.frame_len
= len
;
932 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
937 static void mlme_event_action_tx_status(struct wpa_driver_nl80211_data
*drv
,
938 struct nlattr
*cookie
, const u8
*frame
,
939 size_t len
, struct nlattr
*ack
)
941 union wpa_event_data event
;
942 const struct ieee80211_hdr
*hdr
;
949 cookie_val
= nla_get_u64(cookie
);
950 wpa_printf(MSG_DEBUG
, "nl80211: Action TX status: cookie=0%llx%s "
952 (long long unsigned int) cookie_val
,
953 cookie_val
== drv
->send_action_cookie
?
954 " (match)" : " (unknown)", ack
!= NULL
);
955 if (cookie_val
!= drv
->send_action_cookie
)
958 hdr
= (const struct ieee80211_hdr
*) frame
;
959 fc
= le_to_host16(hdr
->frame_control
);
961 os_memset(&event
, 0, sizeof(event
));
962 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
963 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
964 event
.tx_status
.dst
= hdr
->addr1
;
965 event
.tx_status
.data
= frame
;
966 event
.tx_status
.data_len
= len
;
967 event
.tx_status
.ack
= ack
!= NULL
;
968 wpa_supplicant_event(drv
->ctx
, EVENT_TX_STATUS
, &event
);
972 static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data
*drv
,
973 enum wpa_event_type type
,
974 const u8
*frame
, size_t len
)
976 const struct ieee80211_mgmt
*mgmt
;
977 union wpa_event_data event
;
978 const u8
*bssid
= NULL
;
981 mgmt
= (const struct ieee80211_mgmt
*) frame
;
985 if (drv
->associated
!= 0 &&
986 os_memcmp(bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
987 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0) {
989 * We have presumably received this deauth as a
990 * response to a clear_state_mismatch() outgoing
991 * deauth. Don't let it take us offline!
993 wpa_printf(MSG_DEBUG
, "nl80211: Deauth received "
994 "from Unknown BSSID " MACSTR
" -- ignoring",
1000 drv
->associated
= 0;
1001 os_memset(&event
, 0, sizeof(event
));
1003 /* Note: Same offset for Reason Code in both frame subtypes */
1004 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1005 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1007 if (type
== EVENT_DISASSOC
) {
1008 event
.disassoc_info
.addr
= bssid
;
1009 event
.disassoc_info
.reason_code
= reason_code
;
1010 if (frame
+ len
> mgmt
->u
.disassoc
.variable
) {
1011 event
.disassoc_info
.ie
= mgmt
->u
.disassoc
.variable
;
1012 event
.disassoc_info
.ie_len
= frame
+ len
-
1013 mgmt
->u
.disassoc
.variable
;
1016 event
.deauth_info
.addr
= bssid
;
1017 event
.deauth_info
.reason_code
= reason_code
;
1018 if (frame
+ len
> mgmt
->u
.deauth
.variable
) {
1019 event
.deauth_info
.ie
= mgmt
->u
.deauth
.variable
;
1020 event
.deauth_info
.ie_len
= frame
+ len
-
1021 mgmt
->u
.deauth
.variable
;
1025 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1029 static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data
*drv
,
1030 enum wpa_event_type type
,
1031 const u8
*frame
, size_t len
)
1033 const struct ieee80211_mgmt
*mgmt
;
1034 union wpa_event_data event
;
1035 u16 reason_code
= 0;
1040 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1042 os_memset(&event
, 0, sizeof(event
));
1043 /* Note: Same offset for Reason Code in both frame subtypes */
1044 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1045 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1047 if (type
== EVENT_UNPROT_DISASSOC
) {
1048 event
.unprot_disassoc
.sa
= mgmt
->sa
;
1049 event
.unprot_disassoc
.da
= mgmt
->da
;
1050 event
.unprot_disassoc
.reason_code
= reason_code
;
1052 event
.unprot_deauth
.sa
= mgmt
->sa
;
1053 event
.unprot_deauth
.da
= mgmt
->da
;
1054 event
.unprot_deauth
.reason_code
= reason_code
;
1057 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1061 static void mlme_event(struct wpa_driver_nl80211_data
*drv
,
1062 enum nl80211_commands cmd
, struct nlattr
*frame
,
1063 struct nlattr
*addr
, struct nlattr
*timed_out
,
1064 struct nlattr
*freq
, struct nlattr
*ack
,
1065 struct nlattr
*cookie
)
1067 if (timed_out
&& addr
) {
1068 mlme_timeout_event(drv
, cmd
, addr
);
1072 if (frame
== NULL
) {
1073 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d without frame "
1078 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d", cmd
);
1079 wpa_hexdump(MSG_MSGDUMP
, "nl80211: MLME event frame",
1080 nla_data(frame
), nla_len(frame
));
1083 case NL80211_CMD_AUTHENTICATE
:
1084 mlme_event_auth(drv
, nla_data(frame
), nla_len(frame
));
1086 case NL80211_CMD_ASSOCIATE
:
1087 mlme_event_assoc(drv
, nla_data(frame
), nla_len(frame
));
1089 case NL80211_CMD_DEAUTHENTICATE
:
1090 mlme_event_deauth_disassoc(drv
, EVENT_DEAUTH
,
1091 nla_data(frame
), nla_len(frame
));
1093 case NL80211_CMD_DISASSOCIATE
:
1094 mlme_event_deauth_disassoc(drv
, EVENT_DISASSOC
,
1095 nla_data(frame
), nla_len(frame
));
1097 case NL80211_CMD_FRAME
:
1098 mlme_event_mgmt(drv
, freq
, nla_data(frame
), nla_len(frame
));
1100 case NL80211_CMD_FRAME_TX_STATUS
:
1101 mlme_event_action_tx_status(drv
, cookie
, nla_data(frame
),
1102 nla_len(frame
), ack
);
1104 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1105 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DEAUTH
,
1106 nla_data(frame
), nla_len(frame
));
1108 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1109 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DISASSOC
,
1110 nla_data(frame
), nla_len(frame
));
1118 static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data
*drv
,
1119 struct nlattr
*tb
[])
1121 union wpa_event_data data
;
1123 wpa_printf(MSG_DEBUG
, "nl80211: MLME event Michael MIC failure");
1124 os_memset(&data
, 0, sizeof(data
));
1125 if (tb
[NL80211_ATTR_MAC
]) {
1126 wpa_hexdump(MSG_DEBUG
, "nl80211: Source MAC address",
1127 nla_data(tb
[NL80211_ATTR_MAC
]),
1128 nla_len(tb
[NL80211_ATTR_MAC
]));
1129 data
.michael_mic_failure
.src
= nla_data(tb
[NL80211_ATTR_MAC
]);
1131 if (tb
[NL80211_ATTR_KEY_SEQ
]) {
1132 wpa_hexdump(MSG_DEBUG
, "nl80211: TSC",
1133 nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
1134 nla_len(tb
[NL80211_ATTR_KEY_SEQ
]));
1136 if (tb
[NL80211_ATTR_KEY_TYPE
]) {
1137 enum nl80211_key_type key_type
=
1138 nla_get_u32(tb
[NL80211_ATTR_KEY_TYPE
]);
1139 wpa_printf(MSG_DEBUG
, "nl80211: Key Type %d", key_type
);
1140 if (key_type
== NL80211_KEYTYPE_PAIRWISE
)
1141 data
.michael_mic_failure
.unicast
= 1;
1143 data
.michael_mic_failure
.unicast
= 1;
1145 if (tb
[NL80211_ATTR_KEY_IDX
]) {
1146 u8 key_id
= nla_get_u8(tb
[NL80211_ATTR_KEY_IDX
]);
1147 wpa_printf(MSG_DEBUG
, "nl80211: Key Id %d", key_id
);
1150 wpa_supplicant_event(drv
->ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
1154 static void mlme_event_join_ibss(struct wpa_driver_nl80211_data
*drv
,
1155 struct nlattr
*tb
[])
1157 if (tb
[NL80211_ATTR_MAC
] == NULL
) {
1158 wpa_printf(MSG_DEBUG
, "nl80211: No address in IBSS joined "
1162 os_memcpy(drv
->bssid
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1163 drv
->associated
= 1;
1164 wpa_printf(MSG_DEBUG
, "nl80211: IBSS " MACSTR
" joined",
1165 MAC2STR(drv
->bssid
));
1167 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1171 static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data
*drv
,
1172 int cancel_event
, struct nlattr
*tb
[])
1174 unsigned int freq
, chan_type
, duration
;
1175 union wpa_event_data data
;
1178 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1179 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1183 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1184 chan_type
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1188 if (tb
[NL80211_ATTR_DURATION
])
1189 duration
= nla_get_u32(tb
[NL80211_ATTR_DURATION
]);
1193 if (tb
[NL80211_ATTR_COOKIE
])
1194 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
1198 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel event (cancel=%d "
1199 "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
1200 cancel_event
, freq
, chan_type
, duration
,
1201 (long long unsigned int) cookie
,
1202 cookie
== drv
->remain_on_chan_cookie
? "match" : "unknown");
1204 if (cookie
!= drv
->remain_on_chan_cookie
)
1205 return; /* not for us */
1208 drv
->pending_remain_on_chan
= 0;
1210 os_memset(&data
, 0, sizeof(data
));
1211 data
.remain_on_channel
.freq
= freq
;
1212 data
.remain_on_channel
.duration
= duration
;
1213 wpa_supplicant_event(drv
->ctx
, cancel_event
?
1214 EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1215 EVENT_REMAIN_ON_CHANNEL
, &data
);
1219 static void send_scan_event(struct wpa_driver_nl80211_data
*drv
, int aborted
,
1220 struct nlattr
*tb
[])
1222 union wpa_event_data event
;
1225 struct scan_info
*info
;
1226 #define MAX_REPORT_FREQS 50
1227 int freqs
[MAX_REPORT_FREQS
];
1230 os_memset(&event
, 0, sizeof(event
));
1231 info
= &event
.scan_info
;
1232 info
->aborted
= aborted
;
1234 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
1235 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem
) {
1236 struct wpa_driver_scan_ssid
*s
=
1237 &info
->ssids
[info
->num_ssids
];
1238 s
->ssid
= nla_data(nl
);
1239 s
->ssid_len
= nla_len(nl
);
1241 if (info
->num_ssids
== WPAS_MAX_SCAN_SSIDS
)
1245 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
1246 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem
)
1248 freqs
[num_freqs
] = nla_get_u32(nl
);
1250 if (num_freqs
== MAX_REPORT_FREQS
- 1)
1253 info
->freqs
= freqs
;
1254 info
->num_freqs
= num_freqs
;
1256 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
, &event
);
1260 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1262 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1263 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1264 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1265 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1266 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1268 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1269 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1270 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1271 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1272 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1273 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1275 struct wpa_signal_info
*sig_change
= arg
;
1277 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1278 genlmsg_attrlen(gnlh
, 0), NULL
);
1279 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1280 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1281 tb
[NL80211_ATTR_STA_INFO
], policy
))
1283 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1286 sig_change
->current_signal
=
1287 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1289 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1290 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1291 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1293 sig_change
->current_txrate
= 0;
1295 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1296 sig_change
->current_txrate
=
1298 NL80211_RATE_INFO_BITRATE
]) * 100;
1307 static int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1308 struct wpa_signal_info
*sig
)
1312 sig
->current_signal
= -9999;
1313 sig
->current_txrate
= 0;
1315 msg
= nlmsg_alloc();
1319 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
1321 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1322 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
1324 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1330 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1332 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1333 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1334 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1335 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1336 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1337 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1339 struct wpa_signal_info
*sig_change
= arg
;
1341 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1342 genlmsg_attrlen(gnlh
, 0), NULL
);
1344 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1345 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1349 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1350 tb
[NL80211_ATTR_SURVEY_INFO
],
1352 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1357 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1360 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1361 sig_change
->frequency
)
1364 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1367 sig_change
->current_noise
=
1368 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1374 static int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1375 struct wpa_signal_info
*sig_change
)
1379 sig_change
->current_noise
= 9999;
1380 sig_change
->frequency
= drv
->assoc_freq
;
1382 msg
= nlmsg_alloc();
1386 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1388 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1390 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1396 static void nl80211_cqm_event(struct wpa_driver_nl80211_data
*drv
,
1397 struct nlattr
*tb
[])
1399 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
1400 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
1401 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U8
},
1402 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
1403 [NL80211_ATTR_CQM_PKT_LOSS_EVENT
] = { .type
= NLA_U32
},
1405 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
1406 enum nl80211_cqm_rssi_threshold_event event
;
1407 union wpa_event_data ed
;
1408 struct wpa_signal_info sig
;
1411 if (tb
[NL80211_ATTR_CQM
] == NULL
||
1412 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, tb
[NL80211_ATTR_CQM
],
1414 wpa_printf(MSG_DEBUG
, "nl80211: Ignore invalid CQM event");
1418 os_memset(&ed
, 0, sizeof(ed
));
1420 if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
1421 if (!tb
[NL80211_ATTR_MAC
])
1423 os_memcpy(ed
.low_ack
.addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
1425 wpa_supplicant_event(drv
->ctx
, EVENT_STATION_LOW_ACK
, &ed
);
1429 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] == NULL
)
1431 event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
1433 if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
) {
1434 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1435 "event: RSSI high");
1436 ed
.signal_change
.above_threshold
= 1;
1437 } else if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
) {
1438 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1440 ed
.signal_change
.above_threshold
= 0;
1444 res
= nl80211_get_link_signal(drv
, &sig
);
1446 ed
.signal_change
.current_signal
= sig
.current_signal
;
1447 ed
.signal_change
.current_txrate
= sig
.current_txrate
;
1448 wpa_printf(MSG_DEBUG
, "nl80211: Signal: %d dBm txrate: %d",
1449 sig
.current_signal
, sig
.current_txrate
);
1452 res
= nl80211_get_link_noise(drv
, &sig
);
1454 ed
.signal_change
.current_noise
= sig
.current_noise
;
1455 wpa_printf(MSG_DEBUG
, "nl80211: Noise: %d dBm",
1459 wpa_supplicant_event(drv
->ctx
, EVENT_SIGNAL_CHANGE
, &ed
);
1463 static void nl80211_new_station_event(struct wpa_driver_nl80211_data
*drv
,
1467 union wpa_event_data data
;
1469 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1471 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1472 wpa_printf(MSG_DEBUG
, "nl80211: New station " MACSTR
, MAC2STR(addr
));
1474 if (is_ap_interface(drv
->nlmode
) && drv
->no_monitor_iface_capab
) {
1477 if (tb
[NL80211_ATTR_IE
]) {
1478 ies
= nla_data(tb
[NL80211_ATTR_IE
]);
1479 ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
1481 wpa_hexdump(MSG_DEBUG
, "nl80211: Assoc Req IEs", ies
, ies_len
);
1482 drv_event_assoc(drv
->ctx
, addr
, ies
, ies_len
, 0);
1486 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1489 os_memset(&data
, 0, sizeof(data
));
1490 os_memcpy(data
.ibss_rsn_start
.peer
, addr
, ETH_ALEN
);
1491 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_RSN_START
, &data
);
1495 static void nl80211_del_station_event(struct wpa_driver_nl80211_data
*drv
,
1499 union wpa_event_data data
;
1501 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1503 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1504 wpa_printf(MSG_DEBUG
, "nl80211: Delete station " MACSTR
,
1507 if (is_ap_interface(drv
->nlmode
) && drv
->no_monitor_iface_capab
) {
1508 drv_event_disassoc(drv
->ctx
, addr
);
1512 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1515 os_memset(&data
, 0, sizeof(data
));
1516 os_memcpy(data
.ibss_peer_lost
.peer
, addr
, ETH_ALEN
);
1517 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_PEER_LOST
, &data
);
1521 static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data
*drv
,
1524 struct nlattr
*rekey_info
[NUM_NL80211_REKEY_DATA
];
1525 static struct nla_policy rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
1526 [NL80211_REKEY_DATA_KEK
] = {
1527 .minlen
= NL80211_KEK_LEN
,
1528 .maxlen
= NL80211_KEK_LEN
,
1530 [NL80211_REKEY_DATA_KCK
] = {
1531 .minlen
= NL80211_KCK_LEN
,
1532 .maxlen
= NL80211_KCK_LEN
,
1534 [NL80211_REKEY_DATA_REPLAY_CTR
] = {
1535 .minlen
= NL80211_REPLAY_CTR_LEN
,
1536 .maxlen
= NL80211_REPLAY_CTR_LEN
,
1539 union wpa_event_data data
;
1541 if (!tb
[NL80211_ATTR_MAC
])
1543 if (!tb
[NL80211_ATTR_REKEY_DATA
])
1545 if (nla_parse_nested(rekey_info
, MAX_NL80211_REKEY_DATA
,
1546 tb
[NL80211_ATTR_REKEY_DATA
], rekey_policy
))
1548 if (!rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
])
1551 os_memset(&data
, 0, sizeof(data
));
1552 data
.driver_gtk_rekey
.bssid
= nla_data(tb
[NL80211_ATTR_MAC
]);
1553 wpa_printf(MSG_DEBUG
, "nl80211: Rekey offload event for BSSID " MACSTR
,
1554 MAC2STR(data
.driver_gtk_rekey
.bssid
));
1555 data
.driver_gtk_rekey
.replay_ctr
=
1556 nla_data(rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
]);
1557 wpa_hexdump(MSG_DEBUG
, "nl80211: Rekey offload - Replay Counter",
1558 data
.driver_gtk_rekey
.replay_ctr
, NL80211_REPLAY_CTR_LEN
);
1559 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_GTK_REKEY
, &data
);
1563 static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data
*drv
,
1566 struct nlattr
*cand
[NUM_NL80211_PMKSA_CANDIDATE
];
1567 static struct nla_policy cand_policy
[NUM_NL80211_PMKSA_CANDIDATE
] = {
1568 [NL80211_PMKSA_CANDIDATE_INDEX
] = { .type
= NLA_U32
},
1569 [NL80211_PMKSA_CANDIDATE_BSSID
] = {
1573 [NL80211_PMKSA_CANDIDATE_PREAUTH
] = { .type
= NLA_FLAG
},
1575 union wpa_event_data data
;
1577 if (!tb
[NL80211_ATTR_PMKSA_CANDIDATE
])
1579 if (nla_parse_nested(cand
, MAX_NL80211_PMKSA_CANDIDATE
,
1580 tb
[NL80211_ATTR_PMKSA_CANDIDATE
], cand_policy
))
1582 if (!cand
[NL80211_PMKSA_CANDIDATE_INDEX
] ||
1583 !cand
[NL80211_PMKSA_CANDIDATE_BSSID
])
1586 os_memset(&data
, 0, sizeof(data
));
1587 os_memcpy(data
.pmkid_candidate
.bssid
,
1588 nla_data(cand
[NL80211_PMKSA_CANDIDATE_BSSID
]), ETH_ALEN
);
1589 data
.pmkid_candidate
.index
=
1590 nla_get_u32(cand
[NL80211_PMKSA_CANDIDATE_INDEX
]);
1591 data
.pmkid_candidate
.preauth
=
1592 cand
[NL80211_PMKSA_CANDIDATE_PREAUTH
] != NULL
;
1593 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
1597 static int process_event(struct nl_msg
*msg
, void *arg
)
1599 struct wpa_driver_nl80211_data
*drv
= arg
;
1600 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1601 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1603 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1604 genlmsg_attrlen(gnlh
, 0), NULL
);
1606 if (tb
[NL80211_ATTR_IFINDEX
]) {
1607 int ifindex
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1608 if (ifindex
!= drv
->ifindex
&& !have_ifidx(drv
, ifindex
)) {
1609 wpa_printf(MSG_DEBUG
, "nl80211: Ignored event (cmd=%d)"
1610 " for foreign interface (ifindex %d)",
1611 gnlh
->cmd
, ifindex
);
1616 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
&&
1617 (gnlh
->cmd
== NL80211_CMD_NEW_SCAN_RESULTS
||
1618 gnlh
->cmd
== NL80211_CMD_SCAN_ABORTED
)) {
1619 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
1620 drv
->ap_scan_as_station
);
1621 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
1624 switch (gnlh
->cmd
) {
1625 case NL80211_CMD_TRIGGER_SCAN
:
1626 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger");
1628 case NL80211_CMD_START_SCHED_SCAN
:
1629 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan started");
1631 case NL80211_CMD_SCHED_SCAN_STOPPED
:
1632 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stopped");
1633 wpa_supplicant_event(drv
->ctx
, EVENT_SCHED_SCAN_STOPPED
, NULL
);
1635 case NL80211_CMD_NEW_SCAN_RESULTS
:
1636 wpa_printf(MSG_DEBUG
, "nl80211: New scan results available");
1637 drv
->scan_complete_events
= 1;
1638 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
1640 send_scan_event(drv
, 0, tb
);
1642 case NL80211_CMD_SCHED_SCAN_RESULTS
:
1643 wpa_printf(MSG_DEBUG
,
1644 "nl80211: New sched scan results available");
1645 send_scan_event(drv
, 0, tb
);
1647 case NL80211_CMD_SCAN_ABORTED
:
1648 wpa_printf(MSG_DEBUG
, "nl80211: Scan aborted");
1650 * Need to indicate that scan results are available in order
1651 * not to make wpa_supplicant stop its scanning.
1653 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
1655 send_scan_event(drv
, 1, tb
);
1657 case NL80211_CMD_AUTHENTICATE
:
1658 case NL80211_CMD_ASSOCIATE
:
1659 case NL80211_CMD_DEAUTHENTICATE
:
1660 case NL80211_CMD_DISASSOCIATE
:
1661 case NL80211_CMD_FRAME
:
1662 case NL80211_CMD_FRAME_TX_STATUS
:
1663 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1664 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1665 mlme_event(drv
, gnlh
->cmd
, tb
[NL80211_ATTR_FRAME
],
1666 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
1667 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
1668 tb
[NL80211_ATTR_COOKIE
]);
1670 case NL80211_CMD_CONNECT
:
1671 case NL80211_CMD_ROAM
:
1672 mlme_event_connect(drv
, gnlh
->cmd
,
1673 tb
[NL80211_ATTR_STATUS_CODE
],
1674 tb
[NL80211_ATTR_MAC
],
1675 tb
[NL80211_ATTR_REQ_IE
],
1676 tb
[NL80211_ATTR_RESP_IE
]);
1678 case NL80211_CMD_DISCONNECT
:
1679 mlme_event_disconnect(drv
, tb
[NL80211_ATTR_REASON_CODE
],
1680 tb
[NL80211_ATTR_MAC
]);
1682 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
1683 mlme_event_michael_mic_failure(drv
, tb
);
1685 case NL80211_CMD_JOIN_IBSS
:
1686 mlme_event_join_ibss(drv
, tb
);
1688 case NL80211_CMD_REMAIN_ON_CHANNEL
:
1689 mlme_event_remain_on_channel(drv
, 0, tb
);
1691 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
1692 mlme_event_remain_on_channel(drv
, 1, tb
);
1694 case NL80211_CMD_NOTIFY_CQM
:
1695 nl80211_cqm_event(drv
, tb
);
1697 case NL80211_CMD_REG_CHANGE
:
1698 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory domain change");
1699 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
1702 case NL80211_CMD_REG_BEACON_HINT
:
1703 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory beacon hint");
1704 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
1707 case NL80211_CMD_NEW_STATION
:
1708 nl80211_new_station_event(drv
, tb
);
1710 case NL80211_CMD_DEL_STATION
:
1711 nl80211_del_station_event(drv
, tb
);
1713 case NL80211_CMD_SET_REKEY_OFFLOAD
:
1714 nl80211_rekey_offload_event(drv
, tb
);
1716 case NL80211_CMD_PMKSA_CANDIDATE
:
1717 nl80211_pmksa_candidate_event(drv
, tb
);
1720 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
1721 "(cmd=%d)", gnlh
->cmd
);
1729 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
1733 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
1735 wpa_printf(MSG_DEBUG
, "nl80211: Event message available");
1737 cb
= nl_cb_clone(drv
->global
->nl_cb
);
1740 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
1741 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_event
, drv
);
1742 nl_recvmsgs(handle
, cb
);
1748 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1749 * @priv: driver_nl80211 private data
1750 * @alpha2_arg: country to which to switch to
1751 * Returns: 0 on success, -1 on failure
1753 * This asks nl80211 to set the regulatory domain for given
1754 * country ISO / IEC alpha2.
1756 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
1758 struct i802_bss
*bss
= priv
;
1759 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1763 msg
= nlmsg_alloc();
1767 alpha2
[0] = alpha2_arg
[0];
1768 alpha2
[1] = alpha2_arg
[1];
1771 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
);
1773 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
);
1774 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
1782 struct wiphy_info_data
{
1783 struct wpa_driver_capa
*capa
;
1785 unsigned int error
:1;
1789 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
1791 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1792 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1793 struct wiphy_info_data
*info
= arg
;
1794 int p2p_go_supported
= 0, p2p_client_supported
= 0;
1795 int p2p_concurrent
= 0;
1796 int auth_supported
= 0, connect_supported
= 0;
1797 struct wpa_driver_capa
*capa
= info
->capa
;
1798 static struct nla_policy
1799 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
1800 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
1801 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
1802 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
1803 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
1805 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
1806 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
1807 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
1810 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1811 genlmsg_attrlen(gnlh
, 0), NULL
);
1813 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
1814 capa
->max_scan_ssids
=
1815 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
1817 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
1818 capa
->max_sched_scan_ssids
=
1819 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
1821 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
1822 capa
->max_match_sets
=
1823 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
1825 if (tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]) {
1826 struct nlattr
*nl_mode
;
1828 nla_for_each_nested(nl_mode
,
1829 tb
[NL80211_ATTR_SUPPORTED_IFTYPES
], i
) {
1830 switch (nla_type(nl_mode
)) {
1831 case NL80211_IFTYPE_AP
:
1832 capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
1834 case NL80211_IFTYPE_P2P_GO
:
1835 p2p_go_supported
= 1;
1837 case NL80211_IFTYPE_P2P_CLIENT
:
1838 p2p_client_supported
= 1;
1844 if (tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]) {
1845 struct nlattr
*nl_combi
;
1848 nla_for_each_nested(nl_combi
,
1849 tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
],
1851 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
1852 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
1853 struct nlattr
*nl_limit
, *nl_mode
;
1854 int err
, rem_limit
, rem_mode
;
1855 int combination_has_p2p
= 0, combination_has_mgd
= 0;
1857 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
1859 iface_combination_policy
);
1860 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
1861 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
1862 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
1863 goto broken_combination
;
1865 nla_for_each_nested(nl_limit
,
1866 tb_comb
[NL80211_IFACE_COMB_LIMITS
],
1868 err
= nla_parse_nested(tb_limit
,
1869 MAX_NL80211_IFACE_LIMIT
,
1871 iface_limit_policy
);
1873 !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
1874 goto broken_combination
;
1876 nla_for_each_nested(
1878 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
1880 int ift
= nla_type(nl_mode
);
1881 if (ift
== NL80211_IFTYPE_P2P_GO
||
1882 ift
== NL80211_IFTYPE_P2P_CLIENT
)
1883 combination_has_p2p
= 1;
1884 if (ift
== NL80211_IFTYPE_STATION
)
1885 combination_has_mgd
= 1;
1887 if (combination_has_p2p
&& combination_has_mgd
)
1891 if (combination_has_p2p
&& combination_has_mgd
) {
1901 if (tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]) {
1902 struct nlattr
*nl_cmd
;
1905 nla_for_each_nested(nl_cmd
,
1906 tb
[NL80211_ATTR_SUPPORTED_COMMANDS
], i
) {
1907 switch (nla_get_u32(nl_cmd
)) {
1908 case NL80211_CMD_AUTHENTICATE
:
1911 case NL80211_CMD_CONNECT
:
1912 connect_supported
= 1;
1914 case NL80211_CMD_START_SCHED_SCAN
:
1915 capa
->sched_scan_supported
= 1;
1921 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
1922 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
1924 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
1927 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
1928 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
1929 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
1932 /* default to 5000 since early versions of mac80211 don't set it */
1933 capa
->max_remain_on_chan
= 5000;
1935 if (tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
])
1936 capa
->max_remain_on_chan
=
1937 nla_get_u32(tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
1940 capa
->flags
|= WPA_DRIVER_FLAGS_SME
;
1941 else if (!connect_supported
) {
1942 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
1943 "authentication/association or connect commands");
1947 if (p2p_go_supported
&& p2p_client_supported
)
1948 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
1949 if (p2p_concurrent
) {
1950 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
1951 "interface (driver advertised support)");
1952 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
1953 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
1960 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
1961 struct wiphy_info_data
*info
)
1965 os_memset(info
, 0, sizeof(*info
));
1966 info
->capa
= &drv
->capa
;
1968 msg
= nlmsg_alloc();
1972 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
1974 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->first_bss
.ifindex
);
1976 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
) == 0)
1985 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
1987 struct wiphy_info_data info
;
1988 if (wpa_driver_nl80211_get_info(drv
, &info
))
1994 drv
->has_capability
= 1;
1995 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
1996 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1997 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
1998 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
1999 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
2000 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
2001 WPA_DRIVER_CAPA_ENC_WEP104
|
2002 WPA_DRIVER_CAPA_ENC_TKIP
|
2003 WPA_DRIVER_CAPA_ENC_CCMP
;
2004 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
2005 WPA_DRIVER_AUTH_SHARED
|
2006 WPA_DRIVER_AUTH_LEAP
;
2008 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
2009 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
2010 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2011 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
2017 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
2019 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2020 if (global
->nl_cb
== NULL
) {
2021 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
2026 if (nl_create_handles(&global
->nl
, global
->nl_cb
, "nl"))
2029 global
->nl80211
= genl_ctrl_search_by_name(global
->nl
.cache
,
2031 if (global
->nl80211
== NULL
) {
2032 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
2041 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
2043 struct nl80211_global
*global
= drv
->global
;
2046 /* Initialize generic netlink and nl80211 */
2048 if (nl_create_handles(&drv
->nl_event
, global
->nl_cb
, "event"))
2051 ret
= nl_get_multicast_id(drv
, "nl80211", "scan");
2053 ret
= nl_socket_add_membership(drv
->nl_event
.handle
, ret
);
2055 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2056 "membership for scan events: %d (%s)",
2057 ret
, strerror(-ret
));
2061 ret
= nl_get_multicast_id(drv
, "nl80211", "mlme");
2063 ret
= nl_socket_add_membership(drv
->nl_event
.handle
, ret
);
2065 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2066 "membership for mlme events: %d (%s)",
2067 ret
, strerror(-ret
));
2071 ret
= nl_get_multicast_id(drv
, "nl80211", "regulatory");
2073 ret
= nl_socket_add_membership(drv
->nl_event
.handle
, ret
);
2075 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
2076 "membership for regulatory events: %d (%s)",
2077 ret
, strerror(-ret
));
2078 /* Continue without regulatory events */
2081 eloop_register_read_sock(nl_socket_get_fd(drv
->nl_event
.handle
),
2082 wpa_driver_nl80211_event_receive
, drv
,
2083 drv
->nl_event
.handle
);
2088 nl_destroy_handles(&drv
->nl_event
);
2094 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
2096 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
2098 * This may be for any interface; use ifdown event to disable
2104 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
2106 struct wpa_driver_nl80211_data
*drv
= ctx
;
2107 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
2108 if (linux_set_iface_flags(drv
->global
->ioctl_sock
,
2109 drv
->first_bss
.ifname
, 1)) {
2110 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
2111 "after rfkill unblock");
2114 /* rtnetlink ifup handler will report interface as enabled */
2118 static void nl80211_get_phy_name(struct wpa_driver_nl80211_data
*drv
)
2120 /* Find phy (radio) to which this interface belongs */
2124 drv
->phyname
[0] = '\0';
2125 snprintf(buf
, sizeof(buf
) - 1, "/sys/class/net/%s/phy80211/name",
2126 drv
->first_bss
.ifname
);
2127 f
= open(buf
, O_RDONLY
);
2129 wpa_printf(MSG_DEBUG
, "Could not open file %s: %s",
2130 buf
, strerror(errno
));
2134 rv
= read(f
, drv
->phyname
, sizeof(drv
->phyname
) - 1);
2137 wpa_printf(MSG_DEBUG
, "Could not read file %s: %s",
2138 buf
, strerror(errno
));
2142 drv
->phyname
[rv
] = '\0';
2143 pos
= os_strchr(drv
->phyname
, '\n');
2146 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2147 drv
->first_bss
.ifname
, drv
->phyname
);
2152 static void nl80211_l2_read(void *ctx
, const u8
*src_addr
, const u8
*buf
,
2155 wpa_printf(MSG_DEBUG
, "nl80211: l2_packet read %u",
2156 (unsigned int) len
);
2158 #endif /* CONFIG_AP */
2162 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2163 * @ctx: context to be used when calling wpa_supplicant functions,
2164 * e.g., wpa_supplicant_event()
2165 * @ifname: interface name, e.g., wlan0
2166 * @global_priv: private driver global data from global_init()
2167 * Returns: Pointer to private data, %NULL on failure
2169 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
2172 struct wpa_driver_nl80211_data
*drv
;
2173 struct rfkill_config
*rcfg
;
2174 struct i802_bss
*bss
;
2176 drv
= os_zalloc(sizeof(*drv
));
2179 drv
->global
= global_priv
;
2181 bss
= &drv
->first_bss
;
2183 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
2184 drv
->monitor_ifidx
= -1;
2185 drv
->monitor_sock
= -1;
2186 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2188 if (wpa_driver_nl80211_init_nl(drv
)) {
2193 nl80211_get_phy_name(drv
);
2195 rcfg
= os_zalloc(sizeof(*rcfg
));
2199 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
2200 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
2201 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
2202 drv
->rfkill
= rfkill_init(rcfg
);
2203 if (drv
->rfkill
== NULL
) {
2204 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
2208 if (wpa_driver_nl80211_finish_drv_init(drv
))
2212 drv
->l2
= l2_packet_init(ifname
, NULL
, ETH_P_EAPOL
,
2213 nl80211_l2_read
, drv
, 0);
2214 #endif /* CONFIG_AP */
2217 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
2218 drv
->in_interface_list
= 1;
2224 wpa_driver_nl80211_deinit(bss
);
2229 static int nl80211_register_frame(struct wpa_driver_nl80211_data
*drv
,
2230 struct nl_handle
*nl_handle
,
2231 u16 type
, const u8
*match
, size_t match_len
)
2236 msg
= nlmsg_alloc();
2240 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
2242 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2243 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
2244 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
2246 ret
= send_and_recv(drv
, nl_handle
, msg
, NULL
, NULL
);
2249 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
2250 "failed (type=%u): ret=%d (%s)",
2251 type
, ret
, strerror(-ret
));
2252 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
2254 goto nla_put_failure
;
2263 static int nl80211_register_action_frame(struct wpa_driver_nl80211_data
*drv
,
2264 const u8
*match
, size_t match_len
)
2266 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
2267 return nl80211_register_frame(drv
, drv
->nl_event
.handle
,
2268 type
, match
, match_len
);
2272 static int nl80211_register_action_frames(struct wpa_driver_nl80211_data
*drv
)
2274 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
2275 /* GAS Initial Request */
2276 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0a", 2) < 0)
2278 /* GAS Initial Response */
2279 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0b", 2) < 0)
2281 /* GAS Comeback Request */
2282 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0c", 2) < 0)
2284 /* GAS Comeback Response */
2285 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0d", 2) < 0)
2287 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
2289 /* P2P Public Action */
2290 if (nl80211_register_action_frame(drv
,
2291 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
2295 if (nl80211_register_action_frame(drv
,
2296 (u8
*) "\x7f\x50\x6f\x9a\x09",
2299 #endif /* CONFIG_P2P */
2300 #ifdef CONFIG_IEEE80211W
2301 /* SA Query Response */
2302 if (nl80211_register_action_frame(drv
, (u8
*) "\x08\x01", 2) < 0)
2304 #endif /* CONFIG_IEEE80211W */
2306 /* FT Action frames */
2307 if (nl80211_register_action_frame(drv
, (u8
*) "\x06", 1) < 0)
2310 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
2311 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
2313 /* WNM - BSS Transition Management Request */
2314 if (nl80211_register_action_frame(drv
, (u8
*) "\x0a\x07", 2) < 0)
2321 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
2323 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
2328 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
2330 struct i802_bss
*bss
= &drv
->first_bss
;
2331 int send_rfkill_event
= 0;
2333 drv
->ifindex
= if_nametoindex(bss
->ifname
);
2334 drv
->first_bss
.ifindex
= drv
->ifindex
;
2338 * Make sure the interface starts up in station mode unless this is a
2339 * dynamically added interface (e.g., P2P) that was already configured
2340 * with proper iftype.
2342 if ((drv
->global
== NULL
||
2343 drv
->ifindex
!= drv
->global
->if_add_ifindex
) &&
2344 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
) < 0) {
2345 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to "
2346 "use managed mode");
2350 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
2351 if (rfkill_is_blocked(drv
->rfkill
)) {
2352 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
2353 "interface '%s' due to rfkill",
2355 drv
->if_disabled
= 1;
2356 send_rfkill_event
= 1;
2358 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
2359 "interface '%s' UP", bss
->ifname
);
2364 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
2365 1, IF_OPER_DORMANT
);
2366 #endif /* HOSTAPD */
2368 if (wpa_driver_nl80211_capa(drv
))
2371 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2375 if (nl80211_register_action_frames(drv
) < 0) {
2376 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
2377 "frame processing - ignore for now");
2379 * Older kernel versions did not support this, so ignore the
2380 * error for now. Some functionality may not be available
2385 if (send_rfkill_event
) {
2386 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
2394 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
2398 msg
= nlmsg_alloc();
2402 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
2403 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2405 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2412 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
2413 * @priv: Pointer to private nl80211 data from wpa_driver_nl80211_init()
2415 * Shut down driver interface and processing of driver events. Free
2416 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2418 static void wpa_driver_nl80211_deinit(void *priv
)
2420 struct i802_bss
*bss
= priv
;
2421 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2425 l2_packet_deinit(drv
->l2
);
2426 #endif /* CONFIG_AP */
2428 if (drv
->nl_preq
.handle
)
2429 wpa_driver_nl80211_probe_req_report(bss
, 0);
2430 if (bss
->added_if_into_bridge
) {
2431 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
2433 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2434 "interface %s from bridge %s: %s",
2435 bss
->ifname
, bss
->brname
, strerror(errno
));
2437 if (bss
->added_bridge
) {
2438 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
2439 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2441 bss
->brname
, strerror(errno
));
2444 nl80211_remove_monitor_interface(drv
);
2446 if (is_ap_interface(drv
->nlmode
))
2447 wpa_driver_nl80211_del_beacon(drv
);
2450 if (drv
->last_freq_ht
) {
2451 /* Clear HT flags from the driver */
2452 struct hostapd_freq_params freq
;
2453 os_memset(&freq
, 0, sizeof(freq
));
2454 freq
.freq
= drv
->last_freq
;
2455 i802_set_freq(priv
, &freq
);
2458 if (drv
->eapol_sock
>= 0) {
2459 eloop_unregister_read_sock(drv
->eapol_sock
);
2460 close(drv
->eapol_sock
);
2463 if (drv
->if_indices
!= drv
->default_if_indices
)
2464 os_free(drv
->if_indices
);
2465 #endif /* HOSTAPD */
2467 if (drv
->disable_11b_rates
)
2468 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2470 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
2472 rfkill_deinit(drv
->rfkill
);
2474 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2476 (void) linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0);
2477 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
2479 eloop_unregister_read_sock(nl_socket_get_fd(drv
->nl_event
.handle
));
2480 nl_destroy_handles(&drv
->nl_event
);
2482 os_free(drv
->filter_ssids
);
2484 if (drv
->in_interface_list
)
2485 dl_list_del(&drv
->list
);
2492 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
2493 * @eloop_ctx: Driver private data
2494 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
2496 * This function can be used as registered timeout when starting a scan to
2497 * generate a scan completed event if the driver does not report this.
2499 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
2501 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
2502 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
2503 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
2504 drv
->ap_scan_as_station
);
2505 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2507 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
2508 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
2513 * wpa_driver_nl80211_scan - Request the driver to initiate scan
2514 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
2515 * @params: Scan parameters
2516 * Returns: 0 on success, -1 on failure
2518 static int wpa_driver_nl80211_scan(void *priv
,
2519 struct wpa_driver_scan_params
*params
)
2521 struct i802_bss
*bss
= priv
;
2522 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2523 int ret
= 0, timeout
;
2524 struct nl_msg
*msg
, *ssids
, *freqs
, *rates
;
2527 msg
= nlmsg_alloc();
2528 ssids
= nlmsg_alloc();
2529 freqs
= nlmsg_alloc();
2530 rates
= nlmsg_alloc();
2531 if (!msg
|| !ssids
|| !freqs
|| !rates
) {
2539 os_free(drv
->filter_ssids
);
2540 drv
->filter_ssids
= params
->filter_ssids
;
2541 params
->filter_ssids
= NULL
;
2542 drv
->num_filter_ssids
= params
->num_filter_ssids
;
2544 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TRIGGER_SCAN
);
2546 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2548 for (i
= 0; i
< params
->num_ssids
; i
++) {
2549 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
2550 params
->ssids
[i
].ssid
,
2551 params
->ssids
[i
].ssid_len
);
2552 NLA_PUT(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
2553 params
->ssids
[i
].ssid
);
2555 if (params
->num_ssids
)
2556 nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
2558 if (params
->extra_ies
) {
2559 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
2560 params
->extra_ies
, params
->extra_ies_len
);
2561 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
2565 if (params
->freqs
) {
2566 for (i
= 0; params
->freqs
[i
]; i
++) {
2567 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
2568 "MHz", params
->freqs
[i
]);
2569 NLA_PUT_U32(freqs
, i
+ 1, params
->freqs
[i
]);
2571 nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
, freqs
);
2574 if (params
->p2p_probe
) {
2576 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
2577 * by masking out everything else apart from the OFDM rates 6,
2578 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
2579 * rates are left enabled.
2581 NLA_PUT(rates
, NL80211_BAND_2GHZ
, 8,
2582 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
2583 nla_put_nested(msg
, NL80211_ATTR_SCAN_SUPP_RATES
, rates
);
2586 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2589 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
2590 "(%s)", ret
, strerror(-ret
));
2592 if (is_ap_interface(drv
->nlmode
)) {
2594 * mac80211 does not allow scan requests in AP mode, so
2595 * try to do this in station mode.
2597 if (wpa_driver_nl80211_set_mode(
2598 bss
, NL80211_IFTYPE_STATION
))
2599 goto nla_put_failure
;
2601 if (wpa_driver_nl80211_scan(drv
, params
)) {
2602 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
2603 goto nla_put_failure
;
2606 /* Restore AP mode when processing scan results */
2607 drv
->ap_scan_as_station
= drv
->nlmode
;
2610 goto nla_put_failure
;
2612 goto nla_put_failure
;
2613 #endif /* HOSTAPD */
2616 /* Not all drivers generate "scan completed" wireless event, so try to
2617 * read results after a timeout. */
2619 if (drv
->scan_complete_events
) {
2621 * The driver seems to deliver events to notify when scan is
2622 * complete, so use longer timeout to avoid race conditions
2623 * with scanning and following association request.
2627 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
2628 "seconds", ret
, timeout
);
2629 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2630 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
2643 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
2644 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
2645 * @params: Scan parameters
2646 * @interval: Interval between scan cycles in milliseconds
2647 * Returns: 0 on success, -1 on failure or if not supported
2649 static int wpa_driver_nl80211_sched_scan(void *priv
,
2650 struct wpa_driver_scan_params
*params
,
2653 struct i802_bss
*bss
= priv
;
2654 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2656 struct nl_msg
*msg
, *ssids
, *freqs
, *match_set_ssid
, *match_sets
;
2659 msg
= nlmsg_alloc();
2660 ssids
= nlmsg_alloc();
2661 freqs
= nlmsg_alloc();
2662 if (!msg
|| !ssids
|| !freqs
) {
2669 os_free(drv
->filter_ssids
);
2670 drv
->filter_ssids
= params
->filter_ssids
;
2671 params
->filter_ssids
= NULL
;
2672 drv
->num_filter_ssids
= params
->num_filter_ssids
;
2674 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_START_SCHED_SCAN
);
2676 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2678 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
2680 if (drv
->num_filter_ssids
) {
2681 match_sets
= nlmsg_alloc();
2683 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
2684 wpa_hexdump_ascii(MSG_MSGDUMP
,
2685 "nl80211: Sched scan filter SSID",
2686 drv
->filter_ssids
[i
].ssid
,
2687 drv
->filter_ssids
[i
].ssid_len
);
2689 match_set_ssid
= nlmsg_alloc();
2690 nla_put(match_set_ssid
,
2691 NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
2692 drv
->filter_ssids
[i
].ssid_len
,
2693 drv
->filter_ssids
[i
].ssid
);
2695 nla_put_nested(match_sets
, i
+ 1, match_set_ssid
);
2697 nlmsg_free(match_set_ssid
);
2700 nla_put_nested(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
,
2702 nlmsg_free(match_sets
);
2705 for (i
= 0; i
< params
->num_ssids
; i
++) {
2706 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Sched scan SSID",
2707 params
->ssids
[i
].ssid
,
2708 params
->ssids
[i
].ssid_len
);
2709 NLA_PUT(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
2710 params
->ssids
[i
].ssid
);
2712 if (params
->num_ssids
)
2713 nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
2715 if (params
->extra_ies
) {
2716 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Sched scan extra IEs",
2717 params
->extra_ies
, params
->extra_ies_len
);
2718 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
2722 if (params
->freqs
) {
2723 for (i
= 0; params
->freqs
[i
]; i
++) {
2724 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
2725 "MHz", params
->freqs
[i
]);
2726 NLA_PUT_U32(freqs
, i
+ 1, params
->freqs
[i
]);
2728 nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
, freqs
);
2731 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2733 /* TODO: if we get an error here, we should fall back to normal scan */
2737 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
2738 "ret=%d (%s)", ret
, strerror(-ret
));
2739 goto nla_put_failure
;
2742 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
2743 "scan interval %d msec", ret
, interval
);
2754 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
2755 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
2756 * Returns: 0 on success, -1 on failure or if not supported
2758 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
2760 struct i802_bss
*bss
= priv
;
2761 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2765 msg
= nlmsg_alloc();
2769 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
2771 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2773 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2776 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
2777 "ret=%d (%s)", ret
, strerror(-ret
));
2778 goto nla_put_failure
;
2781 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
2789 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
2791 const u8
*end
, *pos
;
2797 end
= ies
+ ies_len
;
2799 while (pos
+ 1 < end
) {
2800 if (pos
+ 2 + pos
[1] > end
)
2811 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
2812 const u8
*ie
, size_t ie_len
)
2817 if (drv
->filter_ssids
== NULL
)
2820 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
2824 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
2825 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
2826 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
2835 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
2837 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2838 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2839 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
2840 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
2841 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
2842 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
2843 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
2844 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
2845 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
2846 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
2847 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
2848 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
2849 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
2850 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
2851 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
2853 struct nl80211_bss_info_arg
*_arg
= arg
;
2854 struct wpa_scan_results
*res
= _arg
->res
;
2855 struct wpa_scan_res
**tmp
;
2856 struct wpa_scan_res
*r
;
2857 const u8
*ie
, *beacon_ie
;
2858 size_t ie_len
, beacon_ie_len
;
2862 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2863 genlmsg_attrlen(gnlh
, 0), NULL
);
2864 if (!tb
[NL80211_ATTR_BSS
])
2866 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
2869 if (bss
[NL80211_BSS_STATUS
]) {
2870 enum nl80211_bss_status status
;
2871 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
2872 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
2873 bss
[NL80211_BSS_FREQUENCY
]) {
2875 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
2876 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
2879 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
2880 bss
[NL80211_BSS_BSSID
]) {
2881 os_memcpy(_arg
->assoc_bssid
,
2882 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
2883 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
2884 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
2889 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
2890 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
2891 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
2896 if (bss
[NL80211_BSS_BEACON_IES
]) {
2897 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
2898 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
2904 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
2905 ie
? ie_len
: beacon_ie_len
))
2908 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
2911 if (bss
[NL80211_BSS_BSSID
])
2912 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
2914 if (bss
[NL80211_BSS_FREQUENCY
])
2915 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
2916 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
2917 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
2918 if (bss
[NL80211_BSS_CAPABILITY
])
2919 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
2920 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
2921 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
2922 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
2923 r
->level
/= 100; /* mBm to dBm */
2924 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
2925 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
2926 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
2927 r
->flags
|= WPA_SCAN_LEVEL_INVALID
;
2929 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
2930 if (bss
[NL80211_BSS_TSF
])
2931 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
2932 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
2933 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
2935 pos
= (u8
*) (r
+ 1);
2937 os_memcpy(pos
, ie
, ie_len
);
2940 r
->beacon_ie_len
= beacon_ie_len
;
2942 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
2944 if (bss
[NL80211_BSS_STATUS
]) {
2945 enum nl80211_bss_status status
;
2946 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
2948 case NL80211_BSS_STATUS_AUTHENTICATED
:
2949 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
2951 case NL80211_BSS_STATUS_ASSOCIATED
:
2952 r
->flags
|= WPA_SCAN_ASSOCIATED
;
2960 * cfg80211 maintains separate BSS table entries for APs if the same
2961 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
2962 * not use frequency as a separate key in the BSS table, so filter out
2963 * duplicated entries. Prefer associated BSS entry in such a case in
2964 * order to get the correct frequency into the BSS table.
2966 for (i
= 0; i
< res
->num
; i
++) {
2968 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
2971 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
2972 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
2973 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
2974 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
2975 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
2978 /* Same BSSID,SSID was already included in scan results */
2979 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
2980 "for " MACSTR
, MAC2STR(r
->bssid
));
2982 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
2983 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
2984 os_free(res
->res
[i
]);
2991 tmp
= os_realloc(res
->res
,
2992 (res
->num
+ 1) * sizeof(struct wpa_scan_res
*));
2997 tmp
[res
->num
++] = r
;
3004 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
3007 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
3008 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
3009 "mismatch (" MACSTR
")", MAC2STR(addr
));
3010 wpa_driver_nl80211_mlme(drv
, addr
,
3011 NL80211_CMD_DEAUTHENTICATE
,
3012 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
3017 static void wpa_driver_nl80211_check_bss_status(
3018 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
3022 for (i
= 0; i
< res
->num
; i
++) {
3023 struct wpa_scan_res
*r
= res
->res
[i
];
3024 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
3025 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
3026 "indicates BSS status with " MACSTR
3027 " as authenticated",
3029 if (is_sta_interface(drv
->nlmode
) &&
3030 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
3031 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
3033 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
3034 " in local state (auth=" MACSTR
3035 " assoc=" MACSTR
")",
3036 MAC2STR(drv
->auth_bssid
),
3037 MAC2STR(drv
->bssid
));
3038 clear_state_mismatch(drv
, r
->bssid
);
3042 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
3043 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
3044 "indicate BSS status with " MACSTR
3047 if (is_sta_interface(drv
->nlmode
) &&
3049 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
3050 "(not associated) does not match "
3052 clear_state_mismatch(drv
, r
->bssid
);
3053 } else if (is_sta_interface(drv
->nlmode
) &&
3054 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
3056 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
3057 "(associated with " MACSTR
") does "
3058 "not match with BSS state",
3059 MAC2STR(drv
->bssid
));
3060 clear_state_mismatch(drv
, r
->bssid
);
3061 clear_state_mismatch(drv
, drv
->bssid
);
3068 static struct wpa_scan_results
*
3069 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
3072 struct wpa_scan_results
*res
;
3074 struct nl80211_bss_info_arg arg
;
3076 res
= os_zalloc(sizeof(*res
));
3079 msg
= nlmsg_alloc();
3081 goto nla_put_failure
;
3083 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
3084 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3088 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
3091 wpa_printf(MSG_DEBUG
, "Received scan results (%lu BSSes)",
3092 (unsigned long) res
->num
);
3095 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
3096 "(%s)", ret
, strerror(-ret
));
3099 wpa_scan_results_free(res
);
3105 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
3106 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
3107 * Returns: Scan results on success, -1 on failure
3109 static struct wpa_scan_results
*
3110 wpa_driver_nl80211_get_scan_results(void *priv
)
3112 struct i802_bss
*bss
= priv
;
3113 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3114 struct wpa_scan_results
*res
;
3116 res
= nl80211_get_scan_results(drv
);
3118 wpa_driver_nl80211_check_bss_status(drv
, res
);
3123 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
3125 struct wpa_scan_results
*res
;
3128 res
= nl80211_get_scan_results(drv
);
3130 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
3134 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
3135 for (i
= 0; i
< res
->num
; i
++) {
3136 struct wpa_scan_res
*r
= res
->res
[i
];
3137 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
3138 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
3139 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
3140 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
3143 wpa_scan_results_free(res
);
3147 static int wpa_driver_nl80211_set_key(const char *ifname
, void *priv
,
3148 enum wpa_alg alg
, const u8
*addr
,
3149 int key_idx
, int set_tx
,
3150 const u8
*seq
, size_t seq_len
,
3151 const u8
*key
, size_t key_len
)
3153 struct i802_bss
*bss
= priv
;
3154 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3155 int ifindex
= if_nametoindex(ifname
);
3159 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d alg=%d addr=%p key_idx=%d "
3160 "set_tx=%d seq_len=%lu key_len=%lu",
3161 __func__
, ifindex
, alg
, addr
, key_idx
, set_tx
,
3162 (unsigned long) seq_len
, (unsigned long) key_len
);
3164 msg
= nlmsg_alloc();
3168 if (alg
== WPA_ALG_NONE
) {
3169 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
3171 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
3172 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
3176 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3177 WLAN_CIPHER_SUITE_WEP40
);
3179 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3180 WLAN_CIPHER_SUITE_WEP104
);
3183 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3184 WLAN_CIPHER_SUITE_TKIP
);
3187 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3188 WLAN_CIPHER_SUITE_CCMP
);
3191 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3192 WLAN_CIPHER_SUITE_AES_CMAC
);
3195 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
3196 "algorithm %d", __func__
, alg
);
3203 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
3205 if (addr
&& !is_broadcast_ether_addr(addr
)) {
3206 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
3207 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3209 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
3210 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
3211 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
3212 NL80211_KEYTYPE_GROUP
);
3214 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
3215 struct nl_msg
*types
;
3217 wpa_printf(MSG_DEBUG
, " broadcast key");
3218 types
= nlmsg_alloc();
3220 goto nla_put_failure
;
3221 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
3222 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
3226 goto nla_put_failure
;
3228 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
3229 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
3231 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3232 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
3235 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
3236 ret
, strerror(-ret
));
3239 * If we failed or don't need to set the default TX key (below),
3242 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
)
3244 if (is_ap_interface(drv
->nlmode
) && addr
&&
3245 !is_broadcast_ether_addr(addr
))
3248 msg
= nlmsg_alloc();
3252 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
3253 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
3254 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
3255 if (alg
== WPA_ALG_IGTK
)
3256 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
3258 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
3259 if (addr
&& is_broadcast_ether_addr(addr
)) {
3260 struct nl_msg
*types
;
3262 types
= nlmsg_alloc();
3264 goto nla_put_failure
;
3265 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
3266 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
3270 goto nla_put_failure
;
3272 struct nl_msg
*types
;
3274 types
= nlmsg_alloc();
3276 goto nla_put_failure
;
3277 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
3278 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
3282 goto nla_put_failure
;
3285 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3289 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
3290 "err=%d %s)", ret
, strerror(-ret
));
3298 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
3299 int key_idx
, int defkey
,
3300 const u8
*seq
, size_t seq_len
,
3301 const u8
*key
, size_t key_len
)
3303 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
3307 if (defkey
&& alg
== WPA_ALG_IGTK
)
3308 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
3310 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
3312 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
3317 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3318 WLAN_CIPHER_SUITE_WEP40
);
3320 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3321 WLAN_CIPHER_SUITE_WEP104
);
3324 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
3327 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
3330 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3331 WLAN_CIPHER_SUITE_AES_CMAC
);
3334 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
3335 "algorithm %d", __func__
, alg
);
3340 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
3342 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
3344 nla_nest_end(msg
, key_attr
);
3352 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
3356 struct nlattr
*nl_keys
, *nl_key
;
3358 for (i
= 0; i
< 4; i
++) {
3359 if (!params
->wep_key
[i
])
3364 if (params
->wps
== WPS_MODE_PRIVACY
)
3366 if (params
->pairwise_suite
&&
3367 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
3373 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
3375 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
3377 goto nla_put_failure
;
3379 for (i
= 0; i
< 4; i
++) {
3380 if (!params
->wep_key
[i
])
3383 nl_key
= nla_nest_start(msg
, i
);
3385 goto nla_put_failure
;
3387 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
3388 params
->wep_key
[i
]);
3389 if (params
->wep_key_len
[i
] == 5)
3390 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3391 WLAN_CIPHER_SUITE_WEP40
);
3393 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3394 WLAN_CIPHER_SUITE_WEP104
);
3396 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
3398 if (i
== params
->wep_tx_keyidx
)
3399 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
3401 nla_nest_end(msg
, nl_key
);
3403 nla_nest_end(msg
, nl_keys
);
3412 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
3413 const u8
*addr
, int cmd
, u16 reason_code
,
3414 int local_state_change
)
3419 msg
= nlmsg_alloc();
3423 nl80211_cmd(drv
, msg
, 0, cmd
);
3425 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3426 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
3427 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3428 if (local_state_change
)
3429 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
3431 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3434 wpa_printf(MSG_DEBUG
, "nl80211: MLME command failed: ret=%d "
3435 "(%s)", ret
, strerror(-ret
));
3436 goto nla_put_failure
;
3446 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
3447 const u8
*addr
, int reason_code
)
3449 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
3450 __func__
, MAC2STR(addr
), reason_code
);
3451 drv
->associated
= 0;
3452 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISCONNECT
,
3457 static int wpa_driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
3460 struct i802_bss
*bss
= priv
;
3461 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3462 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
3463 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
3464 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
3465 __func__
, MAC2STR(addr
), reason_code
);
3466 drv
->associated
= 0;
3467 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
3468 return nl80211_leave_ibss(drv
);
3469 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
3474 static int wpa_driver_nl80211_disassociate(void *priv
, const u8
*addr
,
3477 struct i802_bss
*bss
= priv
;
3478 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3479 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
3480 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
3481 wpa_printf(MSG_DEBUG
, "%s", __func__
);
3482 drv
->associated
= 0;
3483 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISASSOCIATE
,
3488 static int wpa_driver_nl80211_authenticate(
3489 void *priv
, struct wpa_driver_auth_params
*params
)
3491 struct i802_bss
*bss
= priv
;
3492 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3495 enum nl80211_auth_type type
;
3496 enum nl80211_iftype nlmode
;
3499 drv
->associated
= 0;
3500 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
3501 /* FIX: IBSS mode */
3502 nlmode
= params
->p2p
?
3503 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
3504 if (drv
->nlmode
!= nlmode
&&
3505 wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
3509 msg
= nlmsg_alloc();
3513 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
3516 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
3518 for (i
= 0; i
< 4; i
++) {
3519 if (!params
->wep_key
[i
])
3521 wpa_driver_nl80211_set_key(bss
->ifname
, priv
, WPA_ALG_WEP
,
3523 i
== params
->wep_tx_keyidx
, NULL
, 0,
3525 params
->wep_key_len
[i
]);
3526 if (params
->wep_tx_keyidx
!= i
)
3528 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
3529 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
3535 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3536 if (params
->bssid
) {
3537 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
3538 MAC2STR(params
->bssid
));
3539 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
3542 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
3543 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
3546 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
3547 params
->ssid
, params
->ssid_len
);
3548 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
3551 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
3553 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
3554 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
3555 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
3556 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
3557 type
= NL80211_AUTHTYPE_SHARED_KEY
;
3558 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
3559 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
3560 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
3561 type
= NL80211_AUTHTYPE_FT
;
3563 goto nla_put_failure
;
3564 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
3565 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
3566 if (params
->local_state_change
) {
3567 wpa_printf(MSG_DEBUG
, " * Local state change only");
3568 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
3571 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3574 wpa_printf(MSG_DEBUG
, "nl80211: MLME command failed: ret=%d "
3575 "(%s)", ret
, strerror(-ret
));
3577 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
3578 !params
->local_state_change
) {
3580 * mac80211 does not currently accept new
3581 * authentication if we are already authenticated. As a
3582 * workaround, force deauthentication and try again.
3584 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
3585 "after forced deauthentication");
3586 wpa_driver_nl80211_deauthenticate(
3588 WLAN_REASON_PREV_AUTH_NOT_VALID
);
3592 goto nla_put_failure
;
3595 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
3604 struct phy_info_arg
{
3606 struct hostapd_hw_modes
*modes
;
3609 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
3611 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
3612 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3613 struct phy_info_arg
*phy_info
= arg
;
3615 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
3617 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
3618 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
3619 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
3620 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
3621 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
3622 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
3623 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
3624 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
3627 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
3628 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
3629 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
3630 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] = { .type
= NLA_FLAG
},
3633 struct nlattr
*nl_band
;
3634 struct nlattr
*nl_freq
;
3635 struct nlattr
*nl_rate
;
3636 int rem_band
, rem_freq
, rem_rate
;
3637 struct hostapd_hw_modes
*mode
;
3638 int idx
, mode_is_set
;
3640 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3641 genlmsg_attrlen(gnlh
, 0), NULL
);
3643 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
3646 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
) {
3647 mode
= os_realloc(phy_info
->modes
, (*phy_info
->num_modes
+ 1) * sizeof(*mode
));
3650 phy_info
->modes
= mode
;
3654 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
3655 memset(mode
, 0, sizeof(*mode
));
3656 *(phy_info
->num_modes
) += 1;
3658 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
3659 nla_len(nl_band
), NULL
);
3661 if (tb_band
[NL80211_BAND_ATTR_HT_CAPA
]) {
3662 mode
->ht_capab
= nla_get_u16(
3663 tb_band
[NL80211_BAND_ATTR_HT_CAPA
]);
3666 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) {
3667 mode
->a_mpdu_params
|= nla_get_u8(
3668 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) &
3672 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) {
3673 mode
->a_mpdu_params
|= nla_get_u8(
3674 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) <<
3678 if (tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
] &&
3679 nla_len(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
])) {
3681 mcs
= nla_data(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
3682 os_memcpy(mode
->mcs_set
, mcs
, 16);
3685 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
3686 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
3687 nla_len(nl_freq
), freq_policy
);
3688 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
3690 mode
->num_channels
++;
3693 mode
->channels
= os_zalloc(mode
->num_channels
* sizeof(struct hostapd_channel_data
));
3694 if (!mode
->channels
)
3699 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
3700 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
3701 nla_len(nl_freq
), freq_policy
);
3702 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
3705 mode
->channels
[idx
].freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
3706 mode
->channels
[idx
].flag
= 0;
3709 /* crude heuristic */
3710 if (mode
->channels
[idx
].freq
< 4000)
3711 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
3713 mode
->mode
= HOSTAPD_MODE_IEEE80211A
;
3717 /* crude heuristic */
3718 if (mode
->channels
[idx
].freq
< 4000)
3719 if (mode
->channels
[idx
].freq
== 2484)
3720 mode
->channels
[idx
].chan
= 14;
3722 mode
->channels
[idx
].chan
= (mode
->channels
[idx
].freq
- 2407) / 5;
3724 mode
->channels
[idx
].chan
= mode
->channels
[idx
].freq
/5 - 1000;
3726 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
3727 mode
->channels
[idx
].flag
|=
3728 HOSTAPD_CHAN_DISABLED
;
3729 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
3730 mode
->channels
[idx
].flag
|=
3731 HOSTAPD_CHAN_PASSIVE_SCAN
;
3732 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
3733 mode
->channels
[idx
].flag
|=
3734 HOSTAPD_CHAN_NO_IBSS
;
3735 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
3736 mode
->channels
[idx
].flag
|=
3739 if (tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] &&
3740 !tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
3741 mode
->channels
[idx
].max_tx_power
=
3742 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
]) / 100;
3747 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
3748 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
3749 nla_len(nl_rate
), rate_policy
);
3750 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
3755 mode
->rates
= os_zalloc(mode
->num_rates
* sizeof(int));
3761 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
3762 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
3763 nla_len(nl_rate
), rate_policy
);
3764 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
3766 mode
->rates
[idx
] = nla_get_u32(tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
3768 /* crude heuristic */
3769 if (mode
->mode
== HOSTAPD_MODE_IEEE80211B
&&
3770 mode
->rates
[idx
] > 200)
3771 mode
->mode
= HOSTAPD_MODE_IEEE80211G
;
3780 static struct hostapd_hw_modes
*
3781 wpa_driver_nl80211_add_11b(struct hostapd_hw_modes
*modes
, u16
*num_modes
)
3784 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
3785 int i
, mode11g_idx
= -1;
3787 /* If only 802.11g mode is included, use it to construct matching
3788 * 802.11b mode data. */
3790 for (m
= 0; m
< *num_modes
; m
++) {
3791 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
3792 return modes
; /* 802.11b already included */
3793 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
3797 if (mode11g_idx
< 0)
3798 return modes
; /* 2.4 GHz band not supported at all */
3800 nmodes
= os_realloc(modes
, (*num_modes
+ 1) * sizeof(*nmodes
));
3802 return modes
; /* Could not add 802.11b mode */
3804 mode
= &nmodes
[*num_modes
];
3805 os_memset(mode
, 0, sizeof(*mode
));
3809 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
3811 mode11g
= &modes
[mode11g_idx
];
3812 mode
->num_channels
= mode11g
->num_channels
;
3813 mode
->channels
= os_malloc(mode11g
->num_channels
*
3814 sizeof(struct hostapd_channel_data
));
3815 if (mode
->channels
== NULL
) {
3817 return modes
; /* Could not add 802.11b mode */
3819 os_memcpy(mode
->channels
, mode11g
->channels
,
3820 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
3822 mode
->num_rates
= 0;
3823 mode
->rates
= os_malloc(4 * sizeof(int));
3824 if (mode
->rates
== NULL
) {
3825 os_free(mode
->channels
);
3827 return modes
; /* Could not add 802.11b mode */
3830 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
3831 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
3832 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
3834 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
3836 if (mode
->num_rates
== 4)
3840 if (mode
->num_rates
== 0) {
3841 os_free(mode
->channels
);
3842 os_free(mode
->rates
);
3844 return modes
; /* No 802.11b rates */
3847 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
3854 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
3859 for (c
= 0; c
< mode
->num_channels
; c
++) {
3860 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
3861 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
3862 chan
->flag
|= HOSTAPD_CHAN_HT40
;
3867 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
3872 for (c
= 0; c
< mode
->num_channels
; c
++) {
3873 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
3874 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
3876 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
3877 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
3878 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
3879 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
3884 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
3885 struct phy_info_arg
*results
)
3887 u32 start
, end
, max_bw
;
3890 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
3891 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
3892 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
3895 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
3896 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
3897 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
3899 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
3900 start
, end
, max_bw
);
3904 for (m
= 0; m
< *results
->num_modes
; m
++) {
3905 if (!(results
->modes
[m
].ht_capab
&
3906 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
3908 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
3913 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
3914 struct phy_info_arg
*results
)
3916 u32 start
, end
, max_bw
;
3919 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
3920 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
3921 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
3924 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
3925 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
3926 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
3931 for (m
= 0; m
< *results
->num_modes
; m
++) {
3932 if (!(results
->modes
[m
].ht_capab
&
3933 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
3935 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
3940 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
3942 struct phy_info_arg
*results
= arg
;
3943 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
3944 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3945 struct nlattr
*nl_rule
;
3946 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
3948 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
3949 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3950 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3951 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3952 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3953 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3954 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3957 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3958 genlmsg_attrlen(gnlh
, 0), NULL
);
3959 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
3960 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
3961 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
3966 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
3967 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
3969 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
3971 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
3972 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
3973 nl80211_reg_rule_ht40(tb_rule
, results
);
3976 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
3978 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
3979 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
3980 nl80211_reg_rule_sec(tb_rule
, results
);
3987 static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data
*drv
,
3988 struct phy_info_arg
*results
)
3992 msg
= nlmsg_alloc();
3996 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
3997 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
4001 static struct hostapd_hw_modes
*
4002 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
4004 struct i802_bss
*bss
= priv
;
4005 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4007 struct phy_info_arg result
= {
4008 .num_modes
= num_modes
,
4015 msg
= nlmsg_alloc();
4019 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
4021 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4023 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
4024 nl80211_set_ht40_flags(drv
, &result
);
4025 return wpa_driver_nl80211_add_11b(result
.modes
, num_modes
);
4032 static int wpa_driver_nl80211_send_frame(struct wpa_driver_nl80211_data
*drv
,
4033 const void *data
, size_t len
,
4037 0x00, 0x00, /* radiotap version */
4038 0x0e, 0x00, /* radiotap length */
4039 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
4040 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
4042 0x00, 0x00, /* RX and TX flags to indicate that */
4043 0x00, 0x00, /* this is the injected frame directly */
4045 struct iovec iov
[2] = {
4047 .iov_base
= &rtap_hdr
,
4048 .iov_len
= sizeof(rtap_hdr
),
4051 .iov_base
= (void *) data
,
4055 struct msghdr msg
= {
4060 .msg_control
= NULL
,
4061 .msg_controllen
= 0,
4067 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
4069 if (drv
->monitor_sock
< 0) {
4070 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
4071 "for %s", __func__
);
4075 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
4077 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
4084 static int wpa_driver_nl80211_send_mlme(void *priv
, const u8
*data
,
4087 struct i802_bss
*bss
= priv
;
4088 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4089 struct ieee80211_mgmt
*mgmt
;
4093 mgmt
= (struct ieee80211_mgmt
*) data
;
4094 fc
= le_to_host16(mgmt
->frame_control
);
4096 if (is_sta_interface(drv
->nlmode
) &&
4097 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4098 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
4100 * The use of last_mgmt_freq is a bit of a hack,
4101 * but it works due to the single-threaded nature
4102 * of wpa_supplicant.
4104 return nl80211_send_frame_cmd(drv
, drv
->last_mgmt_freq
, 0,
4105 data
, data_len
, NULL
);
4108 if (drv
->no_monitor_iface_capab
&& is_ap_interface(drv
->nlmode
)) {
4109 return nl80211_send_frame_cmd(drv
, drv
->ap_oper_freq
, 0,
4110 data
, data_len
, NULL
);
4113 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4114 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
4116 * Only one of the authentication frame types is encrypted.
4117 * In order for static WEP encryption to work properly (i.e.,
4118 * to not encrypt the frame), we need to tell mac80211 about
4119 * the frames that must not be encrypted.
4121 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
4122 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
4123 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
4127 return wpa_driver_nl80211_send_frame(drv
, data
, data_len
, encrypt
);
4131 static int nl80211_set_ap_isolate(struct i802_bss
*bss
, int enabled
)
4133 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4136 msg
= nlmsg_alloc();
4140 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
4142 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
4143 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, enabled
);
4145 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4151 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
4152 int slot
, int ht_opmode
)
4154 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4157 msg
= nlmsg_alloc();
4161 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
4164 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
4166 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
4168 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
4170 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
4171 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
4173 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4179 static int wpa_driver_nl80211_set_ap(void *priv
,
4180 struct wpa_driver_ap_params
*params
)
4182 struct i802_bss
*bss
= priv
;
4183 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4185 u8 cmd
= NL80211_CMD_NEW_BEACON
;
4188 int ifindex
= if_nametoindex(bss
->ifname
);
4193 beacon_set
= bss
->beacon_set
;
4195 msg
= nlmsg_alloc();
4199 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
4202 cmd
= NL80211_CMD_SET_BEACON
;
4204 nl80211_cmd(drv
, msg
, 0, cmd
);
4205 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
4206 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
4207 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4208 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
4209 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
4210 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
4212 switch (params
->hide_ssid
) {
4213 case NO_SSID_HIDING
:
4214 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4215 NL80211_HIDDEN_SSID_NOT_IN_USE
);
4217 case HIDDEN_SSID_ZERO_LEN
:
4218 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4219 NL80211_HIDDEN_SSID_ZERO_LEN
);
4221 case HIDDEN_SSID_ZERO_CONTENTS
:
4222 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4223 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
4226 if (params
->privacy
)
4227 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
4228 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
4229 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
4230 /* Leave out the attribute */
4231 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
4232 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
4233 NL80211_AUTHTYPE_SHARED_KEY
);
4235 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
4236 NL80211_AUTHTYPE_OPEN_SYSTEM
);
4239 if (params
->wpa_version
& WPA_PROTO_WPA
)
4240 ver
|= NL80211_WPA_VERSION_1
;
4241 if (params
->wpa_version
& WPA_PROTO_RSN
)
4242 ver
|= NL80211_WPA_VERSION_2
;
4244 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
4247 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
4248 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
4249 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
4250 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
4252 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
4253 num_suites
* sizeof(u32
), suites
);
4257 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
4258 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
4259 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
4260 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
4261 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
4262 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
4263 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
4264 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
4266 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
4267 num_suites
* sizeof(u32
), suites
);
4270 switch (params
->group_cipher
) {
4271 case WPA_CIPHER_CCMP
:
4272 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
4273 WLAN_CIPHER_SUITE_CCMP
);
4275 case WPA_CIPHER_TKIP
:
4276 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
4277 WLAN_CIPHER_SUITE_TKIP
);
4279 case WPA_CIPHER_WEP104
:
4280 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
4281 WLAN_CIPHER_SUITE_WEP104
);
4283 case WPA_CIPHER_WEP40
:
4284 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
4285 WLAN_CIPHER_SUITE_WEP40
);
4289 if (params
->beacon_ies
) {
4290 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
4291 wpabuf_head(params
->beacon_ies
));
4293 if (params
->proberesp_ies
) {
4294 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
4295 wpabuf_len(params
->proberesp_ies
),
4296 wpabuf_head(params
->proberesp_ies
));
4298 if (params
->assocresp_ies
) {
4299 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
4300 wpabuf_len(params
->assocresp_ies
),
4301 wpabuf_head(params
->assocresp_ies
));
4304 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4306 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
4307 ret
, strerror(-ret
));
4309 bss
->beacon_set
= 1;
4310 ret
= nl80211_set_ap_isolate(bss
, params
->isolate
);
4311 if (!params
->isolate
&& ret
) {
4312 wpa_printf(MSG_DEBUG
, "nl80211: Ignore AP isolation "
4313 "configuration error since isolation is "
4318 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
4319 params
->short_slot_time
, params
->ht_opmode
);
4327 static int wpa_driver_nl80211_set_freq(struct wpa_driver_nl80211_data
*drv
,
4328 int freq
, int ht_enabled
,
4329 int sec_channel_offset
)
4334 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d "
4335 "sec_channel_offset=%d)",
4336 freq
, ht_enabled
, sec_channel_offset
);
4337 msg
= nlmsg_alloc();
4341 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
4343 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4344 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
4346 switch (sec_channel_offset
) {
4348 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4349 NL80211_CHAN_HT40MINUS
);
4352 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4353 NL80211_CHAN_HT40PLUS
);
4356 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4362 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4365 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
4366 "%d (%s)", freq
, ret
, strerror(-ret
));
4372 static u32
sta_flags_nl80211(int flags
)
4376 if (flags
& WPA_STA_AUTHORIZED
)
4377 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
4378 if (flags
& WPA_STA_WMM
)
4379 f
|= BIT(NL80211_STA_FLAG_WME
);
4380 if (flags
& WPA_STA_SHORT_PREAMBLE
)
4381 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
4382 if (flags
& WPA_STA_MFP
)
4383 f
|= BIT(NL80211_STA_FLAG_MFP
);
4389 static int wpa_driver_nl80211_sta_add(void *priv
,
4390 struct hostapd_sta_add_params
*params
)
4392 struct i802_bss
*bss
= priv
;
4393 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4395 struct nl80211_sta_flag_update upd
;
4398 msg
= nlmsg_alloc();
4402 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_STATION
);
4404 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
4405 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
4406 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
4407 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
4408 params
->supp_rates
);
4409 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
4410 params
->listen_interval
);
4411 if (params
->ht_capabilities
) {
4412 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
4413 sizeof(*params
->ht_capabilities
),
4414 params
->ht_capabilities
);
4417 os_memset(&upd
, 0, sizeof(upd
));
4418 upd
.mask
= sta_flags_nl80211(params
->flags
);
4420 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
4422 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4424 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_NEW_STATION "
4425 "result: %d (%s)", ret
, strerror(-ret
));
4433 static int wpa_driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
4435 struct i802_bss
*bss
= priv
;
4436 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4440 msg
= nlmsg_alloc();
4444 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
4446 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
4447 if_nametoindex(bss
->ifname
));
4448 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4450 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4459 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
4464 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
4467 /* stop listening for EAPOL on this interface */
4468 del_ifidx(drv
, ifidx
);
4469 #endif /* HOSTAPD */
4471 msg
= nlmsg_alloc();
4473 goto nla_put_failure
;
4475 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
4476 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
4478 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
4481 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
4485 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
4488 case NL80211_IFTYPE_ADHOC
:
4490 case NL80211_IFTYPE_STATION
:
4492 case NL80211_IFTYPE_AP
:
4494 case NL80211_IFTYPE_MONITOR
:
4496 case NL80211_IFTYPE_P2P_CLIENT
:
4497 return "P2P_CLIENT";
4498 case NL80211_IFTYPE_P2P_GO
:
4506 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
4508 enum nl80211_iftype iftype
,
4509 const u8
*addr
, int wds
)
4511 struct nl_msg
*msg
, *flags
= NULL
;
4515 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
4516 iftype
, nl80211_iftype_str(iftype
));
4518 msg
= nlmsg_alloc();
4522 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
4523 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4524 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
4525 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
4527 if (iftype
== NL80211_IFTYPE_MONITOR
) {
4530 flags
= nlmsg_alloc();
4532 goto nla_put_failure
;
4534 NLA_PUT_FLAG(flags
, NL80211_MNTR_FLAG_COOK_FRAMES
);
4536 err
= nla_put_nested(msg
, NL80211_ATTR_MNTR_FLAGS
, flags
);
4541 goto nla_put_failure
;
4543 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
4546 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4549 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
4550 ifname
, ret
, strerror(-ret
));
4554 ifidx
= if_nametoindex(ifname
);
4555 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
4562 /* start listening for EAPOL on this interface */
4563 add_ifidx(drv
, ifidx
);
4564 #endif /* HOSTAPD */
4566 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
4567 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
4568 nl80211_remove_iface(drv
, ifidx
);
4576 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
4577 const char *ifname
, enum nl80211_iftype iftype
,
4578 const u8
*addr
, int wds
)
4582 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
);
4584 /* if error occurred and interface exists already */
4585 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
4586 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
4588 /* Try to remove the interface that was already there. */
4589 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
4591 /* Try to create the interface again */
4592 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
4596 if (ret
>= 0 && drv
->disable_11b_rates
)
4597 nl80211_disable_11b_rates(drv
, ret
, 1);
4603 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
4605 struct ieee80211_hdr
*hdr
;
4607 union wpa_event_data event
;
4609 hdr
= (struct ieee80211_hdr
*) buf
;
4610 fc
= le_to_host16(hdr
->frame_control
);
4612 os_memset(&event
, 0, sizeof(event
));
4613 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
4614 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
4615 event
.tx_status
.dst
= hdr
->addr1
;
4616 event
.tx_status
.data
= buf
;
4617 event
.tx_status
.data_len
= len
;
4618 event
.tx_status
.ack
= ok
;
4619 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
4623 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
4624 u8
*buf
, size_t len
)
4626 struct ieee80211_hdr
*hdr
= (void *)buf
;
4628 union wpa_event_data event
;
4630 if (len
< sizeof(*hdr
))
4633 fc
= le_to_host16(hdr
->frame_control
);
4635 os_memset(&event
, 0, sizeof(event
));
4636 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
4637 event
.rx_from_unknown
.addr
= hdr
->addr2
;
4638 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
4639 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
4640 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
4644 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
4645 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
4647 struct ieee80211_hdr
*hdr
;
4649 union wpa_event_data event
;
4651 hdr
= (struct ieee80211_hdr
*) buf
;
4652 fc
= le_to_host16(hdr
->frame_control
);
4654 switch (WLAN_FC_GET_TYPE(fc
)) {
4655 case WLAN_FC_TYPE_MGMT
:
4656 os_memset(&event
, 0, sizeof(event
));
4657 event
.rx_mgmt
.frame
= buf
;
4658 event
.rx_mgmt
.frame_len
= len
;
4659 event
.rx_mgmt
.datarate
= datarate
;
4660 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
4661 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
4663 case WLAN_FC_TYPE_CTRL
:
4664 /* can only get here with PS-Poll frames */
4665 wpa_printf(MSG_DEBUG
, "CTRL");
4666 from_unknown_sta(drv
, buf
, len
);
4668 case WLAN_FC_TYPE_DATA
:
4669 from_unknown_sta(drv
, buf
, len
);
4675 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
4677 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
4679 unsigned char buf
[3000];
4680 struct ieee80211_radiotap_iterator iter
;
4682 int datarate
= 0, ssi_signal
= 0;
4683 int injected
= 0, failed
= 0, rxflags
= 0;
4685 len
= recv(sock
, buf
, sizeof(buf
), 0);
4691 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
4692 printf("received invalid radiotap frame\n");
4697 ret
= ieee80211_radiotap_iterator_next(&iter
);
4701 printf("received invalid radiotap frame (%d)\n", ret
);
4704 switch (iter
.this_arg_index
) {
4705 case IEEE80211_RADIOTAP_FLAGS
:
4706 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
4709 case IEEE80211_RADIOTAP_RX_FLAGS
:
4712 case IEEE80211_RADIOTAP_TX_FLAGS
:
4714 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
4715 IEEE80211_RADIOTAP_F_TX_FAIL
;
4717 case IEEE80211_RADIOTAP_DATA_RETRIES
:
4719 case IEEE80211_RADIOTAP_CHANNEL
:
4720 /* TODO: convert from freq/flags to channel number */
4722 case IEEE80211_RADIOTAP_RATE
:
4723 datarate
= *iter
.this_arg
* 5;
4725 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
4726 ssi_signal
= *iter
.this_arg
;
4731 if (rxflags
&& injected
)
4735 handle_frame(drv
, buf
+ iter
.max_length
,
4736 len
- iter
.max_length
, datarate
, ssi_signal
);
4738 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
4739 len
- iter
.max_length
, !failed
);
4744 * we post-process the filter code later and rewrite
4745 * this to the offset to the last instruction
4750 static struct sock_filter msock_filter_insns
[] = {
4752 * do a little-endian load of the radiotap length field
4754 /* load lower byte into A */
4755 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
4756 /* put it into X (== index register) */
4757 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
4758 /* load upper byte into A */
4759 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
4760 /* left-shift it by 8 */
4761 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
4763 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
4764 /* put result into X */
4765 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
4768 * Allow management frames through, this also gives us those
4769 * management frames that we sent ourselves with status
4771 /* load the lower byte of the IEEE 802.11 frame control field */
4772 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
4773 /* mask off frame type and version */
4774 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
4775 /* accept frame if it's both 0, fall through otherwise */
4776 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
4779 * TODO: add a bit to radiotap RX flags that indicates
4780 * that the sending station is not associated, then
4781 * add a filter here that filters on our DA and that flag
4782 * to allow us to deauth frames to that bad station.
4784 * For now allow all To DS data frames through.
4786 /* load the IEEE 802.11 frame control field */
4787 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
4788 /* mask off frame type, version and DS status */
4789 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
4790 /* accept frame if version 0, type 2 and To DS, fall through otherwise
4792 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
4796 * drop non-data frames
4798 /* load the lower byte of the frame control field */
4799 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
4800 /* mask off QoS bit */
4801 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
4802 /* drop non-data frames */
4803 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
4805 /* load the upper byte of the frame control field */
4806 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
4807 /* mask off toDS/fromDS */
4808 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
4809 /* accept WDS frames */
4810 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
4813 * add header length to index
4815 /* load the lower byte of the frame control field */
4816 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
4817 /* mask off QoS bit */
4818 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
4819 /* right shift it by 6 to give 0 or 2 */
4820 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
4821 /* add data frame header length */
4822 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
4823 /* add index, was start of 802.11 header */
4824 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
4825 /* move to index, now start of LL header */
4826 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
4829 * Accept empty data frames, we use those for
4832 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
4833 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
4836 * Accept EAPOL frames
4838 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
4839 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
4840 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
4841 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
4843 /* keep these last two statements or change the code below */
4844 /* return 0 == "DROP" */
4845 BPF_STMT(BPF_RET
| BPF_K
, 0),
4846 /* return ~0 == "keep all" */
4847 BPF_STMT(BPF_RET
| BPF_K
, ~0),
4850 static struct sock_fprog msock_filter
= {
4851 .len
= sizeof(msock_filter_insns
)/sizeof(msock_filter_insns
[0]),
4852 .filter
= msock_filter_insns
,
4856 static int add_monitor_filter(int s
)
4860 /* rewrite all PASS/FAIL jump offsets */
4861 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
4862 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
4864 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
4865 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
4866 if (insn
->k
== PASS
)
4867 insn
->k
= msock_filter
.len
- idx
- 2;
4868 else if (insn
->k
== FAIL
)
4869 insn
->k
= msock_filter
.len
- idx
- 3;
4872 if (insn
->jt
== PASS
)
4873 insn
->jt
= msock_filter
.len
- idx
- 2;
4874 else if (insn
->jt
== FAIL
)
4875 insn
->jt
= msock_filter
.len
- idx
- 3;
4877 if (insn
->jf
== PASS
)
4878 insn
->jf
= msock_filter
.len
- idx
- 2;
4879 else if (insn
->jf
== FAIL
)
4880 insn
->jf
= msock_filter
.len
- idx
- 3;
4884 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
4885 &msock_filter
, sizeof(msock_filter
))) {
4886 perror("SO_ATTACH_FILTER");
4894 static void nl80211_remove_monitor_interface(
4895 struct wpa_driver_nl80211_data
*drv
)
4897 if (drv
->monitor_ifidx
>= 0) {
4898 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
4899 drv
->monitor_ifidx
= -1;
4901 if (drv
->monitor_sock
>= 0) {
4902 eloop_unregister_read_sock(drv
->monitor_sock
);
4903 close(drv
->monitor_sock
);
4904 drv
->monitor_sock
= -1;
4910 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
4913 struct sockaddr_ll ll
;
4917 if (os_strncmp(drv
->first_bss
.ifname
, "p2p-", 4) == 0) {
4919 * P2P interface name is of the format p2p-%s-%d. For monitor
4920 * interface name corresponding to P2P GO, replace "p2p-" with
4921 * "mon-" to retain the same interface name length and to
4922 * indicate that it is a monitor interface.
4924 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
.ifname
+ 4);
4926 /* Non-P2P interface with AP functionality. */
4927 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
.ifname
);
4930 buf
[IFNAMSIZ
- 1] = '\0';
4932 drv
->monitor_ifidx
=
4933 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
4936 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
4937 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
4938 "monitor interface type - try to run without it");
4939 drv
->no_monitor_iface_capab
= 1;
4942 if (drv
->monitor_ifidx
< 0)
4945 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
4948 memset(&ll
, 0, sizeof(ll
));
4949 ll
.sll_family
= AF_PACKET
;
4950 ll
.sll_ifindex
= drv
->monitor_ifidx
;
4951 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
4952 if (drv
->monitor_sock
< 0) {
4953 perror("socket[PF_PACKET,SOCK_RAW]");
4957 if (add_monitor_filter(drv
->monitor_sock
)) {
4958 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
4959 "interface; do filtering in user space");
4960 /* This works, but will cost in performance. */
4963 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
4964 perror("monitor socket bind");
4968 optlen
= sizeof(optval
);
4971 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
4972 perror("Failed to set socket priority");
4976 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
4978 printf("Could not register monitor read socket\n");
4984 nl80211_remove_monitor_interface(drv
);
4990 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
4991 const u8
*addr
, const u8
*data
,
4992 size_t data_len
, const u8
*own_addr
)
4994 if (bss
->drv
->l2
== NULL
) {
4995 wpa_printf(MSG_DEBUG
, "nl80211: No l2_packet to send EAPOL");
4999 if (l2_packet_send(bss
->drv
->l2
, addr
, ETH_P_EAPOL
, data
, data_len
) <
5004 #endif /* CONFIG_AP */
5007 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
5009 static int wpa_driver_nl80211_hapd_send_eapol(
5010 void *priv
, const u8
*addr
, const u8
*data
,
5011 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
5013 struct i802_bss
*bss
= priv
;
5014 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5015 struct ieee80211_hdr
*hdr
;
5019 int qos
= flags
& WPA_STA_WMM
;
5022 if (drv
->no_monitor_iface_capab
)
5023 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
,
5025 #endif /* CONFIG_AP */
5027 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
5029 hdr
= os_zalloc(len
);
5031 printf("malloc() failed for i802_send_data(len=%lu)\n",
5032 (unsigned long) len
);
5036 hdr
->frame_control
=
5037 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
5038 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
5040 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
5042 hdr
->frame_control
|=
5043 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
5046 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
5047 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
5048 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
5049 pos
= (u8
*) (hdr
+ 1);
5052 /* add an empty QoS header if needed */
5058 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
5059 pos
+= sizeof(rfc1042_header
);
5060 WPA_PUT_BE16(pos
, ETH_P_PAE
);
5062 memcpy(pos
, data
, data_len
);
5064 res
= wpa_driver_nl80211_send_frame(drv
, (u8
*) hdr
, len
, encrypt
);
5066 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
5068 (unsigned long) len
, errno
, strerror(errno
));
5076 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
5078 int flags_or
, int flags_and
)
5080 struct i802_bss
*bss
= priv
;
5081 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5082 struct nl_msg
*msg
, *flags
= NULL
;
5083 struct nl80211_sta_flag_update upd
;
5085 msg
= nlmsg_alloc();
5089 flags
= nlmsg_alloc();
5095 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
5097 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5098 if_nametoindex(bss
->ifname
));
5099 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5102 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
5103 * can be removed eventually.
5105 if (total_flags
& WPA_STA_AUTHORIZED
)
5106 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_AUTHORIZED
);
5108 if (total_flags
& WPA_STA_WMM
)
5109 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_WME
);
5111 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
5112 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
5114 if (total_flags
& WPA_STA_MFP
)
5115 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_MFP
);
5117 if (nla_put_nested(msg
, NL80211_ATTR_STA_FLAGS
, flags
))
5118 goto nla_put_failure
;
5120 os_memset(&upd
, 0, sizeof(upd
));
5121 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
5122 upd
.set
= sta_flags_nl80211(flags_or
);
5123 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
5127 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5134 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
5135 struct wpa_driver_associate_params
*params
)
5137 enum nl80211_iftype nlmode
;
5140 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
5142 nlmode
= NL80211_IFTYPE_P2P_GO
;
5144 nlmode
= NL80211_IFTYPE_AP
;
5146 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
, nlmode
) ||
5147 wpa_driver_nl80211_set_freq(drv
, params
->freq
, 0, 0)) {
5148 nl80211_remove_monitor_interface(drv
);
5152 if (drv
->no_monitor_iface_capab
) {
5153 if (wpa_driver_nl80211_probe_req_report(&drv
->first_bss
, 1) < 0)
5155 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
5156 "Probe Request frame reporting in AP mode");
5157 /* Try to survive without this */
5161 drv
->ap_oper_freq
= params
->freq
;
5167 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
5172 msg
= nlmsg_alloc();
5176 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
5177 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5178 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5181 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
5182 "(%s)", ret
, strerror(-ret
));
5183 goto nla_put_failure
;
5187 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
5195 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
5196 struct wpa_driver_associate_params
*params
)
5202 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
5204 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
5205 NL80211_IFTYPE_ADHOC
)) {
5206 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
5212 msg
= nlmsg_alloc();
5216 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
5217 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5219 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
5220 goto nla_put_failure
;
5222 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5223 params
->ssid
, params
->ssid_len
);
5224 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5226 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5227 drv
->ssid_len
= params
->ssid_len
;
5229 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5230 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5232 ret
= nl80211_set_conn_keys(params
, msg
);
5234 goto nla_put_failure
;
5236 if (params
->wpa_ie
) {
5237 wpa_hexdump(MSG_DEBUG
,
5238 " * Extra IEs for Beacon/Probe Response frames",
5239 params
->wpa_ie
, params
->wpa_ie_len
);
5240 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5244 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5247 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
5248 ret
, strerror(-ret
));
5250 if (ret
== -EALREADY
&& count
== 1) {
5251 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
5253 nl80211_leave_ibss(drv
);
5258 goto nla_put_failure
;
5261 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
5269 static unsigned int nl80211_get_assoc_bssid(struct wpa_driver_nl80211_data
*drv
,
5274 struct nl80211_bss_info_arg arg
;
5276 os_memset(&arg
, 0, sizeof(arg
));
5277 msg
= nlmsg_alloc();
5279 goto nla_put_failure
;
5281 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
5282 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5285 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
5288 if (is_zero_ether_addr(arg
.assoc_bssid
))
5290 os_memcpy(bssid
, arg
.assoc_bssid
, ETH_ALEN
);
5293 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
5294 "(%s)", ret
, strerror(-ret
));
5297 return drv
->assoc_freq
;
5301 static int nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
5306 if (bssid
== NULL
) {
5307 int res
= nl80211_get_assoc_bssid(drv
, addr
);
5313 return wpa_driver_nl80211_disconnect(drv
, bssid
,
5314 WLAN_REASON_PREV_AUTH_NOT_VALID
);
5318 static int wpa_driver_nl80211_connect(
5319 struct wpa_driver_nl80211_data
*drv
,
5320 struct wpa_driver_associate_params
*params
)
5323 enum nl80211_auth_type type
;
5327 msg
= nlmsg_alloc();
5331 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
5332 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
5334 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5335 if (params
->bssid
) {
5336 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5337 MAC2STR(params
->bssid
));
5338 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
5341 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5342 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5345 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5346 params
->ssid
, params
->ssid_len
);
5347 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5349 if (params
->ssid_len
> sizeof(drv
->ssid
))
5350 goto nla_put_failure
;
5351 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5352 drv
->ssid_len
= params
->ssid_len
;
5354 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
5356 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5360 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5362 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5364 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5367 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
5369 goto skip_auth_type
;
5372 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5373 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
5374 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5375 type
= NL80211_AUTHTYPE_SHARED_KEY
;
5376 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5377 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
5378 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
5379 type
= NL80211_AUTHTYPE_FT
;
5381 goto nla_put_failure
;
5383 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
5384 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
5387 if (params
->wpa_proto
) {
5388 enum nl80211_wpa_versions ver
= 0;
5390 if (params
->wpa_proto
& WPA_PROTO_WPA
)
5391 ver
|= NL80211_WPA_VERSION_1
;
5392 if (params
->wpa_proto
& WPA_PROTO_RSN
)
5393 ver
|= NL80211_WPA_VERSION_2
;
5395 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
5396 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
5399 if (params
->pairwise_suite
!= CIPHER_NONE
) {
5402 switch (params
->pairwise_suite
) {
5404 cipher
= WLAN_CIPHER_SUITE_WEP40
;
5407 cipher
= WLAN_CIPHER_SUITE_WEP104
;
5410 cipher
= WLAN_CIPHER_SUITE_CCMP
;
5414 cipher
= WLAN_CIPHER_SUITE_TKIP
;
5417 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
5420 if (params
->group_suite
!= CIPHER_NONE
) {
5423 switch (params
->group_suite
) {
5425 cipher
= WLAN_CIPHER_SUITE_WEP40
;
5428 cipher
= WLAN_CIPHER_SUITE_WEP104
;
5431 cipher
= WLAN_CIPHER_SUITE_CCMP
;
5435 cipher
= WLAN_CIPHER_SUITE_TKIP
;
5438 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
5441 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
5442 params
->key_mgmt_suite
== KEY_MGMT_PSK
) {
5443 int mgmt
= WLAN_AKM_SUITE_PSK
;
5445 switch (params
->key_mgmt_suite
) {
5446 case KEY_MGMT_802_1X
:
5447 mgmt
= WLAN_AKM_SUITE_8021X
;
5451 mgmt
= WLAN_AKM_SUITE_PSK
;
5454 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
5457 ret
= nl80211_set_conn_keys(params
, msg
);
5459 goto nla_put_failure
;
5461 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5464 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
5465 "(%s)", ret
, strerror(-ret
));
5467 * cfg80211 does not currently accept new connection if we are
5468 * already connected. As a workaround, force disconnection and
5469 * try again once the driver indicates it completed
5472 if (ret
== -EALREADY
)
5473 nl80211_disconnect(drv
, params
->bssid
);
5474 goto nla_put_failure
;
5477 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
5486 static int wpa_driver_nl80211_associate(
5487 void *priv
, struct wpa_driver_associate_params
*params
)
5489 struct i802_bss
*bss
= priv
;
5490 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5494 if (params
->mode
== IEEE80211_MODE_AP
)
5495 return wpa_driver_nl80211_ap(drv
, params
);
5497 if (params
->mode
== IEEE80211_MODE_IBSS
)
5498 return wpa_driver_nl80211_ibss(drv
, params
);
5500 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
5501 enum nl80211_iftype nlmode
= params
->p2p
?
5502 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
5504 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
5506 return wpa_driver_nl80211_connect(drv
, params
);
5509 drv
->associated
= 0;
5511 msg
= nlmsg_alloc();
5515 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
5517 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
5519 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5520 if (params
->bssid
) {
5521 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5522 MAC2STR(params
->bssid
));
5523 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
5526 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5527 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5528 drv
->assoc_freq
= params
->freq
;
5530 drv
->assoc_freq
= 0;
5532 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5533 params
->ssid
, params
->ssid_len
);
5534 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5536 if (params
->ssid_len
> sizeof(drv
->ssid
))
5537 goto nla_put_failure
;
5538 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5539 drv
->ssid_len
= params
->ssid_len
;
5541 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
5543 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5546 if (params
->pairwise_suite
!= CIPHER_NONE
) {
5549 switch (params
->pairwise_suite
) {
5551 cipher
= WLAN_CIPHER_SUITE_WEP40
;
5554 cipher
= WLAN_CIPHER_SUITE_WEP104
;
5557 cipher
= WLAN_CIPHER_SUITE_CCMP
;
5561 cipher
= WLAN_CIPHER_SUITE_TKIP
;
5564 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
5565 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
5568 if (params
->group_suite
!= CIPHER_NONE
) {
5571 switch (params
->group_suite
) {
5573 cipher
= WLAN_CIPHER_SUITE_WEP40
;
5576 cipher
= WLAN_CIPHER_SUITE_WEP104
;
5579 cipher
= WLAN_CIPHER_SUITE_CCMP
;
5583 cipher
= WLAN_CIPHER_SUITE_TKIP
;
5586 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
5587 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
5590 #ifdef CONFIG_IEEE80211W
5591 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
5592 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
5593 #endif /* CONFIG_IEEE80211W */
5595 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
5597 if (params
->prev_bssid
) {
5598 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
5599 MAC2STR(params
->prev_bssid
));
5600 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
5601 params
->prev_bssid
);
5605 wpa_printf(MSG_DEBUG
, " * P2P group");
5607 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5610 wpa_printf(MSG_DEBUG
, "nl80211: MLME command failed: ret=%d "
5611 "(%s)", ret
, strerror(-ret
));
5612 nl80211_dump_scan(drv
);
5613 goto nla_put_failure
;
5616 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
5625 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
5626 int ifindex
, enum nl80211_iftype mode
)
5631 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
5632 ifindex
, mode
, nl80211_iftype_str(mode
));
5634 msg
= nlmsg_alloc();
5638 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
5639 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5640 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
5642 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5646 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
5647 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
5652 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
5653 enum nl80211_iftype nlmode
)
5655 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5658 int was_ap
= is_ap_interface(drv
->nlmode
);
5660 if (nl80211_set_mode(drv
, drv
->ifindex
, nlmode
) == 0) {
5661 drv
->nlmode
= nlmode
;
5666 if (nlmode
== drv
->nlmode
) {
5667 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
5668 "requested mode - ignore error");
5670 goto done
; /* Already in the requested mode */
5673 /* mac80211 doesn't allow mode changes while the device is up, so
5674 * take the device down, try to set the mode again, and bring the
5677 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
5679 for (i
= 0; i
< 10; i
++) {
5681 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
5683 if (res
== -EACCES
|| res
== -ENODEV
)
5686 /* Try to set the mode again while the interface is
5688 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
5691 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
5695 else if (ret
!= -EBUSY
)
5698 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
5700 os_sleep(0, 100000);
5704 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
5705 "interface is down");
5706 drv
->nlmode
= nlmode
;
5707 drv
->ignore_if_down_event
= 1;
5711 if (!ret
&& is_ap_interface(nlmode
)) {
5712 /* Setup additional AP mode functionality if needed */
5713 if (!drv
->no_monitor_iface_capab
&& drv
->monitor_ifidx
< 0 &&
5714 nl80211_create_monitor_interface(drv
) &&
5715 !drv
->no_monitor_iface_capab
)
5717 } else if (!ret
&& !is_ap_interface(nlmode
)) {
5718 /* Remove additional AP mode functionality */
5719 if (was_ap
&& drv
->no_monitor_iface_capab
)
5720 wpa_driver_nl80211_probe_req_report(bss
, 0);
5721 nl80211_remove_monitor_interface(drv
);
5722 bss
->beacon_set
= 0;
5726 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
5727 "from %d failed", nlmode
, drv
->nlmode
);
5733 static int wpa_driver_nl80211_get_capa(void *priv
,
5734 struct wpa_driver_capa
*capa
)
5736 struct i802_bss
*bss
= priv
;
5737 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5738 if (!drv
->has_capability
)
5740 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
5745 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
5747 struct i802_bss
*bss
= priv
;
5748 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5750 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
5751 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
5752 drv
->operstate
= state
;
5753 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
5754 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
5758 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
5760 struct i802_bss
*bss
= priv
;
5761 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5763 struct nl80211_sta_flag_update upd
;
5765 msg
= nlmsg_alloc();
5769 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
5771 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5772 if_nametoindex(bss
->ifname
));
5773 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
5775 os_memset(&upd
, 0, sizeof(upd
));
5776 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5778 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5779 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
5781 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5787 /* Set kernel driver on given frequency (MHz) */
5788 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
5790 struct i802_bss
*bss
= priv
;
5791 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5792 return wpa_driver_nl80211_set_freq(drv
, freq
->freq
, freq
->ht_enabled
,
5793 freq
->sec_channel_offset
);
5797 #if defined(HOSTAPD) || defined(CONFIG_AP)
5799 static inline int min_int(int a
, int b
)
5807 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
5809 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5810 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5812 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5813 genlmsg_attrlen(gnlh
, 0), NULL
);
5816 * TODO: validate the key index and mac address!
5817 * Otherwise, there's a race condition as soon as
5818 * the kernel starts sending key notifications.
5821 if (tb
[NL80211_ATTR_KEY_SEQ
])
5822 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
5823 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
5828 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
5831 struct i802_bss
*bss
= priv
;
5832 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5835 msg
= nlmsg_alloc();
5839 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
5842 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5843 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
5844 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
5848 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
5854 static int i802_set_rate_sets(void *priv
, int *supp_rates
, int *basic_rates
,
5857 struct i802_bss
*bss
= priv
;
5858 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5860 u8 rates
[NL80211_MAX_SUPP_RATES
];
5864 msg
= nlmsg_alloc();
5868 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
5870 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0; i
++)
5871 rates
[rates_len
++] = basic_rates
[i
] / 5;
5873 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
5875 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5877 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5883 static int i802_set_rts(void *priv
, int rts
)
5885 struct i802_bss
*bss
= priv
;
5886 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5891 msg
= nlmsg_alloc();
5900 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
5901 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5902 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
5904 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5908 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
5909 "%d (%s)", rts
, ret
, strerror(-ret
));
5914 static int i802_set_frag(void *priv
, int frag
)
5916 struct i802_bss
*bss
= priv
;
5917 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5922 msg
= nlmsg_alloc();
5931 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
5932 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5933 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
5935 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5939 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
5940 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
5945 static int i802_flush(void *priv
)
5947 struct i802_bss
*bss
= priv
;
5948 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5951 msg
= nlmsg_alloc();
5955 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
5958 * XXX: FIX! this needs to flush all VLANs too
5960 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5961 if_nametoindex(bss
->ifname
));
5963 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5969 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
5971 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5972 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5973 struct hostap_sta_driver_data
*data
= arg
;
5974 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
5975 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
5976 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
5977 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
5978 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
5979 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
5980 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
5983 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5984 genlmsg_attrlen(gnlh
, 0), NULL
);
5987 * TODO: validate the interface and mac address!
5988 * Otherwise, there's a race condition as soon as
5989 * the kernel starts sending station notifications.
5992 if (!tb
[NL80211_ATTR_STA_INFO
]) {
5993 wpa_printf(MSG_DEBUG
, "sta stats missing!");
5996 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
5997 tb
[NL80211_ATTR_STA_INFO
],
5999 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
6003 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
6004 data
->inactive_msec
=
6005 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
6006 if (stats
[NL80211_STA_INFO_RX_BYTES
])
6007 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
6008 if (stats
[NL80211_STA_INFO_TX_BYTES
])
6009 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
6010 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
6012 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
6013 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
6015 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
6020 static int i802_read_sta_data(void *priv
, struct hostap_sta_driver_data
*data
,
6023 struct i802_bss
*bss
= priv
;
6024 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6027 os_memset(data
, 0, sizeof(*data
));
6028 msg
= nlmsg_alloc();
6032 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
6034 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6035 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6037 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
6043 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
6044 int cw_min
, int cw_max
, int burst_time
)
6046 struct i802_bss
*bss
= priv
;
6047 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6049 struct nlattr
*txq
, *params
;
6051 msg
= nlmsg_alloc();
6055 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
6057 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6059 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
6061 goto nla_put_failure
;
6063 /* We are only sending parameters for a single TXQ at a time */
6064 params
= nla_nest_start(msg
, 1);
6066 goto nla_put_failure
;
6070 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
6073 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
6076 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
6079 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
6082 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
6083 * 32 usec, so need to convert the value here. */
6084 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
6085 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
6086 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
6087 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
6089 nla_nest_end(msg
, params
);
6091 nla_nest_end(msg
, txq
);
6093 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
6100 static int i802_set_sta_vlan(void *priv
, const u8
*addr
,
6101 const char *ifname
, int vlan_id
)
6103 struct i802_bss
*bss
= priv
;
6104 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6108 msg
= nlmsg_alloc();
6112 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
6114 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6115 if_nametoindex(bss
->ifname
));
6116 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6117 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
6118 if_nametoindex(ifname
));
6120 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6122 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
6123 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
6124 MAC2STR(addr
), ifname
, vlan_id
, ret
,
6132 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
6134 struct hostap_sta_driver_data data
;
6137 data
.inactive_msec
= (unsigned long) -1;
6138 ret
= i802_read_sta_data(priv
, &data
, addr
);
6139 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
6141 return data
.inactive_msec
/ 1000;
6145 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
6154 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
6157 struct i802_bss
*bss
= priv
;
6158 struct ieee80211_mgmt mgmt
;
6160 memset(&mgmt
, 0, sizeof(mgmt
));
6161 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6162 WLAN_FC_STYPE_DEAUTH
);
6163 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6164 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6165 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6166 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
6167 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6169 sizeof(mgmt
.u
.deauth
));
6173 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
6176 struct i802_bss
*bss
= priv
;
6177 struct ieee80211_mgmt mgmt
;
6179 memset(&mgmt
, 0, sizeof(mgmt
));
6180 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6181 WLAN_FC_STYPE_DISASSOC
);
6182 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6183 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6184 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6185 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
6186 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6188 sizeof(mgmt
.u
.disassoc
));
6191 #endif /* HOSTAPD || CONFIG_AP */
6195 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
6200 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
6202 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6203 if (drv
->if_indices
[i
] == 0) {
6204 drv
->if_indices
[i
] = ifidx
;
6209 if (drv
->if_indices
!= drv
->default_if_indices
)
6210 old
= drv
->if_indices
;
6214 drv
->if_indices
= os_realloc(old
,
6215 sizeof(int) * (drv
->num_if_indices
+ 1));
6216 if (!drv
->if_indices
) {
6218 drv
->if_indices
= drv
->default_if_indices
;
6220 drv
->if_indices
= old
;
6221 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
6223 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
6226 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
6227 sizeof(drv
->default_if_indices
));
6228 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
6229 drv
->num_if_indices
++;
6233 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
6237 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6238 if (drv
->if_indices
[i
] == ifidx
) {
6239 drv
->if_indices
[i
] = 0;
6246 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
6250 for (i
= 0; i
< drv
->num_if_indices
; i
++)
6251 if (drv
->if_indices
[i
] == ifidx
)
6258 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
6259 const char *bridge_ifname
)
6261 struct i802_bss
*bss
= priv
;
6262 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6263 char name
[IFNAMSIZ
+ 1];
6265 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
6266 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
6267 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
6269 if (!if_nametoindex(name
)) {
6270 if (nl80211_create_iface(drv
, name
,
6271 NL80211_IFTYPE_AP_VLAN
,
6274 if (bridge_ifname
&&
6275 linux_br_add_if(drv
->global
->ioctl_sock
,
6276 bridge_ifname
, name
) < 0)
6279 linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1);
6280 return i802_set_sta_vlan(priv
, addr
, name
, 0);
6282 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
6283 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
6289 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
6291 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
6292 struct sockaddr_ll lladdr
;
6293 unsigned char buf
[3000];
6295 socklen_t fromlen
= sizeof(lladdr
);
6297 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
6298 (struct sockaddr
*)&lladdr
, &fromlen
);
6304 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
6305 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
6309 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
6310 struct i802_bss
*bss
,
6311 const char *brname
, const char *ifname
)
6314 char in_br
[IFNAMSIZ
];
6316 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
6317 ifindex
= if_nametoindex(brname
);
6320 * Bridge was configured, but the bridge device does
6321 * not exist. Try to add it now.
6323 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
6324 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
6325 "bridge interface %s: %s",
6326 brname
, strerror(errno
));
6329 bss
->added_bridge
= 1;
6330 add_ifidx(drv
, if_nametoindex(brname
));
6333 if (linux_br_get(in_br
, ifname
) == 0) {
6334 if (os_strcmp(in_br
, brname
) == 0)
6335 return 0; /* already in the bridge */
6337 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
6338 "bridge %s", ifname
, in_br
);
6339 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
6341 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
6342 "remove interface %s from bridge "
6344 ifname
, brname
, strerror(errno
));
6349 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
6351 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
6352 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
6353 "into bridge %s: %s",
6354 ifname
, brname
, strerror(errno
));
6357 bss
->added_if_into_bridge
= 1;
6363 static void *i802_init(struct hostapd_data
*hapd
,
6364 struct wpa_init_params
*params
)
6366 struct wpa_driver_nl80211_data
*drv
;
6367 struct i802_bss
*bss
;
6369 char brname
[IFNAMSIZ
];
6370 int ifindex
, br_ifindex
;
6373 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
6374 params
->global_priv
);
6379 drv
->nlmode
= NL80211_IFTYPE_AP
;
6380 drv
->eapol_sock
= -1;
6382 if (linux_br_get(brname
, params
->ifname
) == 0) {
6383 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
6384 params
->ifname
, brname
);
6385 br_ifindex
= if_nametoindex(brname
);
6391 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
6392 drv
->if_indices
= drv
->default_if_indices
;
6393 for (i
= 0; i
< params
->num_bridge
; i
++) {
6394 if (params
->bridge
[i
]) {
6395 ifindex
= if_nametoindex(params
->bridge
[i
]);
6397 add_ifidx(drv
, ifindex
);
6398 if (ifindex
== br_ifindex
)
6402 if (!br_added
&& br_ifindex
&&
6403 (params
->num_bridge
== 0 || !params
->bridge
[0]))
6404 add_ifidx(drv
, br_ifindex
);
6406 /* start listening for EAPOL on the default AP interface */
6407 add_ifidx(drv
, drv
->ifindex
);
6409 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
6412 if (params
->bssid
) {
6413 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6418 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
6419 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
6420 "into AP mode", bss
->ifname
);
6424 if (params
->num_bridge
&& params
->bridge
[0] &&
6425 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
6428 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
6431 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
6432 if (drv
->eapol_sock
< 0) {
6433 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
6437 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
6439 printf("Could not register read socket for eapol\n");
6443 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6450 wpa_driver_nl80211_deinit(bss
);
6455 static void i802_deinit(void *priv
)
6457 wpa_driver_nl80211_deinit(priv
);
6460 #endif /* HOSTAPD */
6463 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
6464 enum wpa_driver_if_type type
)
6467 case WPA_IF_STATION
:
6468 return NL80211_IFTYPE_STATION
;
6469 case WPA_IF_P2P_CLIENT
:
6470 case WPA_IF_P2P_GROUP
:
6471 return NL80211_IFTYPE_P2P_CLIENT
;
6472 case WPA_IF_AP_VLAN
:
6473 return NL80211_IFTYPE_AP_VLAN
;
6475 return NL80211_IFTYPE_AP
;
6477 return NL80211_IFTYPE_P2P_GO
;
6485 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
6487 struct wpa_driver_nl80211_data
*drv
;
6488 dl_list_for_each(drv
, &global
->interfaces
,
6489 struct wpa_driver_nl80211_data
, list
) {
6490 if (os_memcmp(addr
, drv
->addr
, ETH_ALEN
) == 0)
6497 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
6505 os_memcpy(new_addr
, drv
->addr
, ETH_ALEN
);
6506 for (idx
= 0; idx
< 64; idx
++) {
6507 new_addr
[0] = drv
->addr
[0] | 0x02;
6508 new_addr
[0] ^= idx
<< 2;
6509 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
6515 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
6516 MACSTR
, MAC2STR(new_addr
));
6521 #endif /* CONFIG_P2P */
6524 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
6525 const char *ifname
, const u8
*addr
,
6526 void *bss_ctx
, void **drv_priv
,
6527 char *force_ifname
, u8
*if_addr
,
6530 struct i802_bss
*bss
= priv
;
6531 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6534 struct i802_bss
*new_bss
= NULL
;
6536 if (type
== WPA_IF_AP_BSS
) {
6537 new_bss
= os_zalloc(sizeof(*new_bss
));
6538 if (new_bss
== NULL
)
6541 #endif /* HOSTAPD */
6544 os_memcpy(if_addr
, addr
, ETH_ALEN
);
6545 ifidx
= nl80211_create_iface(drv
, ifname
,
6546 wpa_driver_nl80211_if_type(type
), addr
,
6551 #endif /* HOSTAPD */
6556 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6558 nl80211_remove_iface(drv
, ifidx
);
6564 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
6565 type
== WPA_IF_P2P_GO
)) {
6566 /* Enforce unique P2P Interface Address */
6567 u8 new_addr
[ETH_ALEN
], own_addr
[ETH_ALEN
];
6569 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6571 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
6573 nl80211_remove_iface(drv
, ifidx
);
6576 if (os_memcmp(own_addr
, new_addr
, ETH_ALEN
) == 0) {
6577 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
6578 "for P2P group interface");
6579 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
6580 nl80211_remove_iface(drv
, ifidx
);
6583 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
6585 nl80211_remove_iface(drv
, ifidx
);
6589 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
6591 #endif /* CONFIG_P2P */
6595 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
6596 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
6597 "interface %s to a bridge %s", ifname
, bridge
);
6598 nl80211_remove_iface(drv
, ifidx
);
6603 if (type
== WPA_IF_AP_BSS
) {
6604 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
6606 nl80211_remove_iface(drv
, ifidx
);
6610 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
6611 new_bss
->ifindex
= ifidx
;
6613 new_bss
->next
= drv
->first_bss
.next
;
6614 drv
->first_bss
.next
= new_bss
;
6616 *drv_priv
= new_bss
;
6618 #endif /* HOSTAPD */
6621 drv
->global
->if_add_ifindex
= ifidx
;
6627 static int wpa_driver_nl80211_if_remove(void *priv
,
6628 enum wpa_driver_if_type type
,
6631 struct i802_bss
*bss
= priv
;
6632 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6633 int ifindex
= if_nametoindex(ifname
);
6635 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d",
6636 __func__
, type
, ifname
, ifindex
);
6641 if (bss
->added_if_into_bridge
) {
6642 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
6644 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6645 "interface %s from bridge %s: %s",
6646 bss
->ifname
, bss
->brname
, strerror(errno
));
6648 if (bss
->added_bridge
) {
6649 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
6650 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6652 bss
->brname
, strerror(errno
));
6654 #endif /* HOSTAPD */
6656 nl80211_remove_iface(drv
, ifindex
);
6659 if (type
!= WPA_IF_AP_BSS
)
6662 if (bss
!= &drv
->first_bss
) {
6663 struct i802_bss
*tbss
;
6665 for (tbss
= &drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
6666 if (tbss
->next
== bss
) {
6667 tbss
->next
= bss
->next
;
6674 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
6675 "BSS %p in the list", __func__
, bss
);
6677 #endif /* HOSTAPD */
6683 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
6685 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6686 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6688 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6689 genlmsg_attrlen(gnlh
, 0), NULL
);
6690 if (tb
[NL80211_ATTR_COOKIE
])
6691 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
6696 static int nl80211_send_frame_cmd(struct wpa_driver_nl80211_data
*drv
,
6697 unsigned int freq
, unsigned int wait
,
6698 const u8
*buf
, size_t buf_len
,
6705 msg
= nlmsg_alloc();
6709 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
6711 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6712 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6714 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
6715 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
6716 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
6719 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6722 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
6723 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
6725 goto nla_put_failure
;
6727 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX command accepted; "
6728 "cookie 0x%llx", (long long unsigned int) cookie
);
6731 *cookie_out
= cookie
;
6739 static int wpa_driver_nl80211_send_action(void *priv
, unsigned int freq
,
6740 unsigned int wait_time
,
6741 const u8
*dst
, const u8
*src
,
6743 const u8
*data
, size_t data_len
)
6745 struct i802_bss
*bss
= priv
;
6746 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6749 struct ieee80211_hdr
*hdr
;
6751 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
6752 "wait=%d ms)", drv
->ifindex
, wait_time
);
6754 buf
= os_zalloc(24 + data_len
);
6757 os_memcpy(buf
+ 24, data
, data_len
);
6758 hdr
= (struct ieee80211_hdr
*) buf
;
6759 hdr
->frame_control
=
6760 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
6761 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
6762 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
6763 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
6765 if (is_ap_interface(drv
->nlmode
))
6766 ret
= wpa_driver_nl80211_send_mlme(priv
, buf
, 24 + data_len
);
6768 ret
= nl80211_send_frame_cmd(drv
, freq
, wait_time
, buf
,
6770 &drv
->send_action_cookie
);
6777 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
6779 struct i802_bss
*bss
= priv
;
6780 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6784 msg
= nlmsg_alloc();
6788 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
6790 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6791 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
6793 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6796 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
6797 "(%s)", ret
, strerror(-ret
));
6804 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
6805 unsigned int duration
)
6807 struct i802_bss
*bss
= priv
;
6808 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6813 msg
= nlmsg_alloc();
6817 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
6819 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6820 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6821 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
6824 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6826 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
6827 "0x%llx for freq=%u MHz duration=%u",
6828 (long long unsigned int) cookie
, freq
, duration
);
6829 drv
->remain_on_chan_cookie
= cookie
;
6830 drv
->pending_remain_on_chan
= 1;
6833 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
6834 "(freq=%d duration=%u): %d (%s)",
6835 freq
, duration
, ret
, strerror(-ret
));
6841 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
6843 struct i802_bss
*bss
= priv
;
6844 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6848 if (!drv
->pending_remain_on_chan
) {
6849 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
6854 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
6856 (long long unsigned int) drv
->remain_on_chan_cookie
);
6858 msg
= nlmsg_alloc();
6862 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
6864 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6865 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
6867 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6870 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
6871 "%d (%s)", ret
, strerror(-ret
));
6877 static int wpa_driver_nl80211_probe_req_report(void *priv
, int report
)
6879 struct i802_bss
*bss
= priv
;
6880 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6883 if (drv
->nl_preq
.handle
) {
6884 eloop_unregister_read_sock(
6885 nl_socket_get_fd(drv
->nl_preq
.handle
));
6886 nl_destroy_handles(&drv
->nl_preq
);
6891 if (drv
->nl_preq
.handle
) {
6892 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
6897 if (nl_create_handles(&drv
->nl_preq
, drv
->global
->nl_cb
, "preq"))
6900 if (nl80211_register_frame(drv
, drv
->nl_preq
.handle
,
6901 (WLAN_FC_TYPE_MGMT
<< 2) |
6902 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
6906 eloop_register_read_sock(nl_socket_get_fd(drv
->nl_preq
.handle
),
6907 wpa_driver_nl80211_event_receive
, drv
,
6908 drv
->nl_preq
.handle
);
6913 nl_destroy_handles(&drv
->nl_preq
);
6918 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
6919 int ifindex
, int disabled
)
6922 struct nlattr
*bands
, *band
;
6925 msg
= nlmsg_alloc();
6929 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
6930 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
6932 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
6934 goto nla_put_failure
;
6937 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6938 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6939 * rates. All 5 GHz rates are left enabled.
6941 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
6943 goto nla_put_failure
;
6944 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
6945 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
6946 nla_nest_end(msg
, band
);
6948 nla_nest_end(msg
, bands
);
6950 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6953 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
6954 "(%s)", ret
, strerror(-ret
));
6965 static int wpa_driver_nl80211_disable_11b_rates(void *priv
, int disabled
)
6967 struct i802_bss
*bss
= priv
;
6968 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6969 drv
->disable_11b_rates
= disabled
;
6970 return nl80211_disable_11b_rates(drv
, drv
->ifindex
, disabled
);
6974 static int wpa_driver_nl80211_deinit_ap(void *priv
)
6976 struct i802_bss
*bss
= priv
;
6977 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6978 if (!is_ap_interface(drv
->nlmode
))
6980 wpa_driver_nl80211_del_beacon(drv
);
6981 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
6985 static void wpa_driver_nl80211_resume(void *priv
)
6987 struct i802_bss
*bss
= priv
;
6988 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6989 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
6990 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on "
6996 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
6997 const u8
*ies
, size_t ies_len
)
6999 struct i802_bss
*bss
= priv
;
7000 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7004 u8 own_addr
[ETH_ALEN
];
7006 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7011 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
7012 "action %d", action
);
7017 * Action frame payload:
7018 * Category[1] = 6 (Fast BSS Transition)
7019 * Action[1] = 1 (Fast BSS Transition Request)
7025 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
7026 data
= os_malloc(data_len
);
7030 *pos
++ = 0x06; /* FT Action category */
7032 os_memcpy(pos
, own_addr
, ETH_ALEN
);
7034 os_memcpy(pos
, target_ap
, ETH_ALEN
);
7036 os_memcpy(pos
, ies
, ies_len
);
7038 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
7039 drv
->bssid
, own_addr
, drv
->bssid
,
7047 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
7049 struct i802_bss
*bss
= priv
;
7050 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7051 struct nl_msg
*msg
, *cqm
= NULL
;
7053 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
7054 "hysteresis=%d", threshold
, hysteresis
);
7056 msg
= nlmsg_alloc();
7060 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
7062 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
7064 cqm
= nlmsg_alloc();
7068 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
7069 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
7070 nla_put_nested(msg
, NL80211_ATTR_CQM
, cqm
);
7072 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
7084 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
7086 struct i802_bss
*bss
= priv
;
7087 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7090 os_memset(si
, 0, sizeof(*si
));
7091 res
= nl80211_get_link_signal(drv
, si
);
7095 return nl80211_get_link_noise(drv
, si
);
7099 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
7102 struct i802_bss
*bss
= priv
;
7103 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7104 return wpa_driver_nl80211_send_frame(drv
, data
, data_len
, encrypt
);
7108 static int nl80211_set_param(void *priv
, const char *param
)
7110 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
7115 if (os_strstr(param
, "use_p2p_group_interface=1")) {
7116 struct i802_bss
*bss
= priv
;
7117 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7119 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
7121 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
7122 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
7124 #endif /* CONFIG_P2P */
7130 static void * nl80211_global_init(void)
7132 struct nl80211_global
*global
;
7133 struct netlink_config
*cfg
;
7135 global
= os_zalloc(sizeof(*global
));
7138 global
->ioctl_sock
= -1;
7139 dl_list_init(&global
->interfaces
);
7140 global
->if_add_ifindex
= -1;
7142 cfg
= os_zalloc(sizeof(*cfg
));
7147 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
7148 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
7149 global
->netlink
= netlink_init(cfg
);
7150 if (global
->netlink
== NULL
) {
7155 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
7158 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
7159 if (global
->ioctl_sock
< 0) {
7160 perror("socket(PF_INET,SOCK_DGRAM)");
7167 nl80211_global_deinit(global
);
7172 static void nl80211_global_deinit(void *priv
)
7174 struct nl80211_global
*global
= priv
;
7177 if (!dl_list_empty(&global
->interfaces
)) {
7178 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
7179 "nl80211_global_deinit",
7180 dl_list_len(&global
->interfaces
));
7183 if (global
->netlink
)
7184 netlink_deinit(global
->netlink
);
7186 if (global
->nl80211
)
7187 genl_family_put(global
->nl80211
);
7188 nl_destroy_handles(&global
->nl
);
7191 nl_cb_put(global
->nl_cb
);
7193 if (global
->ioctl_sock
>= 0)
7194 close(global
->ioctl_sock
);
7200 static const char * nl80211_get_radio_name(void *priv
)
7202 struct i802_bss
*bss
= priv
;
7203 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7204 return drv
->phyname
;
7208 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
7213 msg
= nlmsg_alloc();
7217 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
7219 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7221 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
7223 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7225 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
7231 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
7233 struct i802_bss
*bss
= priv
;
7234 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
7235 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
7239 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
7241 struct i802_bss
*bss
= priv
;
7242 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
7244 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
7248 static int nl80211_flush_pmkid(void *priv
)
7250 struct i802_bss
*bss
= priv
;
7251 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
7252 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
7256 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
7257 const u8
*replay_ctr
)
7259 struct i802_bss
*bss
= priv
;
7260 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7261 struct nlattr
*replay_nested
;
7264 msg
= nlmsg_alloc();
7268 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
7270 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
7272 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
7274 goto nla_put_failure
;
7276 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
7277 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
7278 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
7281 nla_nest_end(msg
, replay_nested
);
7283 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7290 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
7293 struct i802_bss
*bss
= priv
;
7295 struct ieee80211_hdr hdr
;
7297 } STRUCT_PACKED nulldata
;
7300 /* Send data frame to poll STA and check whether this frame is ACKed */
7302 os_memset(&nulldata
, 0, sizeof(nulldata
));
7305 nulldata
.hdr
.frame_control
=
7306 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7307 WLAN_FC_STYPE_QOS_NULL
);
7308 size
= sizeof(nulldata
);
7310 nulldata
.hdr
.frame_control
=
7311 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7312 WLAN_FC_STYPE_NULLFUNC
);
7313 size
= sizeof(struct ieee80211_hdr
);
7316 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
7317 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
7318 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
7319 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
7321 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
) < 0)
7322 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
7327 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
7329 .desc
= "Linux nl80211/cfg80211",
7330 .get_bssid
= wpa_driver_nl80211_get_bssid
,
7331 .get_ssid
= wpa_driver_nl80211_get_ssid
,
7332 .set_key
= wpa_driver_nl80211_set_key
,
7333 .scan2
= wpa_driver_nl80211_scan
,
7334 .sched_scan
= wpa_driver_nl80211_sched_scan
,
7335 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
7336 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
7337 .deauthenticate
= wpa_driver_nl80211_deauthenticate
,
7338 .disassociate
= wpa_driver_nl80211_disassociate
,
7339 .authenticate
= wpa_driver_nl80211_authenticate
,
7340 .associate
= wpa_driver_nl80211_associate
,
7341 .global_init
= nl80211_global_init
,
7342 .global_deinit
= nl80211_global_deinit
,
7343 .init2
= wpa_driver_nl80211_init
,
7344 .deinit
= wpa_driver_nl80211_deinit
,
7345 .get_capa
= wpa_driver_nl80211_get_capa
,
7346 .set_operstate
= wpa_driver_nl80211_set_operstate
,
7347 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
7348 .set_country
= wpa_driver_nl80211_set_country
,
7349 .set_ap
= wpa_driver_nl80211_set_ap
,
7350 .if_add
= wpa_driver_nl80211_if_add
,
7351 .if_remove
= wpa_driver_nl80211_if_remove
,
7352 .send_mlme
= wpa_driver_nl80211_send_mlme
,
7353 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
7354 .sta_add
= wpa_driver_nl80211_sta_add
,
7355 .sta_remove
= wpa_driver_nl80211_sta_remove
,
7356 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
7357 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
7359 .hapd_init
= i802_init
,
7360 .hapd_deinit
= i802_deinit
,
7361 .set_wds_sta
= i802_set_wds_sta
,
7362 #endif /* HOSTAPD */
7363 #if defined(HOSTAPD) || defined(CONFIG_AP)
7364 .get_seqnum
= i802_get_seqnum
,
7365 .flush
= i802_flush
,
7366 .read_sta_data
= i802_read_sta_data
,
7367 .get_inact_sec
= i802_get_inact_sec
,
7368 .sta_clear_stats
= i802_sta_clear_stats
,
7369 .set_rts
= i802_set_rts
,
7370 .set_frag
= i802_set_frag
,
7371 .set_tx_queue_params
= i802_set_tx_queue_params
,
7372 .set_sta_vlan
= i802_set_sta_vlan
,
7373 .set_rate_sets
= i802_set_rate_sets
,
7374 .sta_deauth
= i802_sta_deauth
,
7375 .sta_disassoc
= i802_sta_disassoc
,
7376 #endif /* HOSTAPD || CONFIG_AP */
7377 .set_freq
= i802_set_freq
,
7378 .send_action
= wpa_driver_nl80211_send_action
,
7379 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
7380 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
7381 .cancel_remain_on_channel
=
7382 wpa_driver_nl80211_cancel_remain_on_channel
,
7383 .probe_req_report
= wpa_driver_nl80211_probe_req_report
,
7384 .disable_11b_rates
= wpa_driver_nl80211_disable_11b_rates
,
7385 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
7386 .resume
= wpa_driver_nl80211_resume
,
7387 .send_ft_action
= nl80211_send_ft_action
,
7388 .signal_monitor
= nl80211_signal_monitor
,
7389 .signal_poll
= nl80211_signal_poll
,
7390 .send_frame
= nl80211_send_frame
,
7391 .set_param
= nl80211_set_param
,
7392 .get_radio_name
= nl80211_get_radio_name
,
7393 .add_pmkid
= nl80211_add_pmkid
,
7394 .remove_pmkid
= nl80211_remove_pmkid
,
7395 .flush_pmkid
= nl80211_flush_pmkid
,
7396 .set_rekey_info
= nl80211_set_rekey_info
,
7397 .poll_client
= nl80211_poll_client
,