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 inline void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
284 static inline void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
288 static inline int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
294 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
);
295 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
296 int ifindex
, int disabled
);
298 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
);
301 static int is_ap_interface(enum nl80211_iftype nlmode
)
303 return (nlmode
== NL80211_IFTYPE_AP
||
304 nlmode
== NL80211_IFTYPE_P2P_GO
);
308 static int is_sta_interface(enum nl80211_iftype nlmode
)
310 return (nlmode
== NL80211_IFTYPE_STATION
||
311 nlmode
== NL80211_IFTYPE_P2P_CLIENT
);
315 struct nl80211_bss_info_arg
{
316 struct wpa_driver_nl80211_data
*drv
;
317 struct wpa_scan_results
*res
;
318 unsigned int assoc_freq
;
319 u8 assoc_bssid
[ETH_ALEN
];
322 static int bss_info_handler(struct nl_msg
*msg
, void *arg
);
326 static int ack_handler(struct nl_msg
*msg
, void *arg
)
333 static int finish_handler(struct nl_msg
*msg
, void *arg
)
340 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
349 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
355 static int send_and_recv(struct wpa_driver_nl80211_data
*drv
,
356 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
357 int (*valid_handler
)(struct nl_msg
*, void *),
363 cb
= nl_cb_clone(drv
->global
->nl_cb
);
367 err
= nl_send_auto_complete(nl_handle
, msg
);
373 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
374 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
375 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
378 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
379 valid_handler
, valid_data
);
382 nl_recvmsgs(nl_handle
, cb
);
390 static int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
392 int (*valid_handler
)(struct nl_msg
*, void *),
395 return send_and_recv(drv
, drv
->global
->nl
.handle
, msg
, valid_handler
,
406 static int family_handler(struct nl_msg
*msg
, void *arg
)
408 struct family_data
*res
= arg
;
409 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
410 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
411 struct nlattr
*mcgrp
;
414 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
415 genlmsg_attrlen(gnlh
, 0), NULL
);
416 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
419 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
420 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
421 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
422 nla_len(mcgrp
), NULL
);
423 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
424 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
425 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
427 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
429 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
437 static int nl_get_multicast_id(struct wpa_driver_nl80211_data
*drv
,
438 const char *family
, const char *group
)
442 struct family_data res
= { group
, -ENOENT
};
447 genlmsg_put(msg
, 0, 0,
448 genl_ctrl_resolve(drv
->global
->nl
.handle
, "nlctrl"),
449 0, 0, CTRL_CMD_GETFAMILY
, 0);
450 NLA_PUT_STRING(msg
, CTRL_ATTR_FAMILY_NAME
, family
);
452 ret
= send_and_recv_msgs(drv
, msg
, family_handler
, &res
);
463 static void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
464 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
466 return genlmsg_put(msg
, 0, 0, genl_family_get_id(drv
->global
->nl80211
),
471 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
473 struct i802_bss
*bss
= priv
;
474 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
475 if (!drv
->associated
)
477 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
482 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
484 struct i802_bss
*bss
= priv
;
485 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
486 if (!drv
->associated
)
488 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
489 return drv
->ssid_len
;
493 static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data
*drv
,
494 char *buf
, size_t len
, int del
)
496 union wpa_event_data event
;
498 os_memset(&event
, 0, sizeof(event
));
499 if (len
> sizeof(event
.interface_status
.ifname
))
500 len
= sizeof(event
.interface_status
.ifname
) - 1;
501 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
502 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
503 EVENT_INTERFACE_ADDED
;
505 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
507 event
.interface_status
.ifname
,
508 del
? "removed" : "added");
510 if (os_strcmp(drv
->first_bss
.ifname
, event
.interface_status
.ifname
) == 0) {
517 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
521 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
524 int attrlen
, rta_len
;
528 attr
= (struct rtattr
*) buf
;
530 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
531 while (RTA_OK(attr
, attrlen
)) {
532 if (attr
->rta_type
== IFLA_IFNAME
) {
533 if (os_strcmp(((char *) attr
) + rta_len
, drv
->first_bss
.ifname
)
539 attr
= RTA_NEXT(attr
, attrlen
);
546 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
547 int ifindex
, u8
*buf
, size_t len
)
549 if (drv
->ifindex
== ifindex
)
552 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
553 drv
->first_bss
.ifindex
= if_nametoindex(drv
->first_bss
.ifname
);
554 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
556 wpa_driver_nl80211_finish_drv_init(drv
);
564 static struct wpa_driver_nl80211_data
*
565 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
567 struct wpa_driver_nl80211_data
*drv
;
568 dl_list_for_each(drv
, &global
->interfaces
,
569 struct wpa_driver_nl80211_data
, list
) {
570 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
571 have_ifidx(drv
, idx
))
578 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
579 struct ifinfomsg
*ifi
,
582 struct nl80211_global
*global
= ctx
;
583 struct wpa_driver_nl80211_data
*drv
;
584 int attrlen
, rta_len
;
588 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
590 wpa_printf(MSG_DEBUG
, "nl80211: Ignore event for foreign "
591 "ifindex %d", ifi
->ifi_index
);
595 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
597 drv
->operstate
, ifi
->ifi_flags
,
598 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
599 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
600 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
601 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
603 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
604 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
605 if (drv
->ignore_if_down_event
) {
606 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
607 "event generated by mode change");
608 drv
->ignore_if_down_event
= 0;
610 drv
->if_disabled
= 1;
611 wpa_supplicant_event(drv
->ctx
,
612 EVENT_INTERFACE_DISABLED
, NULL
);
616 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
617 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
618 drv
->if_disabled
= 0;
619 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
, NULL
);
623 * Some drivers send the association event before the operup event--in
624 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
625 * fails. This will hit us when wpa_supplicant does not need to do
626 * IEEE 802.1X authentication
628 if (drv
->operstate
== 1 &&
629 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
630 !(ifi
->ifi_flags
& IFF_RUNNING
))
631 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
635 attr
= (struct rtattr
*) buf
;
636 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
637 while (RTA_OK(attr
, attrlen
)) {
638 if (attr
->rta_type
== IFLA_IFNAME
) {
639 wpa_driver_nl80211_event_link(
641 ((char *) attr
) + rta_len
,
642 attr
->rta_len
- rta_len
, 0);
643 } else if (attr
->rta_type
== IFLA_MASTER
)
644 brid
= nla_get_u32((struct nlattr
*) attr
);
645 attr
= RTA_NEXT(attr
, attrlen
);
648 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
649 /* device has been added to bridge */
650 char namebuf
[IFNAMSIZ
];
651 if_indextoname(brid
, namebuf
);
652 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
654 add_ifidx(drv
, brid
);
659 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
660 struct ifinfomsg
*ifi
,
663 struct nl80211_global
*global
= ctx
;
664 struct wpa_driver_nl80211_data
*drv
;
665 int attrlen
, rta_len
;
669 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
671 wpa_printf(MSG_DEBUG
, "nl80211: Ignore dellink event for "
672 "foreign ifindex %d", ifi
->ifi_index
);
677 attr
= (struct rtattr
*) buf
;
679 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
680 while (RTA_OK(attr
, attrlen
)) {
681 if (attr
->rta_type
== IFLA_IFNAME
) {
682 wpa_driver_nl80211_event_link(
684 ((char *) attr
) + rta_len
,
685 attr
->rta_len
- rta_len
, 1);
686 } else if (attr
->rta_type
== IFLA_MASTER
)
687 brid
= nla_get_u32((struct nlattr
*) attr
);
688 attr
= RTA_NEXT(attr
, attrlen
);
691 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
692 /* device has been removed from bridge */
693 char namebuf
[IFNAMSIZ
];
694 if_indextoname(brid
, namebuf
);
695 wpa_printf(MSG_DEBUG
, "nl80211: Remove ifindex %u for bridge "
696 "%s", brid
, namebuf
);
697 del_ifidx(drv
, brid
);
702 static void mlme_event_auth(struct wpa_driver_nl80211_data
*drv
,
703 const u8
*frame
, size_t len
)
705 const struct ieee80211_mgmt
*mgmt
;
706 union wpa_event_data event
;
708 mgmt
= (const struct ieee80211_mgmt
*) frame
;
709 if (len
< 24 + sizeof(mgmt
->u
.auth
)) {
710 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
715 os_memcpy(drv
->auth_bssid
, mgmt
->sa
, ETH_ALEN
);
716 os_memset(&event
, 0, sizeof(event
));
717 os_memcpy(event
.auth
.peer
, mgmt
->sa
, ETH_ALEN
);
718 event
.auth
.auth_type
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
719 event
.auth
.status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
720 if (len
> 24 + sizeof(mgmt
->u
.auth
)) {
721 event
.auth
.ies
= mgmt
->u
.auth
.variable
;
722 event
.auth
.ies_len
= len
- 24 - sizeof(mgmt
->u
.auth
);
725 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH
, &event
);
729 static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
733 struct nl80211_bss_info_arg arg
;
735 os_memset(&arg
, 0, sizeof(arg
));
738 goto nla_put_failure
;
740 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
741 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
744 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
747 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
748 "associated BSS from scan results: %u MHz",
750 return arg
.assoc_freq
? arg
.assoc_freq
: drv
->assoc_freq
;
752 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
753 "(%s)", ret
, strerror(-ret
));
756 return drv
->assoc_freq
;
760 static void mlme_event_assoc(struct wpa_driver_nl80211_data
*drv
,
761 const u8
*frame
, size_t len
)
763 const struct ieee80211_mgmt
*mgmt
;
764 union wpa_event_data event
;
767 mgmt
= (const struct ieee80211_mgmt
*) frame
;
768 if (len
< 24 + sizeof(mgmt
->u
.assoc_resp
)) {
769 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
774 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
775 if (status
!= WLAN_STATUS_SUCCESS
) {
776 os_memset(&event
, 0, sizeof(event
));
777 event
.assoc_reject
.bssid
= mgmt
->bssid
;
778 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
779 event
.assoc_reject
.resp_ies
=
780 (u8
*) mgmt
->u
.assoc_resp
.variable
;
781 event
.assoc_reject
.resp_ies_len
=
782 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
784 event
.assoc_reject
.status_code
= status
;
786 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
791 os_memcpy(drv
->bssid
, mgmt
->sa
, ETH_ALEN
);
793 os_memset(&event
, 0, sizeof(event
));
794 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
795 event
.assoc_info
.resp_ies
= (u8
*) mgmt
->u
.assoc_resp
.variable
;
796 event
.assoc_info
.resp_ies_len
=
797 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
800 event
.assoc_info
.freq
= drv
->assoc_freq
;
802 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
806 static void mlme_event_connect(struct wpa_driver_nl80211_data
*drv
,
807 enum nl80211_commands cmd
, struct nlattr
*status
,
808 struct nlattr
*addr
, struct nlattr
*req_ie
,
809 struct nlattr
*resp_ie
)
811 union wpa_event_data event
;
813 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
815 * Avoid reporting two association events that would confuse
818 wpa_printf(MSG_DEBUG
, "nl80211: Ignore connect event (cmd=%d) "
819 "when using userspace SME", cmd
);
823 os_memset(&event
, 0, sizeof(event
));
824 if (cmd
== NL80211_CMD_CONNECT
&&
825 nla_get_u16(status
) != WLAN_STATUS_SUCCESS
) {
827 event
.assoc_reject
.bssid
= nla_data(addr
);
829 event
.assoc_reject
.resp_ies
= nla_data(resp_ie
);
830 event
.assoc_reject
.resp_ies_len
= nla_len(resp_ie
);
832 event
.assoc_reject
.status_code
= nla_get_u16(status
);
833 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
839 os_memcpy(drv
->bssid
, nla_data(addr
), ETH_ALEN
);
842 event
.assoc_info
.req_ies
= nla_data(req_ie
);
843 event
.assoc_info
.req_ies_len
= nla_len(req_ie
);
846 event
.assoc_info
.resp_ies
= nla_data(resp_ie
);
847 event
.assoc_info
.resp_ies_len
= nla_len(resp_ie
);
850 event
.assoc_info
.freq
= nl80211_get_assoc_freq(drv
);
852 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
856 static void mlme_event_disconnect(struct wpa_driver_nl80211_data
*drv
,
857 struct nlattr
*reason
, struct nlattr
*addr
)
859 union wpa_event_data data
;
861 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
863 * Avoid reporting two disassociation events that could
864 * confuse the core code.
866 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
867 "event when using userspace SME");
872 os_memset(&data
, 0, sizeof(data
));
874 data
.disassoc_info
.reason_code
= nla_get_u16(reason
);
875 wpa_supplicant_event(drv
->ctx
, EVENT_DISASSOC
, &data
);
879 static void mlme_timeout_event(struct wpa_driver_nl80211_data
*drv
,
880 enum nl80211_commands cmd
, struct nlattr
*addr
)
882 union wpa_event_data event
;
883 enum wpa_event_type ev
;
885 if (nla_len(addr
) != ETH_ALEN
)
888 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d; timeout with " MACSTR
,
889 cmd
, MAC2STR((u8
*) nla_data(addr
)));
891 if (cmd
== NL80211_CMD_AUTHENTICATE
)
892 ev
= EVENT_AUTH_TIMED_OUT
;
893 else if (cmd
== NL80211_CMD_ASSOCIATE
)
894 ev
= EVENT_ASSOC_TIMED_OUT
;
898 os_memset(&event
, 0, sizeof(event
));
899 os_memcpy(event
.timeout_event
.addr
, nla_data(addr
), ETH_ALEN
);
900 wpa_supplicant_event(drv
->ctx
, ev
, &event
);
904 static void mlme_event_mgmt(struct wpa_driver_nl80211_data
*drv
,
905 struct nlattr
*freq
, const u8
*frame
, size_t len
)
907 const struct ieee80211_mgmt
*mgmt
;
908 union wpa_event_data event
;
911 mgmt
= (const struct ieee80211_mgmt
*) frame
;
913 wpa_printf(MSG_DEBUG
, "nl80211: Too short action frame");
917 fc
= le_to_host16(mgmt
->frame_control
);
918 stype
= WLAN_FC_GET_STYPE(fc
);
920 os_memset(&event
, 0, sizeof(event
));
922 event
.rx_action
.freq
= nla_get_u32(freq
);
923 drv
->last_mgmt_freq
= event
.rx_action
.freq
;
925 if (stype
== WLAN_FC_STYPE_ACTION
) {
926 event
.rx_action
.da
= mgmt
->da
;
927 event
.rx_action
.sa
= mgmt
->sa
;
928 event
.rx_action
.bssid
= mgmt
->bssid
;
929 event
.rx_action
.category
= mgmt
->u
.action
.category
;
930 event
.rx_action
.data
= &mgmt
->u
.action
.category
+ 1;
931 event
.rx_action
.len
= frame
+ len
- event
.rx_action
.data
;
932 wpa_supplicant_event(drv
->ctx
, EVENT_RX_ACTION
, &event
);
934 event
.rx_mgmt
.frame
= frame
;
935 event
.rx_mgmt
.frame_len
= len
;
936 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
941 static void mlme_event_action_tx_status(struct wpa_driver_nl80211_data
*drv
,
942 struct nlattr
*cookie
, const u8
*frame
,
943 size_t len
, struct nlattr
*ack
)
945 union wpa_event_data event
;
946 const struct ieee80211_hdr
*hdr
;
953 cookie_val
= nla_get_u64(cookie
);
954 wpa_printf(MSG_DEBUG
, "nl80211: Action TX status: cookie=0%llx%s "
956 (long long unsigned int) cookie_val
,
957 cookie_val
== drv
->send_action_cookie
?
958 " (match)" : " (unknown)", ack
!= NULL
);
959 if (cookie_val
!= drv
->send_action_cookie
)
962 hdr
= (const struct ieee80211_hdr
*) frame
;
963 fc
= le_to_host16(hdr
->frame_control
);
965 os_memset(&event
, 0, sizeof(event
));
966 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
967 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
968 event
.tx_status
.dst
= hdr
->addr1
;
969 event
.tx_status
.data
= frame
;
970 event
.tx_status
.data_len
= len
;
971 event
.tx_status
.ack
= ack
!= NULL
;
972 wpa_supplicant_event(drv
->ctx
, EVENT_TX_STATUS
, &event
);
976 static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data
*drv
,
977 enum wpa_event_type type
,
978 const u8
*frame
, size_t len
)
980 const struct ieee80211_mgmt
*mgmt
;
981 union wpa_event_data event
;
982 const u8
*bssid
= NULL
;
985 mgmt
= (const struct ieee80211_mgmt
*) frame
;
989 if (drv
->associated
!= 0 &&
990 os_memcmp(bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
991 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0) {
993 * We have presumably received this deauth as a
994 * response to a clear_state_mismatch() outgoing
995 * deauth. Don't let it take us offline!
997 wpa_printf(MSG_DEBUG
, "nl80211: Deauth received "
998 "from Unknown BSSID " MACSTR
" -- ignoring",
1004 drv
->associated
= 0;
1005 os_memset(&event
, 0, sizeof(event
));
1007 /* Note: Same offset for Reason Code in both frame subtypes */
1008 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1009 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1011 if (type
== EVENT_DISASSOC
) {
1012 event
.disassoc_info
.addr
= bssid
;
1013 event
.disassoc_info
.reason_code
= reason_code
;
1014 if (frame
+ len
> mgmt
->u
.disassoc
.variable
) {
1015 event
.disassoc_info
.ie
= mgmt
->u
.disassoc
.variable
;
1016 event
.disassoc_info
.ie_len
= frame
+ len
-
1017 mgmt
->u
.disassoc
.variable
;
1020 event
.deauth_info
.addr
= bssid
;
1021 event
.deauth_info
.reason_code
= reason_code
;
1022 if (frame
+ len
> mgmt
->u
.deauth
.variable
) {
1023 event
.deauth_info
.ie
= mgmt
->u
.deauth
.variable
;
1024 event
.deauth_info
.ie_len
= frame
+ len
-
1025 mgmt
->u
.deauth
.variable
;
1029 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1033 static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data
*drv
,
1034 enum wpa_event_type type
,
1035 const u8
*frame
, size_t len
)
1037 const struct ieee80211_mgmt
*mgmt
;
1038 union wpa_event_data event
;
1039 u16 reason_code
= 0;
1044 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1046 os_memset(&event
, 0, sizeof(event
));
1047 /* Note: Same offset for Reason Code in both frame subtypes */
1048 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1049 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1051 if (type
== EVENT_UNPROT_DISASSOC
) {
1052 event
.unprot_disassoc
.sa
= mgmt
->sa
;
1053 event
.unprot_disassoc
.da
= mgmt
->da
;
1054 event
.unprot_disassoc
.reason_code
= reason_code
;
1056 event
.unprot_deauth
.sa
= mgmt
->sa
;
1057 event
.unprot_deauth
.da
= mgmt
->da
;
1058 event
.unprot_deauth
.reason_code
= reason_code
;
1061 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1065 static void mlme_event(struct wpa_driver_nl80211_data
*drv
,
1066 enum nl80211_commands cmd
, struct nlattr
*frame
,
1067 struct nlattr
*addr
, struct nlattr
*timed_out
,
1068 struct nlattr
*freq
, struct nlattr
*ack
,
1069 struct nlattr
*cookie
)
1071 if (timed_out
&& addr
) {
1072 mlme_timeout_event(drv
, cmd
, addr
);
1076 if (frame
== NULL
) {
1077 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d without frame "
1082 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d", cmd
);
1083 wpa_hexdump(MSG_MSGDUMP
, "nl80211: MLME event frame",
1084 nla_data(frame
), nla_len(frame
));
1087 case NL80211_CMD_AUTHENTICATE
:
1088 mlme_event_auth(drv
, nla_data(frame
), nla_len(frame
));
1090 case NL80211_CMD_ASSOCIATE
:
1091 mlme_event_assoc(drv
, nla_data(frame
), nla_len(frame
));
1093 case NL80211_CMD_DEAUTHENTICATE
:
1094 mlme_event_deauth_disassoc(drv
, EVENT_DEAUTH
,
1095 nla_data(frame
), nla_len(frame
));
1097 case NL80211_CMD_DISASSOCIATE
:
1098 mlme_event_deauth_disassoc(drv
, EVENT_DISASSOC
,
1099 nla_data(frame
), nla_len(frame
));
1101 case NL80211_CMD_FRAME
:
1102 mlme_event_mgmt(drv
, freq
, nla_data(frame
), nla_len(frame
));
1104 case NL80211_CMD_FRAME_TX_STATUS
:
1105 mlme_event_action_tx_status(drv
, cookie
, nla_data(frame
),
1106 nla_len(frame
), ack
);
1108 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1109 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DEAUTH
,
1110 nla_data(frame
), nla_len(frame
));
1112 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1113 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DISASSOC
,
1114 nla_data(frame
), nla_len(frame
));
1122 static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data
*drv
,
1123 struct nlattr
*tb
[])
1125 union wpa_event_data data
;
1127 wpa_printf(MSG_DEBUG
, "nl80211: MLME event Michael MIC failure");
1128 os_memset(&data
, 0, sizeof(data
));
1129 if (tb
[NL80211_ATTR_MAC
]) {
1130 wpa_hexdump(MSG_DEBUG
, "nl80211: Source MAC address",
1131 nla_data(tb
[NL80211_ATTR_MAC
]),
1132 nla_len(tb
[NL80211_ATTR_MAC
]));
1133 data
.michael_mic_failure
.src
= nla_data(tb
[NL80211_ATTR_MAC
]);
1135 if (tb
[NL80211_ATTR_KEY_SEQ
]) {
1136 wpa_hexdump(MSG_DEBUG
, "nl80211: TSC",
1137 nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
1138 nla_len(tb
[NL80211_ATTR_KEY_SEQ
]));
1140 if (tb
[NL80211_ATTR_KEY_TYPE
]) {
1141 enum nl80211_key_type key_type
=
1142 nla_get_u32(tb
[NL80211_ATTR_KEY_TYPE
]);
1143 wpa_printf(MSG_DEBUG
, "nl80211: Key Type %d", key_type
);
1144 if (key_type
== NL80211_KEYTYPE_PAIRWISE
)
1145 data
.michael_mic_failure
.unicast
= 1;
1147 data
.michael_mic_failure
.unicast
= 1;
1149 if (tb
[NL80211_ATTR_KEY_IDX
]) {
1150 u8 key_id
= nla_get_u8(tb
[NL80211_ATTR_KEY_IDX
]);
1151 wpa_printf(MSG_DEBUG
, "nl80211: Key Id %d", key_id
);
1154 wpa_supplicant_event(drv
->ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
1158 static void mlme_event_join_ibss(struct wpa_driver_nl80211_data
*drv
,
1159 struct nlattr
*tb
[])
1161 if (tb
[NL80211_ATTR_MAC
] == NULL
) {
1162 wpa_printf(MSG_DEBUG
, "nl80211: No address in IBSS joined "
1166 os_memcpy(drv
->bssid
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1167 drv
->associated
= 1;
1168 wpa_printf(MSG_DEBUG
, "nl80211: IBSS " MACSTR
" joined",
1169 MAC2STR(drv
->bssid
));
1171 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1175 static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data
*drv
,
1176 int cancel_event
, struct nlattr
*tb
[])
1178 unsigned int freq
, chan_type
, duration
;
1179 union wpa_event_data data
;
1182 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1183 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1187 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1188 chan_type
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1192 if (tb
[NL80211_ATTR_DURATION
])
1193 duration
= nla_get_u32(tb
[NL80211_ATTR_DURATION
]);
1197 if (tb
[NL80211_ATTR_COOKIE
])
1198 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
1202 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel event (cancel=%d "
1203 "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
1204 cancel_event
, freq
, chan_type
, duration
,
1205 (long long unsigned int) cookie
,
1206 cookie
== drv
->remain_on_chan_cookie
? "match" : "unknown");
1208 if (cookie
!= drv
->remain_on_chan_cookie
)
1209 return; /* not for us */
1212 drv
->pending_remain_on_chan
= 0;
1214 os_memset(&data
, 0, sizeof(data
));
1215 data
.remain_on_channel
.freq
= freq
;
1216 data
.remain_on_channel
.duration
= duration
;
1217 wpa_supplicant_event(drv
->ctx
, cancel_event
?
1218 EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1219 EVENT_REMAIN_ON_CHANNEL
, &data
);
1223 static void send_scan_event(struct wpa_driver_nl80211_data
*drv
, int aborted
,
1224 struct nlattr
*tb
[])
1226 union wpa_event_data event
;
1229 struct scan_info
*info
;
1230 #define MAX_REPORT_FREQS 50
1231 int freqs
[MAX_REPORT_FREQS
];
1234 os_memset(&event
, 0, sizeof(event
));
1235 info
= &event
.scan_info
;
1236 info
->aborted
= aborted
;
1238 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
1239 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem
) {
1240 struct wpa_driver_scan_ssid
*s
=
1241 &info
->ssids
[info
->num_ssids
];
1242 s
->ssid
= nla_data(nl
);
1243 s
->ssid_len
= nla_len(nl
);
1245 if (info
->num_ssids
== WPAS_MAX_SCAN_SSIDS
)
1249 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
1250 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem
)
1252 freqs
[num_freqs
] = nla_get_u32(nl
);
1254 if (num_freqs
== MAX_REPORT_FREQS
- 1)
1257 info
->freqs
= freqs
;
1258 info
->num_freqs
= num_freqs
;
1260 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
, &event
);
1264 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1266 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1267 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1268 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1269 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1270 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1272 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1273 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1274 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1275 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1276 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1277 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1279 struct wpa_signal_info
*sig_change
= arg
;
1281 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1282 genlmsg_attrlen(gnlh
, 0), NULL
);
1283 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1284 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1285 tb
[NL80211_ATTR_STA_INFO
], policy
))
1287 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1290 sig_change
->current_signal
=
1291 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1293 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1294 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1295 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1297 sig_change
->current_txrate
= 0;
1299 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1300 sig_change
->current_txrate
=
1302 NL80211_RATE_INFO_BITRATE
]) * 100;
1311 static int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1312 struct wpa_signal_info
*sig
)
1316 sig
->current_signal
= -9999;
1317 sig
->current_txrate
= 0;
1319 msg
= nlmsg_alloc();
1323 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
1325 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1326 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
1328 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1334 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1336 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1337 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1338 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1339 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1340 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1341 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1343 struct wpa_signal_info
*sig_change
= arg
;
1345 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1346 genlmsg_attrlen(gnlh
, 0), NULL
);
1348 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1349 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1353 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1354 tb
[NL80211_ATTR_SURVEY_INFO
],
1356 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1361 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1364 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1365 sig_change
->frequency
)
1368 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1371 sig_change
->current_noise
=
1372 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1378 static int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1379 struct wpa_signal_info
*sig_change
)
1383 sig_change
->current_noise
= 9999;
1384 sig_change
->frequency
= drv
->assoc_freq
;
1386 msg
= nlmsg_alloc();
1390 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1392 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1394 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1400 static void nl80211_cqm_event(struct wpa_driver_nl80211_data
*drv
,
1401 struct nlattr
*tb
[])
1403 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
1404 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
1405 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U8
},
1406 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
1407 [NL80211_ATTR_CQM_PKT_LOSS_EVENT
] = { .type
= NLA_U32
},
1409 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
1410 enum nl80211_cqm_rssi_threshold_event event
;
1411 union wpa_event_data ed
;
1412 struct wpa_signal_info sig
;
1415 if (tb
[NL80211_ATTR_CQM
] == NULL
||
1416 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, tb
[NL80211_ATTR_CQM
],
1418 wpa_printf(MSG_DEBUG
, "nl80211: Ignore invalid CQM event");
1422 os_memset(&ed
, 0, sizeof(ed
));
1424 if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
1425 if (!tb
[NL80211_ATTR_MAC
])
1427 os_memcpy(ed
.low_ack
.addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
1429 wpa_supplicant_event(drv
->ctx
, EVENT_STATION_LOW_ACK
, &ed
);
1433 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] == NULL
)
1435 event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
1437 if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
) {
1438 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1439 "event: RSSI high");
1440 ed
.signal_change
.above_threshold
= 1;
1441 } else if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
) {
1442 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
1444 ed
.signal_change
.above_threshold
= 0;
1448 res
= nl80211_get_link_signal(drv
, &sig
);
1450 ed
.signal_change
.current_signal
= sig
.current_signal
;
1451 ed
.signal_change
.current_txrate
= sig
.current_txrate
;
1452 wpa_printf(MSG_DEBUG
, "nl80211: Signal: %d dBm txrate: %d",
1453 sig
.current_signal
, sig
.current_txrate
);
1456 res
= nl80211_get_link_noise(drv
, &sig
);
1458 ed
.signal_change
.current_noise
= sig
.current_noise
;
1459 wpa_printf(MSG_DEBUG
, "nl80211: Noise: %d dBm",
1463 wpa_supplicant_event(drv
->ctx
, EVENT_SIGNAL_CHANGE
, &ed
);
1467 static void nl80211_new_station_event(struct wpa_driver_nl80211_data
*drv
,
1471 union wpa_event_data data
;
1473 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1475 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1476 wpa_printf(MSG_DEBUG
, "nl80211: New station " MACSTR
, MAC2STR(addr
));
1478 if (is_ap_interface(drv
->nlmode
) && drv
->no_monitor_iface_capab
) {
1481 if (tb
[NL80211_ATTR_IE
]) {
1482 ies
= nla_data(tb
[NL80211_ATTR_IE
]);
1483 ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
1485 wpa_hexdump(MSG_DEBUG
, "nl80211: Assoc Req IEs", ies
, ies_len
);
1486 drv_event_assoc(drv
->ctx
, addr
, ies
, ies_len
, 0);
1490 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1493 os_memset(&data
, 0, sizeof(data
));
1494 os_memcpy(data
.ibss_rsn_start
.peer
, addr
, ETH_ALEN
);
1495 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_RSN_START
, &data
);
1499 static void nl80211_del_station_event(struct wpa_driver_nl80211_data
*drv
,
1503 union wpa_event_data data
;
1505 if (tb
[NL80211_ATTR_MAC
] == NULL
)
1507 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
1508 wpa_printf(MSG_DEBUG
, "nl80211: Delete station " MACSTR
,
1511 if (is_ap_interface(drv
->nlmode
) && drv
->no_monitor_iface_capab
) {
1512 drv_event_disassoc(drv
->ctx
, addr
);
1516 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
1519 os_memset(&data
, 0, sizeof(data
));
1520 os_memcpy(data
.ibss_peer_lost
.peer
, addr
, ETH_ALEN
);
1521 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_PEER_LOST
, &data
);
1525 static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data
*drv
,
1528 struct nlattr
*rekey_info
[NUM_NL80211_REKEY_DATA
];
1529 static struct nla_policy rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
1530 [NL80211_REKEY_DATA_KEK
] = {
1531 .minlen
= NL80211_KEK_LEN
,
1532 .maxlen
= NL80211_KEK_LEN
,
1534 [NL80211_REKEY_DATA_KCK
] = {
1535 .minlen
= NL80211_KCK_LEN
,
1536 .maxlen
= NL80211_KCK_LEN
,
1538 [NL80211_REKEY_DATA_REPLAY_CTR
] = {
1539 .minlen
= NL80211_REPLAY_CTR_LEN
,
1540 .maxlen
= NL80211_REPLAY_CTR_LEN
,
1543 union wpa_event_data data
;
1545 if (!tb
[NL80211_ATTR_MAC
])
1547 if (!tb
[NL80211_ATTR_REKEY_DATA
])
1549 if (nla_parse_nested(rekey_info
, MAX_NL80211_REKEY_DATA
,
1550 tb
[NL80211_ATTR_REKEY_DATA
], rekey_policy
))
1552 if (!rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
])
1555 os_memset(&data
, 0, sizeof(data
));
1556 data
.driver_gtk_rekey
.bssid
= nla_data(tb
[NL80211_ATTR_MAC
]);
1557 wpa_printf(MSG_DEBUG
, "nl80211: Rekey offload event for BSSID " MACSTR
,
1558 MAC2STR(data
.driver_gtk_rekey
.bssid
));
1559 data
.driver_gtk_rekey
.replay_ctr
=
1560 nla_data(rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
]);
1561 wpa_hexdump(MSG_DEBUG
, "nl80211: Rekey offload - Replay Counter",
1562 data
.driver_gtk_rekey
.replay_ctr
, NL80211_REPLAY_CTR_LEN
);
1563 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_GTK_REKEY
, &data
);
1567 static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data
*drv
,
1570 struct nlattr
*cand
[NUM_NL80211_PMKSA_CANDIDATE
];
1571 static struct nla_policy cand_policy
[NUM_NL80211_PMKSA_CANDIDATE
] = {
1572 [NL80211_PMKSA_CANDIDATE_INDEX
] = { .type
= NLA_U32
},
1573 [NL80211_PMKSA_CANDIDATE_BSSID
] = {
1577 [NL80211_PMKSA_CANDIDATE_PREAUTH
] = { .type
= NLA_FLAG
},
1579 union wpa_event_data data
;
1581 if (!tb
[NL80211_ATTR_PMKSA_CANDIDATE
])
1583 if (nla_parse_nested(cand
, MAX_NL80211_PMKSA_CANDIDATE
,
1584 tb
[NL80211_ATTR_PMKSA_CANDIDATE
], cand_policy
))
1586 if (!cand
[NL80211_PMKSA_CANDIDATE_INDEX
] ||
1587 !cand
[NL80211_PMKSA_CANDIDATE_BSSID
])
1590 os_memset(&data
, 0, sizeof(data
));
1591 os_memcpy(data
.pmkid_candidate
.bssid
,
1592 nla_data(cand
[NL80211_PMKSA_CANDIDATE_BSSID
]), ETH_ALEN
);
1593 data
.pmkid_candidate
.index
=
1594 nla_get_u32(cand
[NL80211_PMKSA_CANDIDATE_INDEX
]);
1595 data
.pmkid_candidate
.preauth
=
1596 cand
[NL80211_PMKSA_CANDIDATE_PREAUTH
] != NULL
;
1597 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
1601 static int process_event(struct nl_msg
*msg
, void *arg
)
1603 struct wpa_driver_nl80211_data
*drv
= arg
;
1604 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1605 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1607 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1608 genlmsg_attrlen(gnlh
, 0), NULL
);
1610 if (tb
[NL80211_ATTR_IFINDEX
]) {
1611 int ifindex
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1612 if (ifindex
!= drv
->ifindex
&& !have_ifidx(drv
, ifindex
)) {
1613 wpa_printf(MSG_DEBUG
, "nl80211: Ignored event (cmd=%d)"
1614 " for foreign interface (ifindex %d)",
1615 gnlh
->cmd
, ifindex
);
1620 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
&&
1621 (gnlh
->cmd
== NL80211_CMD_NEW_SCAN_RESULTS
||
1622 gnlh
->cmd
== NL80211_CMD_SCAN_ABORTED
)) {
1623 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
1624 drv
->ap_scan_as_station
);
1625 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
1628 switch (gnlh
->cmd
) {
1629 case NL80211_CMD_TRIGGER_SCAN
:
1630 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger");
1632 case NL80211_CMD_START_SCHED_SCAN
:
1633 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan started");
1635 case NL80211_CMD_SCHED_SCAN_STOPPED
:
1636 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stopped");
1637 wpa_supplicant_event(drv
->ctx
, EVENT_SCHED_SCAN_STOPPED
, NULL
);
1639 case NL80211_CMD_NEW_SCAN_RESULTS
:
1640 wpa_printf(MSG_DEBUG
, "nl80211: New scan results available");
1641 drv
->scan_complete_events
= 1;
1642 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
1644 send_scan_event(drv
, 0, tb
);
1646 case NL80211_CMD_SCHED_SCAN_RESULTS
:
1647 wpa_printf(MSG_DEBUG
,
1648 "nl80211: New sched scan results available");
1649 send_scan_event(drv
, 0, tb
);
1651 case NL80211_CMD_SCAN_ABORTED
:
1652 wpa_printf(MSG_DEBUG
, "nl80211: Scan aborted");
1654 * Need to indicate that scan results are available in order
1655 * not to make wpa_supplicant stop its scanning.
1657 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
1659 send_scan_event(drv
, 1, tb
);
1661 case NL80211_CMD_AUTHENTICATE
:
1662 case NL80211_CMD_ASSOCIATE
:
1663 case NL80211_CMD_DEAUTHENTICATE
:
1664 case NL80211_CMD_DISASSOCIATE
:
1665 case NL80211_CMD_FRAME
:
1666 case NL80211_CMD_FRAME_TX_STATUS
:
1667 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1668 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1669 mlme_event(drv
, gnlh
->cmd
, tb
[NL80211_ATTR_FRAME
],
1670 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
1671 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
1672 tb
[NL80211_ATTR_COOKIE
]);
1674 case NL80211_CMD_CONNECT
:
1675 case NL80211_CMD_ROAM
:
1676 mlme_event_connect(drv
, gnlh
->cmd
,
1677 tb
[NL80211_ATTR_STATUS_CODE
],
1678 tb
[NL80211_ATTR_MAC
],
1679 tb
[NL80211_ATTR_REQ_IE
],
1680 tb
[NL80211_ATTR_RESP_IE
]);
1682 case NL80211_CMD_DISCONNECT
:
1683 mlme_event_disconnect(drv
, tb
[NL80211_ATTR_REASON_CODE
],
1684 tb
[NL80211_ATTR_MAC
]);
1686 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
1687 mlme_event_michael_mic_failure(drv
, tb
);
1689 case NL80211_CMD_JOIN_IBSS
:
1690 mlme_event_join_ibss(drv
, tb
);
1692 case NL80211_CMD_REMAIN_ON_CHANNEL
:
1693 mlme_event_remain_on_channel(drv
, 0, tb
);
1695 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
1696 mlme_event_remain_on_channel(drv
, 1, tb
);
1698 case NL80211_CMD_NOTIFY_CQM
:
1699 nl80211_cqm_event(drv
, tb
);
1701 case NL80211_CMD_REG_CHANGE
:
1702 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory domain change");
1703 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
1706 case NL80211_CMD_REG_BEACON_HINT
:
1707 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory beacon hint");
1708 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
1711 case NL80211_CMD_NEW_STATION
:
1712 nl80211_new_station_event(drv
, tb
);
1714 case NL80211_CMD_DEL_STATION
:
1715 nl80211_del_station_event(drv
, tb
);
1717 case NL80211_CMD_SET_REKEY_OFFLOAD
:
1718 nl80211_rekey_offload_event(drv
, tb
);
1720 case NL80211_CMD_PMKSA_CANDIDATE
:
1721 nl80211_pmksa_candidate_event(drv
, tb
);
1724 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
1725 "(cmd=%d)", gnlh
->cmd
);
1733 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
1737 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
1739 wpa_printf(MSG_DEBUG
, "nl80211: Event message available");
1741 cb
= nl_cb_clone(drv
->global
->nl_cb
);
1744 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
1745 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_event
, drv
);
1746 nl_recvmsgs(handle
, cb
);
1752 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1753 * @priv: driver_nl80211 private data
1754 * @alpha2_arg: country to which to switch to
1755 * Returns: 0 on success, -1 on failure
1757 * This asks nl80211 to set the regulatory domain for given
1758 * country ISO / IEC alpha2.
1760 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
1762 struct i802_bss
*bss
= priv
;
1763 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1767 msg
= nlmsg_alloc();
1771 alpha2
[0] = alpha2_arg
[0];
1772 alpha2
[1] = alpha2_arg
[1];
1775 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
);
1777 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
);
1778 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
1786 struct wiphy_info_data
{
1787 struct wpa_driver_capa
*capa
;
1789 unsigned int error
:1;
1793 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
1795 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1796 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1797 struct wiphy_info_data
*info
= arg
;
1798 int p2p_go_supported
= 0, p2p_client_supported
= 0;
1799 int p2p_concurrent
= 0;
1800 int auth_supported
= 0, connect_supported
= 0;
1801 struct wpa_driver_capa
*capa
= info
->capa
;
1802 static struct nla_policy
1803 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
1804 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
1805 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
1806 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
1807 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
1809 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
1810 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
1811 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
1814 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1815 genlmsg_attrlen(gnlh
, 0), NULL
);
1817 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
1818 capa
->max_scan_ssids
=
1819 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
1821 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
1822 capa
->max_sched_scan_ssids
=
1823 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
1825 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
1826 capa
->max_match_sets
=
1827 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
1829 if (tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]) {
1830 struct nlattr
*nl_mode
;
1832 nla_for_each_nested(nl_mode
,
1833 tb
[NL80211_ATTR_SUPPORTED_IFTYPES
], i
) {
1834 switch (nla_type(nl_mode
)) {
1835 case NL80211_IFTYPE_AP
:
1836 capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
1838 case NL80211_IFTYPE_P2P_GO
:
1839 p2p_go_supported
= 1;
1841 case NL80211_IFTYPE_P2P_CLIENT
:
1842 p2p_client_supported
= 1;
1848 if (tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]) {
1849 struct nlattr
*nl_combi
;
1852 nla_for_each_nested(nl_combi
,
1853 tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
],
1855 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
1856 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
1857 struct nlattr
*nl_limit
, *nl_mode
;
1858 int err
, rem_limit
, rem_mode
;
1859 int combination_has_p2p
= 0, combination_has_mgd
= 0;
1861 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
1863 iface_combination_policy
);
1864 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
1865 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
1866 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
1867 goto broken_combination
;
1869 nla_for_each_nested(nl_limit
,
1870 tb_comb
[NL80211_IFACE_COMB_LIMITS
],
1872 err
= nla_parse_nested(tb_limit
,
1873 MAX_NL80211_IFACE_LIMIT
,
1875 iface_limit_policy
);
1877 !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
1878 goto broken_combination
;
1880 nla_for_each_nested(
1882 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
1884 int ift
= nla_type(nl_mode
);
1885 if (ift
== NL80211_IFTYPE_P2P_GO
||
1886 ift
== NL80211_IFTYPE_P2P_CLIENT
)
1887 combination_has_p2p
= 1;
1888 if (ift
== NL80211_IFTYPE_STATION
)
1889 combination_has_mgd
= 1;
1891 if (combination_has_p2p
&& combination_has_mgd
)
1895 if (combination_has_p2p
&& combination_has_mgd
) {
1905 if (tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]) {
1906 struct nlattr
*nl_cmd
;
1909 nla_for_each_nested(nl_cmd
,
1910 tb
[NL80211_ATTR_SUPPORTED_COMMANDS
], i
) {
1911 switch (nla_get_u32(nl_cmd
)) {
1912 case NL80211_CMD_AUTHENTICATE
:
1915 case NL80211_CMD_CONNECT
:
1916 connect_supported
= 1;
1918 case NL80211_CMD_START_SCHED_SCAN
:
1919 capa
->sched_scan_supported
= 1;
1925 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
1926 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
1928 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
1931 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
1932 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
1933 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
1936 /* default to 5000 since early versions of mac80211 don't set it */
1937 capa
->max_remain_on_chan
= 5000;
1939 if (tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
])
1940 capa
->max_remain_on_chan
=
1941 nla_get_u32(tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
1944 capa
->flags
|= WPA_DRIVER_FLAGS_SME
;
1945 else if (!connect_supported
) {
1946 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
1947 "authentication/association or connect commands");
1951 if (p2p_go_supported
&& p2p_client_supported
)
1952 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
1953 if (p2p_concurrent
) {
1954 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
1955 "interface (driver advertised support)");
1956 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
1957 capa
->flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
1960 if (tb
[NL80211_ATTR_TDLS_SUPPORT
]) {
1961 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
1962 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
1964 if (tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]) {
1965 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
1967 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
1975 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
1976 struct wiphy_info_data
*info
)
1980 os_memset(info
, 0, sizeof(*info
));
1981 info
->capa
= &drv
->capa
;
1983 msg
= nlmsg_alloc();
1987 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
1989 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->first_bss
.ifindex
);
1991 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
) == 0)
2000 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
2002 struct wiphy_info_data info
;
2003 if (wpa_driver_nl80211_get_info(drv
, &info
))
2009 drv
->has_capability
= 1;
2010 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
2011 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2012 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2013 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2014 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
2015 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
2016 WPA_DRIVER_CAPA_ENC_WEP104
|
2017 WPA_DRIVER_CAPA_ENC_TKIP
|
2018 WPA_DRIVER_CAPA_ENC_CCMP
;
2019 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
2020 WPA_DRIVER_AUTH_SHARED
|
2021 WPA_DRIVER_AUTH_LEAP
;
2023 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
2024 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
2025 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2026 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
2032 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
2034 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
2035 if (global
->nl_cb
== NULL
) {
2036 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
2041 if (nl_create_handles(&global
->nl
, global
->nl_cb
, "nl"))
2044 global
->nl80211
= genl_ctrl_search_by_name(global
->nl
.cache
,
2046 if (global
->nl80211
== NULL
) {
2047 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
2056 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
2058 struct nl80211_global
*global
= drv
->global
;
2061 /* Initialize generic netlink and nl80211 */
2063 if (nl_create_handles(&drv
->nl_event
, global
->nl_cb
, "event"))
2066 ret
= nl_get_multicast_id(drv
, "nl80211", "scan");
2068 ret
= nl_socket_add_membership(drv
->nl_event
.handle
, ret
);
2070 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2071 "membership for scan events: %d (%s)",
2072 ret
, strerror(-ret
));
2076 ret
= nl_get_multicast_id(drv
, "nl80211", "mlme");
2078 ret
= nl_socket_add_membership(drv
->nl_event
.handle
, ret
);
2080 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
2081 "membership for mlme events: %d (%s)",
2082 ret
, strerror(-ret
));
2086 ret
= nl_get_multicast_id(drv
, "nl80211", "regulatory");
2088 ret
= nl_socket_add_membership(drv
->nl_event
.handle
, ret
);
2090 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
2091 "membership for regulatory events: %d (%s)",
2092 ret
, strerror(-ret
));
2093 /* Continue without regulatory events */
2096 eloop_register_read_sock(nl_socket_get_fd(drv
->nl_event
.handle
),
2097 wpa_driver_nl80211_event_receive
, drv
,
2098 drv
->nl_event
.handle
);
2103 nl_destroy_handles(&drv
->nl_event
);
2109 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
2111 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
2113 * This may be for any interface; use ifdown event to disable
2119 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
2121 struct wpa_driver_nl80211_data
*drv
= ctx
;
2122 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
2123 if (linux_set_iface_flags(drv
->global
->ioctl_sock
,
2124 drv
->first_bss
.ifname
, 1)) {
2125 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
2126 "after rfkill unblock");
2129 /* rtnetlink ifup handler will report interface as enabled */
2133 static void nl80211_get_phy_name(struct wpa_driver_nl80211_data
*drv
)
2135 /* Find phy (radio) to which this interface belongs */
2139 drv
->phyname
[0] = '\0';
2140 snprintf(buf
, sizeof(buf
) - 1, "/sys/class/net/%s/phy80211/name",
2141 drv
->first_bss
.ifname
);
2142 f
= open(buf
, O_RDONLY
);
2144 wpa_printf(MSG_DEBUG
, "Could not open file %s: %s",
2145 buf
, strerror(errno
));
2149 rv
= read(f
, drv
->phyname
, sizeof(drv
->phyname
) - 1);
2152 wpa_printf(MSG_DEBUG
, "Could not read file %s: %s",
2153 buf
, strerror(errno
));
2157 drv
->phyname
[rv
] = '\0';
2158 pos
= os_strchr(drv
->phyname
, '\n');
2161 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2162 drv
->first_bss
.ifname
, drv
->phyname
);
2167 static void nl80211_l2_read(void *ctx
, const u8
*src_addr
, const u8
*buf
,
2170 wpa_printf(MSG_DEBUG
, "nl80211: l2_packet read %u",
2171 (unsigned int) len
);
2173 #endif /* CONFIG_AP */
2177 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2178 * @ctx: context to be used when calling wpa_supplicant functions,
2179 * e.g., wpa_supplicant_event()
2180 * @ifname: interface name, e.g., wlan0
2181 * @global_priv: private driver global data from global_init()
2182 * Returns: Pointer to private data, %NULL on failure
2184 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
2187 struct wpa_driver_nl80211_data
*drv
;
2188 struct rfkill_config
*rcfg
;
2189 struct i802_bss
*bss
;
2191 drv
= os_zalloc(sizeof(*drv
));
2194 drv
->global
= global_priv
;
2196 bss
= &drv
->first_bss
;
2198 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
2199 drv
->monitor_ifidx
= -1;
2200 drv
->monitor_sock
= -1;
2201 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2203 if (wpa_driver_nl80211_init_nl(drv
)) {
2208 nl80211_get_phy_name(drv
);
2210 rcfg
= os_zalloc(sizeof(*rcfg
));
2214 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
2215 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
2216 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
2217 drv
->rfkill
= rfkill_init(rcfg
);
2218 if (drv
->rfkill
== NULL
) {
2219 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
2223 if (wpa_driver_nl80211_finish_drv_init(drv
))
2227 drv
->l2
= l2_packet_init(ifname
, NULL
, ETH_P_EAPOL
,
2228 nl80211_l2_read
, drv
, 0);
2229 #endif /* CONFIG_AP */
2232 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
2233 drv
->in_interface_list
= 1;
2239 wpa_driver_nl80211_deinit(bss
);
2244 static int nl80211_register_frame(struct wpa_driver_nl80211_data
*drv
,
2245 struct nl_handle
*nl_handle
,
2246 u16 type
, const u8
*match
, size_t match_len
)
2251 msg
= nlmsg_alloc();
2255 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
2257 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2258 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
2259 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
2261 ret
= send_and_recv(drv
, nl_handle
, msg
, NULL
, NULL
);
2264 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
2265 "failed (type=%u): ret=%d (%s)",
2266 type
, ret
, strerror(-ret
));
2267 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
2269 goto nla_put_failure
;
2278 static int nl80211_register_action_frame(struct wpa_driver_nl80211_data
*drv
,
2279 const u8
*match
, size_t match_len
)
2281 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
2282 return nl80211_register_frame(drv
, drv
->nl_event
.handle
,
2283 type
, match
, match_len
);
2287 static int nl80211_register_action_frames(struct wpa_driver_nl80211_data
*drv
)
2289 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
2290 /* GAS Initial Request */
2291 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0a", 2) < 0)
2293 /* GAS Initial Response */
2294 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0b", 2) < 0)
2296 /* GAS Comeback Request */
2297 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0c", 2) < 0)
2299 /* GAS Comeback Response */
2300 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0d", 2) < 0)
2302 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
2304 /* P2P Public Action */
2305 if (nl80211_register_action_frame(drv
,
2306 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
2310 if (nl80211_register_action_frame(drv
,
2311 (u8
*) "\x7f\x50\x6f\x9a\x09",
2314 #endif /* CONFIG_P2P */
2315 #ifdef CONFIG_IEEE80211W
2316 /* SA Query Response */
2317 if (nl80211_register_action_frame(drv
, (u8
*) "\x08\x01", 2) < 0)
2319 #endif /* CONFIG_IEEE80211W */
2321 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
2322 /* TDLS Discovery Response */
2323 if (nl80211_register_action_frame(drv
, (u8
*) "\x04\x0e", 2) <
2327 #endif /* CONFIG_TDLS */
2329 /* FT Action frames */
2330 if (nl80211_register_action_frame(drv
, (u8
*) "\x06", 1) < 0)
2333 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
2334 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
2336 /* WNM - BSS Transition Management Request */
2337 if (nl80211_register_action_frame(drv
, (u8
*) "\x0a\x07", 2) < 0)
2344 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
2346 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
2351 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
2353 struct i802_bss
*bss
= &drv
->first_bss
;
2354 int send_rfkill_event
= 0;
2356 drv
->ifindex
= if_nametoindex(bss
->ifname
);
2357 drv
->first_bss
.ifindex
= drv
->ifindex
;
2361 * Make sure the interface starts up in station mode unless this is a
2362 * dynamically added interface (e.g., P2P) that was already configured
2363 * with proper iftype.
2365 if ((drv
->global
== NULL
||
2366 drv
->ifindex
!= drv
->global
->if_add_ifindex
) &&
2367 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
) < 0) {
2368 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to "
2369 "use managed mode");
2373 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
2374 if (rfkill_is_blocked(drv
->rfkill
)) {
2375 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
2376 "interface '%s' due to rfkill",
2378 drv
->if_disabled
= 1;
2379 send_rfkill_event
= 1;
2381 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
2382 "interface '%s' UP", bss
->ifname
);
2387 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
2388 1, IF_OPER_DORMANT
);
2389 #endif /* HOSTAPD */
2391 if (wpa_driver_nl80211_capa(drv
))
2394 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2398 if (nl80211_register_action_frames(drv
) < 0) {
2399 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
2400 "frame processing - ignore for now");
2402 * Older kernel versions did not support this, so ignore the
2403 * error for now. Some functionality may not be available
2408 if (send_rfkill_event
) {
2409 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
2417 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
2421 msg
= nlmsg_alloc();
2425 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
2426 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2428 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2435 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
2436 * @priv: Pointer to private nl80211 data from wpa_driver_nl80211_init()
2438 * Shut down driver interface and processing of driver events. Free
2439 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2441 static void wpa_driver_nl80211_deinit(void *priv
)
2443 struct i802_bss
*bss
= priv
;
2444 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2448 l2_packet_deinit(drv
->l2
);
2449 #endif /* CONFIG_AP */
2451 if (drv
->nl_preq
.handle
)
2452 wpa_driver_nl80211_probe_req_report(bss
, 0);
2453 if (bss
->added_if_into_bridge
) {
2454 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
2456 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2457 "interface %s from bridge %s: %s",
2458 bss
->ifname
, bss
->brname
, strerror(errno
));
2460 if (bss
->added_bridge
) {
2461 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
2462 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2464 bss
->brname
, strerror(errno
));
2467 nl80211_remove_monitor_interface(drv
);
2469 if (is_ap_interface(drv
->nlmode
))
2470 wpa_driver_nl80211_del_beacon(drv
);
2473 if (drv
->last_freq_ht
) {
2474 /* Clear HT flags from the driver */
2475 struct hostapd_freq_params freq
;
2476 os_memset(&freq
, 0, sizeof(freq
));
2477 freq
.freq
= drv
->last_freq
;
2478 i802_set_freq(priv
, &freq
);
2481 if (drv
->eapol_sock
>= 0) {
2482 eloop_unregister_read_sock(drv
->eapol_sock
);
2483 close(drv
->eapol_sock
);
2486 if (drv
->if_indices
!= drv
->default_if_indices
)
2487 os_free(drv
->if_indices
);
2488 #endif /* HOSTAPD */
2490 if (drv
->disable_11b_rates
)
2491 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2493 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
2495 rfkill_deinit(drv
->rfkill
);
2497 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2499 (void) linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0);
2500 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
2502 eloop_unregister_read_sock(nl_socket_get_fd(drv
->nl_event
.handle
));
2503 nl_destroy_handles(&drv
->nl_event
);
2505 os_free(drv
->filter_ssids
);
2507 if (drv
->in_interface_list
)
2508 dl_list_del(&drv
->list
);
2515 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
2516 * @eloop_ctx: Driver private data
2517 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
2519 * This function can be used as registered timeout when starting a scan to
2520 * generate a scan completed event if the driver does not report this.
2522 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
2524 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
2525 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
2526 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
2527 drv
->ap_scan_as_station
);
2528 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2530 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
2531 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
2536 * wpa_driver_nl80211_scan - Request the driver to initiate scan
2537 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
2538 * @params: Scan parameters
2539 * Returns: 0 on success, -1 on failure
2541 static int wpa_driver_nl80211_scan(void *priv
,
2542 struct wpa_driver_scan_params
*params
)
2544 struct i802_bss
*bss
= priv
;
2545 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2546 int ret
= 0, timeout
;
2547 struct nl_msg
*msg
, *ssids
, *freqs
, *rates
;
2550 msg
= nlmsg_alloc();
2551 ssids
= nlmsg_alloc();
2552 freqs
= nlmsg_alloc();
2553 rates
= nlmsg_alloc();
2554 if (!msg
|| !ssids
|| !freqs
|| !rates
) {
2562 os_free(drv
->filter_ssids
);
2563 drv
->filter_ssids
= params
->filter_ssids
;
2564 params
->filter_ssids
= NULL
;
2565 drv
->num_filter_ssids
= params
->num_filter_ssids
;
2567 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TRIGGER_SCAN
);
2569 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2571 for (i
= 0; i
< params
->num_ssids
; i
++) {
2572 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
2573 params
->ssids
[i
].ssid
,
2574 params
->ssids
[i
].ssid_len
);
2575 NLA_PUT(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
2576 params
->ssids
[i
].ssid
);
2578 if (params
->num_ssids
)
2579 nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
2581 if (params
->extra_ies
) {
2582 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
2583 params
->extra_ies
, params
->extra_ies_len
);
2584 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
2588 if (params
->freqs
) {
2589 for (i
= 0; params
->freqs
[i
]; i
++) {
2590 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
2591 "MHz", params
->freqs
[i
]);
2592 NLA_PUT_U32(freqs
, i
+ 1, params
->freqs
[i
]);
2594 nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
, freqs
);
2597 if (params
->p2p_probe
) {
2599 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
2600 * by masking out everything else apart from the OFDM rates 6,
2601 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
2602 * rates are left enabled.
2604 NLA_PUT(rates
, NL80211_BAND_2GHZ
, 8,
2605 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
2606 nla_put_nested(msg
, NL80211_ATTR_SCAN_SUPP_RATES
, rates
);
2609 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2612 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
2613 "(%s)", ret
, strerror(-ret
));
2615 if (is_ap_interface(drv
->nlmode
)) {
2617 * mac80211 does not allow scan requests in AP mode, so
2618 * try to do this in station mode.
2620 if (wpa_driver_nl80211_set_mode(
2621 bss
, NL80211_IFTYPE_STATION
))
2622 goto nla_put_failure
;
2624 if (wpa_driver_nl80211_scan(drv
, params
)) {
2625 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
2626 goto nla_put_failure
;
2629 /* Restore AP mode when processing scan results */
2630 drv
->ap_scan_as_station
= drv
->nlmode
;
2633 goto nla_put_failure
;
2635 goto nla_put_failure
;
2636 #endif /* HOSTAPD */
2639 /* Not all drivers generate "scan completed" wireless event, so try to
2640 * read results after a timeout. */
2642 if (drv
->scan_complete_events
) {
2644 * The driver seems to deliver events to notify when scan is
2645 * complete, so use longer timeout to avoid race conditions
2646 * with scanning and following association request.
2650 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
2651 "seconds", ret
, timeout
);
2652 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2653 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
2666 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
2667 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
2668 * @params: Scan parameters
2669 * @interval: Interval between scan cycles in milliseconds
2670 * Returns: 0 on success, -1 on failure or if not supported
2672 static int wpa_driver_nl80211_sched_scan(void *priv
,
2673 struct wpa_driver_scan_params
*params
,
2676 struct i802_bss
*bss
= priv
;
2677 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2679 struct nl_msg
*msg
, *ssids
, *freqs
, *match_set_ssid
, *match_sets
;
2682 msg
= nlmsg_alloc();
2683 ssids
= nlmsg_alloc();
2684 freqs
= nlmsg_alloc();
2685 if (!msg
|| !ssids
|| !freqs
) {
2692 os_free(drv
->filter_ssids
);
2693 drv
->filter_ssids
= params
->filter_ssids
;
2694 params
->filter_ssids
= NULL
;
2695 drv
->num_filter_ssids
= params
->num_filter_ssids
;
2697 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_START_SCHED_SCAN
);
2699 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2701 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
2703 if (drv
->num_filter_ssids
) {
2704 match_sets
= nlmsg_alloc();
2706 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
2707 wpa_hexdump_ascii(MSG_MSGDUMP
,
2708 "nl80211: Sched scan filter SSID",
2709 drv
->filter_ssids
[i
].ssid
,
2710 drv
->filter_ssids
[i
].ssid_len
);
2712 match_set_ssid
= nlmsg_alloc();
2713 nla_put(match_set_ssid
,
2714 NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
2715 drv
->filter_ssids
[i
].ssid_len
,
2716 drv
->filter_ssids
[i
].ssid
);
2718 nla_put_nested(match_sets
, i
+ 1, match_set_ssid
);
2720 nlmsg_free(match_set_ssid
);
2723 nla_put_nested(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
,
2725 nlmsg_free(match_sets
);
2728 for (i
= 0; i
< params
->num_ssids
; i
++) {
2729 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Sched scan SSID",
2730 params
->ssids
[i
].ssid
,
2731 params
->ssids
[i
].ssid_len
);
2732 NLA_PUT(ssids
, i
+ 1, params
->ssids
[i
].ssid_len
,
2733 params
->ssids
[i
].ssid
);
2735 if (params
->num_ssids
)
2736 nla_put_nested(msg
, NL80211_ATTR_SCAN_SSIDS
, ssids
);
2738 if (params
->extra_ies
) {
2739 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Sched scan extra IEs",
2740 params
->extra_ies
, params
->extra_ies_len
);
2741 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
2745 if (params
->freqs
) {
2746 for (i
= 0; params
->freqs
[i
]; i
++) {
2747 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
2748 "MHz", params
->freqs
[i
]);
2749 NLA_PUT_U32(freqs
, i
+ 1, params
->freqs
[i
]);
2751 nla_put_nested(msg
, NL80211_ATTR_SCAN_FREQUENCIES
, freqs
);
2754 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2756 /* TODO: if we get an error here, we should fall back to normal scan */
2760 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
2761 "ret=%d (%s)", ret
, strerror(-ret
));
2762 goto nla_put_failure
;
2765 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
2766 "scan interval %d msec", ret
, interval
);
2777 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
2778 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
2779 * Returns: 0 on success, -1 on failure or if not supported
2781 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
2783 struct i802_bss
*bss
= priv
;
2784 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2788 msg
= nlmsg_alloc();
2792 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
2794 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2796 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2799 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
2800 "ret=%d (%s)", ret
, strerror(-ret
));
2801 goto nla_put_failure
;
2804 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
2812 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
2814 const u8
*end
, *pos
;
2820 end
= ies
+ ies_len
;
2822 while (pos
+ 1 < end
) {
2823 if (pos
+ 2 + pos
[1] > end
)
2834 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
2835 const u8
*ie
, size_t ie_len
)
2840 if (drv
->filter_ssids
== NULL
)
2843 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
2847 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
2848 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
2849 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
2858 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
2860 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2861 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2862 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
2863 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
2864 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
2865 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
2866 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
2867 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
2868 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
2869 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
2870 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
2871 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
2872 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
2873 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
2874 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
2876 struct nl80211_bss_info_arg
*_arg
= arg
;
2877 struct wpa_scan_results
*res
= _arg
->res
;
2878 struct wpa_scan_res
**tmp
;
2879 struct wpa_scan_res
*r
;
2880 const u8
*ie
, *beacon_ie
;
2881 size_t ie_len
, beacon_ie_len
;
2885 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2886 genlmsg_attrlen(gnlh
, 0), NULL
);
2887 if (!tb
[NL80211_ATTR_BSS
])
2889 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
2892 if (bss
[NL80211_BSS_STATUS
]) {
2893 enum nl80211_bss_status status
;
2894 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
2895 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
2896 bss
[NL80211_BSS_FREQUENCY
]) {
2898 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
2899 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
2902 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
2903 bss
[NL80211_BSS_BSSID
]) {
2904 os_memcpy(_arg
->assoc_bssid
,
2905 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
2906 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
2907 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
2912 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
2913 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
2914 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
2919 if (bss
[NL80211_BSS_BEACON_IES
]) {
2920 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
2921 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
2927 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
2928 ie
? ie_len
: beacon_ie_len
))
2931 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
2934 if (bss
[NL80211_BSS_BSSID
])
2935 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
2937 if (bss
[NL80211_BSS_FREQUENCY
])
2938 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
2939 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
2940 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
2941 if (bss
[NL80211_BSS_CAPABILITY
])
2942 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
2943 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
2944 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
2945 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
2946 r
->level
/= 100; /* mBm to dBm */
2947 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
2948 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
2949 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
2950 r
->flags
|= WPA_SCAN_LEVEL_INVALID
;
2952 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
2953 if (bss
[NL80211_BSS_TSF
])
2954 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
2955 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
2956 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
2958 pos
= (u8
*) (r
+ 1);
2960 os_memcpy(pos
, ie
, ie_len
);
2963 r
->beacon_ie_len
= beacon_ie_len
;
2965 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
2967 if (bss
[NL80211_BSS_STATUS
]) {
2968 enum nl80211_bss_status status
;
2969 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
2971 case NL80211_BSS_STATUS_AUTHENTICATED
:
2972 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
2974 case NL80211_BSS_STATUS_ASSOCIATED
:
2975 r
->flags
|= WPA_SCAN_ASSOCIATED
;
2983 * cfg80211 maintains separate BSS table entries for APs if the same
2984 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
2985 * not use frequency as a separate key in the BSS table, so filter out
2986 * duplicated entries. Prefer associated BSS entry in such a case in
2987 * order to get the correct frequency into the BSS table.
2989 for (i
= 0; i
< res
->num
; i
++) {
2991 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
2994 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
2995 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
2996 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
2997 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
2998 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
3001 /* Same BSSID,SSID was already included in scan results */
3002 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
3003 "for " MACSTR
, MAC2STR(r
->bssid
));
3005 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
3006 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
3007 os_free(res
->res
[i
]);
3014 tmp
= os_realloc(res
->res
,
3015 (res
->num
+ 1) * sizeof(struct wpa_scan_res
*));
3020 tmp
[res
->num
++] = r
;
3027 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
3030 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
3031 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
3032 "mismatch (" MACSTR
")", MAC2STR(addr
));
3033 wpa_driver_nl80211_mlme(drv
, addr
,
3034 NL80211_CMD_DEAUTHENTICATE
,
3035 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
3040 static void wpa_driver_nl80211_check_bss_status(
3041 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
3045 for (i
= 0; i
< res
->num
; i
++) {
3046 struct wpa_scan_res
*r
= res
->res
[i
];
3047 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
3048 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
3049 "indicates BSS status with " MACSTR
3050 " as authenticated",
3052 if (is_sta_interface(drv
->nlmode
) &&
3053 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
3054 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
3056 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
3057 " in local state (auth=" MACSTR
3058 " assoc=" MACSTR
")",
3059 MAC2STR(drv
->auth_bssid
),
3060 MAC2STR(drv
->bssid
));
3061 clear_state_mismatch(drv
, r
->bssid
);
3065 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
3066 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
3067 "indicate BSS status with " MACSTR
3070 if (is_sta_interface(drv
->nlmode
) &&
3072 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
3073 "(not associated) does not match "
3075 clear_state_mismatch(drv
, r
->bssid
);
3076 } else if (is_sta_interface(drv
->nlmode
) &&
3077 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
3079 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
3080 "(associated with " MACSTR
") does "
3081 "not match with BSS state",
3082 MAC2STR(drv
->bssid
));
3083 clear_state_mismatch(drv
, r
->bssid
);
3084 clear_state_mismatch(drv
, drv
->bssid
);
3091 static struct wpa_scan_results
*
3092 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
3095 struct wpa_scan_results
*res
;
3097 struct nl80211_bss_info_arg arg
;
3099 res
= os_zalloc(sizeof(*res
));
3102 msg
= nlmsg_alloc();
3104 goto nla_put_failure
;
3106 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
3107 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3111 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
3114 wpa_printf(MSG_DEBUG
, "Received scan results (%lu BSSes)",
3115 (unsigned long) res
->num
);
3118 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
3119 "(%s)", ret
, strerror(-ret
));
3122 wpa_scan_results_free(res
);
3128 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
3129 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
3130 * Returns: Scan results on success, -1 on failure
3132 static struct wpa_scan_results
*
3133 wpa_driver_nl80211_get_scan_results(void *priv
)
3135 struct i802_bss
*bss
= priv
;
3136 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3137 struct wpa_scan_results
*res
;
3139 res
= nl80211_get_scan_results(drv
);
3141 wpa_driver_nl80211_check_bss_status(drv
, res
);
3146 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
3148 struct wpa_scan_results
*res
;
3151 res
= nl80211_get_scan_results(drv
);
3153 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
3157 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
3158 for (i
= 0; i
< res
->num
; i
++) {
3159 struct wpa_scan_res
*r
= res
->res
[i
];
3160 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
3161 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
3162 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
3163 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
3166 wpa_scan_results_free(res
);
3170 static int wpa_driver_nl80211_set_key(const char *ifname
, void *priv
,
3171 enum wpa_alg alg
, const u8
*addr
,
3172 int key_idx
, int set_tx
,
3173 const u8
*seq
, size_t seq_len
,
3174 const u8
*key
, size_t key_len
)
3176 struct i802_bss
*bss
= priv
;
3177 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3178 int ifindex
= if_nametoindex(ifname
);
3182 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d alg=%d addr=%p key_idx=%d "
3183 "set_tx=%d seq_len=%lu key_len=%lu",
3184 __func__
, ifindex
, alg
, addr
, key_idx
, set_tx
,
3185 (unsigned long) seq_len
, (unsigned long) key_len
);
3189 #endif /* CONFIG_TDLS */
3191 msg
= nlmsg_alloc();
3195 if (alg
== WPA_ALG_NONE
) {
3196 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
3198 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
3199 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
3203 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3204 WLAN_CIPHER_SUITE_WEP40
);
3206 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3207 WLAN_CIPHER_SUITE_WEP104
);
3210 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3211 WLAN_CIPHER_SUITE_TKIP
);
3214 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3215 WLAN_CIPHER_SUITE_CCMP
);
3218 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
3219 WLAN_CIPHER_SUITE_AES_CMAC
);
3222 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
3223 "algorithm %d", __func__
, alg
);
3230 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
3232 if (addr
&& !is_broadcast_ether_addr(addr
)) {
3233 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
3234 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3236 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
3237 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
3238 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
3239 NL80211_KEYTYPE_GROUP
);
3241 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
3242 struct nl_msg
*types
;
3244 wpa_printf(MSG_DEBUG
, " broadcast key");
3245 types
= nlmsg_alloc();
3247 goto nla_put_failure
;
3248 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
3249 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
3253 goto nla_put_failure
;
3255 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
3256 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
3258 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3259 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
3262 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
3263 ret
, strerror(-ret
));
3266 * If we failed or don't need to set the default TX key (below),
3269 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
)
3271 if (is_ap_interface(drv
->nlmode
) && addr
&&
3272 !is_broadcast_ether_addr(addr
))
3275 msg
= nlmsg_alloc();
3279 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
3280 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
3281 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
3282 if (alg
== WPA_ALG_IGTK
)
3283 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
3285 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
3286 if (addr
&& is_broadcast_ether_addr(addr
)) {
3287 struct nl_msg
*types
;
3289 types
= nlmsg_alloc();
3291 goto nla_put_failure
;
3292 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
3293 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
3297 goto nla_put_failure
;
3299 struct nl_msg
*types
;
3301 types
= nlmsg_alloc();
3303 goto nla_put_failure
;
3304 NLA_PUT_FLAG(types
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
3305 err
= nla_put_nested(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
,
3309 goto nla_put_failure
;
3312 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3316 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
3317 "err=%d %s)", ret
, strerror(-ret
));
3325 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
3326 int key_idx
, int defkey
,
3327 const u8
*seq
, size_t seq_len
,
3328 const u8
*key
, size_t key_len
)
3330 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
3334 if (defkey
&& alg
== WPA_ALG_IGTK
)
3335 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
3337 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
3339 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
3344 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3345 WLAN_CIPHER_SUITE_WEP40
);
3347 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3348 WLAN_CIPHER_SUITE_WEP104
);
3351 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
3354 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
3357 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3358 WLAN_CIPHER_SUITE_AES_CMAC
);
3361 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
3362 "algorithm %d", __func__
, alg
);
3367 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
3369 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
3371 nla_nest_end(msg
, key_attr
);
3379 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
3383 struct nlattr
*nl_keys
, *nl_key
;
3385 for (i
= 0; i
< 4; i
++) {
3386 if (!params
->wep_key
[i
])
3391 if (params
->wps
== WPS_MODE_PRIVACY
)
3393 if (params
->pairwise_suite
&&
3394 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
3400 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
3402 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
3404 goto nla_put_failure
;
3406 for (i
= 0; i
< 4; i
++) {
3407 if (!params
->wep_key
[i
])
3410 nl_key
= nla_nest_start(msg
, i
);
3412 goto nla_put_failure
;
3414 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
3415 params
->wep_key
[i
]);
3416 if (params
->wep_key_len
[i
] == 5)
3417 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3418 WLAN_CIPHER_SUITE_WEP40
);
3420 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
3421 WLAN_CIPHER_SUITE_WEP104
);
3423 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
3425 if (i
== params
->wep_tx_keyidx
)
3426 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
3428 nla_nest_end(msg
, nl_key
);
3430 nla_nest_end(msg
, nl_keys
);
3439 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
3440 const u8
*addr
, int cmd
, u16 reason_code
,
3441 int local_state_change
)
3446 msg
= nlmsg_alloc();
3450 nl80211_cmd(drv
, msg
, 0, cmd
);
3452 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3453 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
3454 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3455 if (local_state_change
)
3456 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
3458 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3461 wpa_printf(MSG_DEBUG
, "nl80211: MLME command failed: ret=%d "
3462 "(%s)", ret
, strerror(-ret
));
3463 goto nla_put_failure
;
3473 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
3474 const u8
*addr
, int reason_code
)
3476 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
3477 __func__
, MAC2STR(addr
), reason_code
);
3478 drv
->associated
= 0;
3479 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISCONNECT
,
3484 static int wpa_driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
3487 struct i802_bss
*bss
= priv
;
3488 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3489 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
3490 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
3491 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
3492 __func__
, MAC2STR(addr
), reason_code
);
3493 drv
->associated
= 0;
3494 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
3495 return nl80211_leave_ibss(drv
);
3496 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
3501 static int wpa_driver_nl80211_disassociate(void *priv
, const u8
*addr
,
3504 struct i802_bss
*bss
= priv
;
3505 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3506 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
3507 return wpa_driver_nl80211_disconnect(drv
, addr
, reason_code
);
3508 wpa_printf(MSG_DEBUG
, "%s", __func__
);
3509 drv
->associated
= 0;
3510 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DISASSOCIATE
,
3515 static int wpa_driver_nl80211_authenticate(
3516 void *priv
, struct wpa_driver_auth_params
*params
)
3518 struct i802_bss
*bss
= priv
;
3519 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3522 enum nl80211_auth_type type
;
3523 enum nl80211_iftype nlmode
;
3526 drv
->associated
= 0;
3527 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
3528 /* FIX: IBSS mode */
3529 nlmode
= params
->p2p
?
3530 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
3531 if (drv
->nlmode
!= nlmode
&&
3532 wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
3536 msg
= nlmsg_alloc();
3540 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
3543 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
3545 for (i
= 0; i
< 4; i
++) {
3546 if (!params
->wep_key
[i
])
3548 wpa_driver_nl80211_set_key(bss
->ifname
, priv
, WPA_ALG_WEP
,
3550 i
== params
->wep_tx_keyidx
, NULL
, 0,
3552 params
->wep_key_len
[i
]);
3553 if (params
->wep_tx_keyidx
!= i
)
3555 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
3556 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
3562 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3563 if (params
->bssid
) {
3564 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
3565 MAC2STR(params
->bssid
));
3566 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
3569 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
3570 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
3573 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
3574 params
->ssid
, params
->ssid_len
);
3575 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
3578 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
3580 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
3581 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
3582 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
3583 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
3584 type
= NL80211_AUTHTYPE_SHARED_KEY
;
3585 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
3586 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
3587 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
3588 type
= NL80211_AUTHTYPE_FT
;
3590 goto nla_put_failure
;
3591 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
3592 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
3593 if (params
->local_state_change
) {
3594 wpa_printf(MSG_DEBUG
, " * Local state change only");
3595 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
3598 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3601 wpa_printf(MSG_DEBUG
, "nl80211: MLME command failed: ret=%d "
3602 "(%s)", ret
, strerror(-ret
));
3604 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
3605 !params
->local_state_change
) {
3607 * mac80211 does not currently accept new
3608 * authentication if we are already authenticated. As a
3609 * workaround, force deauthentication and try again.
3611 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
3612 "after forced deauthentication");
3613 wpa_driver_nl80211_deauthenticate(
3615 WLAN_REASON_PREV_AUTH_NOT_VALID
);
3619 goto nla_put_failure
;
3622 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
3631 struct phy_info_arg
{
3633 struct hostapd_hw_modes
*modes
;
3636 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
3638 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
3639 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3640 struct phy_info_arg
*phy_info
= arg
;
3642 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
3644 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
3645 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
3646 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
3647 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
3648 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
3649 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
3650 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
3651 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
3654 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
3655 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
3656 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
3657 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] = { .type
= NLA_FLAG
},
3660 struct nlattr
*nl_band
;
3661 struct nlattr
*nl_freq
;
3662 struct nlattr
*nl_rate
;
3663 int rem_band
, rem_freq
, rem_rate
;
3664 struct hostapd_hw_modes
*mode
;
3665 int idx
, mode_is_set
;
3667 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3668 genlmsg_attrlen(gnlh
, 0), NULL
);
3670 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
3673 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
) {
3674 mode
= os_realloc(phy_info
->modes
, (*phy_info
->num_modes
+ 1) * sizeof(*mode
));
3677 phy_info
->modes
= mode
;
3681 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
3682 memset(mode
, 0, sizeof(*mode
));
3683 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
;
3684 *(phy_info
->num_modes
) += 1;
3686 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
3687 nla_len(nl_band
), NULL
);
3689 if (tb_band
[NL80211_BAND_ATTR_HT_CAPA
]) {
3690 mode
->ht_capab
= nla_get_u16(
3691 tb_band
[NL80211_BAND_ATTR_HT_CAPA
]);
3694 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) {
3695 mode
->a_mpdu_params
|= nla_get_u8(
3696 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) &
3700 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) {
3701 mode
->a_mpdu_params
|= nla_get_u8(
3702 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) <<
3706 if (tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
] &&
3707 nla_len(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
])) {
3709 mcs
= nla_data(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
3710 os_memcpy(mode
->mcs_set
, mcs
, 16);
3713 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
3714 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
3715 nla_len(nl_freq
), freq_policy
);
3716 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
3718 mode
->num_channels
++;
3721 mode
->channels
= os_zalloc(mode
->num_channels
* sizeof(struct hostapd_channel_data
));
3722 if (!mode
->channels
)
3727 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
3728 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
3729 nla_len(nl_freq
), freq_policy
);
3730 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
3733 mode
->channels
[idx
].freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
3734 mode
->channels
[idx
].flag
= 0;
3737 /* crude heuristic */
3738 if (mode
->channels
[idx
].freq
< 4000)
3739 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
3741 mode
->mode
= HOSTAPD_MODE_IEEE80211A
;
3745 /* crude heuristic */
3746 if (mode
->channels
[idx
].freq
< 4000)
3747 if (mode
->channels
[idx
].freq
== 2484)
3748 mode
->channels
[idx
].chan
= 14;
3750 mode
->channels
[idx
].chan
= (mode
->channels
[idx
].freq
- 2407) / 5;
3752 mode
->channels
[idx
].chan
= mode
->channels
[idx
].freq
/5 - 1000;
3754 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
3755 mode
->channels
[idx
].flag
|=
3756 HOSTAPD_CHAN_DISABLED
;
3757 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
3758 mode
->channels
[idx
].flag
|=
3759 HOSTAPD_CHAN_PASSIVE_SCAN
;
3760 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
3761 mode
->channels
[idx
].flag
|=
3762 HOSTAPD_CHAN_NO_IBSS
;
3763 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
3764 mode
->channels
[idx
].flag
|=
3767 if (tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] &&
3768 !tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
3769 mode
->channels
[idx
].max_tx_power
=
3770 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
]) / 100;
3775 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
3776 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
3777 nla_len(nl_rate
), rate_policy
);
3778 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
3783 mode
->rates
= os_zalloc(mode
->num_rates
* sizeof(int));
3789 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
3790 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
3791 nla_len(nl_rate
), rate_policy
);
3792 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
3794 mode
->rates
[idx
] = nla_get_u32(tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
3796 /* crude heuristic */
3797 if (mode
->mode
== HOSTAPD_MODE_IEEE80211B
&&
3798 mode
->rates
[idx
] > 200)
3799 mode
->mode
= HOSTAPD_MODE_IEEE80211G
;
3808 static struct hostapd_hw_modes
*
3809 wpa_driver_nl80211_add_11b(struct hostapd_hw_modes
*modes
, u16
*num_modes
)
3812 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
3813 int i
, mode11g_idx
= -1;
3815 /* If only 802.11g mode is included, use it to construct matching
3816 * 802.11b mode data. */
3818 for (m
= 0; m
< *num_modes
; m
++) {
3819 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
3820 return modes
; /* 802.11b already included */
3821 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
3825 if (mode11g_idx
< 0)
3826 return modes
; /* 2.4 GHz band not supported at all */
3828 nmodes
= os_realloc(modes
, (*num_modes
+ 1) * sizeof(*nmodes
));
3830 return modes
; /* Could not add 802.11b mode */
3832 mode
= &nmodes
[*num_modes
];
3833 os_memset(mode
, 0, sizeof(*mode
));
3837 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
3839 mode11g
= &modes
[mode11g_idx
];
3840 mode
->num_channels
= mode11g
->num_channels
;
3841 mode
->channels
= os_malloc(mode11g
->num_channels
*
3842 sizeof(struct hostapd_channel_data
));
3843 if (mode
->channels
== NULL
) {
3845 return modes
; /* Could not add 802.11b mode */
3847 os_memcpy(mode
->channels
, mode11g
->channels
,
3848 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
3850 mode
->num_rates
= 0;
3851 mode
->rates
= os_malloc(4 * sizeof(int));
3852 if (mode
->rates
== NULL
) {
3853 os_free(mode
->channels
);
3855 return modes
; /* Could not add 802.11b mode */
3858 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
3859 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
3860 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
3862 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
3864 if (mode
->num_rates
== 4)
3868 if (mode
->num_rates
== 0) {
3869 os_free(mode
->channels
);
3870 os_free(mode
->rates
);
3872 return modes
; /* No 802.11b rates */
3875 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
3882 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
3887 for (c
= 0; c
< mode
->num_channels
; c
++) {
3888 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
3889 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
3890 chan
->flag
|= HOSTAPD_CHAN_HT40
;
3895 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
3900 for (c
= 0; c
< mode
->num_channels
; c
++) {
3901 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
3902 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
3904 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
3905 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
3906 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
3907 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
3912 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
3913 struct phy_info_arg
*results
)
3915 u32 start
, end
, max_bw
;
3918 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
3919 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
3920 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
3923 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
3924 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
3925 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
3927 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
3928 start
, end
, max_bw
);
3932 for (m
= 0; m
< *results
->num_modes
; m
++) {
3933 if (!(results
->modes
[m
].ht_capab
&
3934 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
3936 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
3941 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
3942 struct phy_info_arg
*results
)
3944 u32 start
, end
, max_bw
;
3947 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
3948 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
3949 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
3952 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
3953 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
3954 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
3959 for (m
= 0; m
< *results
->num_modes
; m
++) {
3960 if (!(results
->modes
[m
].ht_capab
&
3961 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
3963 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
3968 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
3970 struct phy_info_arg
*results
= arg
;
3971 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
3972 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3973 struct nlattr
*nl_rule
;
3974 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
3976 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
3977 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3978 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3979 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3980 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3981 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3982 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3985 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3986 genlmsg_attrlen(gnlh
, 0), NULL
);
3987 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
3988 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
3989 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
3994 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
3995 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
3997 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
3999 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
4000 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
4001 nl80211_reg_rule_ht40(tb_rule
, results
);
4004 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
4006 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
4007 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
4008 nl80211_reg_rule_sec(tb_rule
, results
);
4015 static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data
*drv
,
4016 struct phy_info_arg
*results
)
4020 msg
= nlmsg_alloc();
4024 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
4025 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
4029 static struct hostapd_hw_modes
*
4030 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
4032 struct i802_bss
*bss
= priv
;
4033 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4035 struct phy_info_arg result
= {
4036 .num_modes
= num_modes
,
4043 msg
= nlmsg_alloc();
4047 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
4049 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4051 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
4052 nl80211_set_ht40_flags(drv
, &result
);
4053 return wpa_driver_nl80211_add_11b(result
.modes
, num_modes
);
4060 static int wpa_driver_nl80211_send_frame(struct wpa_driver_nl80211_data
*drv
,
4061 const void *data
, size_t len
,
4065 0x00, 0x00, /* radiotap version */
4066 0x0e, 0x00, /* radiotap length */
4067 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
4068 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
4070 0x00, 0x00, /* RX and TX flags to indicate that */
4071 0x00, 0x00, /* this is the injected frame directly */
4073 struct iovec iov
[2] = {
4075 .iov_base
= &rtap_hdr
,
4076 .iov_len
= sizeof(rtap_hdr
),
4079 .iov_base
= (void *) data
,
4083 struct msghdr msg
= {
4088 .msg_control
= NULL
,
4089 .msg_controllen
= 0,
4095 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
4097 if (drv
->monitor_sock
< 0) {
4098 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
4099 "for %s", __func__
);
4103 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
4105 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
4112 static int wpa_driver_nl80211_send_mlme(void *priv
, const u8
*data
,
4115 struct i802_bss
*bss
= priv
;
4116 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4117 struct ieee80211_mgmt
*mgmt
;
4121 mgmt
= (struct ieee80211_mgmt
*) data
;
4122 fc
= le_to_host16(mgmt
->frame_control
);
4124 if (is_sta_interface(drv
->nlmode
) &&
4125 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4126 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
4128 * The use of last_mgmt_freq is a bit of a hack,
4129 * but it works due to the single-threaded nature
4130 * of wpa_supplicant.
4132 return nl80211_send_frame_cmd(drv
, drv
->last_mgmt_freq
, 0,
4133 data
, data_len
, NULL
);
4136 if (drv
->no_monitor_iface_capab
&& is_ap_interface(drv
->nlmode
)) {
4137 return nl80211_send_frame_cmd(drv
, drv
->ap_oper_freq
, 0,
4138 data
, data_len
, NULL
);
4141 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4142 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
4144 * Only one of the authentication frame types is encrypted.
4145 * In order for static WEP encryption to work properly (i.e.,
4146 * to not encrypt the frame), we need to tell mac80211 about
4147 * the frames that must not be encrypted.
4149 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
4150 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
4151 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
4155 return wpa_driver_nl80211_send_frame(drv
, data
, data_len
, encrypt
);
4159 static int nl80211_set_ap_isolate(struct i802_bss
*bss
, int enabled
)
4161 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4164 msg
= nlmsg_alloc();
4168 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
4170 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
4171 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, enabled
);
4173 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4179 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
4180 int slot
, int ht_opmode
)
4182 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4185 msg
= nlmsg_alloc();
4189 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
4192 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
4194 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
4196 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
4198 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
4199 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
4201 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4207 static int wpa_driver_nl80211_set_ap(void *priv
,
4208 struct wpa_driver_ap_params
*params
)
4210 struct i802_bss
*bss
= priv
;
4211 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4213 u8 cmd
= NL80211_CMD_NEW_BEACON
;
4216 int ifindex
= if_nametoindex(bss
->ifname
);
4221 beacon_set
= bss
->beacon_set
;
4223 msg
= nlmsg_alloc();
4227 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
4230 cmd
= NL80211_CMD_SET_BEACON
;
4232 nl80211_cmd(drv
, msg
, 0, cmd
);
4233 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
4234 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
4235 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4236 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
4237 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
4238 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
4240 switch (params
->hide_ssid
) {
4241 case NO_SSID_HIDING
:
4242 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4243 NL80211_HIDDEN_SSID_NOT_IN_USE
);
4245 case HIDDEN_SSID_ZERO_LEN
:
4246 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4247 NL80211_HIDDEN_SSID_ZERO_LEN
);
4249 case HIDDEN_SSID_ZERO_CONTENTS
:
4250 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4251 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
4254 if (params
->privacy
)
4255 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
4256 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
4257 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
4258 /* Leave out the attribute */
4259 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
4260 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
4261 NL80211_AUTHTYPE_SHARED_KEY
);
4263 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
4264 NL80211_AUTHTYPE_OPEN_SYSTEM
);
4267 if (params
->wpa_version
& WPA_PROTO_WPA
)
4268 ver
|= NL80211_WPA_VERSION_1
;
4269 if (params
->wpa_version
& WPA_PROTO_RSN
)
4270 ver
|= NL80211_WPA_VERSION_2
;
4272 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
4275 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
4276 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
4277 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
4278 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
4280 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
4281 num_suites
* sizeof(u32
), suites
);
4285 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
4286 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
4287 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
4288 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
4289 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
4290 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
4291 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
4292 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
4294 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
4295 num_suites
* sizeof(u32
), suites
);
4298 switch (params
->group_cipher
) {
4299 case WPA_CIPHER_CCMP
:
4300 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
4301 WLAN_CIPHER_SUITE_CCMP
);
4303 case WPA_CIPHER_TKIP
:
4304 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
4305 WLAN_CIPHER_SUITE_TKIP
);
4307 case WPA_CIPHER_WEP104
:
4308 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
4309 WLAN_CIPHER_SUITE_WEP104
);
4311 case WPA_CIPHER_WEP40
:
4312 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
4313 WLAN_CIPHER_SUITE_WEP40
);
4317 if (params
->beacon_ies
) {
4318 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
4319 wpabuf_head(params
->beacon_ies
));
4321 if (params
->proberesp_ies
) {
4322 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
4323 wpabuf_len(params
->proberesp_ies
),
4324 wpabuf_head(params
->proberesp_ies
));
4326 if (params
->assocresp_ies
) {
4327 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
4328 wpabuf_len(params
->assocresp_ies
),
4329 wpabuf_head(params
->assocresp_ies
));
4332 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4334 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
4335 ret
, strerror(-ret
));
4337 bss
->beacon_set
= 1;
4338 ret
= nl80211_set_ap_isolate(bss
, params
->isolate
);
4339 if (!params
->isolate
&& ret
) {
4340 wpa_printf(MSG_DEBUG
, "nl80211: Ignore AP isolation "
4341 "configuration error since isolation is "
4346 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
4347 params
->short_slot_time
, params
->ht_opmode
);
4355 static int wpa_driver_nl80211_set_freq(struct wpa_driver_nl80211_data
*drv
,
4356 int freq
, int ht_enabled
,
4357 int sec_channel_offset
)
4362 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d "
4363 "sec_channel_offset=%d)",
4364 freq
, ht_enabled
, sec_channel_offset
);
4365 msg
= nlmsg_alloc();
4369 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
4371 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4372 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
4374 switch (sec_channel_offset
) {
4376 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4377 NL80211_CHAN_HT40MINUS
);
4380 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4381 NL80211_CHAN_HT40PLUS
);
4384 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4390 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4393 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
4394 "%d (%s)", freq
, ret
, strerror(-ret
));
4400 static u32
sta_flags_nl80211(int flags
)
4404 if (flags
& WPA_STA_AUTHORIZED
)
4405 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
4406 if (flags
& WPA_STA_WMM
)
4407 f
|= BIT(NL80211_STA_FLAG_WME
);
4408 if (flags
& WPA_STA_SHORT_PREAMBLE
)
4409 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
4410 if (flags
& WPA_STA_MFP
)
4411 f
|= BIT(NL80211_STA_FLAG_MFP
);
4412 if (flags
& WPA_STA_TDLS_PEER
)
4413 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
4419 static int wpa_driver_nl80211_sta_add(void *priv
,
4420 struct hostapd_sta_add_params
*params
)
4422 struct i802_bss
*bss
= priv
;
4423 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4425 struct nl80211_sta_flag_update upd
;
4428 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
4429 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
4432 msg
= nlmsg_alloc();
4436 nl80211_cmd(drv
, msg
, 0, params
->set
? NL80211_CMD_SET_STATION
:
4437 NL80211_CMD_NEW_STATION
);
4439 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
4440 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
4441 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
4442 params
->supp_rates
);
4444 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
4445 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
4446 params
->listen_interval
);
4448 if (params
->ht_capabilities
) {
4449 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
4450 sizeof(*params
->ht_capabilities
),
4451 params
->ht_capabilities
);
4454 os_memset(&upd
, 0, sizeof(upd
));
4455 upd
.mask
= sta_flags_nl80211(params
->flags
);
4457 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
4459 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4461 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
4462 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
4471 static int wpa_driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
4473 struct i802_bss
*bss
= priv
;
4474 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4478 msg
= nlmsg_alloc();
4482 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
4484 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
4485 if_nametoindex(bss
->ifname
));
4486 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4488 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4497 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
4502 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
4504 /* stop listening for EAPOL on this interface */
4505 del_ifidx(drv
, ifidx
);
4507 msg
= nlmsg_alloc();
4509 goto nla_put_failure
;
4511 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
4512 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
4514 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
4517 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
4521 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
4524 case NL80211_IFTYPE_ADHOC
:
4526 case NL80211_IFTYPE_STATION
:
4528 case NL80211_IFTYPE_AP
:
4530 case NL80211_IFTYPE_MONITOR
:
4532 case NL80211_IFTYPE_P2P_CLIENT
:
4533 return "P2P_CLIENT";
4534 case NL80211_IFTYPE_P2P_GO
:
4542 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
4544 enum nl80211_iftype iftype
,
4545 const u8
*addr
, int wds
)
4547 struct nl_msg
*msg
, *flags
= NULL
;
4551 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
4552 iftype
, nl80211_iftype_str(iftype
));
4554 msg
= nlmsg_alloc();
4558 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
4559 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4560 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
4561 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
4563 if (iftype
== NL80211_IFTYPE_MONITOR
) {
4566 flags
= nlmsg_alloc();
4568 goto nla_put_failure
;
4570 NLA_PUT_FLAG(flags
, NL80211_MNTR_FLAG_COOK_FRAMES
);
4572 err
= nla_put_nested(msg
, NL80211_ATTR_MNTR_FLAGS
, flags
);
4577 goto nla_put_failure
;
4579 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
4582 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4585 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
4586 ifname
, ret
, strerror(-ret
));
4590 ifidx
= if_nametoindex(ifname
);
4591 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
4597 /* start listening for EAPOL on this interface */
4598 add_ifidx(drv
, ifidx
);
4600 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
4601 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
4602 nl80211_remove_iface(drv
, ifidx
);
4610 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
4611 const char *ifname
, enum nl80211_iftype iftype
,
4612 const u8
*addr
, int wds
)
4616 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
);
4618 /* if error occurred and interface exists already */
4619 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
4620 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
4622 /* Try to remove the interface that was already there. */
4623 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
4625 /* Try to create the interface again */
4626 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
4630 if (ret
>= 0 && drv
->disable_11b_rates
)
4631 nl80211_disable_11b_rates(drv
, ret
, 1);
4637 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
4639 struct ieee80211_hdr
*hdr
;
4641 union wpa_event_data event
;
4643 hdr
= (struct ieee80211_hdr
*) buf
;
4644 fc
= le_to_host16(hdr
->frame_control
);
4646 os_memset(&event
, 0, sizeof(event
));
4647 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
4648 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
4649 event
.tx_status
.dst
= hdr
->addr1
;
4650 event
.tx_status
.data
= buf
;
4651 event
.tx_status
.data_len
= len
;
4652 event
.tx_status
.ack
= ok
;
4653 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
4657 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
4658 u8
*buf
, size_t len
)
4660 struct ieee80211_hdr
*hdr
= (void *)buf
;
4662 union wpa_event_data event
;
4664 if (len
< sizeof(*hdr
))
4667 fc
= le_to_host16(hdr
->frame_control
);
4669 os_memset(&event
, 0, sizeof(event
));
4670 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
4671 event
.rx_from_unknown
.addr
= hdr
->addr2
;
4672 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
4673 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
4674 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
4678 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
4679 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
4681 struct ieee80211_hdr
*hdr
;
4683 union wpa_event_data event
;
4685 hdr
= (struct ieee80211_hdr
*) buf
;
4686 fc
= le_to_host16(hdr
->frame_control
);
4688 switch (WLAN_FC_GET_TYPE(fc
)) {
4689 case WLAN_FC_TYPE_MGMT
:
4690 os_memset(&event
, 0, sizeof(event
));
4691 event
.rx_mgmt
.frame
= buf
;
4692 event
.rx_mgmt
.frame_len
= len
;
4693 event
.rx_mgmt
.datarate
= datarate
;
4694 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
4695 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
4697 case WLAN_FC_TYPE_CTRL
:
4698 /* can only get here with PS-Poll frames */
4699 wpa_printf(MSG_DEBUG
, "CTRL");
4700 from_unknown_sta(drv
, buf
, len
);
4702 case WLAN_FC_TYPE_DATA
:
4703 from_unknown_sta(drv
, buf
, len
);
4709 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
4711 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
4713 unsigned char buf
[3000];
4714 struct ieee80211_radiotap_iterator iter
;
4716 int datarate
= 0, ssi_signal
= 0;
4717 int injected
= 0, failed
= 0, rxflags
= 0;
4719 len
= recv(sock
, buf
, sizeof(buf
), 0);
4725 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
4726 printf("received invalid radiotap frame\n");
4731 ret
= ieee80211_radiotap_iterator_next(&iter
);
4735 printf("received invalid radiotap frame (%d)\n", ret
);
4738 switch (iter
.this_arg_index
) {
4739 case IEEE80211_RADIOTAP_FLAGS
:
4740 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
4743 case IEEE80211_RADIOTAP_RX_FLAGS
:
4746 case IEEE80211_RADIOTAP_TX_FLAGS
:
4748 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
4749 IEEE80211_RADIOTAP_F_TX_FAIL
;
4751 case IEEE80211_RADIOTAP_DATA_RETRIES
:
4753 case IEEE80211_RADIOTAP_CHANNEL
:
4754 /* TODO: convert from freq/flags to channel number */
4756 case IEEE80211_RADIOTAP_RATE
:
4757 datarate
= *iter
.this_arg
* 5;
4759 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
4760 ssi_signal
= *iter
.this_arg
;
4765 if (rxflags
&& injected
)
4769 handle_frame(drv
, buf
+ iter
.max_length
,
4770 len
- iter
.max_length
, datarate
, ssi_signal
);
4772 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
4773 len
- iter
.max_length
, !failed
);
4778 * we post-process the filter code later and rewrite
4779 * this to the offset to the last instruction
4784 static struct sock_filter msock_filter_insns
[] = {
4786 * do a little-endian load of the radiotap length field
4788 /* load lower byte into A */
4789 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
4790 /* put it into X (== index register) */
4791 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
4792 /* load upper byte into A */
4793 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
4794 /* left-shift it by 8 */
4795 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
4797 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
4798 /* put result into X */
4799 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
4802 * Allow management frames through, this also gives us those
4803 * management frames that we sent ourselves with status
4805 /* load the lower byte of the IEEE 802.11 frame control field */
4806 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
4807 /* mask off frame type and version */
4808 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
4809 /* accept frame if it's both 0, fall through otherwise */
4810 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
4813 * TODO: add a bit to radiotap RX flags that indicates
4814 * that the sending station is not associated, then
4815 * add a filter here that filters on our DA and that flag
4816 * to allow us to deauth frames to that bad station.
4818 * For now allow all To DS data frames through.
4820 /* load the IEEE 802.11 frame control field */
4821 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
4822 /* mask off frame type, version and DS status */
4823 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
4824 /* accept frame if version 0, type 2 and To DS, fall through otherwise
4826 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
4830 * drop non-data frames
4832 /* load the lower byte of the frame control field */
4833 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
4834 /* mask off QoS bit */
4835 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
4836 /* drop non-data frames */
4837 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
4839 /* load the upper byte of the frame control field */
4840 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
4841 /* mask off toDS/fromDS */
4842 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
4843 /* accept WDS frames */
4844 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
4847 * add header length to index
4849 /* load the lower byte of the frame control field */
4850 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
4851 /* mask off QoS bit */
4852 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
4853 /* right shift it by 6 to give 0 or 2 */
4854 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
4855 /* add data frame header length */
4856 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
4857 /* add index, was start of 802.11 header */
4858 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
4859 /* move to index, now start of LL header */
4860 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
4863 * Accept empty data frames, we use those for
4866 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
4867 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
4870 * Accept EAPOL frames
4872 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
4873 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
4874 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
4875 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
4877 /* keep these last two statements or change the code below */
4878 /* return 0 == "DROP" */
4879 BPF_STMT(BPF_RET
| BPF_K
, 0),
4880 /* return ~0 == "keep all" */
4881 BPF_STMT(BPF_RET
| BPF_K
, ~0),
4884 static struct sock_fprog msock_filter
= {
4885 .len
= sizeof(msock_filter_insns
)/sizeof(msock_filter_insns
[0]),
4886 .filter
= msock_filter_insns
,
4890 static int add_monitor_filter(int s
)
4894 /* rewrite all PASS/FAIL jump offsets */
4895 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
4896 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
4898 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
4899 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
4900 if (insn
->k
== PASS
)
4901 insn
->k
= msock_filter
.len
- idx
- 2;
4902 else if (insn
->k
== FAIL
)
4903 insn
->k
= msock_filter
.len
- idx
- 3;
4906 if (insn
->jt
== PASS
)
4907 insn
->jt
= msock_filter
.len
- idx
- 2;
4908 else if (insn
->jt
== FAIL
)
4909 insn
->jt
= msock_filter
.len
- idx
- 3;
4911 if (insn
->jf
== PASS
)
4912 insn
->jf
= msock_filter
.len
- idx
- 2;
4913 else if (insn
->jf
== FAIL
)
4914 insn
->jf
= msock_filter
.len
- idx
- 3;
4918 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
4919 &msock_filter
, sizeof(msock_filter
))) {
4920 perror("SO_ATTACH_FILTER");
4928 static void nl80211_remove_monitor_interface(
4929 struct wpa_driver_nl80211_data
*drv
)
4931 if (drv
->monitor_ifidx
>= 0) {
4932 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
4933 drv
->monitor_ifidx
= -1;
4935 if (drv
->monitor_sock
>= 0) {
4936 eloop_unregister_read_sock(drv
->monitor_sock
);
4937 close(drv
->monitor_sock
);
4938 drv
->monitor_sock
= -1;
4944 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
4947 struct sockaddr_ll ll
;
4951 if (os_strncmp(drv
->first_bss
.ifname
, "p2p-", 4) == 0) {
4953 * P2P interface name is of the format p2p-%s-%d. For monitor
4954 * interface name corresponding to P2P GO, replace "p2p-" with
4955 * "mon-" to retain the same interface name length and to
4956 * indicate that it is a monitor interface.
4958 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
.ifname
+ 4);
4960 /* Non-P2P interface with AP functionality. */
4961 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
.ifname
);
4964 buf
[IFNAMSIZ
- 1] = '\0';
4966 drv
->monitor_ifidx
=
4967 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
4970 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
4971 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
4972 "monitor interface type - try to run without it");
4973 drv
->no_monitor_iface_capab
= 1;
4976 if (drv
->monitor_ifidx
< 0)
4979 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
4982 memset(&ll
, 0, sizeof(ll
));
4983 ll
.sll_family
= AF_PACKET
;
4984 ll
.sll_ifindex
= drv
->monitor_ifidx
;
4985 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
4986 if (drv
->monitor_sock
< 0) {
4987 perror("socket[PF_PACKET,SOCK_RAW]");
4991 if (add_monitor_filter(drv
->monitor_sock
)) {
4992 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
4993 "interface; do filtering in user space");
4994 /* This works, but will cost in performance. */
4997 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
4998 perror("monitor socket bind");
5002 optlen
= sizeof(optval
);
5005 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
5006 perror("Failed to set socket priority");
5010 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
5012 printf("Could not register monitor read socket\n");
5018 nl80211_remove_monitor_interface(drv
);
5024 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
5025 const u8
*addr
, const u8
*data
,
5026 size_t data_len
, const u8
*own_addr
)
5028 if (bss
->drv
->l2
== NULL
) {
5029 wpa_printf(MSG_DEBUG
, "nl80211: No l2_packet to send EAPOL");
5033 if (l2_packet_send(bss
->drv
->l2
, addr
, ETH_P_EAPOL
, data
, data_len
) <
5038 #endif /* CONFIG_AP */
5041 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
5043 static int wpa_driver_nl80211_hapd_send_eapol(
5044 void *priv
, const u8
*addr
, const u8
*data
,
5045 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
5047 struct i802_bss
*bss
= priv
;
5048 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5049 struct ieee80211_hdr
*hdr
;
5053 int qos
= flags
& WPA_STA_WMM
;
5056 if (drv
->no_monitor_iface_capab
)
5057 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
,
5059 #endif /* CONFIG_AP */
5061 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
5063 hdr
= os_zalloc(len
);
5065 printf("malloc() failed for i802_send_data(len=%lu)\n",
5066 (unsigned long) len
);
5070 hdr
->frame_control
=
5071 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
5072 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
5074 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
5076 hdr
->frame_control
|=
5077 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
5080 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
5081 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
5082 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
5083 pos
= (u8
*) (hdr
+ 1);
5086 /* add an empty QoS header if needed */
5092 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
5093 pos
+= sizeof(rfc1042_header
);
5094 WPA_PUT_BE16(pos
, ETH_P_PAE
);
5096 memcpy(pos
, data
, data_len
);
5098 res
= wpa_driver_nl80211_send_frame(drv
, (u8
*) hdr
, len
, encrypt
);
5100 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
5102 (unsigned long) len
, errno
, strerror(errno
));
5110 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
5112 int flags_or
, int flags_and
)
5114 struct i802_bss
*bss
= priv
;
5115 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5116 struct nl_msg
*msg
, *flags
= NULL
;
5117 struct nl80211_sta_flag_update upd
;
5119 msg
= nlmsg_alloc();
5123 flags
= nlmsg_alloc();
5129 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
5131 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5132 if_nametoindex(bss
->ifname
));
5133 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5136 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
5137 * can be removed eventually.
5139 if (total_flags
& WPA_STA_AUTHORIZED
)
5140 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_AUTHORIZED
);
5142 if (total_flags
& WPA_STA_WMM
)
5143 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_WME
);
5145 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
5146 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
5148 if (total_flags
& WPA_STA_MFP
)
5149 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_MFP
);
5151 if (total_flags
& WPA_STA_TDLS_PEER
)
5152 NLA_PUT_FLAG(flags
, NL80211_STA_FLAG_TDLS_PEER
);
5154 if (nla_put_nested(msg
, NL80211_ATTR_STA_FLAGS
, flags
))
5155 goto nla_put_failure
;
5157 os_memset(&upd
, 0, sizeof(upd
));
5158 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
5159 upd
.set
= sta_flags_nl80211(flags_or
);
5160 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
5164 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5171 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
5172 struct wpa_driver_associate_params
*params
)
5174 enum nl80211_iftype nlmode
;
5177 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
5179 nlmode
= NL80211_IFTYPE_P2P_GO
;
5181 nlmode
= NL80211_IFTYPE_AP
;
5183 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
, nlmode
) ||
5184 wpa_driver_nl80211_set_freq(drv
, params
->freq
, 0, 0)) {
5185 nl80211_remove_monitor_interface(drv
);
5189 if (drv
->no_monitor_iface_capab
) {
5190 if (wpa_driver_nl80211_probe_req_report(&drv
->first_bss
, 1) < 0)
5192 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
5193 "Probe Request frame reporting in AP mode");
5194 /* Try to survive without this */
5198 drv
->ap_oper_freq
= params
->freq
;
5204 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
5209 msg
= nlmsg_alloc();
5213 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
5214 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5215 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5218 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
5219 "(%s)", ret
, strerror(-ret
));
5220 goto nla_put_failure
;
5224 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
5232 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
5233 struct wpa_driver_associate_params
*params
)
5239 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
5241 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
5242 NL80211_IFTYPE_ADHOC
)) {
5243 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
5249 msg
= nlmsg_alloc();
5253 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
5254 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5256 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
5257 goto nla_put_failure
;
5259 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5260 params
->ssid
, params
->ssid_len
);
5261 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5263 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5264 drv
->ssid_len
= params
->ssid_len
;
5266 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5267 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5269 ret
= nl80211_set_conn_keys(params
, msg
);
5271 goto nla_put_failure
;
5273 if (params
->wpa_ie
) {
5274 wpa_hexdump(MSG_DEBUG
,
5275 " * Extra IEs for Beacon/Probe Response frames",
5276 params
->wpa_ie
, params
->wpa_ie_len
);
5277 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5281 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5284 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
5285 ret
, strerror(-ret
));
5287 if (ret
== -EALREADY
&& count
== 1) {
5288 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
5290 nl80211_leave_ibss(drv
);
5295 goto nla_put_failure
;
5298 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
5306 static unsigned int nl80211_get_assoc_bssid(struct wpa_driver_nl80211_data
*drv
,
5311 struct nl80211_bss_info_arg arg
;
5313 os_memset(&arg
, 0, sizeof(arg
));
5314 msg
= nlmsg_alloc();
5316 goto nla_put_failure
;
5318 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
5319 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5322 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
5325 if (is_zero_ether_addr(arg
.assoc_bssid
))
5327 os_memcpy(bssid
, arg
.assoc_bssid
, ETH_ALEN
);
5330 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
5331 "(%s)", ret
, strerror(-ret
));
5334 return drv
->assoc_freq
;
5338 static int nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
5343 if (bssid
== NULL
) {
5344 int res
= nl80211_get_assoc_bssid(drv
, addr
);
5350 return wpa_driver_nl80211_disconnect(drv
, bssid
,
5351 WLAN_REASON_PREV_AUTH_NOT_VALID
);
5355 static int wpa_driver_nl80211_connect(
5356 struct wpa_driver_nl80211_data
*drv
,
5357 struct wpa_driver_associate_params
*params
)
5360 enum nl80211_auth_type type
;
5364 msg
= nlmsg_alloc();
5368 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
5369 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
5371 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5372 if (params
->bssid
) {
5373 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5374 MAC2STR(params
->bssid
));
5375 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
5378 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5379 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5382 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5383 params
->ssid
, params
->ssid_len
);
5384 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5386 if (params
->ssid_len
> sizeof(drv
->ssid
))
5387 goto nla_put_failure
;
5388 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5389 drv
->ssid_len
= params
->ssid_len
;
5391 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
5393 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5397 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5399 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5401 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5404 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
5406 goto skip_auth_type
;
5409 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5410 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
5411 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5412 type
= NL80211_AUTHTYPE_SHARED_KEY
;
5413 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5414 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
5415 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
5416 type
= NL80211_AUTHTYPE_FT
;
5418 goto nla_put_failure
;
5420 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
5421 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
5424 if (params
->wpa_proto
) {
5425 enum nl80211_wpa_versions ver
= 0;
5427 if (params
->wpa_proto
& WPA_PROTO_WPA
)
5428 ver
|= NL80211_WPA_VERSION_1
;
5429 if (params
->wpa_proto
& WPA_PROTO_RSN
)
5430 ver
|= NL80211_WPA_VERSION_2
;
5432 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
5433 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
5436 if (params
->pairwise_suite
!= CIPHER_NONE
) {
5439 switch (params
->pairwise_suite
) {
5441 cipher
= WLAN_CIPHER_SUITE_WEP40
;
5444 cipher
= WLAN_CIPHER_SUITE_WEP104
;
5447 cipher
= WLAN_CIPHER_SUITE_CCMP
;
5451 cipher
= WLAN_CIPHER_SUITE_TKIP
;
5454 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
5457 if (params
->group_suite
!= CIPHER_NONE
) {
5460 switch (params
->group_suite
) {
5462 cipher
= WLAN_CIPHER_SUITE_WEP40
;
5465 cipher
= WLAN_CIPHER_SUITE_WEP104
;
5468 cipher
= WLAN_CIPHER_SUITE_CCMP
;
5472 cipher
= WLAN_CIPHER_SUITE_TKIP
;
5475 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
5478 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
5479 params
->key_mgmt_suite
== KEY_MGMT_PSK
) {
5480 int mgmt
= WLAN_AKM_SUITE_PSK
;
5482 switch (params
->key_mgmt_suite
) {
5483 case KEY_MGMT_802_1X
:
5484 mgmt
= WLAN_AKM_SUITE_8021X
;
5488 mgmt
= WLAN_AKM_SUITE_PSK
;
5491 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
5494 ret
= nl80211_set_conn_keys(params
, msg
);
5496 goto nla_put_failure
;
5498 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5501 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
5502 "(%s)", ret
, strerror(-ret
));
5504 * cfg80211 does not currently accept new connection if we are
5505 * already connected. As a workaround, force disconnection and
5506 * try again once the driver indicates it completed
5509 if (ret
== -EALREADY
)
5510 nl80211_disconnect(drv
, params
->bssid
);
5511 goto nla_put_failure
;
5514 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
5523 static int wpa_driver_nl80211_associate(
5524 void *priv
, struct wpa_driver_associate_params
*params
)
5526 struct i802_bss
*bss
= priv
;
5527 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5531 if (params
->mode
== IEEE80211_MODE_AP
)
5532 return wpa_driver_nl80211_ap(drv
, params
);
5534 if (params
->mode
== IEEE80211_MODE_IBSS
)
5535 return wpa_driver_nl80211_ibss(drv
, params
);
5537 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
5538 enum nl80211_iftype nlmode
= params
->p2p
?
5539 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
5541 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
5543 return wpa_driver_nl80211_connect(drv
, params
);
5546 drv
->associated
= 0;
5548 msg
= nlmsg_alloc();
5552 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
5554 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
5556 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5557 if (params
->bssid
) {
5558 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5559 MAC2STR(params
->bssid
));
5560 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
5563 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5564 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5565 drv
->assoc_freq
= params
->freq
;
5567 drv
->assoc_freq
= 0;
5569 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5570 params
->ssid
, params
->ssid_len
);
5571 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5573 if (params
->ssid_len
> sizeof(drv
->ssid
))
5574 goto nla_put_failure
;
5575 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5576 drv
->ssid_len
= params
->ssid_len
;
5578 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
5580 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5583 if (params
->pairwise_suite
!= CIPHER_NONE
) {
5586 switch (params
->pairwise_suite
) {
5588 cipher
= WLAN_CIPHER_SUITE_WEP40
;
5591 cipher
= WLAN_CIPHER_SUITE_WEP104
;
5594 cipher
= WLAN_CIPHER_SUITE_CCMP
;
5598 cipher
= WLAN_CIPHER_SUITE_TKIP
;
5601 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
5602 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
5605 if (params
->group_suite
!= CIPHER_NONE
) {
5608 switch (params
->group_suite
) {
5610 cipher
= WLAN_CIPHER_SUITE_WEP40
;
5613 cipher
= WLAN_CIPHER_SUITE_WEP104
;
5616 cipher
= WLAN_CIPHER_SUITE_CCMP
;
5620 cipher
= WLAN_CIPHER_SUITE_TKIP
;
5623 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
5624 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
5627 #ifdef CONFIG_IEEE80211W
5628 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
5629 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
5630 #endif /* CONFIG_IEEE80211W */
5632 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
5634 if (params
->prev_bssid
) {
5635 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
5636 MAC2STR(params
->prev_bssid
));
5637 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
5638 params
->prev_bssid
);
5642 wpa_printf(MSG_DEBUG
, " * P2P group");
5644 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5647 wpa_printf(MSG_DEBUG
, "nl80211: MLME command failed: ret=%d "
5648 "(%s)", ret
, strerror(-ret
));
5649 nl80211_dump_scan(drv
);
5650 goto nla_put_failure
;
5653 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
5662 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
5663 int ifindex
, enum nl80211_iftype mode
)
5668 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
5669 ifindex
, mode
, nl80211_iftype_str(mode
));
5671 msg
= nlmsg_alloc();
5675 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
5676 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5677 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
5679 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5683 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
5684 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
5689 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
5690 enum nl80211_iftype nlmode
)
5692 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5695 int was_ap
= is_ap_interface(drv
->nlmode
);
5697 if (nl80211_set_mode(drv
, drv
->ifindex
, nlmode
) == 0) {
5698 drv
->nlmode
= nlmode
;
5703 if (nlmode
== drv
->nlmode
) {
5704 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
5705 "requested mode - ignore error");
5707 goto done
; /* Already in the requested mode */
5710 /* mac80211 doesn't allow mode changes while the device is up, so
5711 * take the device down, try to set the mode again, and bring the
5714 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
5716 for (i
= 0; i
< 10; i
++) {
5718 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
5720 if (res
== -EACCES
|| res
== -ENODEV
)
5723 /* Try to set the mode again while the interface is
5725 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
5728 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
5732 else if (ret
!= -EBUSY
)
5735 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
5737 os_sleep(0, 100000);
5741 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
5742 "interface is down");
5743 drv
->nlmode
= nlmode
;
5744 drv
->ignore_if_down_event
= 1;
5748 if (!ret
&& is_ap_interface(nlmode
)) {
5749 /* Setup additional AP mode functionality if needed */
5750 if (!drv
->no_monitor_iface_capab
&& drv
->monitor_ifidx
< 0 &&
5751 nl80211_create_monitor_interface(drv
) &&
5752 !drv
->no_monitor_iface_capab
)
5754 } else if (!ret
&& !is_ap_interface(nlmode
)) {
5755 /* Remove additional AP mode functionality */
5756 if (was_ap
&& drv
->no_monitor_iface_capab
)
5757 wpa_driver_nl80211_probe_req_report(bss
, 0);
5758 nl80211_remove_monitor_interface(drv
);
5759 bss
->beacon_set
= 0;
5763 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
5764 "from %d failed", nlmode
, drv
->nlmode
);
5770 static int wpa_driver_nl80211_get_capa(void *priv
,
5771 struct wpa_driver_capa
*capa
)
5773 struct i802_bss
*bss
= priv
;
5774 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5775 if (!drv
->has_capability
)
5777 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
5782 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
5784 struct i802_bss
*bss
= priv
;
5785 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5787 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
5788 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
5789 drv
->operstate
= state
;
5790 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
5791 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
5795 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
5797 struct i802_bss
*bss
= priv
;
5798 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5800 struct nl80211_sta_flag_update upd
;
5802 msg
= nlmsg_alloc();
5806 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
5808 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5809 if_nametoindex(bss
->ifname
));
5810 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
5812 os_memset(&upd
, 0, sizeof(upd
));
5813 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5815 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5816 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
5818 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5824 /* Set kernel driver on given frequency (MHz) */
5825 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
5827 struct i802_bss
*bss
= priv
;
5828 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5829 return wpa_driver_nl80211_set_freq(drv
, freq
->freq
, freq
->ht_enabled
,
5830 freq
->sec_channel_offset
);
5834 #if defined(HOSTAPD) || defined(CONFIG_AP)
5836 static inline int min_int(int a
, int b
)
5844 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
5846 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5847 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5849 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5850 genlmsg_attrlen(gnlh
, 0), NULL
);
5853 * TODO: validate the key index and mac address!
5854 * Otherwise, there's a race condition as soon as
5855 * the kernel starts sending key notifications.
5858 if (tb
[NL80211_ATTR_KEY_SEQ
])
5859 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
5860 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
5865 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
5868 struct i802_bss
*bss
= priv
;
5869 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5872 msg
= nlmsg_alloc();
5876 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
5879 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5880 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
5881 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
5885 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
5891 static int i802_set_rate_sets(void *priv
, int *supp_rates
, int *basic_rates
,
5894 struct i802_bss
*bss
= priv
;
5895 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5897 u8 rates
[NL80211_MAX_SUPP_RATES
];
5901 msg
= nlmsg_alloc();
5905 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
5907 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0; i
++)
5908 rates
[rates_len
++] = basic_rates
[i
] / 5;
5910 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
5912 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
5914 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5920 static int i802_set_rts(void *priv
, int rts
)
5922 struct i802_bss
*bss
= priv
;
5923 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5928 msg
= nlmsg_alloc();
5937 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
5938 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5939 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
5941 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5945 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
5946 "%d (%s)", rts
, ret
, strerror(-ret
));
5951 static int i802_set_frag(void *priv
, int frag
)
5953 struct i802_bss
*bss
= priv
;
5954 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5959 msg
= nlmsg_alloc();
5968 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
5969 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5970 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
5972 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5976 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
5977 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
5982 static int i802_flush(void *priv
)
5984 struct i802_bss
*bss
= priv
;
5985 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5988 msg
= nlmsg_alloc();
5992 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
5995 * XXX: FIX! this needs to flush all VLANs too
5997 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
5998 if_nametoindex(bss
->ifname
));
6000 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6006 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
6008 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6009 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6010 struct hostap_sta_driver_data
*data
= arg
;
6011 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
6012 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
6013 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
6014 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
6015 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
6016 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
6017 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
6020 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6021 genlmsg_attrlen(gnlh
, 0), NULL
);
6024 * TODO: validate the interface and mac address!
6025 * Otherwise, there's a race condition as soon as
6026 * the kernel starts sending station notifications.
6029 if (!tb
[NL80211_ATTR_STA_INFO
]) {
6030 wpa_printf(MSG_DEBUG
, "sta stats missing!");
6033 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
6034 tb
[NL80211_ATTR_STA_INFO
],
6036 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
6040 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
6041 data
->inactive_msec
=
6042 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
6043 if (stats
[NL80211_STA_INFO_RX_BYTES
])
6044 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
6045 if (stats
[NL80211_STA_INFO_TX_BYTES
])
6046 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
6047 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
6049 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
6050 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
6052 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
6057 static int i802_read_sta_data(void *priv
, struct hostap_sta_driver_data
*data
,
6060 struct i802_bss
*bss
= priv
;
6061 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6064 os_memset(data
, 0, sizeof(*data
));
6065 msg
= nlmsg_alloc();
6069 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
6071 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6072 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6074 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
6080 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
6081 int cw_min
, int cw_max
, int burst_time
)
6083 struct i802_bss
*bss
= priv
;
6084 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6086 struct nlattr
*txq
, *params
;
6088 msg
= nlmsg_alloc();
6092 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
6094 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6096 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
6098 goto nla_put_failure
;
6100 /* We are only sending parameters for a single TXQ at a time */
6101 params
= nla_nest_start(msg
, 1);
6103 goto nla_put_failure
;
6107 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
6110 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
6113 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
6116 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
6119 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
6120 * 32 usec, so need to convert the value here. */
6121 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
6122 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
6123 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
6124 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
6126 nla_nest_end(msg
, params
);
6128 nla_nest_end(msg
, txq
);
6130 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
6137 static int i802_set_sta_vlan(void *priv
, const u8
*addr
,
6138 const char *ifname
, int vlan_id
)
6140 struct i802_bss
*bss
= priv
;
6141 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6145 msg
= nlmsg_alloc();
6149 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
6151 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6152 if_nametoindex(bss
->ifname
));
6153 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6154 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
6155 if_nametoindex(ifname
));
6157 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6159 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
6160 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
6161 MAC2STR(addr
), ifname
, vlan_id
, ret
,
6169 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
6171 struct hostap_sta_driver_data data
;
6174 data
.inactive_msec
= (unsigned long) -1;
6175 ret
= i802_read_sta_data(priv
, &data
, addr
);
6176 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
6178 return data
.inactive_msec
/ 1000;
6182 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
6191 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
6194 struct i802_bss
*bss
= priv
;
6195 struct ieee80211_mgmt mgmt
;
6197 memset(&mgmt
, 0, sizeof(mgmt
));
6198 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6199 WLAN_FC_STYPE_DEAUTH
);
6200 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6201 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6202 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6203 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
6204 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6206 sizeof(mgmt
.u
.deauth
));
6210 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
6213 struct i802_bss
*bss
= priv
;
6214 struct ieee80211_mgmt mgmt
;
6216 memset(&mgmt
, 0, sizeof(mgmt
));
6217 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6218 WLAN_FC_STYPE_DISASSOC
);
6219 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6220 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6221 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6222 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
6223 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6225 sizeof(mgmt
.u
.disassoc
));
6228 #endif /* HOSTAPD || CONFIG_AP */
6232 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
6237 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
6239 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6240 if (drv
->if_indices
[i
] == 0) {
6241 drv
->if_indices
[i
] = ifidx
;
6246 if (drv
->if_indices
!= drv
->default_if_indices
)
6247 old
= drv
->if_indices
;
6251 drv
->if_indices
= os_realloc(old
,
6252 sizeof(int) * (drv
->num_if_indices
+ 1));
6253 if (!drv
->if_indices
) {
6255 drv
->if_indices
= drv
->default_if_indices
;
6257 drv
->if_indices
= old
;
6258 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
6260 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
6263 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
6264 sizeof(drv
->default_if_indices
));
6265 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
6266 drv
->num_if_indices
++;
6270 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
6274 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6275 if (drv
->if_indices
[i
] == ifidx
) {
6276 drv
->if_indices
[i
] = 0;
6283 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
6287 for (i
= 0; i
< drv
->num_if_indices
; i
++)
6288 if (drv
->if_indices
[i
] == ifidx
)
6295 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
6296 const char *bridge_ifname
)
6298 struct i802_bss
*bss
= priv
;
6299 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6300 char name
[IFNAMSIZ
+ 1];
6302 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
6303 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
6304 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
6306 if (!if_nametoindex(name
)) {
6307 if (nl80211_create_iface(drv
, name
,
6308 NL80211_IFTYPE_AP_VLAN
,
6311 if (bridge_ifname
&&
6312 linux_br_add_if(drv
->global
->ioctl_sock
,
6313 bridge_ifname
, name
) < 0)
6316 linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1);
6317 return i802_set_sta_vlan(priv
, addr
, name
, 0);
6319 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
6320 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
6326 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
6328 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
6329 struct sockaddr_ll lladdr
;
6330 unsigned char buf
[3000];
6332 socklen_t fromlen
= sizeof(lladdr
);
6334 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
6335 (struct sockaddr
*)&lladdr
, &fromlen
);
6341 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
6342 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
6346 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
6347 struct i802_bss
*bss
,
6348 const char *brname
, const char *ifname
)
6351 char in_br
[IFNAMSIZ
];
6353 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
6354 ifindex
= if_nametoindex(brname
);
6357 * Bridge was configured, but the bridge device does
6358 * not exist. Try to add it now.
6360 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
6361 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
6362 "bridge interface %s: %s",
6363 brname
, strerror(errno
));
6366 bss
->added_bridge
= 1;
6367 add_ifidx(drv
, if_nametoindex(brname
));
6370 if (linux_br_get(in_br
, ifname
) == 0) {
6371 if (os_strcmp(in_br
, brname
) == 0)
6372 return 0; /* already in the bridge */
6374 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
6375 "bridge %s", ifname
, in_br
);
6376 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
6378 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
6379 "remove interface %s from bridge "
6381 ifname
, brname
, strerror(errno
));
6386 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
6388 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
6389 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
6390 "into bridge %s: %s",
6391 ifname
, brname
, strerror(errno
));
6394 bss
->added_if_into_bridge
= 1;
6400 static void *i802_init(struct hostapd_data
*hapd
,
6401 struct wpa_init_params
*params
)
6403 struct wpa_driver_nl80211_data
*drv
;
6404 struct i802_bss
*bss
;
6406 char brname
[IFNAMSIZ
];
6407 int ifindex
, br_ifindex
;
6410 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
6411 params
->global_priv
);
6416 drv
->nlmode
= NL80211_IFTYPE_AP
;
6417 drv
->eapol_sock
= -1;
6419 if (linux_br_get(brname
, params
->ifname
) == 0) {
6420 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
6421 params
->ifname
, brname
);
6422 br_ifindex
= if_nametoindex(brname
);
6428 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
6429 drv
->if_indices
= drv
->default_if_indices
;
6430 for (i
= 0; i
< params
->num_bridge
; i
++) {
6431 if (params
->bridge
[i
]) {
6432 ifindex
= if_nametoindex(params
->bridge
[i
]);
6434 add_ifidx(drv
, ifindex
);
6435 if (ifindex
== br_ifindex
)
6439 if (!br_added
&& br_ifindex
&&
6440 (params
->num_bridge
== 0 || !params
->bridge
[0]))
6441 add_ifidx(drv
, br_ifindex
);
6443 /* start listening for EAPOL on the default AP interface */
6444 add_ifidx(drv
, drv
->ifindex
);
6446 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
6449 if (params
->bssid
) {
6450 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6455 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
6456 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
6457 "into AP mode", bss
->ifname
);
6461 if (params
->num_bridge
&& params
->bridge
[0] &&
6462 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
6465 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
6468 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
6469 if (drv
->eapol_sock
< 0) {
6470 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
6474 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
6476 printf("Could not register read socket for eapol\n");
6480 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6487 wpa_driver_nl80211_deinit(bss
);
6492 static void i802_deinit(void *priv
)
6494 wpa_driver_nl80211_deinit(priv
);
6497 #endif /* HOSTAPD */
6500 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
6501 enum wpa_driver_if_type type
)
6504 case WPA_IF_STATION
:
6505 return NL80211_IFTYPE_STATION
;
6506 case WPA_IF_P2P_CLIENT
:
6507 case WPA_IF_P2P_GROUP
:
6508 return NL80211_IFTYPE_P2P_CLIENT
;
6509 case WPA_IF_AP_VLAN
:
6510 return NL80211_IFTYPE_AP_VLAN
;
6512 return NL80211_IFTYPE_AP
;
6514 return NL80211_IFTYPE_P2P_GO
;
6522 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
6524 struct wpa_driver_nl80211_data
*drv
;
6525 dl_list_for_each(drv
, &global
->interfaces
,
6526 struct wpa_driver_nl80211_data
, list
) {
6527 if (os_memcmp(addr
, drv
->addr
, ETH_ALEN
) == 0)
6534 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
6542 os_memcpy(new_addr
, drv
->addr
, ETH_ALEN
);
6543 for (idx
= 0; idx
< 64; idx
++) {
6544 new_addr
[0] = drv
->addr
[0] | 0x02;
6545 new_addr
[0] ^= idx
<< 2;
6546 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
6552 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
6553 MACSTR
, MAC2STR(new_addr
));
6558 #endif /* CONFIG_P2P */
6561 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
6562 const char *ifname
, const u8
*addr
,
6563 void *bss_ctx
, void **drv_priv
,
6564 char *force_ifname
, u8
*if_addr
,
6567 struct i802_bss
*bss
= priv
;
6568 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6571 struct i802_bss
*new_bss
= NULL
;
6573 if (type
== WPA_IF_AP_BSS
) {
6574 new_bss
= os_zalloc(sizeof(*new_bss
));
6575 if (new_bss
== NULL
)
6578 #endif /* HOSTAPD */
6581 os_memcpy(if_addr
, addr
, ETH_ALEN
);
6582 ifidx
= nl80211_create_iface(drv
, ifname
,
6583 wpa_driver_nl80211_if_type(type
), addr
,
6588 #endif /* HOSTAPD */
6593 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6595 nl80211_remove_iface(drv
, ifidx
);
6601 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
6602 type
== WPA_IF_P2P_GO
)) {
6603 /* Enforce unique P2P Interface Address */
6604 u8 new_addr
[ETH_ALEN
], own_addr
[ETH_ALEN
];
6606 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6608 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
6610 nl80211_remove_iface(drv
, ifidx
);
6613 if (os_memcmp(own_addr
, new_addr
, ETH_ALEN
) == 0) {
6614 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
6615 "for P2P group interface");
6616 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
6617 nl80211_remove_iface(drv
, ifidx
);
6620 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
6622 nl80211_remove_iface(drv
, ifidx
);
6626 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
6628 #endif /* CONFIG_P2P */
6632 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
6633 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
6634 "interface %s to a bridge %s", ifname
, bridge
);
6635 nl80211_remove_iface(drv
, ifidx
);
6640 if (type
== WPA_IF_AP_BSS
) {
6641 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
6643 nl80211_remove_iface(drv
, ifidx
);
6647 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
6648 new_bss
->ifindex
= ifidx
;
6650 new_bss
->next
= drv
->first_bss
.next
;
6651 drv
->first_bss
.next
= new_bss
;
6653 *drv_priv
= new_bss
;
6655 #endif /* HOSTAPD */
6658 drv
->global
->if_add_ifindex
= ifidx
;
6664 static int wpa_driver_nl80211_if_remove(void *priv
,
6665 enum wpa_driver_if_type type
,
6668 struct i802_bss
*bss
= priv
;
6669 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6670 int ifindex
= if_nametoindex(ifname
);
6672 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d",
6673 __func__
, type
, ifname
, ifindex
);
6678 if (bss
->added_if_into_bridge
) {
6679 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
6681 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6682 "interface %s from bridge %s: %s",
6683 bss
->ifname
, bss
->brname
, strerror(errno
));
6685 if (bss
->added_bridge
) {
6686 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
6687 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6689 bss
->brname
, strerror(errno
));
6691 #endif /* HOSTAPD */
6693 nl80211_remove_iface(drv
, ifindex
);
6696 if (type
!= WPA_IF_AP_BSS
)
6699 if (bss
!= &drv
->first_bss
) {
6700 struct i802_bss
*tbss
;
6702 for (tbss
= &drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
6703 if (tbss
->next
== bss
) {
6704 tbss
->next
= bss
->next
;
6711 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
6712 "BSS %p in the list", __func__
, bss
);
6714 #endif /* HOSTAPD */
6720 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
6722 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6723 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6725 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6726 genlmsg_attrlen(gnlh
, 0), NULL
);
6727 if (tb
[NL80211_ATTR_COOKIE
])
6728 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
6733 static int nl80211_send_frame_cmd(struct wpa_driver_nl80211_data
*drv
,
6734 unsigned int freq
, unsigned int wait
,
6735 const u8
*buf
, size_t buf_len
,
6742 msg
= nlmsg_alloc();
6746 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
6748 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6749 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6751 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
6752 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
6753 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
6756 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6759 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
6760 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
6762 goto nla_put_failure
;
6764 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX command accepted; "
6765 "cookie 0x%llx", (long long unsigned int) cookie
);
6768 *cookie_out
= cookie
;
6776 static int wpa_driver_nl80211_send_action(void *priv
, unsigned int freq
,
6777 unsigned int wait_time
,
6778 const u8
*dst
, const u8
*src
,
6780 const u8
*data
, size_t data_len
)
6782 struct i802_bss
*bss
= priv
;
6783 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6786 struct ieee80211_hdr
*hdr
;
6788 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
6789 "wait=%d ms)", drv
->ifindex
, wait_time
);
6791 buf
= os_zalloc(24 + data_len
);
6794 os_memcpy(buf
+ 24, data
, data_len
);
6795 hdr
= (struct ieee80211_hdr
*) buf
;
6796 hdr
->frame_control
=
6797 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
6798 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
6799 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
6800 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
6802 if (is_ap_interface(drv
->nlmode
))
6803 ret
= wpa_driver_nl80211_send_mlme(priv
, buf
, 24 + data_len
);
6805 ret
= nl80211_send_frame_cmd(drv
, freq
, wait_time
, buf
,
6807 &drv
->send_action_cookie
);
6814 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
6816 struct i802_bss
*bss
= priv
;
6817 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6821 msg
= nlmsg_alloc();
6825 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
6827 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6828 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
6830 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6833 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
6834 "(%s)", ret
, strerror(-ret
));
6841 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
6842 unsigned int duration
)
6844 struct i802_bss
*bss
= priv
;
6845 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6850 msg
= nlmsg_alloc();
6854 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
6856 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6857 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6858 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
6861 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
6863 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
6864 "0x%llx for freq=%u MHz duration=%u",
6865 (long long unsigned int) cookie
, freq
, duration
);
6866 drv
->remain_on_chan_cookie
= cookie
;
6867 drv
->pending_remain_on_chan
= 1;
6870 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
6871 "(freq=%d duration=%u): %d (%s)",
6872 freq
, duration
, ret
, strerror(-ret
));
6878 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
6880 struct i802_bss
*bss
= priv
;
6881 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6885 if (!drv
->pending_remain_on_chan
) {
6886 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
6891 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
6893 (long long unsigned int) drv
->remain_on_chan_cookie
);
6895 msg
= nlmsg_alloc();
6899 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
6901 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6902 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
6904 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6907 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
6908 "%d (%s)", ret
, strerror(-ret
));
6914 static int wpa_driver_nl80211_probe_req_report(void *priv
, int report
)
6916 struct i802_bss
*bss
= priv
;
6917 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6920 if (drv
->nl_preq
.handle
) {
6921 eloop_unregister_read_sock(
6922 nl_socket_get_fd(drv
->nl_preq
.handle
));
6923 nl_destroy_handles(&drv
->nl_preq
);
6928 if (drv
->nl_preq
.handle
) {
6929 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
6934 if (nl_create_handles(&drv
->nl_preq
, drv
->global
->nl_cb
, "preq"))
6937 if (nl80211_register_frame(drv
, drv
->nl_preq
.handle
,
6938 (WLAN_FC_TYPE_MGMT
<< 2) |
6939 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
6943 eloop_register_read_sock(nl_socket_get_fd(drv
->nl_preq
.handle
),
6944 wpa_driver_nl80211_event_receive
, drv
,
6945 drv
->nl_preq
.handle
);
6950 nl_destroy_handles(&drv
->nl_preq
);
6955 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
6956 int ifindex
, int disabled
)
6959 struct nlattr
*bands
, *band
;
6962 msg
= nlmsg_alloc();
6966 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
6967 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
6969 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
6971 goto nla_put_failure
;
6974 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6975 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6976 * rates. All 5 GHz rates are left enabled.
6978 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
6980 goto nla_put_failure
;
6981 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
6982 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
6983 nla_nest_end(msg
, band
);
6985 nla_nest_end(msg
, bands
);
6987 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6990 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
6991 "(%s)", ret
, strerror(-ret
));
7002 static int wpa_driver_nl80211_disable_11b_rates(void *priv
, int disabled
)
7004 struct i802_bss
*bss
= priv
;
7005 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7006 drv
->disable_11b_rates
= disabled
;
7007 return nl80211_disable_11b_rates(drv
, drv
->ifindex
, disabled
);
7011 static int wpa_driver_nl80211_deinit_ap(void *priv
)
7013 struct i802_bss
*bss
= priv
;
7014 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7015 if (!is_ap_interface(drv
->nlmode
))
7017 wpa_driver_nl80211_del_beacon(drv
);
7018 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
7022 static void wpa_driver_nl80211_resume(void *priv
)
7024 struct i802_bss
*bss
= priv
;
7025 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7026 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
7027 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on "
7033 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
7034 const u8
*ies
, size_t ies_len
)
7036 struct i802_bss
*bss
= priv
;
7037 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7041 u8 own_addr
[ETH_ALEN
];
7043 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7048 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
7049 "action %d", action
);
7054 * Action frame payload:
7055 * Category[1] = 6 (Fast BSS Transition)
7056 * Action[1] = 1 (Fast BSS Transition Request)
7062 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
7063 data
= os_malloc(data_len
);
7067 *pos
++ = 0x06; /* FT Action category */
7069 os_memcpy(pos
, own_addr
, ETH_ALEN
);
7071 os_memcpy(pos
, target_ap
, ETH_ALEN
);
7073 os_memcpy(pos
, ies
, ies_len
);
7075 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
7076 drv
->bssid
, own_addr
, drv
->bssid
,
7084 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
7086 struct i802_bss
*bss
= priv
;
7087 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7088 struct nl_msg
*msg
, *cqm
= NULL
;
7090 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
7091 "hysteresis=%d", threshold
, hysteresis
);
7093 msg
= nlmsg_alloc();
7097 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
7099 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
7101 cqm
= nlmsg_alloc();
7105 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
7106 NLA_PUT_U32(cqm
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
7107 nla_put_nested(msg
, NL80211_ATTR_CQM
, cqm
);
7109 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
7121 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
7123 struct i802_bss
*bss
= priv
;
7124 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7127 os_memset(si
, 0, sizeof(*si
));
7128 res
= nl80211_get_link_signal(drv
, si
);
7132 return nl80211_get_link_noise(drv
, si
);
7136 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
7139 struct i802_bss
*bss
= priv
;
7140 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7141 return wpa_driver_nl80211_send_frame(drv
, data
, data_len
, encrypt
);
7145 static int nl80211_set_param(void *priv
, const char *param
)
7147 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
7152 if (os_strstr(param
, "use_p2p_group_interface=1")) {
7153 struct i802_bss
*bss
= priv
;
7154 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7156 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
7158 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
7159 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
7161 #endif /* CONFIG_P2P */
7167 static void * nl80211_global_init(void)
7169 struct nl80211_global
*global
;
7170 struct netlink_config
*cfg
;
7172 global
= os_zalloc(sizeof(*global
));
7175 global
->ioctl_sock
= -1;
7176 dl_list_init(&global
->interfaces
);
7177 global
->if_add_ifindex
= -1;
7179 cfg
= os_zalloc(sizeof(*cfg
));
7184 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
7185 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
7186 global
->netlink
= netlink_init(cfg
);
7187 if (global
->netlink
== NULL
) {
7192 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
7195 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
7196 if (global
->ioctl_sock
< 0) {
7197 perror("socket(PF_INET,SOCK_DGRAM)");
7204 nl80211_global_deinit(global
);
7209 static void nl80211_global_deinit(void *priv
)
7211 struct nl80211_global
*global
= priv
;
7214 if (!dl_list_empty(&global
->interfaces
)) {
7215 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
7216 "nl80211_global_deinit",
7217 dl_list_len(&global
->interfaces
));
7220 if (global
->netlink
)
7221 netlink_deinit(global
->netlink
);
7223 if (global
->nl80211
)
7224 genl_family_put(global
->nl80211
);
7225 nl_destroy_handles(&global
->nl
);
7228 nl_cb_put(global
->nl_cb
);
7230 if (global
->ioctl_sock
>= 0)
7231 close(global
->ioctl_sock
);
7237 static const char * nl80211_get_radio_name(void *priv
)
7239 struct i802_bss
*bss
= priv
;
7240 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7241 return drv
->phyname
;
7245 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
7250 msg
= nlmsg_alloc();
7254 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
7256 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
7258 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
7260 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7262 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
7268 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
7270 struct i802_bss
*bss
= priv
;
7271 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
7272 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
7276 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
7278 struct i802_bss
*bss
= priv
;
7279 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
7281 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
7285 static int nl80211_flush_pmkid(void *priv
)
7287 struct i802_bss
*bss
= priv
;
7288 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
7289 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
7293 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
7294 const u8
*replay_ctr
)
7296 struct i802_bss
*bss
= priv
;
7297 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7298 struct nlattr
*replay_nested
;
7301 msg
= nlmsg_alloc();
7305 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
7307 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
7309 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
7311 goto nla_put_failure
;
7313 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
7314 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
7315 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
7318 nla_nest_end(msg
, replay_nested
);
7320 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7327 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
7330 struct i802_bss
*bss
= priv
;
7332 struct ieee80211_hdr hdr
;
7334 } STRUCT_PACKED nulldata
;
7337 /* Send data frame to poll STA and check whether this frame is ACKed */
7339 os_memset(&nulldata
, 0, sizeof(nulldata
));
7342 nulldata
.hdr
.frame_control
=
7343 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7344 WLAN_FC_STYPE_QOS_NULL
);
7345 size
= sizeof(nulldata
);
7347 nulldata
.hdr
.frame_control
=
7348 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7349 WLAN_FC_STYPE_NULLFUNC
);
7350 size
= sizeof(struct ieee80211_hdr
);
7353 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
7354 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
7355 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
7356 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
7358 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
) < 0)
7359 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
7366 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
7367 u8 dialog_token
, u16 status_code
,
7368 const u8
*buf
, size_t len
)
7370 struct i802_bss
*bss
= priv
;
7371 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7374 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
7380 msg
= nlmsg_alloc();
7384 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_MGMT
);
7385 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7386 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
7387 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
);
7388 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
);
7389 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
);
7390 NLA_PUT(msg
, NL80211_ATTR_IE
, len
, buf
);
7392 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7400 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
7402 struct i802_bss
*bss
= priv
;
7403 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7405 enum nl80211_tdls_operation nl80211_oper
;
7407 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
7411 case TDLS_DISCOVERY_REQ
:
7412 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
7415 nl80211_oper
= NL80211_TDLS_SETUP
;
7418 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
7420 case TDLS_ENABLE_LINK
:
7421 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
7423 case TDLS_DISABLE_LINK
:
7424 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
7434 msg
= nlmsg_alloc();
7438 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_OPER
);
7439 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
);
7440 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7441 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
7443 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7450 #endif /* CONFIG TDLS */
7453 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
7455 .desc
= "Linux nl80211/cfg80211",
7456 .get_bssid
= wpa_driver_nl80211_get_bssid
,
7457 .get_ssid
= wpa_driver_nl80211_get_ssid
,
7458 .set_key
= wpa_driver_nl80211_set_key
,
7459 .scan2
= wpa_driver_nl80211_scan
,
7460 .sched_scan
= wpa_driver_nl80211_sched_scan
,
7461 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
7462 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
7463 .deauthenticate
= wpa_driver_nl80211_deauthenticate
,
7464 .disassociate
= wpa_driver_nl80211_disassociate
,
7465 .authenticate
= wpa_driver_nl80211_authenticate
,
7466 .associate
= wpa_driver_nl80211_associate
,
7467 .global_init
= nl80211_global_init
,
7468 .global_deinit
= nl80211_global_deinit
,
7469 .init2
= wpa_driver_nl80211_init
,
7470 .deinit
= wpa_driver_nl80211_deinit
,
7471 .get_capa
= wpa_driver_nl80211_get_capa
,
7472 .set_operstate
= wpa_driver_nl80211_set_operstate
,
7473 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
7474 .set_country
= wpa_driver_nl80211_set_country
,
7475 .set_ap
= wpa_driver_nl80211_set_ap
,
7476 .if_add
= wpa_driver_nl80211_if_add
,
7477 .if_remove
= wpa_driver_nl80211_if_remove
,
7478 .send_mlme
= wpa_driver_nl80211_send_mlme
,
7479 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
7480 .sta_add
= wpa_driver_nl80211_sta_add
,
7481 .sta_remove
= wpa_driver_nl80211_sta_remove
,
7482 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
7483 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
7485 .hapd_init
= i802_init
,
7486 .hapd_deinit
= i802_deinit
,
7487 .set_wds_sta
= i802_set_wds_sta
,
7488 #endif /* HOSTAPD */
7489 #if defined(HOSTAPD) || defined(CONFIG_AP)
7490 .get_seqnum
= i802_get_seqnum
,
7491 .flush
= i802_flush
,
7492 .read_sta_data
= i802_read_sta_data
,
7493 .get_inact_sec
= i802_get_inact_sec
,
7494 .sta_clear_stats
= i802_sta_clear_stats
,
7495 .set_rts
= i802_set_rts
,
7496 .set_frag
= i802_set_frag
,
7497 .set_tx_queue_params
= i802_set_tx_queue_params
,
7498 .set_sta_vlan
= i802_set_sta_vlan
,
7499 .set_rate_sets
= i802_set_rate_sets
,
7500 .sta_deauth
= i802_sta_deauth
,
7501 .sta_disassoc
= i802_sta_disassoc
,
7502 #endif /* HOSTAPD || CONFIG_AP */
7503 .set_freq
= i802_set_freq
,
7504 .send_action
= wpa_driver_nl80211_send_action
,
7505 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
7506 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
7507 .cancel_remain_on_channel
=
7508 wpa_driver_nl80211_cancel_remain_on_channel
,
7509 .probe_req_report
= wpa_driver_nl80211_probe_req_report
,
7510 .disable_11b_rates
= wpa_driver_nl80211_disable_11b_rates
,
7511 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
7512 .resume
= wpa_driver_nl80211_resume
,
7513 .send_ft_action
= nl80211_send_ft_action
,
7514 .signal_monitor
= nl80211_signal_monitor
,
7515 .signal_poll
= nl80211_signal_poll
,
7516 .send_frame
= nl80211_send_frame
,
7517 .set_param
= nl80211_set_param
,
7518 .get_radio_name
= nl80211_get_radio_name
,
7519 .add_pmkid
= nl80211_add_pmkid
,
7520 .remove_pmkid
= nl80211_remove_pmkid
,
7521 .flush_pmkid
= nl80211_flush_pmkid
,
7522 .set_rekey_info
= nl80211_set_rekey_info
,
7523 .poll_client
= nl80211_poll_client
,
7525 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
7526 .tdls_oper
= nl80211_tdls_oper
,
7527 #endif /* CONFIG_TDLS */