2 * Driver interaction with Linux nl80211/cfg80211
3 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2003-2004, Instant802 Networks, Inc.
5 * Copyright (c) 2005-2006, Devicescape Software, Inc.
6 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (c) 2009-2010, Atheros Communications
9 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
14 #include <sys/types.h>
17 #include <netlink/genl/genl.h>
18 #include <netlink/genl/ctrl.h>
19 #ifdef CONFIG_LIBNL3_ROUTE
20 #include <netlink/route/neighbour.h>
21 #endif /* CONFIG_LIBNL3_ROUTE */
22 #include <linux/rtnetlink.h>
23 #include <netpacket/packet.h>
24 #include <linux/errqueue.h>
28 #include "common/qca-vendor.h"
29 #include "common/qca-vendor-attr.h"
30 #include "common/ieee802_11_defs.h"
31 #include "common/ieee802_11_common.h"
32 #include "common/wpa_common.h"
33 #include "l2_packet/l2_packet.h"
35 #include "linux_defines.h"
36 #include "linux_ioctl.h"
38 #include "radiotap_iter.h"
40 #include "driver_nl80211.h"
43 #ifndef NETLINK_CAP_ACK
44 #define NETLINK_CAP_ACK 10
45 #endif /* NETLINK_CAP_ACK */
46 /* support for extack if compilation headers are too old */
47 #ifndef NETLINK_EXT_ACK
48 #define NETLINK_EXT_ACK 11
56 NLMSGERR_ATTR_MAX
= __NLMSGERR_ATTR_MAX
- 1
60 #define NLM_F_CAPPED 0x100
62 #ifndef NLM_F_ACK_TLVS
63 #define NLM_F_ACK_TLVS 0x200
66 #define SOL_NETLINK 270
71 /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
72 #undef nl_socket_set_nonblocking
73 #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
78 static struct nl_sock
* nl_create_handle(struct nl_cb
*cb
, const char *dbg
)
80 struct nl_sock
*handle
;
82 handle
= nl_socket_alloc_cb(cb
);
84 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
85 "callbacks (%s)", dbg
);
89 if (genl_connect(handle
)) {
90 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect to generic "
92 nl_socket_free(handle
);
100 static void nl_destroy_handles(struct nl_sock
**handle
)
104 nl_socket_free(*handle
);
110 #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
112 #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
115 static void nl80211_register_eloop_read(struct nl_sock
**handle
,
116 eloop_sock_handler handler
,
117 void *eloop_data
, int persist
)
120 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
121 * by default. It is possible to hit that limit in some cases where
122 * operations are blocked, e.g., with a burst of Deauthentication frames
123 * to hostapd and STA entry deletion. Try to increase the buffer to make
124 * this less likely to occur.
128 err
= nl_socket_set_buffer_size(*handle
, 262144, 0);
130 wpa_printf(MSG_DEBUG
,
131 "nl80211: Could not set nl_socket RX buffer size: %s",
133 /* continue anyway with the default (smaller) buffer */
136 nl_socket_set_nonblocking(*handle
);
137 eloop_register_read_sock(nl_socket_get_fd(*handle
), handler
,
138 eloop_data
, *handle
);
140 *handle
= (void *) (((intptr_t) *handle
) ^
141 ELOOP_SOCKET_INVALID
);
145 static void nl80211_destroy_eloop_handle(struct nl_sock
**handle
, int persist
)
148 *handle
= (void *) (((intptr_t) *handle
) ^
149 ELOOP_SOCKET_INVALID
);
150 eloop_unregister_read_sock(nl_socket_get_fd(*handle
));
151 nl_destroy_handles(handle
);
155 static void nl80211_global_deinit(void *priv
);
156 static void nl80211_check_global(struct nl80211_global
*global
);
158 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
);
159 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
160 struct hostapd_freq_params
*freq
);
163 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
164 const u8
*set_addr
, int first
,
165 const char *driver_params
);
166 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
167 unsigned int freq
, unsigned int wait
,
168 const u8
*buf
, size_t buf_len
,
170 int no_cck
, int no_ack
, int offchanok
,
171 const u16
*csa_offs
, size_t csa_offs_len
);
172 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
,
177 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
179 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
181 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
184 static int nl80211_set_channel(struct i802_bss
*bss
,
185 struct hostapd_freq_params
*freq
, int set_chan
);
186 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
187 int ifindex
, int disabled
);
189 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
192 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
);
193 static int nl80211_set_param(void *priv
, const char *param
);
195 static int nl80211_put_mesh_config(struct nl_msg
*msg
,
196 struct wpa_driver_mesh_bss_params
*params
);
197 #endif /* CONFIG_MESH */
198 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
202 /* Converts nl80211_chan_width to a common format */
203 enum chan_width
convert2width(int width
)
206 case NL80211_CHAN_WIDTH_20_NOHT
:
207 return CHAN_WIDTH_20_NOHT
;
208 case NL80211_CHAN_WIDTH_20
:
209 return CHAN_WIDTH_20
;
210 case NL80211_CHAN_WIDTH_40
:
211 return CHAN_WIDTH_40
;
212 case NL80211_CHAN_WIDTH_80
:
213 return CHAN_WIDTH_80
;
214 case NL80211_CHAN_WIDTH_80P80
:
215 return CHAN_WIDTH_80P80
;
216 case NL80211_CHAN_WIDTH_160
:
217 return CHAN_WIDTH_160
;
219 return CHAN_WIDTH_UNKNOWN
;
223 int is_ap_interface(enum nl80211_iftype nlmode
)
225 return nlmode
== NL80211_IFTYPE_AP
||
226 nlmode
== NL80211_IFTYPE_P2P_GO
;
230 int is_sta_interface(enum nl80211_iftype nlmode
)
232 return nlmode
== NL80211_IFTYPE_STATION
||
233 nlmode
== NL80211_IFTYPE_P2P_CLIENT
;
237 static int is_p2p_net_interface(enum nl80211_iftype nlmode
)
239 return nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
240 nlmode
== NL80211_IFTYPE_P2P_GO
;
244 struct i802_bss
* get_bss_ifindex(struct wpa_driver_nl80211_data
*drv
,
247 struct i802_bss
*bss
;
249 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
250 if (bss
->ifindex
== ifindex
)
258 static int is_mesh_interface(enum nl80211_iftype nlmode
)
260 return nlmode
== NL80211_IFTYPE_MESH_POINT
;
264 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data
*drv
)
267 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
269 os_memset(drv
->bssid
, 0, ETH_ALEN
);
270 drv
->first_bss
->freq
= 0;
275 static int ack_handler(struct nl_msg
*msg
, void *arg
)
282 static int finish_handler(struct nl_msg
*msg
, void *arg
)
289 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
292 struct nlmsghdr
*nlh
= (struct nlmsghdr
*) err
- 1;
293 int len
= nlh
->nlmsg_len
;
294 struct nlattr
*attrs
;
295 struct nlattr
*tb
[NLMSGERR_ATTR_MAX
+ 1];
297 int ack_len
= sizeof(*nlh
) + sizeof(int) + sizeof(*nlh
);
301 if (!(nlh
->nlmsg_flags
& NLM_F_ACK_TLVS
))
304 if (!(nlh
->nlmsg_flags
& NLM_F_CAPPED
))
305 ack_len
+= err
->msg
.nlmsg_len
- sizeof(*nlh
);
310 attrs
= (void *) ((unsigned char *) nlh
+ ack_len
);
313 nla_parse(tb
, NLMSGERR_ATTR_MAX
, attrs
, len
, NULL
);
314 if (tb
[NLMSGERR_ATTR_MSG
]) {
315 len
= strnlen((char *) nla_data(tb
[NLMSGERR_ATTR_MSG
]),
316 nla_len(tb
[NLMSGERR_ATTR_MSG
]));
317 wpa_printf(MSG_ERROR
, "nl80211: kernel reports: %*s",
318 len
, (char *) nla_data(tb
[NLMSGERR_ATTR_MSG
]));
325 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
331 static void nl80211_nlmsg_clear(struct nl_msg
*msg
)
334 * Clear nlmsg data, e.g., to make sure key material is not left in
335 * heap memory for unnecessarily long time.
338 struct nlmsghdr
*hdr
= nlmsg_hdr(msg
);
339 void *data
= nlmsg_data(hdr
);
341 * This would use nlmsg_datalen() or the older nlmsg_len() if
342 * only libnl were to maintain a stable API.. Neither will work
343 * with all released versions, so just calculate the length
346 int len
= hdr
->nlmsg_len
- NLMSG_HDRLEN
;
348 os_memset(data
, 0, len
);
353 static int send_and_recv(struct nl80211_global
*global
,
354 struct nl_sock
*nl_handle
, struct nl_msg
*msg
,
355 int (*valid_handler
)(struct nl_msg
*, void *),
359 int err
= -ENOMEM
, opt
;
364 cb
= nl_cb_clone(global
->nl_cb
);
368 /* try to set NETLINK_EXT_ACK to 1, ignoring errors */
370 setsockopt(nl_socket_get_fd(nl_handle
), SOL_NETLINK
,
371 NETLINK_EXT_ACK
, &opt
, sizeof(opt
));
373 /* try to set NETLINK_CAP_ACK to 1, ignoring errors */
375 setsockopt(nl_socket_get_fd(nl_handle
), SOL_NETLINK
,
376 NETLINK_CAP_ACK
, &opt
, sizeof(opt
));
378 err
= nl_send_auto_complete(nl_handle
, msg
);
381 "nl80211: nl_send_auto_complete() failed: %s",
383 /* Need to convert libnl error code to an errno value. For now,
384 * just hardcode this to EBADF; the real error reason is shown
385 * in that error print above. */
392 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
393 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
394 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
397 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
398 valid_handler
, valid_data
);
401 int res
= nl_recvmsgs(nl_handle
, cb
);
403 if (res
== -NLE_DUMP_INTR
) {
404 /* Most likely one of the nl80211 dump routines hit a
405 * case where internal results changed while the dump
406 * was being sent. The most common known case for this
407 * is scan results fetching while associated were every
408 * received Beacon frame from the AP may end up
409 * incrementing bss_generation. This
410 * NL80211_CMD_GET_SCAN case tries again in the caller;
411 * other cases (of which there are no known common ones)
412 * will stop and return an error. */
413 wpa_printf(MSG_DEBUG
, "nl80211: %s; convert to -EAGAIN",
416 } else if (res
< 0) {
418 "nl80211: %s->nl_recvmsgs failed: %d (%s)",
419 __func__
, res
, nl_geterror(res
));
424 if (!valid_handler
&& valid_data
== (void *) -1)
425 nl80211_nlmsg_clear(msg
);
431 int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
433 int (*valid_handler
)(struct nl_msg
*, void *),
436 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
437 valid_handler
, valid_data
);
447 static int family_handler(struct nl_msg
*msg
, void *arg
)
449 struct family_data
*res
= arg
;
450 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
451 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
452 struct nlattr
*mcgrp
;
455 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
456 genlmsg_attrlen(gnlh
, 0), NULL
);
457 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
460 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
461 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
462 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
463 nla_len(mcgrp
), NULL
);
464 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
465 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
466 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
468 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
470 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
478 static int nl_get_multicast_id(struct nl80211_global
*global
,
479 const char *family
, const char *group
)
483 struct family_data res
= { group
, -ENOENT
};
488 if (!genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
489 0, 0, CTRL_CMD_GETFAMILY
, 0) ||
490 nla_put_string(msg
, CTRL_ATTR_FAMILY_NAME
, family
)) {
495 ret
= send_and_recv(global
, global
->nl
, msg
, family_handler
, &res
);
502 void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
503 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
507 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
512 static int nl80211_set_iface_id(struct nl_msg
*msg
, struct i802_bss
*bss
)
514 if (bss
->wdev_id_set
)
515 return nla_put_u64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
516 return nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
520 struct nl_msg
* nl80211_cmd_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
528 if (!nl80211_cmd(bss
->drv
, msg
, flags
, cmd
) ||
529 nl80211_set_iface_id(msg
, bss
) < 0) {
538 static struct nl_msg
*
539 nl80211_ifindex_msg(struct wpa_driver_nl80211_data
*drv
, int ifindex
,
540 int flags
, uint8_t cmd
)
548 if (!nl80211_cmd(drv
, msg
, flags
, cmd
) ||
549 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, ifindex
)) {
558 struct nl_msg
* nl80211_drv_msg(struct wpa_driver_nl80211_data
*drv
, int flags
,
561 return nl80211_ifindex_msg(drv
, drv
->ifindex
, flags
, cmd
);
565 struct nl_msg
* nl80211_bss_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
567 return nl80211_ifindex_msg(bss
->drv
, bss
->ifindex
, flags
, cmd
);
571 struct wiphy_idx_data
{
573 enum nl80211_iftype nlmode
;
578 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
580 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
581 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
582 struct wiphy_idx_data
*info
= arg
;
584 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
585 genlmsg_attrlen(gnlh
, 0), NULL
);
587 if (tb
[NL80211_ATTR_WIPHY
])
588 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
590 if (tb
[NL80211_ATTR_IFTYPE
])
591 info
->nlmode
= nla_get_u32(tb
[NL80211_ATTR_IFTYPE
]);
593 if (tb
[NL80211_ATTR_MAC
] && info
->macaddr
)
594 os_memcpy(info
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
601 int nl80211_get_wiphy_index(struct i802_bss
*bss
)
604 struct wiphy_idx_data data
= {
609 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
612 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
613 return data
.wiphy_idx
;
618 static enum nl80211_iftype
nl80211_get_ifmode(struct i802_bss
*bss
)
621 struct wiphy_idx_data data
= {
622 .nlmode
= NL80211_IFTYPE_UNSPECIFIED
,
626 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
627 return NL80211_IFTYPE_UNSPECIFIED
;
629 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
631 return NL80211_IFTYPE_UNSPECIFIED
;
635 static int nl80211_get_macaddr(struct i802_bss
*bss
)
638 struct wiphy_idx_data data
= {
639 .macaddr
= bss
->addr
,
642 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
645 return send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
);
649 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
650 struct nl80211_wiphy_data
*w
)
659 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
) ||
660 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
)) {
665 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
667 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
668 "failed: ret=%d (%s)",
669 ret
, strerror(-ret
));
675 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
677 struct nl80211_wiphy_data
*w
= eloop_ctx
;
680 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
682 res
= nl_recvmsgs(handle
, w
->nl_cb
);
684 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
690 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
692 struct nl80211_wiphy_data
*w
= arg
;
693 struct wpa_driver_nl80211_data
*drv
;
694 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
695 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
696 union wpa_event_data event
;
698 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
699 genlmsg_attrlen(gnlh
, 0), NULL
);
701 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
702 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
707 if (!tb
[NL80211_ATTR_FRAME
])
710 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
712 os_memset(&event
, 0, sizeof(event
));
713 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
714 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
715 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
722 static struct nl80211_wiphy_data
*
723 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
725 static DEFINE_DL_LIST(nl80211_wiphys
);
726 struct nl80211_wiphy_data
*w
;
727 int wiphy_idx
, found
= 0;
728 struct i802_bss
*tmp_bss
;
731 if (bss
->wiphy_data
!= NULL
)
732 return bss
->wiphy_data
;
734 wiphy_idx
= nl80211_get_wiphy_index(bss
);
736 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
737 if (w
->wiphy_idx
== wiphy_idx
)
742 w
= os_zalloc(sizeof(*w
));
745 w
->wiphy_idx
= wiphy_idx
;
746 dl_list_init(&w
->bsss
);
747 dl_list_init(&w
->drvs
);
749 /* Beacon frames not supported in IEEE 802.11ad */
750 if (ieee80211_freq_to_chan(bss
->freq
, &channel
) !=
751 HOSTAPD_MODE_IEEE80211AD
) {
752 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
757 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
759 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
760 process_beacon_event
, w
);
762 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
764 if (w
->nl_beacons
== NULL
) {
769 if (nl80211_register_beacons(bss
->drv
, w
)) {
770 nl_destroy_handles(&w
->nl_beacons
);
775 nl80211_register_eloop_read(&w
->nl_beacons
,
776 nl80211_recv_beacons
, w
, 0);
779 dl_list_add(&nl80211_wiphys
, &w
->list
);
782 /* drv entry for this bss already there? */
783 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
784 if (tmp_bss
->drv
== bss
->drv
) {
791 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
793 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
799 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
801 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
802 struct i802_bss
*tmp_bss
;
807 bss
->wiphy_data
= NULL
;
808 dl_list_del(&bss
->wiphy_list
);
810 /* still any for this drv present? */
811 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
812 if (tmp_bss
->drv
== bss
->drv
) {
817 /* if not remove it */
819 dl_list_del(&bss
->drv
->wiphy_list
);
821 if (!dl_list_empty(&w
->bsss
))
825 nl80211_destroy_eloop_handle(&w
->nl_beacons
, 0);
828 dl_list_del(&w
->list
);
833 static unsigned int nl80211_get_ifindex(void *priv
)
835 struct i802_bss
*bss
= priv
;
836 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
842 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
844 struct i802_bss
*bss
= priv
;
845 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
846 if (!drv
->associated
)
848 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
853 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
855 struct i802_bss
*bss
= priv
;
856 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
857 if (!drv
->associated
)
859 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
860 return drv
->ssid_len
;
864 static void wpa_driver_nl80211_event_newlink(
865 struct nl80211_global
*global
, struct wpa_driver_nl80211_data
*drv
,
866 int ifindex
, const char *ifname
)
868 union wpa_event_data event
;
870 if (drv
&& os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
871 if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
872 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
873 drv
->first_bss
->ifname
);
876 if (!drv
->if_removed
)
878 wpa_printf(MSG_DEBUG
, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
879 drv
->first_bss
->ifname
);
883 os_memset(&event
, 0, sizeof(event
));
884 event
.interface_status
.ifindex
= ifindex
;
885 os_strlcpy(event
.interface_status
.ifname
, ifname
,
886 sizeof(event
.interface_status
.ifname
));
887 event
.interface_status
.ievent
= EVENT_INTERFACE_ADDED
;
889 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
891 wpa_supplicant_event_global(global
->ctx
, EVENT_INTERFACE_STATUS
,
896 static void wpa_driver_nl80211_event_dellink(
897 struct nl80211_global
*global
, struct wpa_driver_nl80211_data
*drv
,
898 int ifindex
, const char *ifname
)
900 union wpa_event_data event
;
902 if (drv
&& os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
903 if (drv
->if_removed
) {
904 wpa_printf(MSG_DEBUG
, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
908 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
912 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed",
916 os_memset(&event
, 0, sizeof(event
));
917 event
.interface_status
.ifindex
= ifindex
;
918 os_strlcpy(event
.interface_status
.ifname
, ifname
,
919 sizeof(event
.interface_status
.ifname
));
920 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
922 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
924 wpa_supplicant_event_global(global
->ctx
, EVENT_INTERFACE_STATUS
,
929 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
932 int attrlen
, rta_len
;
936 attr
= (struct rtattr
*) buf
;
938 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
939 while (RTA_OK(attr
, attrlen
)) {
940 if (attr
->rta_type
== IFLA_IFNAME
) {
941 if (os_strcmp(((char *) attr
) + rta_len
,
942 drv
->first_bss
->ifname
) == 0)
947 attr
= RTA_NEXT(attr
, attrlen
);
954 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
955 int ifindex
, u8
*buf
, size_t len
)
957 if (drv
->ifindex
== ifindex
)
960 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
961 nl80211_check_global(drv
->global
);
962 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
964 if (wpa_driver_nl80211_finish_drv_init(drv
, NULL
, 0, NULL
) < 0)
973 static struct wpa_driver_nl80211_data
*
974 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
,
977 struct wpa_driver_nl80211_data
*drv
;
982 dl_list_for_each(drv
, &global
->interfaces
,
983 struct wpa_driver_nl80211_data
, list
) {
984 res
= wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
);
986 wpa_printf(MSG_DEBUG
,
987 "nl80211: Found matching own interface, but failed to complete reinitialization");
992 if (res
> 0 || have_ifidx(drv
, idx
, IFIDX_ANY
))
999 static void nl80211_refresh_mac(struct wpa_driver_nl80211_data
*drv
,
1000 int ifindex
, int notify
)
1002 struct i802_bss
*bss
;
1005 bss
= get_bss_ifindex(drv
, ifindex
);
1007 linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
1008 bss
->ifname
, addr
) < 0) {
1009 wpa_printf(MSG_DEBUG
,
1010 "nl80211: %s: failed to re-read MAC address",
1012 } else if (bss
&& os_memcmp(addr
, bss
->addr
, ETH_ALEN
) != 0) {
1013 wpa_printf(MSG_DEBUG
,
1014 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1015 MACSTR
" to " MACSTR
,
1016 ifindex
, bss
->ifname
,
1017 MAC2STR(bss
->addr
), MAC2STR(addr
));
1018 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
1020 wpa_supplicant_event(drv
->ctx
,
1021 EVENT_INTERFACE_MAC_CHANGED
, NULL
);
1026 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
1027 struct ifinfomsg
*ifi
,
1028 u8
*buf
, size_t len
)
1030 struct nl80211_global
*global
= ctx
;
1031 struct wpa_driver_nl80211_data
*drv
;
1033 struct rtattr
*attr
;
1035 char namebuf
[IFNAMSIZ
];
1036 char ifname
[IFNAMSIZ
+ 1];
1037 char extra
[100], *pos
, *end
;
1042 end
= pos
+ sizeof(extra
);
1046 attr
= (struct rtattr
*) buf
;
1047 while (RTA_OK(attr
, attrlen
)) {
1048 switch (attr
->rta_type
) {
1050 if (RTA_PAYLOAD(attr
) > IFNAMSIZ
)
1052 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
1053 ifname
[RTA_PAYLOAD(attr
)] = '\0';
1056 brid
= nla_get_u32((struct nlattr
*) attr
);
1057 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
1060 pos
+= os_snprintf(pos
, end
- pos
, " wext");
1062 case IFLA_OPERSTATE
:
1063 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
1064 nla_get_u32((struct nlattr
*) attr
));
1067 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
1068 nla_get_u32((struct nlattr
*) attr
));
1071 attr
= RTA_NEXT(attr
, attrlen
);
1073 extra
[sizeof(extra
) - 1] = '\0';
1075 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1076 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
1078 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1079 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1080 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1081 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1083 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
, &init_failed
);
1087 return; /* do not update interface state */
1089 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
1091 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1092 linux_iface_up(drv
->global
->ioctl_sock
, namebuf
) > 0) {
1093 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1094 "event since interface %s is up", namebuf
);
1095 drv
->ignore_if_down_event
= 0;
1096 /* Re-read MAC address as it may have changed */
1097 nl80211_refresh_mac(drv
, ifi
->ifi_index
, 1);
1100 wpa_printf(MSG_DEBUG
, "nl80211: Interface down (%s/%s)",
1102 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) != 0) {
1103 wpa_printf(MSG_DEBUG
,
1104 "nl80211: Not the main interface (%s) - do not indicate interface down",
1105 drv
->first_bss
->ifname
);
1106 } else if (drv
->ignore_if_down_event
) {
1107 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1108 "event generated by mode change");
1109 drv
->ignore_if_down_event
= 0;
1111 drv
->if_disabled
= 1;
1112 wpa_supplicant_event(drv
->ctx
,
1113 EVENT_INTERFACE_DISABLED
, NULL
);
1116 * Try to get drv again, since it may be removed as
1117 * part of the EVENT_INTERFACE_DISABLED handling for
1118 * dynamic interfaces
1120 drv
= nl80211_find_drv(global
, ifi
->ifi_index
,
1127 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
1129 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1130 linux_iface_up(drv
->global
->ioctl_sock
, namebuf
) == 0) {
1131 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1132 "event since interface %s is down",
1136 wpa_printf(MSG_DEBUG
, "nl80211: Interface up (%s/%s)",
1138 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) != 0) {
1139 wpa_printf(MSG_DEBUG
,
1140 "nl80211: Not the main interface (%s) - do not indicate interface up",
1141 drv
->first_bss
->ifname
);
1142 } else if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
1143 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1144 "event since interface %s does not exist",
1145 drv
->first_bss
->ifname
);
1146 } else if (drv
->if_removed
) {
1147 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1148 "event since interface %s is marked "
1149 "removed", drv
->first_bss
->ifname
);
1151 /* Re-read MAC address as it may have changed */
1152 nl80211_refresh_mac(drv
, ifi
->ifi_index
, 0);
1154 drv
->if_disabled
= 0;
1155 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
1161 * Some drivers send the association event before the operup event--in
1162 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1163 * fails. This will hit us when wpa_supplicant does not need to do
1164 * IEEE 802.1X authentication
1166 if (drv
->operstate
== 1 &&
1167 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
1168 !(ifi
->ifi_flags
& IFF_RUNNING
)) {
1169 wpa_printf(MSG_DEBUG
, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
1170 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
1176 wpa_driver_nl80211_event_newlink(global
, drv
, ifi
->ifi_index
,
1179 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
&& drv
) {
1180 struct i802_bss
*bss
;
1182 /* device has been added to bridge */
1183 if (!if_indextoname(brid
, namebuf
)) {
1184 wpa_printf(MSG_DEBUG
,
1185 "nl80211: Could not find bridge ifname for ifindex %u",
1189 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
1191 add_ifidx(drv
, brid
, ifi
->ifi_index
);
1193 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
1194 if (os_strcmp(ifname
, bss
->ifname
) == 0) {
1195 os_strlcpy(bss
->brname
, namebuf
, IFNAMSIZ
);
1203 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
1204 struct ifinfomsg
*ifi
,
1205 u8
*buf
, size_t len
)
1207 struct nl80211_global
*global
= ctx
;
1208 struct wpa_driver_nl80211_data
*drv
;
1210 struct rtattr
*attr
;
1212 char ifname
[IFNAMSIZ
+ 1];
1213 char extra
[100], *pos
, *end
;
1217 end
= pos
+ sizeof(extra
);
1221 attr
= (struct rtattr
*) buf
;
1222 while (RTA_OK(attr
, attrlen
)) {
1223 switch (attr
->rta_type
) {
1225 if (RTA_PAYLOAD(attr
) > IFNAMSIZ
)
1227 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
1228 ifname
[RTA_PAYLOAD(attr
)] = '\0';
1231 brid
= nla_get_u32((struct nlattr
*) attr
);
1232 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
1234 case IFLA_OPERSTATE
:
1235 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
1236 nla_get_u32((struct nlattr
*) attr
));
1239 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
1240 nla_get_u32((struct nlattr
*) attr
));
1243 attr
= RTA_NEXT(attr
, attrlen
);
1245 extra
[sizeof(extra
) - 1] = '\0';
1247 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1248 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
1250 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1251 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1252 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1253 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1255 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
, NULL
);
1257 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
&& drv
) {
1258 /* device has been removed from bridge */
1259 char namebuf
[IFNAMSIZ
];
1261 if (!if_indextoname(brid
, namebuf
)) {
1262 wpa_printf(MSG_DEBUG
,
1263 "nl80211: Could not find bridge ifname for ifindex %u",
1266 wpa_printf(MSG_DEBUG
,
1267 "nl80211: Remove ifindex %u for bridge %s",
1270 del_ifidx(drv
, brid
, ifi
->ifi_index
);
1273 if (ifi
->ifi_family
!= AF_BRIDGE
|| !brid
)
1274 wpa_driver_nl80211_event_dellink(global
, drv
, ifi
->ifi_index
,
1279 struct nl80211_get_assoc_freq_arg
{
1280 struct wpa_driver_nl80211_data
*drv
;
1281 unsigned int assoc_freq
;
1282 unsigned int ibss_freq
;
1283 u8 assoc_bssid
[ETH_ALEN
];
1284 u8 assoc_ssid
[SSID_MAX_LEN
];
1288 static int nl80211_get_assoc_freq_handler(struct nl_msg
*msg
, void *arg
)
1290 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1291 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1292 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
1293 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
1294 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
1295 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
1296 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
1297 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
1299 struct nl80211_get_assoc_freq_arg
*ctx
= arg
;
1300 enum nl80211_bss_status status
;
1302 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1303 genlmsg_attrlen(gnlh
, 0), NULL
);
1304 if (!tb
[NL80211_ATTR_BSS
] ||
1305 nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
1307 !bss
[NL80211_BSS_STATUS
])
1310 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
1311 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1312 bss
[NL80211_BSS_FREQUENCY
]) {
1313 ctx
->assoc_freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
1314 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
1317 if (status
== NL80211_BSS_STATUS_IBSS_JOINED
&&
1318 bss
[NL80211_BSS_FREQUENCY
]) {
1319 ctx
->ibss_freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
1320 wpa_printf(MSG_DEBUG
, "nl80211: IBSS-joined on %u MHz",
1323 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1324 bss
[NL80211_BSS_BSSID
]) {
1325 os_memcpy(ctx
->assoc_bssid
,
1326 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
1327 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
1328 MACSTR
, MAC2STR(ctx
->assoc_bssid
));
1331 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1332 bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
1333 const u8
*ie
, *ssid
;
1336 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
1337 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
1338 ssid
= get_ie(ie
, ie_len
, WLAN_EID_SSID
);
1339 if (ssid
&& ssid
[1] > 0 && ssid
[1] <= SSID_MAX_LEN
) {
1340 ctx
->assoc_ssid_len
= ssid
[1];
1341 os_memcpy(ctx
->assoc_ssid
, ssid
+ 2, ssid
[1]);
1349 int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data
*drv
, u8
*ssid
)
1353 struct nl80211_get_assoc_freq_arg arg
;
1357 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1358 os_memset(&arg
, 0, sizeof(arg
));
1360 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_assoc_freq_handler
,
1362 if (ret
== -EAGAIN
) {
1365 wpa_printf(MSG_INFO
,
1366 "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid");
1368 wpa_printf(MSG_DEBUG
,
1369 "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again");
1374 os_memcpy(ssid
, arg
.assoc_ssid
, arg
.assoc_ssid_len
);
1375 return arg
.assoc_ssid_len
;
1377 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d (%s)",
1378 ret
, strerror(-ret
));
1383 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1387 struct nl80211_get_assoc_freq_arg arg
;
1391 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1392 os_memset(&arg
, 0, sizeof(arg
));
1394 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_assoc_freq_handler
,
1396 if (ret
== -EAGAIN
) {
1399 wpa_printf(MSG_INFO
,
1400 "nl80211: Failed to receive consistent scan result dump for get_assoc_freq");
1402 wpa_printf(MSG_DEBUG
,
1403 "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again");
1408 unsigned int freq
= drv
->nlmode
== NL80211_IFTYPE_ADHOC
?
1409 arg
.ibss_freq
: arg
.assoc_freq
;
1410 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1411 "associated BSS from scan results: %u MHz", freq
);
1413 drv
->assoc_freq
= freq
;
1414 return drv
->assoc_freq
;
1416 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1417 "(%s)", ret
, strerror(-ret
));
1418 return drv
->assoc_freq
;
1422 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1424 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1425 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1426 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1427 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1428 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1429 [NL80211_STA_INFO_SIGNAL_AVG
] = { .type
= NLA_U8
},
1430 [NL80211_STA_INFO_BEACON_SIGNAL_AVG
] = { .type
= NLA_U8
},
1432 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1433 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1434 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1435 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1436 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1437 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1439 struct wpa_signal_info
*sig_change
= arg
;
1441 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1442 genlmsg_attrlen(gnlh
, 0), NULL
);
1443 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1444 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1445 tb
[NL80211_ATTR_STA_INFO
], policy
))
1447 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1450 sig_change
->current_signal
=
1451 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1453 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
1454 sig_change
->avg_signal
=
1455 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]);
1457 sig_change
->avg_signal
= 0;
1459 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
1460 sig_change
->avg_beacon_signal
=
1462 nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]);
1464 sig_change
->avg_beacon_signal
= 0;
1466 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1467 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1468 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1470 sig_change
->current_txrate
= 0;
1472 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1473 sig_change
->current_txrate
=
1475 NL80211_RATE_INFO_BITRATE
]) * 100;
1484 int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1485 struct wpa_signal_info
*sig
)
1489 sig
->current_signal
= -WPA_INVALID_NOISE
;
1490 sig
->current_txrate
= 0;
1492 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_STATION
)) ||
1493 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
)) {
1498 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1502 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1504 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1505 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1506 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1507 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1508 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1509 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1511 struct wpa_signal_info
*sig_change
= arg
;
1513 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1514 genlmsg_attrlen(gnlh
, 0), NULL
);
1516 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1517 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1521 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1522 tb
[NL80211_ATTR_SURVEY_INFO
],
1524 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1529 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1532 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1533 sig_change
->frequency
)
1536 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1539 sig_change
->current_noise
=
1540 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1546 int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1547 struct wpa_signal_info
*sig_change
)
1551 sig_change
->current_noise
= WPA_INVALID_NOISE
;
1552 sig_change
->frequency
= drv
->assoc_freq
;
1554 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1555 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1559 static int get_channel_info(struct nl_msg
*msg
, void *arg
)
1561 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1] = { 0 };
1562 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1563 struct wpa_channel_info
*chan_info
= arg
;
1565 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1566 genlmsg_attrlen(gnlh
, 0), NULL
);
1568 os_memset(chan_info
, 0, sizeof(struct wpa_channel_info
));
1569 chan_info
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
1571 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1572 chan_info
->frequency
=
1573 nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1574 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
])
1575 chan_info
->chanwidth
= convert2width(
1576 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
1577 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1578 enum nl80211_channel_type ct
=
1579 nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1582 case NL80211_CHAN_HT40MINUS
:
1583 chan_info
->sec_channel
= -1;
1585 case NL80211_CHAN_HT40PLUS
:
1586 chan_info
->sec_channel
= 1;
1589 chan_info
->sec_channel
= 0;
1593 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
1594 chan_info
->center_frq1
=
1595 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
1596 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
1597 chan_info
->center_frq2
=
1598 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
1600 if (chan_info
->center_frq2
) {
1603 if (ieee80211_freq_to_chan(chan_info
->center_frq2
, &seg1_idx
) !=
1605 chan_info
->seg1_idx
= seg1_idx
;
1612 static int nl80211_channel_info(void *priv
, struct wpa_channel_info
*ci
)
1614 struct i802_bss
*bss
= priv
;
1615 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1618 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_INTERFACE
);
1619 return send_and_recv_msgs(drv
, msg
, get_channel_info
, ci
);
1623 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
1626 struct nl_cb
*cb
= eloop_ctx
;
1629 wpa_printf(MSG_MSGDUMP
, "nl80211: Event message available");
1631 res
= nl_recvmsgs(handle
, cb
);
1633 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
1640 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1641 * @priv: driver_nl80211 private data
1642 * @alpha2_arg: country to which to switch to
1643 * Returns: 0 on success, -1 on failure
1645 * This asks nl80211 to set the regulatory domain for given
1646 * country ISO / IEC alpha2.
1648 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
1650 struct i802_bss
*bss
= priv
;
1651 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1655 msg
= nlmsg_alloc();
1659 alpha2
[0] = alpha2_arg
[0];
1660 alpha2
[1] = alpha2_arg
[1];
1663 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
) ||
1664 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
)) {
1668 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
1674 static int nl80211_get_country(struct nl_msg
*msg
, void *arg
)
1677 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
1678 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1680 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1681 genlmsg_attrlen(gnlh
, 0), NULL
);
1682 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
]) {
1683 wpa_printf(MSG_DEBUG
, "nl80211: No country information available");
1686 os_strlcpy(alpha2
, nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]), 3);
1691 static int wpa_driver_nl80211_get_country(void *priv
, char *alpha2
)
1693 struct i802_bss
*bss
= priv
;
1694 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1698 msg
= nlmsg_alloc();
1702 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
1704 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_country
, alpha2
);
1712 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
1716 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1717 if (global
->nl_cb
== NULL
) {
1718 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
1723 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
1724 if (global
->nl
== NULL
)
1727 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
1728 if (global
->nl80211_id
< 0) {
1729 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
1734 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
1735 if (global
->nl_event
== NULL
)
1738 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
1740 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1742 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1743 "membership for scan events: %d (%s)",
1744 ret
, nl_geterror(ret
));
1748 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
1750 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1752 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1753 "membership for mlme events: %d (%s)",
1754 ret
, nl_geterror(ret
));
1758 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
1760 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1762 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1763 "membership for regulatory events: %d (%s)",
1764 ret
, nl_geterror(ret
));
1765 /* Continue without regulatory events */
1768 ret
= nl_get_multicast_id(global
, "nl80211", "vendor");
1770 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1772 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1773 "membership for vendor events: %d (%s)",
1774 ret
, nl_geterror(ret
));
1775 /* Continue without vendor events */
1778 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1779 no_seq_check
, NULL
);
1780 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1781 process_global_event
, global
);
1783 nl80211_register_eloop_read(&global
->nl_event
,
1784 wpa_driver_nl80211_event_receive
,
1790 nl_destroy_handles(&global
->nl_event
);
1791 nl_destroy_handles(&global
->nl
);
1792 nl_cb_put(global
->nl_cb
);
1793 global
->nl_cb
= NULL
;
1798 static void nl80211_check_global(struct nl80211_global
*global
)
1800 struct nl_sock
*handle
;
1801 const char *groups
[] = { "scan", "mlme", "regulatory", "vendor", NULL
};
1806 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1807 * and all registration having been cleared.
1809 handle
= (void *) (((intptr_t) global
->nl_event
) ^
1810 ELOOP_SOCKET_INVALID
);
1812 for (i
= 0; groups
[i
]; i
++) {
1813 ret
= nl_get_multicast_id(global
, "nl80211", groups
[i
]);
1815 ret
= nl_socket_add_membership(handle
, ret
);
1817 wpa_printf(MSG_INFO
,
1818 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1819 groups
[i
], ret
, nl_geterror(ret
));
1825 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
1827 struct wpa_driver_nl80211_data
*drv
= ctx
;
1829 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
1832 * rtnetlink ifdown handler will report interfaces other than the P2P
1833 * Device interface as disabled.
1835 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
1836 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
1840 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
1842 struct wpa_driver_nl80211_data
*drv
= ctx
;
1843 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
1844 if (i802_set_iface_flags(drv
->first_bss
, 1)) {
1845 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
1846 "after rfkill unblock");
1850 if (is_p2p_net_interface(drv
->nlmode
))
1851 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
1854 * rtnetlink ifup handler will report interfaces other than the P2P
1855 * Device interface as enabled.
1857 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
1858 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
, NULL
);
1862 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
1866 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
1871 struct cmsghdr
*cmsg
;
1872 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
1873 union wpa_event_data event
;
1875 memset(&msg
, 0, sizeof(msg
));
1876 msg
.msg_iov
= &entry
;
1878 entry
.iov_base
= data
;
1879 entry
.iov_len
= sizeof(data
);
1880 msg
.msg_control
= &control
;
1881 msg
.msg_controllen
= sizeof(control
);
1883 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
1884 /* if error or not fitting 802.3 header, return */
1888 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
1890 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
1891 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
1895 ack
= (void *)CMSG_DATA(cmsg
);
1899 if (cmsg
->cmsg_level
== SOL_PACKET
&&
1900 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
1901 struct sock_extended_err
*err
=
1902 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
1904 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
1909 if (!found_ee
|| !found_wifi
)
1912 memset(&event
, 0, sizeof(event
));
1913 event
.eapol_tx_status
.dst
= data
;
1914 event
.eapol_tx_status
.data
= data
+ 14;
1915 event
.eapol_tx_status
.data_len
= res
- 14;
1916 event
.eapol_tx_status
.ack
= acked
;
1917 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
1921 static int nl80211_init_bss(struct i802_bss
*bss
)
1923 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1927 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1928 no_seq_check
, NULL
);
1929 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1930 process_bss_event
, bss
);
1936 static void nl80211_destroy_bss(struct i802_bss
*bss
)
1938 nl_cb_put(bss
->nl_cb
);
1944 wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data
*drv
)
1946 struct rfkill_config
*rcfg
;
1951 rcfg
= os_zalloc(sizeof(*rcfg
));
1957 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
1958 * not associated with a netdev, so use the name of some other interface
1959 * sharing the same wiphy as the P2P Device interface.
1961 * Note: This is valid, as a P2P Device interface is always dynamically
1962 * created and is created only once another wpa_s interface was added.
1964 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
1965 struct nl80211_global
*global
= drv
->global
;
1966 struct wpa_driver_nl80211_data
*tmp1
;
1968 dl_list_for_each(tmp1
, &global
->interfaces
,
1969 struct wpa_driver_nl80211_data
, list
) {
1970 if (drv
== tmp1
|| drv
->wiphy_idx
!= tmp1
->wiphy_idx
||
1974 wpa_printf(MSG_DEBUG
,
1975 "nl80211: Use (%s) to initialize P2P Device rfkill",
1976 tmp1
->first_bss
->ifname
);
1977 os_strlcpy(rcfg
->ifname
, tmp1
->first_bss
->ifname
,
1978 sizeof(rcfg
->ifname
));
1982 os_strlcpy(rcfg
->ifname
, drv
->first_bss
->ifname
,
1983 sizeof(rcfg
->ifname
));
1986 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
1987 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
1988 drv
->rfkill
= rfkill_init(rcfg
);
1990 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
1996 static void * wpa_driver_nl80211_drv_init(void *ctx
, const char *ifname
,
1997 void *global_priv
, int hostapd
,
1999 const char *driver_params
)
2001 struct wpa_driver_nl80211_data
*drv
;
2002 struct i802_bss
*bss
;
2004 if (global_priv
== NULL
)
2006 drv
= os_zalloc(sizeof(*drv
));
2009 drv
->global
= global_priv
;
2011 drv
->hostapd
= !!hostapd
;
2012 drv
->eapol_sock
= -1;
2015 * There is no driver capability flag for this, so assume it is
2016 * supported and disable this on first attempt to use if the driver
2017 * rejects the command due to missing support.
2019 drv
->set_rekey_offload
= 1;
2021 drv
->num_if_indices
= ARRAY_SIZE(drv
->default_if_indices
);
2022 drv
->if_indices
= drv
->default_if_indices
;
2024 drv
->first_bss
= os_zalloc(sizeof(*drv
->first_bss
));
2025 if (!drv
->first_bss
) {
2029 bss
= drv
->first_bss
;
2033 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
2034 drv
->monitor_ifidx
= -1;
2035 drv
->monitor_sock
= -1;
2036 drv
->eapol_tx_sock
= -1;
2037 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2039 if (nl80211_init_bss(bss
))
2042 if (wpa_driver_nl80211_finish_drv_init(drv
, set_addr
, 1, driver_params
))
2045 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
2046 if (drv
->eapol_tx_sock
< 0)
2049 if (drv
->data_tx_status
) {
2052 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
2053 &enabled
, sizeof(enabled
)) < 0) {
2054 wpa_printf(MSG_DEBUG
,
2055 "nl80211: wifi status sockopt failed\n");
2056 drv
->data_tx_status
= 0;
2057 if (!drv
->use_monitor
)
2059 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
2061 eloop_register_read_sock(drv
->eapol_tx_sock
,
2062 wpa_driver_nl80211_handle_eapol_tx_status
,
2068 nl80211_check_global(drv
->global
);
2069 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
2070 drv
->in_interface_list
= 1;
2076 wpa_driver_nl80211_deinit(bss
);
2082 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2083 * @ctx: context to be used when calling wpa_supplicant functions,
2084 * e.g., wpa_supplicant_event()
2085 * @ifname: interface name, e.g., wlan0
2086 * @global_priv: private driver global data from global_init()
2087 * Returns: Pointer to private data, %NULL on failure
2089 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
2092 return wpa_driver_nl80211_drv_init(ctx
, ifname
, global_priv
, 0, NULL
,
2097 static int nl80211_register_frame(struct i802_bss
*bss
,
2098 struct nl_sock
*nl_handle
,
2099 u16 type
, const u8
*match
, size_t match_len
)
2101 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2107 wpa_snprintf_hex(buf
, sizeof(buf
), match
, match_len
);
2108 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
2109 type
, fc2str(type
), nl_handle
, buf
);
2111 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REGISTER_FRAME
)) ||
2112 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
, type
) ||
2113 nla_put(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
)) {
2118 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
2120 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
2121 "failed (type=%u): ret=%d (%s)",
2122 type
, ret
, strerror(-ret
));
2123 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
2130 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
2133 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
2134 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
2138 bss
->nl_mgmt
= nl_create_handle(bss
->nl_cb
, "mgmt");
2139 if (bss
->nl_mgmt
== NULL
)
2146 static void nl80211_mgmt_handle_register_eloop(struct i802_bss
*bss
)
2148 nl80211_register_eloop_read(&bss
->nl_mgmt
,
2149 wpa_driver_nl80211_event_receive
,
2154 static int nl80211_register_action_frame(struct i802_bss
*bss
,
2155 const u8
*match
, size_t match_len
)
2157 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
2158 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
2159 type
, match
, match_len
);
2163 static int nl80211_init_connect_handle(struct i802_bss
*bss
)
2165 if (bss
->nl_connect
) {
2166 wpa_printf(MSG_DEBUG
,
2167 "nl80211: Connect handle already created (nl_connect=%p)",
2172 bss
->nl_connect
= nl_create_handle(bss
->nl_cb
, "connect");
2173 if (!bss
->nl_connect
)
2175 nl80211_register_eloop_read(&bss
->nl_connect
,
2176 wpa_driver_nl80211_event_receive
,
2182 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
2184 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2185 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_AUTH
<< 4);
2188 if (nl80211_alloc_mgmt_handle(bss
))
2190 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
2191 "handle %p", bss
->nl_mgmt
);
2193 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
2194 /* register for any AUTH message */
2195 nl80211_register_frame(bss
, bss
->nl_mgmt
, type
, NULL
, 0);
2196 } else if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_SAE
) &&
2197 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
2198 /* register for SAE Authentication frames */
2199 nl80211_register_frame(bss
, bss
->nl_mgmt
, type
,
2200 (u8
*) "\x03\x00", 2);
2203 #ifdef CONFIG_INTERWORKING
2204 /* QoS Map Configure */
2205 if (nl80211_register_action_frame(bss
, (u8
*) "\x01\x04", 2) < 0)
2207 #endif /* CONFIG_INTERWORKING */
2208 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
2209 /* GAS Initial Request */
2210 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
2212 /* GAS Initial Response */
2213 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
2215 /* GAS Comeback Request */
2216 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
2218 /* GAS Comeback Response */
2219 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
2221 /* Protected GAS Initial Request */
2222 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0a", 2) < 0)
2224 /* Protected GAS Initial Response */
2225 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0b", 2) < 0)
2227 /* Protected GAS Comeback Request */
2228 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0c", 2) < 0)
2230 /* Protected GAS Comeback Response */
2231 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0d", 2) < 0)
2233 #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */
2235 /* P2P Public Action */
2236 if (nl80211_register_action_frame(bss
,
2237 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
2241 if (nl80211_register_action_frame(bss
,
2242 (u8
*) "\x7f\x50\x6f\x9a\x09",
2245 #endif /* CONFIG_P2P */
2247 /* DPP Public Action */
2248 if (nl80211_register_action_frame(bss
,
2249 (u8
*) "\x04\x09\x50\x6f\x9a\x1a",
2252 #endif /* CONFIG_DPP */
2254 /* SA Query Request */
2255 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x00", 2) < 0)
2257 #endif /* CONFIG_OCV */
2258 /* SA Query Response */
2259 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
2262 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
2263 /* TDLS Discovery Response */
2264 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
2268 #endif /* CONFIG_TDLS */
2270 /* FST Action frames */
2271 if (nl80211_register_action_frame(bss
, (u8
*) "\x12", 1) < 0)
2273 #endif /* CONFIG_FST */
2275 /* FT Action frames */
2276 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
2279 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
2280 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
2282 /* WNM - BSS Transition Management Request */
2283 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
2285 /* WNM-Sleep Mode Response */
2286 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
2289 /* WNM - Collocated Interference Request */
2290 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x0b", 2) < 0)
2292 #endif /* CONFIG_WNM */
2295 /* WNM-Notification */
2296 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x1a", 2) < 0)
2298 #endif /* CONFIG_HS20 */
2300 /* WMM-AC ADDTS Response */
2301 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x01", 2) < 0)
2305 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x02", 2) < 0)
2308 /* Radio Measurement - Neighbor Report Response */
2309 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x05", 2) < 0)
2312 /* Radio Measurement - Radio Measurement Request */
2313 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x00", 2) < 0)
2316 /* Radio Measurement - Link Measurement Request */
2317 if ((drv
->capa
.rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
) &&
2318 (nl80211_register_action_frame(bss
, (u8
*) "\x05\x02", 2) < 0))
2321 nl80211_mgmt_handle_register_eloop(bss
);
2327 static int nl80211_mgmt_subscribe_mesh(struct i802_bss
*bss
)
2331 if (nl80211_alloc_mgmt_handle(bss
))
2334 wpa_printf(MSG_DEBUG
,
2335 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2338 /* Auth frames for mesh SAE */
2339 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
2340 (WLAN_FC_TYPE_MGMT
<< 2) |
2341 (WLAN_FC_STYPE_AUTH
<< 4),
2345 /* Mesh peering open */
2346 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x01", 2) < 0)
2348 /* Mesh peering confirm */
2349 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x02", 2) < 0)
2351 /* Mesh peering close */
2352 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x03", 2) < 0)
2355 nl80211_mgmt_handle_register_eloop(bss
);
2361 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
2366 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
2367 ret
= send_and_recv(bss
->drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
2369 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
2370 "failed: ret=%d (%s)",
2371 ret
, strerror(-ret
));
2377 static int nl80211_action_subscribe_ap(struct i802_bss
*bss
)
2381 /* Public Action frames */
2382 if (nl80211_register_action_frame(bss
, (u8
*) "\x04", 1) < 0)
2384 /* RRM Measurement Report */
2385 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x01", 2) < 0)
2387 /* RRM Link Measurement Report */
2388 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x03", 2) < 0)
2390 /* RRM Neighbor Report Request */
2391 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x04", 2) < 0)
2393 /* FT Action frames */
2394 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
2397 if (nl80211_register_action_frame(bss
, (u8
*) "\x08", 1) < 0)
2399 /* Protected Dual of Public Action */
2400 if (nl80211_register_action_frame(bss
, (u8
*) "\x09", 1) < 0)
2403 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a", 1) < 0)
2406 if (nl80211_register_action_frame(bss
, (u8
*) "\x11", 1) < 0)
2409 /* FST Action frames */
2410 if (nl80211_register_action_frame(bss
, (u8
*) "\x12", 1) < 0)
2412 #endif /* CONFIG_FST */
2413 /* Vendor-specific */
2414 if (nl80211_register_action_frame(bss
, (u8
*) "\x7f", 1) < 0)
2421 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
2423 static const int stypes
[] = {
2425 WLAN_FC_STYPE_ASSOC_REQ
,
2426 WLAN_FC_STYPE_REASSOC_REQ
,
2427 WLAN_FC_STYPE_DISASSOC
,
2428 WLAN_FC_STYPE_DEAUTH
,
2429 WLAN_FC_STYPE_PROBE_REQ
,
2430 /* Beacon doesn't work as mac80211 doesn't currently allow
2431 * it, but it wouldn't really be the right thing anyway as
2432 * it isn't per interface ... maybe just dump the scan
2433 * results periodically for OLBC?
2435 /* WLAN_FC_STYPE_BEACON, */
2439 if (nl80211_alloc_mgmt_handle(bss
))
2441 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
2442 "handle %p", bss
->nl_mgmt
);
2444 for (i
= 0; i
< ARRAY_SIZE(stypes
); i
++) {
2445 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
2446 (WLAN_FC_TYPE_MGMT
<< 2) |
2453 if (nl80211_action_subscribe_ap(bss
))
2456 if (nl80211_register_spurious_class3(bss
))
2459 nl80211_mgmt_handle_register_eloop(bss
);
2463 nl_destroy_handles(&bss
->nl_mgmt
);
2468 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
2470 if (nl80211_alloc_mgmt_handle(bss
))
2472 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
2473 "handle %p (device SME)", bss
->nl_mgmt
);
2475 if (nl80211_action_subscribe_ap(bss
))
2478 if (bss
->drv
->device_ap_sme
) {
2479 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_AUTH
<< 4);
2481 /* Register for all Authentication frames */
2482 if (nl80211_register_frame(bss
, bss
->nl_mgmt
, type
, NULL
, 0)
2484 wpa_printf(MSG_DEBUG
,
2485 "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work");
2488 nl80211_mgmt_handle_register_eloop(bss
);
2492 nl_destroy_handles(&bss
->nl_mgmt
);
2497 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
2499 if (bss
->nl_mgmt
== NULL
)
2501 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
2502 "(%s)", bss
->nl_mgmt
, reason
);
2503 nl80211_destroy_eloop_handle(&bss
->nl_mgmt
, 0);
2505 nl80211_put_wiphy_data_ap(bss
);
2509 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
2511 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
2515 static void nl80211_del_p2pdev(struct i802_bss
*bss
)
2520 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_INTERFACE
);
2521 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2523 wpa_printf(MSG_DEBUG
, "nl80211: Delete P2P Device %s (0x%llx): %s",
2524 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2529 static int nl80211_set_p2pdev(struct i802_bss
*bss
, int start
)
2534 msg
= nl80211_cmd_msg(bss
, 0, start
? NL80211_CMD_START_P2P_DEVICE
:
2535 NL80211_CMD_STOP_P2P_DEVICE
);
2536 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2538 wpa_printf(MSG_DEBUG
, "nl80211: %s P2P Device %s (0x%llx): %s",
2539 start
? "Start" : "Stop",
2540 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2546 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
)
2548 enum nl80211_iftype nlmode
;
2550 nlmode
= nl80211_get_ifmode(bss
);
2551 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2552 return linux_set_iface_flags(bss
->drv
->global
->ioctl_sock
,
2556 /* P2P Device has start/stop which is equivalent */
2557 return nl80211_set_p2pdev(bss
, up
);
2561 #ifdef CONFIG_TESTING_OPTIONS
2562 static int qca_vendor_test_cmd_handler(struct nl_msg
*msg
, void *arg
)
2564 /* struct wpa_driver_nl80211_data *drv = arg; */
2565 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2566 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2569 wpa_printf(MSG_DEBUG
,
2570 "nl80211: QCA vendor test command response received");
2572 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2573 genlmsg_attrlen(gnlh
, 0), NULL
);
2574 if (!tb
[NL80211_ATTR_VENDOR_DATA
]) {
2575 wpa_printf(MSG_DEBUG
, "nl80211: No vendor data attribute");
2579 wpa_hexdump(MSG_DEBUG
,
2580 "nl80211: Received QCA vendor test command response",
2581 nla_data(tb
[NL80211_ATTR_VENDOR_DATA
]),
2582 nla_len(tb
[NL80211_ATTR_VENDOR_DATA
]));
2586 #endif /* CONFIG_TESTING_OPTIONS */
2589 static void qca_vendor_test(struct wpa_driver_nl80211_data
*drv
)
2591 #ifdef CONFIG_TESTING_OPTIONS
2593 struct nlattr
*params
;
2596 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2597 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2598 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2599 QCA_NL80211_VENDOR_SUBCMD_TEST
) ||
2600 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
2601 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_TEST
, 123)) {
2605 nla_nest_end(msg
, params
);
2607 ret
= send_and_recv_msgs(drv
, msg
, qca_vendor_test_cmd_handler
, drv
);
2608 wpa_printf(MSG_DEBUG
,
2609 "nl80211: QCA vendor test command returned %d (%s)",
2610 ret
, strerror(-ret
));
2611 #endif /* CONFIG_TESTING_OPTIONS */
2616 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
2617 const u8
*set_addr
, int first
,
2618 const char *driver_params
)
2620 struct i802_bss
*bss
= drv
->first_bss
;
2621 int send_rfkill_event
= 0;
2622 enum nl80211_iftype nlmode
;
2624 drv
->ifindex
= if_nametoindex(bss
->ifname
);
2625 bss
->ifindex
= drv
->ifindex
;
2626 bss
->wdev_id
= drv
->global
->if_add_wdevid
;
2627 bss
->wdev_id_set
= drv
->global
->if_add_wdevid_set
;
2629 bss
->if_dynamic
= drv
->ifindex
== drv
->global
->if_add_ifindex
;
2630 bss
->if_dynamic
= bss
->if_dynamic
|| drv
->global
->if_add_wdevid_set
;
2631 drv
->global
->if_add_wdevid_set
= 0;
2633 if (!bss
->if_dynamic
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2637 nl80211_get_ifmode(bss
) != NL80211_IFTYPE_P2P_DEVICE
&&
2638 linux_iface_up(drv
->global
->ioctl_sock
, bss
->ifname
) > 0)
2639 drv
->start_iface_up
= 1;
2641 if (wpa_driver_nl80211_capa(drv
))
2644 if (driver_params
&& nl80211_set_param(bss
, driver_params
) < 0)
2647 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2648 bss
->ifname
, drv
->phyname
);
2651 (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) ||
2652 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2656 if (first
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2657 drv
->start_mode_ap
= 1;
2659 if (drv
->hostapd
|| bss
->static_ap
)
2660 nlmode
= NL80211_IFTYPE_AP
;
2661 else if (bss
->if_dynamic
||
2662 nl80211_get_ifmode(bss
) == NL80211_IFTYPE_MESH_POINT
)
2663 nlmode
= nl80211_get_ifmode(bss
);
2665 nlmode
= NL80211_IFTYPE_STATION
;
2667 if (wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0) {
2668 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver mode");
2672 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2673 nl80211_get_macaddr(bss
);
2675 wpa_driver_nl80211_drv_init_rfkill(drv
);
2677 if (!rfkill_is_blocked(drv
->rfkill
)) {
2678 int ret
= i802_set_iface_flags(bss
, 1);
2680 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
2681 "interface '%s' UP", bss
->ifname
);
2685 if (is_p2p_net_interface(nlmode
))
2686 nl80211_disable_11b_rates(bss
->drv
,
2687 bss
->drv
->ifindex
, 1);
2689 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2692 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
2693 "interface '%s' due to rfkill", bss
->ifname
);
2694 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
2695 drv
->if_disabled
= 1;
2697 send_rfkill_event
= 1;
2700 if (!drv
->hostapd
&& nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
2701 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
2702 1, IF_OPER_DORMANT
);
2704 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2705 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2708 os_memcpy(drv
->perm_addr
, bss
->addr
, ETH_ALEN
);
2711 if (send_rfkill_event
) {
2712 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
2716 if (drv
->vendor_cmd_test_avail
)
2717 qca_vendor_test(drv
);
2719 nl80211_init_connect_handle(bss
);
2725 static int wpa_driver_nl80211_del_beacon(struct i802_bss
*bss
)
2728 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2730 wpa_printf(MSG_DEBUG
, "nl80211: Remove beacon (ifindex=%d)",
2732 nl80211_put_wiphy_data_ap(bss
);
2733 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_DEL_BEACON
);
2734 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2739 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
2740 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
2742 * Shut down driver interface and processing of driver events. Free
2743 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2745 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
2747 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2750 wpa_printf(MSG_INFO
, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2751 bss
->ifname
, drv
->disabled_11b_rates
);
2754 if (drv
->data_tx_status
)
2755 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
2756 if (drv
->eapol_tx_sock
>= 0)
2757 close(drv
->eapol_tx_sock
);
2760 wpa_driver_nl80211_probe_req_report(bss
, 0);
2761 if (bss
->added_if_into_bridge
) {
2762 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
2764 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2765 "interface %s from bridge %s: %s",
2766 bss
->ifname
, bss
->brname
, strerror(errno
));
2770 nl_socket_free(drv
->rtnl_sk
);
2772 if (bss
->added_bridge
) {
2773 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->brname
,
2775 wpa_printf(MSG_INFO
,
2776 "nl80211: Could not set bridge %s down",
2778 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
2779 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2781 bss
->brname
, strerror(errno
));
2784 nl80211_remove_monitor_interface(drv
);
2786 if (is_ap_interface(drv
->nlmode
))
2787 wpa_driver_nl80211_del_beacon(bss
);
2789 if (drv
->eapol_sock
>= 0) {
2790 eloop_unregister_read_sock(drv
->eapol_sock
);
2791 close(drv
->eapol_sock
);
2794 if (drv
->if_indices
!= drv
->default_if_indices
)
2795 os_free(drv
->if_indices
);
2797 if (drv
->disabled_11b_rates
)
2798 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2800 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
2802 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill
, drv
, drv
->ctx
);
2803 rfkill_deinit(drv
->rfkill
);
2805 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2807 if (!drv
->start_iface_up
)
2808 (void) i802_set_iface_flags(bss
, 0);
2810 if (drv
->addr_changed
) {
2811 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
2813 wpa_printf(MSG_DEBUG
,
2814 "nl80211: Could not set interface down to restore permanent MAC address");
2816 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2817 drv
->perm_addr
) < 0) {
2818 wpa_printf(MSG_DEBUG
,
2819 "nl80211: Could not restore permanent MAC address");
2823 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2824 if (!drv
->hostapd
|| !drv
->start_mode_ap
)
2825 wpa_driver_nl80211_set_mode(bss
,
2826 NL80211_IFTYPE_STATION
);
2827 nl80211_mgmt_unsubscribe(bss
, "deinit");
2829 nl80211_mgmt_unsubscribe(bss
, "deinit");
2830 nl80211_del_p2pdev(bss
);
2833 if (bss
->nl_connect
)
2834 nl80211_destroy_eloop_handle(&bss
->nl_connect
, 1);
2836 nl80211_destroy_bss(drv
->first_bss
);
2838 os_free(drv
->filter_ssids
);
2840 os_free(drv
->auth_ie
);
2842 if (drv
->in_interface_list
)
2843 dl_list_del(&drv
->list
);
2845 os_free(drv
->extended_capa
);
2846 os_free(drv
->extended_capa_mask
);
2847 for (i
= 0; i
< drv
->num_iface_ext_capa
; i
++) {
2848 os_free(drv
->iface_ext_capa
[i
].ext_capa
);
2849 os_free(drv
->iface_ext_capa
[i
].ext_capa_mask
);
2851 os_free(drv
->first_bss
);
2856 static u32
wpa_alg_to_cipher_suite(enum wpa_alg alg
, size_t key_len
)
2861 return RSN_CIPHER_SUITE_WEP40
;
2862 return RSN_CIPHER_SUITE_WEP104
;
2864 return RSN_CIPHER_SUITE_TKIP
;
2866 return RSN_CIPHER_SUITE_CCMP
;
2868 return RSN_CIPHER_SUITE_GCMP
;
2869 case WPA_ALG_CCMP_256
:
2870 return RSN_CIPHER_SUITE_CCMP_256
;
2871 case WPA_ALG_GCMP_256
:
2872 return RSN_CIPHER_SUITE_GCMP_256
;
2874 return RSN_CIPHER_SUITE_AES_128_CMAC
;
2875 case WPA_ALG_BIP_GMAC_128
:
2876 return RSN_CIPHER_SUITE_BIP_GMAC_128
;
2877 case WPA_ALG_BIP_GMAC_256
:
2878 return RSN_CIPHER_SUITE_BIP_GMAC_256
;
2879 case WPA_ALG_BIP_CMAC_256
:
2880 return RSN_CIPHER_SUITE_BIP_CMAC_256
;
2882 return RSN_CIPHER_SUITE_SMS4
;
2884 return RSN_CIPHER_SUITE_KRK
;
2886 wpa_printf(MSG_ERROR
, "nl80211: Unexpected encryption algorithm %d",
2891 wpa_printf(MSG_ERROR
, "nl80211: Unsupported encryption algorithm %d",
2897 static u32
wpa_cipher_to_cipher_suite(unsigned int cipher
)
2900 case WPA_CIPHER_CCMP_256
:
2901 return RSN_CIPHER_SUITE_CCMP_256
;
2902 case WPA_CIPHER_GCMP_256
:
2903 return RSN_CIPHER_SUITE_GCMP_256
;
2904 case WPA_CIPHER_CCMP
:
2905 return RSN_CIPHER_SUITE_CCMP
;
2906 case WPA_CIPHER_GCMP
:
2907 return RSN_CIPHER_SUITE_GCMP
;
2908 case WPA_CIPHER_TKIP
:
2909 return RSN_CIPHER_SUITE_TKIP
;
2910 case WPA_CIPHER_WEP104
:
2911 return RSN_CIPHER_SUITE_WEP104
;
2912 case WPA_CIPHER_WEP40
:
2913 return RSN_CIPHER_SUITE_WEP40
;
2914 case WPA_CIPHER_GTK_NOT_USED
:
2915 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED
;
2922 static int wpa_cipher_to_cipher_suites(unsigned int ciphers
, u32 suites
[],
2927 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP_256
)
2928 suites
[num_suites
++] = RSN_CIPHER_SUITE_CCMP_256
;
2929 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP_256
)
2930 suites
[num_suites
++] = RSN_CIPHER_SUITE_GCMP_256
;
2931 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP
)
2932 suites
[num_suites
++] = RSN_CIPHER_SUITE_CCMP
;
2933 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP
)
2934 suites
[num_suites
++] = RSN_CIPHER_SUITE_GCMP
;
2935 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_TKIP
)
2936 suites
[num_suites
++] = RSN_CIPHER_SUITE_TKIP
;
2937 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP104
)
2938 suites
[num_suites
++] = RSN_CIPHER_SUITE_WEP104
;
2939 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP40
)
2940 suites
[num_suites
++] = RSN_CIPHER_SUITE_WEP40
;
2946 static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites
, u32 suites
[],
2951 #define __AKM(a, b) \
2952 if (num_suites < max_suites && \
2953 (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \
2954 suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b)
2955 __AKM(IEEE8021X
, UNSPEC_802_1X
);
2956 __AKM(PSK
, PSK_OVER_802_1X
);
2957 __AKM(FT_IEEE8021X
, FT_802_1X
);
2958 __AKM(FT_PSK
, FT_PSK
);
2959 __AKM(IEEE8021X_SHA256
, 802_1X_SHA256
);
2960 __AKM(PSK_SHA256
, PSK_SHA256
);
2962 __AKM(FT_SAE
, FT_SAE
);
2965 __AKM(IEEE8021X_SUITE_B
, 802_1X_SUITE_B
);
2966 __AKM(IEEE8021X_SUITE_B_192
, 802_1X_SUITE_B_192
);
2967 __AKM(FILS_SHA256
, FILS_SHA256
);
2968 __AKM(FILS_SHA384
, FILS_SHA384
);
2969 __AKM(FT_FILS_SHA256
, FT_FILS_SHA256
);
2970 __AKM(FT_FILS_SHA384
, FT_FILS_SHA384
);
2973 __AKM(FT_IEEE8021X_SHA384
, FT_802_1X_SHA384
);
2980 #ifdef CONFIG_DRIVER_NL80211_QCA
2981 static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data
*drv
,
2982 const u8
*key
, size_t key_len
)
2987 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
))
2990 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2991 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2992 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2993 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY
) ||
2994 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, key_len
, key
)) {
2995 nl80211_nlmsg_clear(msg
);
2999 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
3001 wpa_printf(MSG_DEBUG
,
3002 "nl80211: Key management set key failed: ret=%d (%s)",
3003 ret
, strerror(-ret
));
3008 #endif /* CONFIG_DRIVER_NL80211_QCA */
3011 static int nl80211_set_pmk(struct wpa_driver_nl80211_data
*drv
,
3012 const u8
*key
, size_t key_len
,
3015 struct nl_msg
*msg
= NULL
;
3019 * If the authenticator address is not set, assume it is
3020 * the current BSSID.
3022 if (!addr
&& drv
->associated
)
3027 wpa_printf(MSG_DEBUG
, "nl80211: Set PMK to the driver for " MACSTR
,
3029 wpa_hexdump_key(MSG_DEBUG
, "nl80211: PMK", key
, key_len
);
3030 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_PMK
);
3032 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
3033 nla_put(msg
, NL80211_ATTR_PMK
, key_len
, key
)) {
3034 nl80211_nlmsg_clear(msg
);
3039 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
3041 wpa_printf(MSG_DEBUG
, "nl80211: Set PMK failed: ret=%d (%s)",
3042 ret
, strerror(-ret
));
3049 static int wpa_driver_nl80211_set_key(struct i802_bss
*bss
,
3050 struct wpa_driver_set_key_params
*params
)
3052 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3055 struct nl_msg
*key_msg
;
3057 int skip_set_key
= 1;
3058 const char *ifname
= params
->ifname
;
3059 enum wpa_alg alg
= params
->alg
;
3060 const u8
*addr
= params
->addr
;
3061 int key_idx
= params
->key_idx
;
3062 int set_tx
= params
->set_tx
;
3063 const u8
*seq
= params
->seq
;
3064 size_t seq_len
= params
->seq_len
;
3065 const u8
*key
= params
->key
;
3066 size_t key_len
= params
->key_len
;
3067 int vlan_id
= params
->vlan_id
;
3068 enum key_flag key_flag
= params
->key_flag
;
3070 /* Ignore for P2P Device */
3071 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
3074 ifindex
= if_nametoindex(ifname
);
3075 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
3076 "set_tx=%d seq_len=%lu key_len=%lu key_flag=0x%x",
3077 __func__
, ifindex
, ifname
, alg
, addr
, key_idx
, set_tx
,
3078 (unsigned long) seq_len
, (unsigned long) key_len
, key_flag
);
3080 if (check_key_flag(key_flag
)) {
3081 wpa_printf(MSG_DEBUG
, "%s: invalid key_flag", __func__
);
3085 #ifdef CONFIG_DRIVER_NL80211_QCA
3086 if ((key_flag
& KEY_FLAG_PMK
) &&
3087 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
)) {
3088 wpa_printf(MSG_DEBUG
, "%s: calling issue_key_mgmt_set_key",
3090 ret
= issue_key_mgmt_set_key(drv
, key
, key_len
);
3093 #endif /* CONFIG_DRIVER_NL80211_QCA */
3095 if (key_flag
& KEY_FLAG_PMK
) {
3096 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X
)
3097 return nl80211_set_pmk(drv
, key
, key_len
, addr
);
3098 /* The driver does not have any offload mechanism for PMK, so
3099 * there is no need to configure this key. */
3104 key_msg
= nlmsg_alloc();
3108 if ((key_flag
& KEY_FLAG_PAIRWISE_MASK
) ==
3109 KEY_FLAG_PAIRWISE_RX_TX_MODIFY
) {
3110 wpa_printf(MSG_DEBUG
,
3111 "nl80211: SET_KEY (pairwise RX/TX modify)");
3112 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_SET_KEY
);
3115 } else if (alg
== WPA_ALG_NONE
&& (key_flag
& KEY_FLAG_RX_TX
)) {
3116 wpa_printf(MSG_DEBUG
, "%s: invalid key_flag to delete key",
3120 } else if (alg
== WPA_ALG_NONE
) {
3121 wpa_printf(MSG_DEBUG
, "nl80211: DEL_KEY");
3122 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_DEL_KEY
);
3128 suite
= wpa_alg_to_cipher_suite(alg
, key_len
);
3133 wpa_printf(MSG_DEBUG
, "nl80211: NEW_KEY");
3134 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_NEW_KEY
);
3137 if (nla_put(key_msg
, NL80211_KEY_DATA
, key_len
, key
) ||
3138 nla_put_u32(key_msg
, NL80211_KEY_CIPHER
, suite
))
3140 wpa_hexdump_key(MSG_DEBUG
, "nl80211: KEY_DATA", key
, key_len
);
3142 if (seq
&& seq_len
) {
3143 if (nla_put(key_msg
, NL80211_KEY_SEQ
, seq_len
, seq
))
3145 wpa_hexdump(MSG_DEBUG
, "nl80211: KEY_SEQ",
3150 if (addr
&& !is_broadcast_ether_addr(addr
)) {
3151 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
3152 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
3155 if ((key_flag
& KEY_FLAG_PAIRWISE_MASK
) ==
3156 KEY_FLAG_PAIRWISE_RX
||
3157 (key_flag
& KEY_FLAG_PAIRWISE_MASK
) ==
3158 KEY_FLAG_PAIRWISE_RX_TX_MODIFY
) {
3159 if (nla_put_u8(key_msg
, NL80211_KEY_MODE
,
3160 key_flag
== KEY_FLAG_PAIRWISE_RX
?
3161 NL80211_KEY_NO_TX
: NL80211_KEY_SET_TX
))
3163 } else if ((key_flag
& KEY_FLAG_GROUP_MASK
) ==
3164 KEY_FLAG_GROUP_RX
) {
3165 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
3166 if (nla_put_u32(key_msg
, NL80211_KEY_TYPE
,
3167 NL80211_KEYTYPE_GROUP
))
3169 } else if (!(key_flag
& KEY_FLAG_PAIRWISE
)) {
3170 wpa_printf(MSG_DEBUG
,
3171 " key_flag missing PAIRWISE when setting a pairwise key");
3174 } else if (alg
== WPA_ALG_WEP
&&
3175 (key_flag
& KEY_FLAG_RX_TX
) == KEY_FLAG_RX_TX
) {
3176 wpa_printf(MSG_DEBUG
, " unicast WEP key");
3179 wpa_printf(MSG_DEBUG
, " pairwise key");
3181 } else if ((key_flag
& KEY_FLAG_PAIRWISE
) ||
3182 !(key_flag
& KEY_FLAG_GROUP
)) {
3183 wpa_printf(MSG_DEBUG
,
3184 " invalid key_flag for a broadcast key");
3188 wpa_printf(MSG_DEBUG
, " broadcast key");
3189 if (key_flag
& KEY_FLAG_DEFAULT
)
3192 if (nla_put_u8(key_msg
, NL80211_KEY_IDX
, key_idx
) ||
3193 nla_put_nested(msg
, NL80211_ATTR_KEY
, key_msg
))
3195 nl80211_nlmsg_clear(key_msg
);
3196 nlmsg_free(key_msg
);
3199 if (vlan_id
&& (drv
->capa
.flags
& WPA_DRIVER_FLAGS_VLAN_OFFLOAD
)) {
3200 wpa_printf(MSG_DEBUG
, "nl80211: VLAN ID %d", vlan_id
);
3201 if (nla_put_u16(msg
, NL80211_ATTR_VLAN_ID
, vlan_id
))
3205 ret
= send_and_recv_msgs(drv
, msg
, NULL
, key
? (void *) -1 : NULL
);
3206 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
3209 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s",
3210 ret
, strerror(-ret
));
3213 * If we failed or don't need to set the key as default (below),
3216 if (ret
|| skip_set_key
)
3218 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_SET_KEY - default key");
3221 key_msg
= nlmsg_alloc();
3225 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_SET_KEY
);
3229 nla_put_u8(key_msg
, NL80211_KEY_IDX
, key_idx
) ||
3230 nla_put_flag(key_msg
, (alg
== WPA_ALG_IGTK
||
3231 alg
== WPA_ALG_BIP_GMAC_128
||
3232 alg
== WPA_ALG_BIP_GMAC_256
||
3233 alg
== WPA_ALG_BIP_CMAC_256
) ?
3234 (key_idx
== 6 || key_idx
== 7 ?
3235 NL80211_KEY_DEFAULT_BEACON
:
3236 NL80211_KEY_DEFAULT_MGMT
) :
3237 NL80211_KEY_DEFAULT
))
3239 if (addr
&& is_broadcast_ether_addr(addr
)) {
3240 struct nlattr
*types
;
3242 types
= nla_nest_start(key_msg
, NL80211_KEY_DEFAULT_TYPES
);
3244 nla_put_flag(key_msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
3246 nla_nest_end(key_msg
, types
);
3248 struct nlattr
*types
;
3250 types
= nla_nest_start(key_msg
, NL80211_KEY_DEFAULT_TYPES
);
3252 nla_put_flag(key_msg
, NL80211_KEY_DEFAULT_TYPE_UNICAST
))
3254 nla_nest_end(key_msg
, types
);
3257 if (nla_put_nested(msg
, NL80211_ATTR_KEY
, key_msg
))
3259 nl80211_nlmsg_clear(key_msg
);
3260 nlmsg_free(key_msg
);
3263 if (vlan_id
&& (drv
->capa
.flags
& WPA_DRIVER_FLAGS_VLAN_OFFLOAD
)) {
3264 wpa_printf(MSG_DEBUG
, "nl80211: set_key default - VLAN ID %d",
3266 if (nla_put_u16(msg
, NL80211_ATTR_VLAN_ID
, vlan_id
))
3270 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3272 wpa_printf(MSG_DEBUG
,
3273 "nl80211: set_key default failed; err=%d %s",
3274 ret
, strerror(-ret
));
3278 nl80211_nlmsg_clear(msg
);
3281 nl80211_nlmsg_clear(key_msg
);
3282 nlmsg_free(key_msg
);
3287 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
3288 int key_idx
, int defkey
,
3289 const u8
*seq
, size_t seq_len
,
3290 const u8
*key
, size_t key_len
)
3292 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
3298 suite
= wpa_alg_to_cipher_suite(alg
, key_len
);
3302 if (defkey
&& alg
== WPA_ALG_IGTK
) {
3303 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT_MGMT
))
3305 } else if (defkey
) {
3306 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT
))
3310 if (nla_put_u8(msg
, NL80211_KEY_IDX
, key_idx
) ||
3311 nla_put_u32(msg
, NL80211_KEY_CIPHER
, suite
) ||
3313 nla_put(msg
, NL80211_KEY_SEQ
, seq_len
, seq
)) ||
3314 nla_put(msg
, NL80211_KEY_DATA
, key_len
, key
))
3317 nla_nest_end(msg
, key_attr
);
3323 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
3327 struct nlattr
*nl_keys
, *nl_key
;
3329 for (i
= 0; i
< 4; i
++) {
3330 if (!params
->wep_key
[i
])
3335 if (params
->wps
== WPS_MODE_PRIVACY
)
3337 if (params
->pairwise_suite
&&
3338 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
3344 if (nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
3347 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
3351 for (i
= 0; i
< 4; i
++) {
3352 if (!params
->wep_key
[i
])
3355 nl_key
= nla_nest_start(msg
, i
);
3357 nla_put(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
3358 params
->wep_key
[i
]) ||
3359 nla_put_u32(msg
, NL80211_KEY_CIPHER
,
3360 params
->wep_key_len
[i
] == 5 ?
3361 RSN_CIPHER_SUITE_WEP40
:
3362 RSN_CIPHER_SUITE_WEP104
) ||
3363 nla_put_u8(msg
, NL80211_KEY_IDX
, i
) ||
3364 (i
== params
->wep_tx_keyidx
&&
3365 nla_put_flag(msg
, NL80211_KEY_DEFAULT
)))
3368 nla_nest_end(msg
, nl_key
);
3370 nla_nest_end(msg
, nl_keys
);
3376 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
3377 const u8
*addr
, int cmd
, u16 reason_code
,
3378 int local_state_change
,
3379 struct nl_sock
*nl_connect
)
3384 if (!(msg
= nl80211_drv_msg(drv
, 0, cmd
)) ||
3385 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
) ||
3386 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
3387 (local_state_change
&&
3388 nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))) {
3394 ret
= send_and_recv(drv
->global
, nl_connect
, msg
, NULL
, NULL
);
3396 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3398 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
3399 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
3400 reason_code
, ret
, strerror(-ret
));
3406 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
3408 struct nl_sock
*nl_connect
)
3411 int drv_associated
= drv
->associated
;
3413 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
3414 nl80211_mark_disconnected(drv
);
3415 /* Disconnect command doesn't need BSSID - it uses cached value */
3416 ret
= wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
3417 reason_code
, 0, nl_connect
);
3419 * For locally generated disconnect, supplicant already generates a
3420 * DEAUTH event, so ignore the event from NL80211.
3422 drv
->ignore_next_local_disconnect
= drv_associated
&& (ret
== 0);
3428 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
3429 const u8
*addr
, u16 reason_code
)
3431 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3433 int drv_associated
= drv
->associated
;
3435 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3436 nl80211_mark_disconnected(drv
);
3437 return nl80211_leave_ibss(drv
, 1);
3439 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
3440 struct nl_sock
*nl_connect
= NULL
;
3442 if (bss
->use_nl_connect
)
3443 nl_connect
= bss
->nl_connect
;
3444 return wpa_driver_nl80211_disconnect(drv
, reason_code
,
3447 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
3448 __func__
, MAC2STR(addr
), reason_code
);
3449 nl80211_mark_disconnected(drv
);
3450 ret
= wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
3451 reason_code
, 0, NULL
);
3453 * For locally generated deauthenticate, supplicant already generates a
3454 * DEAUTH event, so ignore the event from NL80211.
3456 drv
->ignore_next_local_deauth
= drv_associated
&& (ret
== 0);
3462 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
3463 struct wpa_driver_auth_params
*params
)
3467 drv
->auth_freq
= params
->freq
;
3468 drv
->auth_alg
= params
->auth_alg
;
3469 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
3470 drv
->auth_local_state_change
= params
->local_state_change
;
3471 drv
->auth_p2p
= params
->p2p
;
3474 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
3476 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
3479 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
3480 drv
->auth_ssid_len
= params
->ssid_len
;
3482 drv
->auth_ssid_len
= 0;
3485 os_free(drv
->auth_ie
);
3486 drv
->auth_ie
= NULL
;
3487 drv
->auth_ie_len
= 0;
3489 drv
->auth_ie
= os_malloc(params
->ie_len
);
3491 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
3492 drv
->auth_ie_len
= params
->ie_len
;
3496 for (i
= 0; i
< 4; i
++) {
3497 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
3498 params
->wep_key_len
[i
] <= 16) {
3499 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
3500 params
->wep_key_len
[i
]);
3501 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
3503 drv
->auth_wep_key_len
[i
] = 0;
3508 static void nl80211_unmask_11b_rates(struct i802_bss
*bss
)
3510 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3512 if (is_p2p_net_interface(drv
->nlmode
) || !drv
->disabled_11b_rates
)
3516 * Looks like we failed to unmask 11b rates previously. This could
3517 * happen, e.g., if the interface was down at the point in time when a
3518 * P2P group was terminated.
3520 wpa_printf(MSG_DEBUG
,
3521 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
3523 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
3527 static enum nl80211_auth_type
get_nl_auth_type(int wpa_auth_alg
)
3529 if (wpa_auth_alg
& WPA_AUTH_ALG_OPEN
)
3530 return NL80211_AUTHTYPE_OPEN_SYSTEM
;
3531 if (wpa_auth_alg
& WPA_AUTH_ALG_SHARED
)
3532 return NL80211_AUTHTYPE_SHARED_KEY
;
3533 if (wpa_auth_alg
& WPA_AUTH_ALG_LEAP
)
3534 return NL80211_AUTHTYPE_NETWORK_EAP
;
3535 if (wpa_auth_alg
& WPA_AUTH_ALG_FT
)
3536 return NL80211_AUTHTYPE_FT
;
3537 if (wpa_auth_alg
& WPA_AUTH_ALG_SAE
)
3538 return NL80211_AUTHTYPE_SAE
;
3539 if (wpa_auth_alg
& WPA_AUTH_ALG_FILS
)
3540 return NL80211_AUTHTYPE_FILS_SK
;
3541 if (wpa_auth_alg
& WPA_AUTH_ALG_FILS_SK_PFS
)
3542 return NL80211_AUTHTYPE_FILS_SK_PFS
;
3544 return NL80211_AUTHTYPE_MAX
;
3548 static int wpa_driver_nl80211_authenticate(
3549 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
3551 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3554 enum nl80211_auth_type type
;
3555 enum nl80211_iftype nlmode
;
3558 struct wpa_driver_set_key_params p
;
3560 nl80211_unmask_11b_rates(bss
);
3562 is_retry
= drv
->retry_auth
;
3563 drv
->retry_auth
= 0;
3564 drv
->ignore_deauth_event
= 0;
3566 nl80211_mark_disconnected(drv
);
3567 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
3569 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
3571 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
3572 /* FIX: IBSS mode */
3573 nlmode
= params
->p2p
?
3574 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
3575 if (drv
->nlmode
!= nlmode
&&
3576 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
3580 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
3583 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_AUTHENTICATE
);
3587 os_memset(&p
, 0, sizeof(p
));
3588 p
.ifname
= bss
->ifname
;
3589 p
.alg
= WPA_ALG_WEP
;
3590 for (i
= 0; i
< 4; i
++) {
3591 if (!params
->wep_key
[i
])
3594 p
.set_tx
= i
== params
->wep_tx_keyidx
;
3595 p
.key
= params
->wep_key
[i
];
3596 p
.key_len
= params
->wep_key_len
[i
];
3597 p
.key_flag
= i
== params
->wep_tx_keyidx
?
3598 KEY_FLAG_GROUP_RX_TX_DEFAULT
:
3599 KEY_FLAG_GROUP_RX_TX
;
3600 wpa_driver_nl80211_set_key(bss
, &p
);
3601 if (params
->wep_tx_keyidx
!= i
)
3603 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
3604 params
->wep_key
[i
], params
->wep_key_len
[i
]))
3608 if (params
->bssid
) {
3609 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
3610 MAC2STR(params
->bssid
));
3611 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
3615 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
3616 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
))
3620 wpa_printf(MSG_DEBUG
, " * SSID=%s",
3621 wpa_ssid_txt(params
->ssid
, params
->ssid_len
));
3622 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
3626 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
3628 nla_put(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
))
3630 if (params
->auth_data
) {
3631 wpa_hexdump(MSG_DEBUG
, " * auth_data", params
->auth_data
,
3632 params
->auth_data_len
);
3633 if (nla_put(msg
, NL80211_ATTR_SAE_DATA
, params
->auth_data_len
,
3637 type
= get_nl_auth_type(params
->auth_alg
);
3638 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
3639 if (type
== NL80211_AUTHTYPE_MAX
||
3640 nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
3642 if (params
->local_state_change
) {
3643 wpa_printf(MSG_DEBUG
, " * Local state change only");
3644 if (nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))
3648 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3651 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
3652 "nl80211: MLME command failed (auth): count=%d ret=%d (%s)",
3653 count
, ret
, strerror(-ret
));
3655 if ((ret
== -EALREADY
|| ret
== -EEXIST
) && count
== 1 &&
3656 params
->bssid
&& !params
->local_state_change
) {
3658 * mac80211 does not currently accept new
3659 * authentication if we are already authenticated. As a
3660 * workaround, force deauthentication and try again.
3662 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
3663 "after forced deauthentication");
3664 drv
->ignore_deauth_event
= 1;
3665 wpa_driver_nl80211_deauthenticate(
3667 WLAN_REASON_PREV_AUTH_NOT_VALID
);
3672 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
3674 * cfg80211 has likely expired the BSS entry even
3675 * though it was previously available in our internal
3676 * BSS table. To recover quickly, start a single
3677 * channel scan on the specified channel.
3679 struct wpa_driver_scan_params scan
;
3682 os_memset(&scan
, 0, sizeof(scan
));
3685 scan
.ssids
[0].ssid
= params
->ssid
;
3686 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
3688 freqs
[0] = params
->freq
;
3691 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
3692 "channel scan to refresh cfg80211 BSS "
3694 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
3696 nl80211_copy_auth_params(drv
, params
);
3697 drv
->scan_for_auth
= 1;
3699 } else if (is_retry
) {
3701 * Need to indicate this with an event since the return
3702 * value from the retry is not delivered to core code.
3704 union wpa_event_data event
;
3705 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
3707 os_memset(&event
, 0, sizeof(event
));
3708 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
3710 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
3714 wpa_printf(MSG_DEBUG
,
3715 "nl80211: Authentication request send successfully");
3724 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data
*drv
)
3726 struct wpa_driver_auth_params params
;
3727 struct i802_bss
*bss
= drv
->first_bss
;
3730 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
3732 os_memset(¶ms
, 0, sizeof(params
));
3733 params
.freq
= drv
->auth_freq
;
3734 params
.auth_alg
= drv
->auth_alg
;
3735 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
3736 params
.local_state_change
= drv
->auth_local_state_change
;
3737 params
.p2p
= drv
->auth_p2p
;
3739 if (!is_zero_ether_addr(drv
->auth_bssid_
))
3740 params
.bssid
= drv
->auth_bssid_
;
3742 if (drv
->auth_ssid_len
) {
3743 params
.ssid
= drv
->auth_ssid
;
3744 params
.ssid_len
= drv
->auth_ssid_len
;
3747 params
.ie
= drv
->auth_ie
;
3748 params
.ie_len
= drv
->auth_ie_len
;
3750 for (i
= 0; i
< 4; i
++) {
3751 if (drv
->auth_wep_key_len
[i
]) {
3752 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
3753 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
3757 drv
->retry_auth
= 1;
3758 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
3762 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
3763 size_t data_len
, int noack
,
3764 unsigned int freq
, int no_cck
,
3766 unsigned int wait_time
,
3767 const u16
*csa_offs
,
3768 size_t csa_offs_len
, int no_encrypt
)
3770 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3771 struct ieee80211_mgmt
*mgmt
;
3772 int encrypt
= !no_encrypt
;
3777 mgmt
= (struct ieee80211_mgmt
*) data
;
3778 fc
= le_to_host16(mgmt
->frame_control
);
3779 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme - da=" MACSTR
3780 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u no_encrypt=%d fc=0x%x (%s) nlmode=%d",
3781 MAC2STR(mgmt
->da
), noack
, freq
, no_cck
, offchanok
, wait_time
,
3782 no_encrypt
, fc
, fc2str(fc
), drv
->nlmode
);
3784 if ((is_sta_interface(drv
->nlmode
) ||
3785 drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) &&
3786 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3787 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
3789 * The use of last_mgmt_freq is a bit of a hack,
3790 * but it works due to the single-threaded nature
3791 * of wpa_supplicant.
3794 wpa_printf(MSG_DEBUG
, "nl80211: Use last_mgmt_freq=%d",
3795 drv
->last_mgmt_freq
);
3796 freq
= drv
->last_mgmt_freq
;
3802 goto send_frame_cmd
;
3805 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
3807 wpa_printf(MSG_DEBUG
, "nl80211: Use bss->freq=%d",
3811 if ((int) freq
== bss
->freq
)
3813 goto send_frame_cmd
;
3816 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3817 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
3819 * Only one of the authentication frame types is encrypted.
3820 * In order for static WEP encryption to work properly (i.e.,
3821 * to not encrypt the frame), we need to tell mac80211 about
3822 * the frames that must not be encrypted.
3824 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
3825 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
3826 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
3830 if (freq
== 0 && drv
->nlmode
== NL80211_IFTYPE_STATION
&&
3831 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SAE
) &&
3832 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) &&
3833 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3834 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
3835 freq
= nl80211_get_assoc_freq(drv
);
3836 wpa_printf(MSG_DEBUG
,
3837 "nl80211: send_mlme - Use assoc_freq=%u for external auth",
3841 if (freq
== 0 && drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3842 freq
= nl80211_get_assoc_freq(drv
);
3843 wpa_printf(MSG_DEBUG
,
3844 "nl80211: send_mlme - Use assoc_freq=%u for IBSS",
3848 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme - Use bss->freq=%u",
3853 if (drv
->use_monitor
) {
3854 wpa_printf(MSG_DEBUG
,
3855 "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
3857 return nl80211_send_monitor(drv
, data
, data_len
, encrypt
,
3861 if (noack
|| WLAN_FC_GET_TYPE(fc
) != WLAN_FC_TYPE_MGMT
||
3862 WLAN_FC_GET_STYPE(fc
) != WLAN_FC_STYPE_ACTION
)
3865 #ifdef CONFIG_TESTING_OPTIONS
3866 if (no_encrypt
&& !encrypt
&& !drv
->use_monitor
) {
3867 wpa_printf(MSG_DEBUG
,
3868 "nl80211: Request to send an unencrypted frame - use a monitor interface for this");
3869 if (nl80211_create_monitor_interface(drv
) < 0)
3871 res
= nl80211_send_monitor(drv
, data
, data_len
, encrypt
,
3873 nl80211_remove_monitor_interface(drv
);
3876 #endif /* CONFIG_TESTING_OPTIONS */
3878 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme -> send_frame_cmd");
3879 res
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, data_len
,
3880 use_cookie
, no_cck
, noack
, offchanok
,
3881 csa_offs
, csa_offs_len
);
3887 static int nl80211_put_basic_rates(struct nl_msg
*msg
, const int *basic_rates
)
3889 u8 rates
[NL80211_MAX_SUPP_RATES
];
3896 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0; i
++)
3897 rates
[rates_len
++] = basic_rates
[i
] / 5;
3899 return nla_put(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
3903 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
3904 int slot
, int ht_opmode
, int ap_isolate
,
3905 const int *basic_rates
)
3907 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3910 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_BSS
)) ||
3912 nla_put_u8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
)) ||
3914 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
)) ||
3916 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
)) ||
3918 nla_put_u16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
)) ||
3920 nla_put_u8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
)) ||
3921 nl80211_put_basic_rates(msg
, basic_rates
)) {
3926 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3930 static int wpa_driver_nl80211_set_acl(void *priv
,
3931 struct hostapd_acl_params
*params
)
3933 struct i802_bss
*bss
= priv
;
3934 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3940 if (!(drv
->capa
.max_acl_mac_addrs
))
3943 if (params
->num_mac_acl
> drv
->capa
.max_acl_mac_addrs
)
3946 wpa_printf(MSG_DEBUG
, "nl80211: Set %s ACL (num_mac_acl=%u)",
3947 params
->acl_policy
? "Accept" : "Deny", params
->num_mac_acl
);
3949 acl
= nlmsg_alloc();
3952 for (i
= 0; i
< params
->num_mac_acl
; i
++) {
3953 if (nla_put(acl
, i
+ 1, ETH_ALEN
, params
->mac_acl
[i
].addr
)) {
3959 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_MAC_ACL
)) ||
3960 nla_put_u32(msg
, NL80211_ATTR_ACL_POLICY
, params
->acl_policy
?
3961 NL80211_ACL_POLICY_DENY_UNLESS_LISTED
:
3962 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
) ||
3963 nla_put_nested(msg
, NL80211_ATTR_MAC_ADDRS
, acl
)) {
3970 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3972 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set MAC ACL: %d (%s)",
3973 ret
, strerror(-ret
));
3980 static int nl80211_put_beacon_int(struct nl_msg
*msg
, int beacon_int
)
3982 if (beacon_int
> 0) {
3983 wpa_printf(MSG_DEBUG
, " * beacon_int=%d", beacon_int
);
3984 return nla_put_u32(msg
, NL80211_ATTR_BEACON_INTERVAL
,
3992 static int nl80211_put_dtim_period(struct nl_msg
*msg
, int dtim_period
)
3994 if (dtim_period
> 0) {
3995 wpa_printf(MSG_DEBUG
, " * dtim_period=%d", dtim_period
);
3996 return nla_put_u32(msg
, NL80211_ATTR_DTIM_PERIOD
, dtim_period
);
4004 static int nl80211_set_mesh_config(void *priv
,
4005 struct wpa_driver_mesh_bss_params
*params
)
4007 struct i802_bss
*bss
= priv
;
4008 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4012 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_MESH_CONFIG
);
4016 ret
= nl80211_put_mesh_config(msg
, params
);
4022 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4024 wpa_printf(MSG_ERROR
,
4025 "nl80211: Mesh config set failed: %d (%s)",
4026 ret
, strerror(-ret
));
4031 #endif /* CONFIG_MESH */
4034 static int nl80211_put_beacon_rate(struct nl_msg
*msg
, const u64 flags
,
4035 struct wpa_driver_ap_params
*params
)
4037 struct nlattr
*bands
, *band
;
4038 struct nl80211_txrate_vht vht_rate
;
4040 if (!params
->freq
||
4041 (params
->beacon_rate
== 0 &&
4042 params
->rate_type
== BEACON_RATE_LEGACY
))
4045 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
4049 switch (params
->freq
->mode
) {
4050 case HOSTAPD_MODE_IEEE80211B
:
4051 case HOSTAPD_MODE_IEEE80211G
:
4052 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
4054 case HOSTAPD_MODE_IEEE80211A
:
4055 band
= nla_nest_start(msg
, NL80211_BAND_5GHZ
);
4057 case HOSTAPD_MODE_IEEE80211AD
:
4058 band
= nla_nest_start(msg
, NL80211_BAND_60GHZ
);
4067 os_memset(&vht_rate
, 0, sizeof(vht_rate
));
4069 switch (params
->rate_type
) {
4070 case BEACON_RATE_LEGACY
:
4071 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY
)) {
4072 wpa_printf(MSG_INFO
,
4073 "nl80211: Driver does not support setting Beacon frame rate (legacy)");
4077 if (nla_put_u8(msg
, NL80211_TXRATE_LEGACY
,
4078 (u8
) params
->beacon_rate
/ 5) ||
4079 nla_put(msg
, NL80211_TXRATE_HT
, 0, NULL
) ||
4080 (params
->freq
->vht_enabled
&&
4081 nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
4085 wpa_printf(MSG_DEBUG
, " * beacon_rate = legacy:%u (* 100 kbps)",
4086 params
->beacon_rate
);
4088 case BEACON_RATE_HT
:
4089 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_HT
)) {
4090 wpa_printf(MSG_INFO
,
4091 "nl80211: Driver does not support setting Beacon frame rate (HT)");
4094 if (nla_put(msg
, NL80211_TXRATE_LEGACY
, 0, NULL
) ||
4095 nla_put_u8(msg
, NL80211_TXRATE_HT
, params
->beacon_rate
) ||
4096 (params
->freq
->vht_enabled
&&
4097 nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
4100 wpa_printf(MSG_DEBUG
, " * beacon_rate = HT-MCS %u",
4101 params
->beacon_rate
);
4103 case BEACON_RATE_VHT
:
4104 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_VHT
)) {
4105 wpa_printf(MSG_INFO
,
4106 "nl80211: Driver does not support setting Beacon frame rate (VHT)");
4109 vht_rate
.mcs
[0] = BIT(params
->beacon_rate
);
4110 if (nla_put(msg
, NL80211_TXRATE_LEGACY
, 0, NULL
))
4112 if (nla_put(msg
, NL80211_TXRATE_HT
, 0, NULL
))
4114 if (nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
4117 wpa_printf(MSG_DEBUG
, " * beacon_rate = VHT-MCS %u",
4118 params
->beacon_rate
);
4122 nla_nest_end(msg
, band
);
4123 nla_nest_end(msg
, bands
);
4129 static int nl80211_set_multicast_to_unicast(struct i802_bss
*bss
,
4130 int multicast_to_unicast
)
4132 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4136 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST
);
4138 (multicast_to_unicast
&&
4139 nla_put_flag(msg
, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
))) {
4140 wpa_printf(MSG_ERROR
,
4141 "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s",
4147 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4151 wpa_printf(MSG_DEBUG
,
4152 "nl80211: multicast to unicast %s on interface %s",
4153 multicast_to_unicast
? "enabled" : "disabled",
4157 if (!multicast_to_unicast
)
4159 wpa_printf(MSG_INFO
,
4160 "nl80211: multicast to unicast not supported on interface %s",
4164 wpa_printf(MSG_ERROR
,
4165 "nl80211: %s multicast to unicast failed with %d (%s) on interface %s",
4166 multicast_to_unicast
? "enabling" : "disabling",
4167 ret
, strerror(-ret
), bss
->ifname
);
4175 static int wpa_driver_nl80211_set_ap(void *priv
,
4176 struct wpa_driver_ap_params
*params
)
4178 struct i802_bss
*bss
= priv
;
4179 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4181 u8 cmd
= NL80211_CMD_NEW_BEACON
;
4185 u32 suites
[20], suite
;
4188 struct wpa_driver_mesh_bss_params mesh_params
;
4189 #endif /* CONFIG_MESH */
4191 beacon_set
= params
->reenable
? 0 : bss
->beacon_set
;
4193 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
4196 cmd
= NL80211_CMD_SET_BEACON
;
4197 else if (!drv
->device_ap_sme
&& !drv
->use_monitor
&&
4198 !nl80211_get_wiphy_data_ap(bss
))
4201 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon head",
4202 params
->head
, params
->head_len
);
4203 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon tail",
4204 params
->tail
, params
->tail_len
);
4205 wpa_printf(MSG_DEBUG
, "nl80211: ifindex=%d", bss
->ifindex
);
4206 wpa_printf(MSG_DEBUG
, "nl80211: beacon_int=%d", params
->beacon_int
);
4207 wpa_printf(MSG_DEBUG
, "nl80211: beacon_rate=%u", params
->beacon_rate
);
4208 wpa_printf(MSG_DEBUG
, "nl80211: rate_type=%d", params
->rate_type
);
4209 wpa_printf(MSG_DEBUG
, "nl80211: dtim_period=%d", params
->dtim_period
);
4210 wpa_printf(MSG_DEBUG
, "nl80211: ssid=%s",
4211 wpa_ssid_txt(params
->ssid
, params
->ssid_len
));
4212 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
4213 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
,
4215 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
,
4217 nl80211_put_beacon_int(msg
, params
->beacon_int
) ||
4218 nl80211_put_beacon_rate(msg
, drv
->capa
.flags
, params
) ||
4219 nl80211_put_dtim_period(msg
, params
->dtim_period
) ||
4220 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
4222 if (params
->proberesp
&& params
->proberesp_len
) {
4223 wpa_hexdump(MSG_DEBUG
, "nl80211: proberesp (offload)",
4224 params
->proberesp
, params
->proberesp_len
);
4225 if (nla_put(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
4229 switch (params
->hide_ssid
) {
4230 case NO_SSID_HIDING
:
4231 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID not in use");
4232 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4233 NL80211_HIDDEN_SSID_NOT_IN_USE
))
4236 case HIDDEN_SSID_ZERO_LEN
:
4237 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero len");
4238 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4239 NL80211_HIDDEN_SSID_ZERO_LEN
))
4242 case HIDDEN_SSID_ZERO_CONTENTS
:
4243 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero contents");
4244 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
4245 NL80211_HIDDEN_SSID_ZERO_CONTENTS
))
4249 wpa_printf(MSG_DEBUG
, "nl80211: privacy=%d", params
->privacy
);
4250 if (params
->privacy
&&
4251 nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
4253 wpa_printf(MSG_DEBUG
, "nl80211: auth_algs=0x%x", params
->auth_algs
);
4254 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
4255 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
4256 /* Leave out the attribute */
4257 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
) {
4258 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
4259 NL80211_AUTHTYPE_SHARED_KEY
))
4262 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
4263 NL80211_AUTHTYPE_OPEN_SYSTEM
))
4267 wpa_printf(MSG_DEBUG
, "nl80211: wpa_version=0x%x", params
->wpa_version
);
4269 if (params
->wpa_version
& WPA_PROTO_WPA
)
4270 ver
|= NL80211_WPA_VERSION_1
;
4271 if (params
->wpa_version
& WPA_PROTO_RSN
)
4272 ver
|= NL80211_WPA_VERSION_2
;
4274 nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
4277 wpa_printf(MSG_DEBUG
, "nl80211: key_mgmt_suites=0x%x",
4278 params
->key_mgmt_suites
);
4279 num_suites
= wpa_key_mgmt_to_suites(params
->key_mgmt_suites
,
4280 suites
, ARRAY_SIZE(suites
));
4281 if (num_suites
> NL80211_MAX_NR_AKM_SUITES
)
4282 wpa_printf(MSG_WARNING
,
4283 "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)",
4285 else if (num_suites
&&
4286 nla_put(msg
, NL80211_ATTR_AKM_SUITES
, num_suites
* sizeof(u32
),
4290 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
4291 (!params
->pairwise_ciphers
||
4292 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
)) &&
4293 (nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, ETH_P_PAE
) ||
4294 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
4297 if (drv
->device_ap_sme
&&
4298 (params
->key_mgmt_suites
& WPA_KEY_MGMT_SAE
) &&
4299 nla_put_flag(msg
, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
))
4302 wpa_printf(MSG_DEBUG
, "nl80211: pairwise_ciphers=0x%x",
4303 params
->pairwise_ciphers
);
4304 num_suites
= wpa_cipher_to_cipher_suites(params
->pairwise_ciphers
,
4305 suites
, ARRAY_SIZE(suites
));
4307 nla_put(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
4308 num_suites
* sizeof(u32
), suites
))
4311 wpa_printf(MSG_DEBUG
, "nl80211: group_cipher=0x%x",
4312 params
->group_cipher
);
4313 suite
= wpa_cipher_to_cipher_suite(params
->group_cipher
);
4315 nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, suite
))
4318 if (params
->beacon_ies
) {
4319 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: beacon_ies",
4320 params
->beacon_ies
);
4321 if (nla_put(msg
, NL80211_ATTR_IE
,
4322 wpabuf_len(params
->beacon_ies
),
4323 wpabuf_head(params
->beacon_ies
)))
4326 if (params
->proberesp_ies
) {
4327 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: proberesp_ies",
4328 params
->proberesp_ies
);
4329 if (nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
4330 wpabuf_len(params
->proberesp_ies
),
4331 wpabuf_head(params
->proberesp_ies
)))
4334 if (params
->assocresp_ies
) {
4335 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: assocresp_ies",
4336 params
->assocresp_ies
);
4337 if (nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
4338 wpabuf_len(params
->assocresp_ies
),
4339 wpabuf_head(params
->assocresp_ies
)))
4343 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
4344 wpa_printf(MSG_DEBUG
, "nl80211: ap_max_inactivity=%d",
4345 params
->ap_max_inactivity
);
4346 if (nla_put_u16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
4347 params
->ap_max_inactivity
))
4352 if (params
->p2p_go_ctwindow
> 0) {
4353 if (drv
->p2p_go_ctwindow_supported
) {
4354 wpa_printf(MSG_DEBUG
, "nl80211: P2P GO ctwindow=%d",
4355 params
->p2p_go_ctwindow
);
4356 if (nla_put_u8(msg
, NL80211_ATTR_P2P_CTWINDOW
,
4357 params
->p2p_go_ctwindow
))
4360 wpa_printf(MSG_INFO
,
4361 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
4364 #endif /* CONFIG_P2P */
4367 wpa_printf(MSG_DEBUG
, "nl80211: PBSS");
4368 if (nla_put_flag(msg
, NL80211_ATTR_PBSS
))
4372 if (params
->ftm_responder
) {
4375 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_FTM_RESPONDER
)) {
4380 ftm
= nla_nest_start(msg
, NL80211_ATTR_FTM_RESPONDER
);
4382 nla_put_flag(msg
, NL80211_FTM_RESP_ATTR_ENABLED
) ||
4384 nla_put(msg
, NL80211_FTM_RESP_ATTR_LCI
,
4385 wpabuf_len(params
->lci
),
4386 wpabuf_head(params
->lci
))) ||
4388 nla_put(msg
, NL80211_FTM_RESP_ATTR_CIVICLOC
,
4389 wpabuf_len(params
->civic
),
4390 wpabuf_head(params
->civic
))))
4392 nla_nest_end(msg
, ftm
);
4395 #ifdef CONFIG_IEEE80211AX
4396 if (params
->he_spr
) {
4399 spr
= nla_nest_start(msg
, NL80211_ATTR_HE_OBSS_PD
);
4400 wpa_printf(MSG_DEBUG
, "nl80211: he_spr=%d", params
->he_spr
);
4403 nla_put_u8(msg
, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET
,
4404 params
->he_spr_srg_obss_pd_min_offset
) ||
4405 nla_put_u8(msg
, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET
,
4406 params
->he_spr_srg_obss_pd_max_offset
))
4409 nla_nest_end(msg
, spr
);
4412 if (params
->freq
&& params
->freq
->he_enabled
) {
4413 struct nlattr
*bss_color
;
4415 bss_color
= nla_nest_start(msg
, NL80211_ATTR_HE_BSS_COLOR
);
4417 (params
->he_bss_color_disabled
&&
4418 nla_put_flag(msg
, NL80211_HE_BSS_COLOR_ATTR_DISABLED
)) ||
4419 (params
->he_bss_color_partial
&&
4420 nla_put_flag(msg
, NL80211_HE_BSS_COLOR_ATTR_PARTIAL
)) ||
4421 nla_put_u8(msg
, NL80211_HE_BSS_COLOR_ATTR_COLOR
,
4422 params
->he_bss_color
))
4424 nla_nest_end(msg
, bss_color
);
4427 if (params
->twt_responder
) {
4428 wpa_printf(MSG_DEBUG
, "nl80211: twt_responder=%d",
4429 params
->twt_responder
);
4430 if (nla_put_flag(msg
, NL80211_ATTR_TWT_RESPONDER
))
4433 #endif /* CONFIG_IEEE80211AX */
4435 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4437 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
4438 ret
, strerror(-ret
));
4440 bss
->beacon_set
= 1;
4441 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
4442 params
->short_slot_time
, params
->ht_opmode
,
4443 params
->isolate
, params
->basic_rates
);
4444 nl80211_set_multicast_to_unicast(bss
,
4445 params
->multicast_to_unicast
);
4446 if (beacon_set
&& params
->freq
&&
4447 params
->freq
->bandwidth
!= bss
->bandwidth
) {
4448 wpa_printf(MSG_DEBUG
,
4449 "nl80211: Update BSS %s bandwidth: %d -> %d",
4450 bss
->ifname
, bss
->bandwidth
,
4451 params
->freq
->bandwidth
);
4452 ret
= nl80211_set_channel(bss
, params
->freq
, 1);
4454 wpa_printf(MSG_DEBUG
,
4455 "nl80211: Frequency set failed: %d (%s)",
4456 ret
, strerror(-ret
));
4458 wpa_printf(MSG_DEBUG
,
4459 "nl80211: Frequency set succeeded for ht2040 coex");
4460 bss
->bandwidth
= params
->freq
->bandwidth
;
4462 } else if (!beacon_set
&& params
->freq
) {
4464 * cfg80211 updates the driver on frequence change in AP
4465 * mode only at the point when beaconing is started, so
4466 * set the initial value here.
4468 bss
->bandwidth
= params
->freq
->bandwidth
;
4473 if (is_mesh_interface(drv
->nlmode
) && params
->ht_opmode
!= -1) {
4474 os_memset(&mesh_params
, 0, sizeof(mesh_params
));
4475 mesh_params
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE
;
4476 mesh_params
.ht_opmode
= params
->ht_opmode
;
4477 ret
= nl80211_set_mesh_config(priv
, &mesh_params
);
4481 #endif /* CONFIG_MESH */
4490 static int nl80211_put_freq_params(struct nl_msg
*msg
,
4491 const struct hostapd_freq_params
*freq
)
4493 enum hostapd_hw_mode hw_mode
;
4497 wpa_printf(MSG_DEBUG
, " * freq=%d", freq
->freq
);
4498 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
))
4501 wpa_printf(MSG_DEBUG
, " * he_enabled=%d", freq
->he_enabled
);
4502 wpa_printf(MSG_DEBUG
, " * vht_enabled=%d", freq
->vht_enabled
);
4503 wpa_printf(MSG_DEBUG
, " * ht_enabled=%d", freq
->ht_enabled
);
4505 hw_mode
= ieee80211_freq_to_chan(freq
->freq
, &channel
);
4506 is_24ghz
= hw_mode
== HOSTAPD_MODE_IEEE80211G
||
4507 hw_mode
== HOSTAPD_MODE_IEEE80211B
;
4509 if (freq
->vht_enabled
|| (freq
->he_enabled
&& !is_24ghz
)) {
4510 enum nl80211_chan_width cw
;
4512 wpa_printf(MSG_DEBUG
, " * bandwidth=%d", freq
->bandwidth
);
4513 switch (freq
->bandwidth
) {
4515 cw
= NL80211_CHAN_WIDTH_20
;
4518 cw
= NL80211_CHAN_WIDTH_40
;
4521 if (freq
->center_freq2
)
4522 cw
= NL80211_CHAN_WIDTH_80P80
;
4524 cw
= NL80211_CHAN_WIDTH_80
;
4527 cw
= NL80211_CHAN_WIDTH_160
;
4533 wpa_printf(MSG_DEBUG
, " * channel_width=%d", cw
);
4534 wpa_printf(MSG_DEBUG
, " * center_freq1=%d",
4535 freq
->center_freq1
);
4536 wpa_printf(MSG_DEBUG
, " * center_freq2=%d",
4537 freq
->center_freq2
);
4538 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, cw
) ||
4539 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
,
4540 freq
->center_freq1
) ||
4541 (freq
->center_freq2
&&
4542 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
,
4543 freq
->center_freq2
)))
4545 } else if (freq
->ht_enabled
) {
4546 enum nl80211_channel_type ct
;
4548 wpa_printf(MSG_DEBUG
, " * sec_channel_offset=%d",
4549 freq
->sec_channel_offset
);
4550 switch (freq
->sec_channel_offset
) {
4552 ct
= NL80211_CHAN_HT40MINUS
;
4555 ct
= NL80211_CHAN_HT40PLUS
;
4558 ct
= NL80211_CHAN_HT20
;
4562 wpa_printf(MSG_DEBUG
, " * channel_type=%d", ct
);
4563 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, ct
))
4565 } else if (freq
->edmg
.channels
&& freq
->edmg
.bw_config
) {
4566 wpa_printf(MSG_DEBUG
,
4567 " * EDMG configuration: channels=0x%x bw_config=%d",
4568 freq
->edmg
.channels
, freq
->edmg
.bw_config
);
4569 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_EDMG_CHANNELS
,
4570 freq
->edmg
.channels
) ||
4571 nla_put_u8(msg
, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
,
4572 freq
->edmg
.bw_config
))
4575 wpa_printf(MSG_DEBUG
, " * channel_type=%d",
4576 NL80211_CHAN_NO_HT
);
4577 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4578 NL80211_CHAN_NO_HT
))
4585 static int nl80211_set_channel(struct i802_bss
*bss
,
4586 struct hostapd_freq_params
*freq
, int set_chan
)
4588 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4592 wpa_printf(MSG_DEBUG
,
4593 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
4594 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
, freq
->he_enabled
,
4595 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
4597 msg
= nl80211_drv_msg(drv
, 0, set_chan
? NL80211_CMD_SET_CHANNEL
:
4598 NL80211_CMD_SET_WIPHY
);
4599 if (!msg
|| nl80211_put_freq_params(msg
, freq
) < 0) {
4604 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4606 bss
->freq
= freq
->freq
;
4609 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
4610 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
4615 static u32
sta_flags_nl80211(int flags
)
4619 if (flags
& WPA_STA_AUTHORIZED
)
4620 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
4621 if (flags
& WPA_STA_WMM
)
4622 f
|= BIT(NL80211_STA_FLAG_WME
);
4623 if (flags
& WPA_STA_SHORT_PREAMBLE
)
4624 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
4625 if (flags
& WPA_STA_MFP
)
4626 f
|= BIT(NL80211_STA_FLAG_MFP
);
4627 if (flags
& WPA_STA_TDLS_PEER
)
4628 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
4629 if (flags
& WPA_STA_AUTHENTICATED
)
4630 f
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
4631 if (flags
& WPA_STA_ASSOCIATED
)
4632 f
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
4639 static u32
sta_plink_state_nl80211(enum mesh_plink_state state
)
4643 return NL80211_PLINK_LISTEN
;
4645 return NL80211_PLINK_OPN_SNT
;
4646 case PLINK_OPN_RCVD
:
4647 return NL80211_PLINK_OPN_RCVD
;
4648 case PLINK_CNF_RCVD
:
4649 return NL80211_PLINK_CNF_RCVD
;
4651 return NL80211_PLINK_ESTAB
;
4653 return NL80211_PLINK_HOLDING
;
4655 return NL80211_PLINK_BLOCKED
;
4657 wpa_printf(MSG_ERROR
, "nl80211: Invalid mesh plink state %d",
4662 #endif /* CONFIG_MESH */
4665 static int wpa_driver_nl80211_sta_add(void *priv
,
4666 struct hostapd_sta_add_params
*params
)
4668 struct i802_bss
*bss
= priv
;
4669 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4671 struct nl80211_sta_flag_update upd
;
4674 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
4675 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
4678 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
4679 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
4680 msg
= nl80211_bss_msg(bss
, 0, params
->set
? NL80211_CMD_SET_STATION
:
4681 NL80211_CMD_NEW_STATION
);
4682 if (!msg
|| nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
))
4686 * Set the below properties only in one of the following cases:
4687 * 1. New station is added, already associated.
4688 * 2. Set WPA_STA_TDLS_PEER station.
4689 * 3. Set an already added unassociated station, if driver supports
4690 * full AP client state. (Set these properties after station became
4691 * associated will be rejected by the driver).
4693 if (!params
->set
|| (params
->flags
& WPA_STA_TDLS_PEER
) ||
4694 (params
->set
&& FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
) &&
4695 (params
->flags
& WPA_STA_ASSOCIATED
))) {
4696 wpa_hexdump(MSG_DEBUG
, " * supported rates",
4697 params
->supp_rates
, params
->supp_rates_len
);
4698 wpa_printf(MSG_DEBUG
, " * capability=0x%x",
4699 params
->capability
);
4700 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
,
4701 params
->supp_rates_len
, params
->supp_rates
) ||
4702 nla_put_u16(msg
, NL80211_ATTR_STA_CAPABILITY
,
4703 params
->capability
))
4706 if (params
->ht_capabilities
) {
4707 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
4708 (u8
*) params
->ht_capabilities
,
4709 sizeof(*params
->ht_capabilities
));
4710 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
,
4711 sizeof(*params
->ht_capabilities
),
4712 params
->ht_capabilities
))
4716 if (params
->vht_capabilities
) {
4717 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
4718 (u8
*) params
->vht_capabilities
,
4719 sizeof(*params
->vht_capabilities
));
4720 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
,
4721 sizeof(*params
->vht_capabilities
),
4722 params
->vht_capabilities
))
4726 if (params
->he_capab
) {
4727 wpa_hexdump(MSG_DEBUG
, " * he_capab",
4728 params
->he_capab
, params
->he_capab_len
);
4729 if (nla_put(msg
, NL80211_ATTR_HE_CAPABILITY
,
4730 params
->he_capab_len
, params
->he_capab
))
4734 if (params
->ext_capab
) {
4735 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
4736 params
->ext_capab
, params
->ext_capab_len
);
4737 if (nla_put(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
4738 params
->ext_capab_len
, params
->ext_capab
))
4742 if (is_ap_interface(drv
->nlmode
) &&
4743 nla_put_u8(msg
, NL80211_ATTR_STA_SUPPORT_P2P_PS
,
4744 params
->support_p2p_ps
?
4745 NL80211_P2P_PS_SUPPORTED
:
4746 NL80211_P2P_PS_UNSUPPORTED
))
4751 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
4752 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, params
->aid
))
4756 * cfg80211 validates that AID is non-zero, so we have
4757 * to make this a non-zero value for the TDLS case where
4758 * a dummy STA entry is used for now and for a station
4759 * that is still not associated.
4761 wpa_printf(MSG_DEBUG
, " * aid=1 (%s workaround)",
4762 (params
->flags
& WPA_STA_TDLS_PEER
) ?
4763 "TDLS" : "UNASSOC_STA");
4764 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, 1))
4767 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
4768 params
->listen_interval
);
4769 if (nla_put_u16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
4770 params
->listen_interval
))
4772 } else if (params
->aid
&& (params
->flags
& WPA_STA_TDLS_PEER
)) {
4773 wpa_printf(MSG_DEBUG
, " * peer_aid=%u", params
->aid
);
4774 if (nla_put_u16(msg
, NL80211_ATTR_PEER_AID
, params
->aid
))
4776 } else if (FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
) &&
4777 (params
->flags
& WPA_STA_ASSOCIATED
)) {
4778 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
4779 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
4780 params
->listen_interval
);
4781 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, params
->aid
) ||
4782 nla_put_u16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
4783 params
->listen_interval
))
4787 if (params
->vht_opmode_enabled
) {
4788 wpa_printf(MSG_DEBUG
, " * opmode=%u", params
->vht_opmode
);
4789 if (nla_put_u8(msg
, NL80211_ATTR_OPMODE_NOTIF
,
4790 params
->vht_opmode
))
4794 if (params
->supp_channels
) {
4795 wpa_hexdump(MSG_DEBUG
, " * supported channels",
4796 params
->supp_channels
, params
->supp_channels_len
);
4797 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_CHANNELS
,
4798 params
->supp_channels_len
, params
->supp_channels
))
4802 if (params
->supp_oper_classes
) {
4803 wpa_hexdump(MSG_DEBUG
, " * supported operating classes",
4804 params
->supp_oper_classes
,
4805 params
->supp_oper_classes_len
);
4806 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
,
4807 params
->supp_oper_classes_len
,
4808 params
->supp_oper_classes
))
4812 os_memset(&upd
, 0, sizeof(upd
));
4813 upd
.set
= sta_flags_nl80211(params
->flags
);
4814 upd
.mask
= upd
.set
| sta_flags_nl80211(params
->flags_mask
);
4817 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
4818 * flags, as nl80211 driver moves a new station, by default, into
4821 * On the other hand, if the driver supports that feature and the
4822 * station is added in unauthenticated state, set the
4823 * authenticated/associated bits in the mask to prevent moving this
4824 * station to associated state before it is actually associated.
4826 * This is irrelevant for mesh mode where the station is added to the
4827 * driver as authenticated already, and ASSOCIATED isn't part of the
4830 if (!is_mesh_interface(drv
->nlmode
)) {
4831 if (!FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
)) {
4832 wpa_printf(MSG_DEBUG
,
4833 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
4834 upd
.mask
&= ~(BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4835 BIT(NL80211_STA_FLAG_AUTHENTICATED
));
4836 } else if (!params
->set
&&
4837 !(params
->flags
& WPA_STA_TDLS_PEER
)) {
4838 if (!(params
->flags
& WPA_STA_AUTHENTICATED
))
4839 upd
.mask
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
4840 if (!(params
->flags
& WPA_STA_ASSOCIATED
))
4841 upd
.mask
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
4845 if (params
->plink_state
== PLINK_ESTAB
&& params
->peer_aid
) {
4846 ret
= nla_put_u16(msg
, NL80211_ATTR_MESH_PEER_AID
,
4851 #endif /* CONFIG_MESH */
4854 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
4856 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
4860 if (params
->plink_state
&&
4861 nla_put_u8(msg
, NL80211_ATTR_STA_PLINK_STATE
,
4862 sta_plink_state_nl80211(params
->plink_state
)))
4864 #endif /* CONFIG_MESH */
4866 if ((!params
->set
|| (params
->flags
& WPA_STA_TDLS_PEER
) ||
4867 FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
)) &&
4868 (params
->flags
& WPA_STA_WMM
)) {
4869 struct nlattr
*wme
= nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
4871 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
4873 nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
4874 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
) ||
4875 nla_put_u8(msg
, NL80211_STA_WME_MAX_SP
,
4876 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
4877 WMM_QOSINFO_STA_SP_MASK
))
4879 nla_nest_end(msg
, wme
);
4882 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4885 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
4886 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
4896 static void rtnl_neigh_delete_fdb_entry(struct i802_bss
*bss
, const u8
*addr
)
4898 #ifdef CONFIG_LIBNL3_ROUTE
4899 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4900 struct rtnl_neigh
*rn
;
4901 struct nl_addr
*nl_addr
;
4904 rn
= rtnl_neigh_alloc();
4908 rtnl_neigh_set_family(rn
, AF_BRIDGE
);
4909 rtnl_neigh_set_ifindex(rn
, bss
->ifindex
);
4910 nl_addr
= nl_addr_build(AF_BRIDGE
, (void *) addr
, ETH_ALEN
);
4915 rtnl_neigh_set_lladdr(rn
, nl_addr
);
4917 err
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
4919 wpa_printf(MSG_DEBUG
, "nl80211: bridge FDB entry delete for "
4920 MACSTR
" ifindex=%d failed: %s", MAC2STR(addr
),
4921 bss
->ifindex
, nl_geterror(err
));
4923 wpa_printf(MSG_DEBUG
, "nl80211: deleted bridge FDB entry for "
4924 MACSTR
, MAC2STR(addr
));
4927 nl_addr_put(nl_addr
);
4929 #endif /* CONFIG_LIBNL3_ROUTE */
4933 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
,
4934 int deauth
, u16 reason_code
)
4936 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4940 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
)) ||
4941 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
4943 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
4944 WLAN_FC_STYPE_DISASSOC
)) ||
4946 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
4947 WLAN_FC_STYPE_DEAUTH
)) ||
4949 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
))) {
4954 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4955 wpa_printf(MSG_DEBUG
, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
4957 bss
->ifname
, MAC2STR(addr
), ret
, strerror(-ret
));
4960 rtnl_neigh_delete_fdb_entry(bss
, addr
);
4968 void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
4971 struct wpa_driver_nl80211_data
*drv2
;
4973 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
4975 /* stop listening for EAPOL on this interface */
4976 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
4977 struct wpa_driver_nl80211_data
, list
)
4979 del_ifidx(drv2
, ifidx
, IFIDX_ANY
);
4980 /* Remove all bridges learned for this iface */
4981 del_ifidx(drv2
, IFIDX_ANY
, ifidx
);
4984 msg
= nl80211_ifindex_msg(drv
, ifidx
, 0, NL80211_CMD_DEL_INTERFACE
);
4985 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
4987 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
4991 const char * nl80211_iftype_str(enum nl80211_iftype mode
)
4994 case NL80211_IFTYPE_ADHOC
:
4996 case NL80211_IFTYPE_STATION
:
4998 case NL80211_IFTYPE_AP
:
5000 case NL80211_IFTYPE_AP_VLAN
:
5002 case NL80211_IFTYPE_WDS
:
5004 case NL80211_IFTYPE_MONITOR
:
5006 case NL80211_IFTYPE_MESH_POINT
:
5007 return "MESH_POINT";
5008 case NL80211_IFTYPE_P2P_CLIENT
:
5009 return "P2P_CLIENT";
5010 case NL80211_IFTYPE_P2P_GO
:
5012 case NL80211_IFTYPE_P2P_DEVICE
:
5013 return "P2P_DEVICE";
5020 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
5022 enum nl80211_iftype iftype
,
5023 const u8
*addr
, int wds
,
5024 int (*handler
)(struct nl_msg
*, void *),
5031 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
5032 iftype
, nl80211_iftype_str(iftype
));
5034 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_NEW_INTERFACE
);
5036 nla_put_string(msg
, NL80211_ATTR_IFNAME
, ifname
) ||
5037 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, iftype
))
5040 if (iftype
== NL80211_IFTYPE_MONITOR
) {
5041 struct nlattr
*flags
;
5043 flags
= nla_nest_start(msg
, NL80211_ATTR_MNTR_FLAGS
);
5045 nla_put_flag(msg
, NL80211_MNTR_FLAG_COOK_FRAMES
))
5048 nla_nest_end(msg
, flags
);
5050 if (nla_put_u8(msg
, NL80211_ATTR_4ADDR
, wds
))
5055 * Tell cfg80211 that the interface belongs to the socket that created
5056 * it, and the interface should be deleted when the socket is closed.
5058 if (nla_put_flag(msg
, NL80211_ATTR_IFACE_SOCKET_OWNER
))
5061 ret
= send_and_recv_msgs(drv
, msg
, handler
, arg
);
5066 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
5067 ifname
, ret
, strerror(-ret
));
5071 if (iftype
== NL80211_IFTYPE_P2P_DEVICE
)
5074 ifidx
= if_nametoindex(ifname
);
5075 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
5082 * Some virtual interfaces need to process EAPOL packets and events on
5083 * the parent interface. This is used mainly with hostapd.
5086 iftype
== NL80211_IFTYPE_AP_VLAN
||
5087 iftype
== NL80211_IFTYPE_WDS
||
5088 iftype
== NL80211_IFTYPE_MONITOR
) {
5089 /* start listening for EAPOL on this interface */
5090 add_ifidx(drv
, ifidx
, IFIDX_ANY
);
5093 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
5094 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
5095 nl80211_remove_iface(drv
, ifidx
);
5103 int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
5104 const char *ifname
, enum nl80211_iftype iftype
,
5105 const u8
*addr
, int wds
,
5106 int (*handler
)(struct nl_msg
*, void *),
5107 void *arg
, int use_existing
)
5111 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
, handler
,
5114 /* if error occurred and interface exists already */
5115 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
5117 wpa_printf(MSG_DEBUG
, "nl80211: Continue using existing interface %s",
5119 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
5120 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
5122 (linux_set_iface_flags(drv
->global
->ioctl_sock
,
5124 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
5126 linux_set_iface_flags(drv
->global
->ioctl_sock
,
5131 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
5133 /* Try to remove the interface that was already there. */
5134 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
5136 /* Try to create the interface again */
5137 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
5141 if (ret
>= 0 && is_p2p_net_interface(iftype
)) {
5142 wpa_printf(MSG_DEBUG
,
5143 "nl80211: Interface %s created for P2P - disable 11b rates",
5145 nl80211_disable_11b_rates(drv
, ret
, 1);
5152 static int nl80211_setup_ap(struct i802_bss
*bss
)
5154 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5156 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
5157 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
5160 * Disable Probe Request reporting unless we need it in this way for
5161 * devices that include the AP SME, in the other case (unless using
5162 * monitor iface) we'll get it through the nl_mgmt socket instead.
5164 if (!drv
->device_ap_sme
)
5165 wpa_driver_nl80211_probe_req_report(bss
, 0);
5167 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
5168 if (nl80211_mgmt_subscribe_ap(bss
))
5171 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
5172 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
5173 wpa_printf(MSG_DEBUG
,
5174 "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
5176 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
5177 nl80211_create_monitor_interface(drv
) &&
5178 !drv
->device_ap_sme
)
5181 if (drv
->device_ap_sme
&&
5182 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
5183 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
5184 "Probe Request frame reporting in AP mode");
5185 /* Try to survive without this */
5192 static void nl80211_teardown_ap(struct i802_bss
*bss
)
5194 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5196 wpa_printf(MSG_DEBUG
, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
5197 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
5198 if (drv
->device_ap_sme
) {
5199 wpa_driver_nl80211_probe_req_report(bss
, 0);
5200 if (!drv
->use_monitor
)
5201 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
5202 } else if (drv
->use_monitor
)
5203 nl80211_remove_monitor_interface(drv
);
5205 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
5207 nl80211_put_wiphy_data_ap(bss
);
5208 bss
->beacon_set
= 0;
5212 static int nl80211_tx_control_port(void *priv
, const u8
*dest
,
5213 u16 proto
, const u8
*buf
, size_t len
,
5216 struct i802_bss
*bss
= priv
;
5220 wpa_printf(MSG_DEBUG
,
5221 "nl80211: Send over control port dest=" MACSTR
5222 " proto=0x%04x len=%u no_encrypt=%d",
5223 MAC2STR(dest
), proto
, (unsigned int) len
, no_encrypt
);
5225 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_CONTROL_PORT_FRAME
);
5227 nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, proto
) ||
5228 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dest
) ||
5229 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
5231 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
))) {
5236 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
5238 wpa_printf(MSG_DEBUG
,
5239 "nl80211: tx_control_port failed: ret=%d (%s)",
5240 ret
, strerror(-ret
));
5246 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
5247 const u8
*addr
, const u8
*data
,
5250 struct sockaddr_ll ll
;
5253 if (bss
->drv
->eapol_tx_sock
< 0) {
5254 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
5258 os_memset(&ll
, 0, sizeof(ll
));
5259 ll
.sll_family
= AF_PACKET
;
5260 ll
.sll_ifindex
= bss
->ifindex
;
5261 ll
.sll_protocol
= htons(ETH_P_PAE
);
5262 ll
.sll_halen
= ETH_ALEN
;
5263 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
5264 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
5265 (struct sockaddr
*) &ll
, sizeof(ll
));
5267 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
5274 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
5276 static int wpa_driver_nl80211_hapd_send_eapol(
5277 void *priv
, const u8
*addr
, const u8
*data
,
5278 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
5280 struct i802_bss
*bss
= priv
;
5281 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5282 struct ieee80211_hdr
*hdr
;
5286 int qos
= flags
& WPA_STA_WMM
;
5288 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_CONTROL_PORT
)
5289 return nl80211_tx_control_port(bss
, addr
, ETH_P_EAPOL
,
5290 data
, data_len
, !encrypt
);
5292 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
5293 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
5295 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
5297 hdr
= os_zalloc(len
);
5299 wpa_printf(MSG_INFO
, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
5300 (unsigned long) len
);
5304 hdr
->frame_control
=
5305 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
5306 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
5308 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
5310 hdr
->frame_control
|=
5311 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
5314 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
5315 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
5316 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
5317 pos
= (u8
*) (hdr
+ 1);
5320 /* Set highest priority in QoS header */
5326 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
5327 pos
+= sizeof(rfc1042_header
);
5328 WPA_PUT_BE16(pos
, ETH_P_PAE
);
5330 memcpy(pos
, data
, data_len
);
5332 res
= nl80211_send_monitor(drv
, hdr
, len
, encrypt
, 0);
5334 wpa_printf(MSG_ERROR
,
5335 "hapd_send_eapol - packet len: %lu - failed",
5336 (unsigned long) len
);
5344 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
5345 unsigned int total_flags
,
5346 unsigned int flags_or
,
5347 unsigned int flags_and
)
5349 struct i802_bss
*bss
= priv
;
5351 struct nlattr
*flags
;
5352 struct nl80211_sta_flag_update upd
;
5354 wpa_printf(MSG_DEBUG
, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
5355 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
5356 bss
->ifname
, MAC2STR(addr
), total_flags
, flags_or
, flags_and
,
5357 !!(total_flags
& WPA_STA_AUTHORIZED
));
5359 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
5360 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
5364 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
5365 * can be removed eventually.
5367 flags
= nla_nest_start(msg
, NL80211_ATTR_STA_FLAGS
);
5369 ((total_flags
& WPA_STA_AUTHORIZED
) &&
5370 nla_put_flag(msg
, NL80211_STA_FLAG_AUTHORIZED
)) ||
5371 ((total_flags
& WPA_STA_WMM
) &&
5372 nla_put_flag(msg
, NL80211_STA_FLAG_WME
)) ||
5373 ((total_flags
& WPA_STA_SHORT_PREAMBLE
) &&
5374 nla_put_flag(msg
, NL80211_STA_FLAG_SHORT_PREAMBLE
)) ||
5375 ((total_flags
& WPA_STA_MFP
) &&
5376 nla_put_flag(msg
, NL80211_STA_FLAG_MFP
)) ||
5377 ((total_flags
& WPA_STA_TDLS_PEER
) &&
5378 nla_put_flag(msg
, NL80211_STA_FLAG_TDLS_PEER
)))
5381 nla_nest_end(msg
, flags
);
5383 os_memset(&upd
, 0, sizeof(upd
));
5384 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
5385 upd
.set
= sta_flags_nl80211(flags_or
);
5386 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
5389 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
5396 static int driver_nl80211_sta_set_airtime_weight(void *priv
, const u8
*addr
,
5397 unsigned int weight
)
5399 struct i802_bss
*bss
= priv
;
5402 wpa_printf(MSG_DEBUG
,
5403 "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR
5404 " weight=%u", bss
->ifname
, MAC2STR(addr
), weight
);
5406 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
5407 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
5408 nla_put_u16(msg
, NL80211_ATTR_AIRTIME_WEIGHT
, weight
))
5411 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
5418 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
5419 struct wpa_driver_associate_params
*params
)
5421 enum nl80211_iftype nlmode
, old_mode
;
5424 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
5426 nlmode
= NL80211_IFTYPE_P2P_GO
;
5428 nlmode
= NL80211_IFTYPE_AP
;
5430 old_mode
= drv
->nlmode
;
5431 if (wpa_driver_nl80211_set_mode(drv
->first_bss
, nlmode
)) {
5432 nl80211_remove_monitor_interface(drv
);
5436 if (params
->freq
.freq
&&
5437 nl80211_set_channel(drv
->first_bss
, ¶ms
->freq
, 0)) {
5438 if (old_mode
!= nlmode
)
5439 wpa_driver_nl80211_set_mode(drv
->first_bss
, old_mode
);
5440 nl80211_remove_monitor_interface(drv
);
5448 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
5454 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_IBSS
);
5455 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5457 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
5458 "(%s)", ret
, strerror(-ret
));
5460 wpa_printf(MSG_DEBUG
,
5461 "nl80211: Leave IBSS request sent successfully");
5465 wpa_driver_nl80211_set_mode(drv
->first_bss
,
5466 NL80211_IFTYPE_STATION
)) {
5467 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
5475 static int nl80211_ht_vht_overrides(struct nl_msg
*msg
,
5476 struct wpa_driver_associate_params
*params
)
5478 if (params
->disable_ht
&& nla_put_flag(msg
, NL80211_ATTR_DISABLE_HT
))
5481 if (params
->htcaps
&& params
->htcaps_mask
) {
5482 int sz
= sizeof(struct ieee80211_ht_capabilities
);
5483 wpa_hexdump(MSG_DEBUG
, " * htcaps", params
->htcaps
, sz
);
5484 wpa_hexdump(MSG_DEBUG
, " * htcaps_mask",
5485 params
->htcaps_mask
, sz
);
5486 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
,
5488 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
5489 params
->htcaps_mask
))
5493 #ifdef CONFIG_VHT_OVERRIDES
5494 if (params
->disable_vht
) {
5495 wpa_printf(MSG_DEBUG
, " * VHT disabled");
5496 if (nla_put_flag(msg
, NL80211_ATTR_DISABLE_VHT
))
5500 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
5501 int sz
= sizeof(struct ieee80211_vht_capabilities
);
5502 wpa_hexdump(MSG_DEBUG
, " * vhtcaps", params
->vhtcaps
, sz
);
5503 wpa_hexdump(MSG_DEBUG
, " * vhtcaps_mask",
5504 params
->vhtcaps_mask
, sz
);
5505 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
,
5507 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
5508 params
->vhtcaps_mask
))
5511 #endif /* CONFIG_VHT_OVERRIDES */
5517 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
5518 struct wpa_driver_associate_params
*params
)
5524 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
5526 if (wpa_driver_nl80211_set_mode_ibss(drv
->first_bss
, ¶ms
->freq
)) {
5527 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
5533 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_IBSS
)) ||
5534 params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
5537 wpa_printf(MSG_DEBUG
, " * SSID=%s",
5538 wpa_ssid_txt(params
->ssid
, params
->ssid_len
));
5539 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
5541 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5542 drv
->ssid_len
= params
->ssid_len
;
5544 if (nl80211_put_freq_params(msg
, ¶ms
->freq
) < 0 ||
5545 nl80211_put_beacon_int(msg
, params
->beacon_int
))
5548 ret
= nl80211_set_conn_keys(params
, msg
);
5552 if (params
->bssid
&& params
->fixed_bssid
) {
5553 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
5554 MAC2STR(params
->bssid
));
5555 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
5559 if (params
->fixed_freq
) {
5560 wpa_printf(MSG_DEBUG
, " * fixed_freq");
5561 if (nla_put_flag(msg
, NL80211_ATTR_FREQ_FIXED
))
5565 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
5566 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5567 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
5568 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
) {
5569 wpa_printf(MSG_DEBUG
, " * control port");
5570 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
5574 if (params
->wpa_ie
) {
5575 wpa_hexdump(MSG_DEBUG
,
5576 " * Extra IEs for Beacon/Probe Response frames",
5577 params
->wpa_ie
, params
->wpa_ie_len
);
5578 if (nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5583 ret
= nl80211_ht_vht_overrides(msg
, params
);
5587 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5590 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
5591 ret
, strerror(-ret
));
5593 if (ret
== -EALREADY
&& count
== 1) {
5594 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
5596 nl80211_leave_ibss(drv
, 0);
5601 wpa_printf(MSG_DEBUG
,
5602 "nl80211: Join IBSS request sent successfully");
5611 static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data
*drv
,
5612 struct wpa_driver_associate_params
*params
,
5615 if (params
->fils_erp_username_len
) {
5616 wpa_hexdump_ascii(MSG_DEBUG
, " * FILS ERP EMSKname/username",
5617 params
->fils_erp_username
,
5618 params
->fils_erp_username_len
);
5619 if (nla_put(msg
, NL80211_ATTR_FILS_ERP_USERNAME
,
5620 params
->fils_erp_username_len
,
5621 params
->fils_erp_username
))
5625 if (params
->fils_erp_realm_len
) {
5626 wpa_hexdump_ascii(MSG_DEBUG
, " * FILS ERP Realm",
5627 params
->fils_erp_realm
,
5628 params
->fils_erp_realm_len
);
5629 if (nla_put(msg
, NL80211_ATTR_FILS_ERP_REALM
,
5630 params
->fils_erp_realm_len
, params
->fils_erp_realm
))
5634 wpa_printf(MSG_DEBUG
, " * FILS ERP next seq %u",
5635 params
->fils_erp_next_seq_num
);
5636 if (nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
5637 params
->fils_erp_next_seq_num
))
5640 if (params
->fils_erp_rrk_len
) {
5641 wpa_printf(MSG_DEBUG
, " * FILS ERP rRK (len=%lu)",
5642 (unsigned long) params
->fils_erp_rrk_len
);
5643 if (nla_put(msg
, NL80211_ATTR_FILS_ERP_RRK
,
5644 params
->fils_erp_rrk_len
, params
->fils_erp_rrk
))
5652 static int nl80211_connect_common(struct wpa_driver_nl80211_data
*drv
,
5653 struct wpa_driver_associate_params
*params
,
5656 if (nla_put_flag(msg
, NL80211_ATTR_IFACE_SOCKET_OWNER
))
5659 if (params
->bssid
) {
5660 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5661 MAC2STR(params
->bssid
));
5662 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
5666 if (params
->bssid_hint
) {
5667 wpa_printf(MSG_DEBUG
, " * bssid_hint=" MACSTR
,
5668 MAC2STR(params
->bssid_hint
));
5669 if (nla_put(msg
, NL80211_ATTR_MAC_HINT
, ETH_ALEN
,
5670 params
->bssid_hint
))
5674 if (params
->freq
.freq
) {
5675 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
.freq
);
5676 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
5679 drv
->assoc_freq
= params
->freq
.freq
;
5681 drv
->assoc_freq
= 0;
5683 if (params
->freq_hint
) {
5684 wpa_printf(MSG_DEBUG
, " * freq_hint=%d", params
->freq_hint
);
5685 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_HINT
,
5690 if (params
->freq
.edmg
.channels
&& params
->freq
.edmg
.bw_config
) {
5691 wpa_printf(MSG_DEBUG
,
5692 " * EDMG configuration: channels=0x%x bw_config=%d",
5693 params
->freq
.edmg
.channels
,
5694 params
->freq
.edmg
.bw_config
);
5695 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_EDMG_CHANNELS
,
5696 params
->freq
.edmg
.channels
) ||
5697 nla_put_u8(msg
, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG
,
5698 params
->freq
.edmg
.bw_config
))
5702 if (params
->bg_scan_period
>= 0) {
5703 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
5704 params
->bg_scan_period
);
5705 if (nla_put_u16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
5706 params
->bg_scan_period
))
5711 wpa_printf(MSG_DEBUG
, " * SSID=%s",
5712 wpa_ssid_txt(params
->ssid
, params
->ssid_len
));
5713 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5716 if (params
->ssid_len
> sizeof(drv
->ssid
))
5718 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5719 drv
->ssid_len
= params
->ssid_len
;
5722 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
5723 if (params
->wpa_ie
&&
5724 nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
, params
->wpa_ie
))
5727 if (params
->wpa_proto
) {
5728 enum nl80211_wpa_versions ver
= 0;
5730 if (params
->wpa_proto
& WPA_PROTO_WPA
)
5731 ver
|= NL80211_WPA_VERSION_1
;
5732 if (params
->wpa_proto
& WPA_PROTO_RSN
)
5733 ver
|= NL80211_WPA_VERSION_2
;
5735 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
5736 if (nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
5740 if (params
->pairwise_suite
!= WPA_CIPHER_NONE
) {
5741 u32 cipher
= wpa_cipher_to_cipher_suite(params
->pairwise_suite
);
5742 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
5743 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
5748 if (params
->group_suite
== WPA_CIPHER_GTK_NOT_USED
&&
5749 !(drv
->capa
.enc
& WPA_DRIVER_CAPA_ENC_GTK_NOT_USED
)) {
5751 * This is likely to work even though many drivers do not
5752 * advertise support for operations without GTK.
5754 wpa_printf(MSG_DEBUG
, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
5755 } else if (params
->group_suite
!= WPA_CIPHER_NONE
) {
5756 u32 cipher
= wpa_cipher_to_cipher_suite(params
->group_suite
);
5757 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
5758 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
))
5762 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
5763 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5764 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_IEEE8021X
||
5765 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
||
5766 params
->key_mgmt_suite
== WPA_KEY_MGMT_CCKM
||
5767 params
->key_mgmt_suite
== WPA_KEY_MGMT_OSEN
||
5768 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
5769 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
5770 params
->key_mgmt_suite
== WPA_KEY_MGMT_SAE
||
5771 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_SAE
||
5772 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B
||
5773 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
||
5774 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_IEEE8021X_SHA384
||
5775 params
->key_mgmt_suite
== WPA_KEY_MGMT_FILS_SHA256
||
5776 params
->key_mgmt_suite
== WPA_KEY_MGMT_FILS_SHA384
||
5777 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_FILS_SHA256
||
5778 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_FILS_SHA384
||
5779 params
->key_mgmt_suite
== WPA_KEY_MGMT_OWE
||
5780 params
->key_mgmt_suite
== WPA_KEY_MGMT_DPP
) {
5781 int mgmt
= RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
;
5783 switch (params
->key_mgmt_suite
) {
5784 case WPA_KEY_MGMT_CCKM
:
5785 mgmt
= RSN_AUTH_KEY_MGMT_CCKM
;
5787 case WPA_KEY_MGMT_IEEE8021X
:
5788 mgmt
= RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
;
5790 case WPA_KEY_MGMT_FT_IEEE8021X
:
5791 mgmt
= RSN_AUTH_KEY_MGMT_FT_802_1X
;
5793 case WPA_KEY_MGMT_FT_PSK
:
5794 mgmt
= RSN_AUTH_KEY_MGMT_FT_PSK
;
5796 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
5797 mgmt
= RSN_AUTH_KEY_MGMT_802_1X_SHA256
;
5799 case WPA_KEY_MGMT_PSK_SHA256
:
5800 mgmt
= RSN_AUTH_KEY_MGMT_PSK_SHA256
;
5802 case WPA_KEY_MGMT_OSEN
:
5803 mgmt
= RSN_AUTH_KEY_MGMT_OSEN
;
5805 case WPA_KEY_MGMT_SAE
:
5806 mgmt
= RSN_AUTH_KEY_MGMT_SAE
;
5808 case WPA_KEY_MGMT_FT_SAE
:
5809 mgmt
= RSN_AUTH_KEY_MGMT_FT_SAE
;
5811 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
5812 mgmt
= RSN_AUTH_KEY_MGMT_802_1X_SUITE_B
;
5814 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
5815 mgmt
= RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192
;
5817 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384
:
5818 mgmt
= RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384
;
5820 case WPA_KEY_MGMT_FILS_SHA256
:
5821 mgmt
= RSN_AUTH_KEY_MGMT_FILS_SHA256
;
5823 case WPA_KEY_MGMT_FILS_SHA384
:
5824 mgmt
= RSN_AUTH_KEY_MGMT_FILS_SHA384
;
5826 case WPA_KEY_MGMT_FT_FILS_SHA256
:
5827 mgmt
= RSN_AUTH_KEY_MGMT_FT_FILS_SHA256
;
5829 case WPA_KEY_MGMT_FT_FILS_SHA384
:
5830 mgmt
= RSN_AUTH_KEY_MGMT_FT_FILS_SHA384
;
5832 case WPA_KEY_MGMT_OWE
:
5833 mgmt
= RSN_AUTH_KEY_MGMT_OWE
;
5835 case WPA_KEY_MGMT_DPP
:
5836 mgmt
= RSN_AUTH_KEY_MGMT_DPP
;
5838 case WPA_KEY_MGMT_PSK
:
5840 mgmt
= RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
;
5843 wpa_printf(MSG_DEBUG
, " * akm=0x%x", mgmt
);
5844 if (nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
))
5848 if (params
->req_handshake_offload
&&
5849 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X
)) {
5850 wpa_printf(MSG_DEBUG
, " * WANT_1X_4WAY_HS");
5851 if (nla_put_flag(msg
, NL80211_ATTR_WANT_1X_4WAY_HS
))
5855 /* Add PSK in case of 4-way handshake offload */
5857 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK
)) {
5858 wpa_hexdump_key(MSG_DEBUG
, " * PSK", params
->psk
, 32);
5859 if (nla_put(msg
, NL80211_ATTR_PMK
, 32, params
->psk
))
5863 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
5866 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
5867 (params
->pairwise_suite
== WPA_CIPHER_NONE
||
5868 params
->pairwise_suite
== WPA_CIPHER_WEP104
||
5869 params
->pairwise_suite
== WPA_CIPHER_WEP40
) &&
5870 (nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, ETH_P_PAE
) ||
5871 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
5874 if (params
->rrm_used
) {
5875 u32 drv_rrm_flags
= drv
->capa
.rrm_flags
;
5876 if ((!((drv_rrm_flags
&
5877 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) &&
5878 (drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
)) &&
5879 !(drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_RRM
)) ||
5880 nla_put_flag(msg
, NL80211_ATTR_USE_RRM
))
5884 if (nl80211_ht_vht_overrides(msg
, params
) < 0)
5888 wpa_printf(MSG_DEBUG
, " * P2P group");
5891 wpa_printf(MSG_DEBUG
, " * PBSS");
5892 if (nla_put_flag(msg
, NL80211_ATTR_PBSS
))
5896 drv
->connect_reassoc
= 0;
5897 if (params
->prev_bssid
) {
5898 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
5899 MAC2STR(params
->prev_bssid
));
5900 if (nla_put(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
5901 params
->prev_bssid
))
5903 drv
->connect_reassoc
= 1;
5906 if ((params
->auth_alg
& WPA_AUTH_ALG_FILS
) &&
5907 nl80211_put_fils_connect_params(drv
, params
, msg
) != 0)
5910 if ((params
->key_mgmt_suite
== WPA_KEY_MGMT_SAE
||
5911 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_SAE
) &&
5912 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) &&
5913 nla_put_flag(msg
, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
))
5920 static int wpa_driver_nl80211_try_connect(
5921 struct wpa_driver_nl80211_data
*drv
,
5922 struct wpa_driver_associate_params
*params
,
5923 struct nl_sock
*nl_connect
)
5926 enum nl80211_auth_type type
;
5930 #ifdef CONFIG_DRIVER_NL80211_QCA
5931 if (params
->req_key_mgmt_offload
&& params
->psk
&&
5932 (params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5933 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
5934 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
)) {
5935 wpa_printf(MSG_DEBUG
, "nl80211: Key management set PSK");
5936 ret
= issue_key_mgmt_set_key(drv
, params
->psk
, 32);
5940 #endif /* CONFIG_DRIVER_NL80211_QCA */
5942 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
5943 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_CONNECT
);
5947 ret
= nl80211_connect_common(drv
, params
, msg
);
5951 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
&&
5952 nla_put_u32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
))
5955 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_OPTIONAL
&&
5956 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_MFP_OPTIONAL
) &&
5957 nla_put_u32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_OPTIONAL
))
5961 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5963 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5965 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5967 if (params
->auth_alg
& WPA_AUTH_ALG_FILS
)
5969 if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
5972 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
5974 goto skip_auth_type
;
5977 type
= get_nl_auth_type(params
->auth_alg
);
5978 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
5979 if (type
== NL80211_AUTHTYPE_MAX
||
5980 nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
5984 ret
= nl80211_set_conn_keys(params
, msg
);
5989 ret
= send_and_recv(drv
->global
, nl_connect
, msg
,
5992 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
5996 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
5997 "(%s)", ret
, strerror(-ret
));
5999 wpa_printf(MSG_DEBUG
,
6000 "nl80211: Connect request send successfully");
6004 nl80211_nlmsg_clear(msg
);
6011 static int wpa_driver_nl80211_connect(
6012 struct wpa_driver_nl80211_data
*drv
,
6013 struct wpa_driver_associate_params
*params
,
6014 struct nl_sock
*nl_connect
)
6018 /* Store the connection attempted bssid for future use */
6020 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
6022 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
6024 ret
= wpa_driver_nl80211_try_connect(drv
, params
, nl_connect
);
6025 if (ret
== -EALREADY
) {
6027 * cfg80211 does not currently accept new connections if
6028 * we are already connected. As a workaround, force
6029 * disconnection and try again.
6031 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
6032 "disconnecting before reassociation "
6034 if (wpa_driver_nl80211_disconnect(
6035 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
, nl_connect
))
6037 ret
= wpa_driver_nl80211_try_connect(drv
, params
, nl_connect
);
6043 static int wpa_driver_nl80211_associate(
6044 void *priv
, struct wpa_driver_associate_params
*params
)
6046 struct i802_bss
*bss
= priv
;
6047 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6051 nl80211_unmask_11b_rates(bss
);
6053 if (params
->mode
== IEEE80211_MODE_AP
)
6054 return wpa_driver_nl80211_ap(drv
, params
);
6056 if (params
->mode
== IEEE80211_MODE_IBSS
)
6057 return wpa_driver_nl80211_ibss(drv
, params
);
6059 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
6060 enum nl80211_iftype nlmode
= params
->p2p
?
6061 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
6062 struct nl_sock
*nl_connect
= NULL
;
6064 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
6066 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_SAE
||
6067 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_SAE
) {
6068 nl_connect
= bss
->nl_connect
;
6069 bss
->use_nl_connect
= 1;
6071 bss
->use_nl_connect
= 0;
6074 return wpa_driver_nl80211_connect(drv
, params
, nl_connect
);
6077 nl80211_mark_disconnected(drv
);
6079 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
6081 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_ASSOCIATE
);
6085 ret
= nl80211_connect_common(drv
, params
, msg
);
6089 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
&&
6090 nla_put_u32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
))
6093 if (params
->fils_kek
) {
6094 wpa_printf(MSG_DEBUG
, " * FILS KEK (len=%u)",
6095 (unsigned int) params
->fils_kek_len
);
6096 if (nla_put(msg
, NL80211_ATTR_FILS_KEK
, params
->fils_kek_len
,
6100 if (params
->fils_nonces
) {
6101 wpa_hexdump(MSG_DEBUG
, " * FILS nonces (for AAD)",
6102 params
->fils_nonces
,
6103 params
->fils_nonces_len
);
6104 if (nla_put(msg
, NL80211_ATTR_FILS_NONCES
,
6105 params
->fils_nonces_len
, params
->fils_nonces
))
6109 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6112 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
6113 "nl80211: MLME command failed (assoc): ret=%d (%s)",
6114 ret
, strerror(-ret
));
6115 nl80211_dump_scan(drv
);
6117 wpa_printf(MSG_DEBUG
,
6118 "nl80211: Association request send successfully");
6127 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
6128 int ifindex
, enum nl80211_iftype mode
)
6133 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
6134 ifindex
, mode
, nl80211_iftype_str(mode
));
6136 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_SET_INTERFACE
);
6137 if (!msg
|| nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, mode
))
6140 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6146 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
6147 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
6152 static int wpa_driver_nl80211_set_mode_impl(
6153 struct i802_bss
*bss
,
6154 enum nl80211_iftype nlmode
,
6155 struct hostapd_freq_params
*desired_freq_params
)
6157 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6160 int was_ap
= is_ap_interface(drv
->nlmode
);
6162 int mode_switch_res
;
6167 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
6168 if (mode_switch_res
&& nlmode
== nl80211_get_ifmode(bss
))
6169 mode_switch_res
= 0;
6171 if (mode_switch_res
== 0) {
6172 drv
->nlmode
= nlmode
;
6177 if (mode_switch_res
== -ENODEV
)
6180 if (nlmode
== drv
->nlmode
) {
6181 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
6182 "requested mode - ignore error");
6184 goto done
; /* Already in the requested mode */
6187 /* mac80211 doesn't allow mode changes while the device is up, so
6188 * take the device down, try to set the mode again, and bring the
6191 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
6193 for (i
= 0; i
< 10; i
++) {
6194 res
= i802_set_iface_flags(bss
, 0);
6195 if (res
== -EACCES
|| res
== -ENODEV
)
6198 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
6200 os_sleep(0, 100000);
6205 * Setting the mode will fail for some drivers if the phy is
6206 * on a frequency that the mode is disallowed in.
6208 if (desired_freq_params
) {
6209 res
= nl80211_set_channel(bss
, desired_freq_params
, 0);
6211 wpa_printf(MSG_DEBUG
,
6212 "nl80211: Failed to set frequency on interface");
6216 /* Try to set the mode again while the interface is down */
6217 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
6218 if (mode_switch_res
== -EBUSY
) {
6219 wpa_printf(MSG_DEBUG
,
6220 "nl80211: Delaying mode set while interface going down");
6221 os_sleep(0, 100000);
6224 ret
= mode_switch_res
;
6229 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
6230 "interface is down");
6231 drv
->nlmode
= nlmode
;
6232 drv
->ignore_if_down_event
= 1;
6235 /* Bring the interface back up */
6236 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1);
6238 wpa_printf(MSG_DEBUG
,
6239 "nl80211: Failed to set interface up after switching mode");
6245 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
6246 "from %d failed", nlmode
, drv
->nlmode
);
6250 if (is_p2p_net_interface(nlmode
)) {
6251 wpa_printf(MSG_DEBUG
,
6252 "nl80211: Interface %s mode change to P2P - disable 11b rates",
6254 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
6255 } else if (drv
->disabled_11b_rates
) {
6256 wpa_printf(MSG_DEBUG
,
6257 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
6259 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
6262 if (is_ap_interface(nlmode
)) {
6263 nl80211_mgmt_unsubscribe(bss
, "start AP");
6264 /* Setup additional AP mode functionality if needed */
6265 if (nl80211_setup_ap(bss
))
6267 } else if (was_ap
) {
6268 /* Remove additional AP mode functionality */
6269 nl80211_teardown_ap(bss
);
6271 nl80211_mgmt_unsubscribe(bss
, "mode change");
6274 if (is_mesh_interface(nlmode
) &&
6275 nl80211_mgmt_subscribe_mesh(bss
))
6278 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
6279 !is_mesh_interface(nlmode
) &&
6280 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
6281 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
6282 "frame processing - ignore for now");
6288 int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
6289 enum nl80211_iftype nlmode
)
6291 return wpa_driver_nl80211_set_mode_impl(bss
, nlmode
, NULL
);
6295 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
6296 struct hostapd_freq_params
*freq
)
6298 return wpa_driver_nl80211_set_mode_impl(bss
, NL80211_IFTYPE_ADHOC
,
6303 static int wpa_driver_nl80211_get_capa(void *priv
,
6304 struct wpa_driver_capa
*capa
)
6306 struct i802_bss
*bss
= priv
;
6307 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6309 if (!drv
->has_capability
)
6311 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
6312 if (drv
->extended_capa
&& drv
->extended_capa_mask
) {
6313 capa
->extended_capa
= drv
->extended_capa
;
6314 capa
->extended_capa_mask
= drv
->extended_capa_mask
;
6315 capa
->extended_capa_len
= drv
->extended_capa_len
;
6322 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
6324 struct i802_bss
*bss
= priv
;
6325 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6327 wpa_printf(MSG_DEBUG
, "nl80211: Set %s operstate %d->%d (%s)",
6328 bss
->ifname
, drv
->operstate
, state
,
6329 state
? "UP" : "DORMANT");
6330 drv
->operstate
= state
;
6331 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
6332 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
6336 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
6338 struct i802_bss
*bss
= priv
;
6339 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6341 struct nl80211_sta_flag_update upd
;
6344 if (!drv
->associated
&& is_zero_ether_addr(drv
->bssid
) && !authorized
) {
6345 wpa_printf(MSG_DEBUG
, "nl80211: Skip set_supp_port(unauthorized) while not associated");
6349 wpa_printf(MSG_DEBUG
, "nl80211: Set supplicant port %sauthorized for "
6350 MACSTR
, authorized
? "" : "un", MAC2STR(drv
->bssid
));
6352 os_memset(&upd
, 0, sizeof(upd
));
6353 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6355 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6357 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
6358 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
) ||
6359 nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
)) {
6364 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6367 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set STA flag: %d (%s)",
6368 ret
, strerror(-ret
));
6373 /* Set kernel driver on given frequency (MHz) */
6374 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
6376 struct i802_bss
*bss
= priv
;
6377 return nl80211_set_channel(bss
, freq
, 0);
6381 static inline int min_int(int a
, int b
)
6389 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
6391 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6392 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6394 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6395 genlmsg_attrlen(gnlh
, 0), NULL
);
6398 * TODO: validate the key index and mac address!
6399 * Otherwise, there's a race condition as soon as
6400 * the kernel starts sending key notifications.
6403 if (tb
[NL80211_ATTR_KEY_SEQ
])
6404 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
6405 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
6406 nl80211_nlmsg_clear(msg
);
6411 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
6414 struct i802_bss
*bss
= priv
;
6415 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6418 msg
= nl80211_ifindex_msg(drv
, if_nametoindex(iface
), 0,
6419 NL80211_CMD_GET_KEY
);
6421 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
6422 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, idx
)) {
6429 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
6433 static int i802_set_rts(void *priv
, int rts
)
6435 struct i802_bss
*bss
= priv
;
6436 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6441 if (rts
>= 2347 || rts
== -1)
6446 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
6447 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
)) {
6452 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6455 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
6456 "%d (%s)", rts
, ret
, strerror(-ret
));
6461 static int i802_set_frag(void *priv
, int frag
)
6463 struct i802_bss
*bss
= priv
;
6464 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6469 if (frag
>= 2346 || frag
== -1)
6474 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
6475 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
)) {
6480 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6483 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
6484 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
6489 static int i802_flush(void *priv
)
6491 struct i802_bss
*bss
= priv
;
6495 wpa_printf(MSG_DEBUG
, "nl80211: flush -> DEL_STATION %s (all)",
6499 * XXX: FIX! this needs to flush all VLANs too
6501 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
);
6502 res
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
6504 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
6505 "(%s)", res
, strerror(-res
));
6511 static void get_sta_tid_stats(struct hostap_sta_driver_data
*data
,
6512 struct nlattr
*attr
)
6514 struct nlattr
*tid_stats
[NL80211_TID_STATS_MAX
+ 1], *tidattr
;
6515 struct nlattr
*txq_stats
[NL80211_TXQ_STATS_MAX
+ 1];
6516 static struct nla_policy txq_stats_policy
[NL80211_TXQ_STATS_MAX
+ 1] = {
6517 [NL80211_TXQ_STATS_BACKLOG_BYTES
] = { .type
= NLA_U32
},
6518 [NL80211_TXQ_STATS_BACKLOG_PACKETS
] = { .type
= NLA_U32
},
6522 nla_for_each_nested(tidattr
, attr
, rem
) {
6523 if (nla_parse_nested(tid_stats
, NL80211_TID_STATS_MAX
,
6524 tidattr
, NULL
) != 0 ||
6525 !tid_stats
[NL80211_TID_STATS_TXQ_STATS
] ||
6526 nla_parse_nested(txq_stats
, NL80211_TXQ_STATS_MAX
,
6527 tid_stats
[NL80211_TID_STATS_TXQ_STATS
],
6528 txq_stats_policy
) != 0)
6530 /* sum the backlogs over all TIDs for station */
6531 if (txq_stats
[NL80211_TXQ_STATS_BACKLOG_BYTES
])
6532 data
->backlog_bytes
+= nla_get_u32(
6533 txq_stats
[NL80211_TXQ_STATS_BACKLOG_BYTES
]);
6534 if (txq_stats
[NL80211_TXQ_STATS_BACKLOG_PACKETS
])
6535 data
->backlog_bytes
+= nla_get_u32(
6536 txq_stats
[NL80211_TXQ_STATS_BACKLOG_PACKETS
]);
6541 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
6543 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6544 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6545 struct hostap_sta_driver_data
*data
= arg
;
6546 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
6547 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
6548 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
6549 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
6550 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
6551 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
6552 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
6553 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
6554 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
6555 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
6556 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
6557 [NL80211_STA_INFO_ACK_SIGNAL
] = { .type
= NLA_U8
},
6558 [NL80211_STA_INFO_RX_DURATION
] = { .type
= NLA_U64
},
6559 [NL80211_STA_INFO_TX_DURATION
] = { .type
= NLA_U64
},
6561 struct nlattr
*rate
[NL80211_RATE_INFO_MAX
+ 1];
6562 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
6563 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
6564 [NL80211_RATE_INFO_BITRATE32
] = { .type
= NLA_U32
},
6565 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
6566 [NL80211_RATE_INFO_VHT_MCS
] = { .type
= NLA_U8
},
6567 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
6568 [NL80211_RATE_INFO_VHT_NSS
] = { .type
= NLA_U8
},
6571 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6572 genlmsg_attrlen(gnlh
, 0), NULL
);
6575 * TODO: validate the interface and mac address!
6576 * Otherwise, there's a race condition as soon as
6577 * the kernel starts sending station notifications.
6580 if (!tb
[NL80211_ATTR_STA_INFO
]) {
6581 wpa_printf(MSG_DEBUG
, "sta stats missing!");
6584 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
6585 tb
[NL80211_ATTR_STA_INFO
],
6587 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
6591 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
6592 data
->inactive_msec
=
6593 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
6594 /* For backwards compatibility, fetch the 32-bit counters first. */
6595 if (stats
[NL80211_STA_INFO_RX_BYTES
])
6596 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
6597 if (stats
[NL80211_STA_INFO_TX_BYTES
])
6598 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
6599 if (stats
[NL80211_STA_INFO_RX_BYTES64
] &&
6600 stats
[NL80211_STA_INFO_TX_BYTES64
]) {
6602 * The driver supports 64-bit counters, so use them to override
6603 * the 32-bit values.
6606 nla_get_u64(stats
[NL80211_STA_INFO_RX_BYTES64
]);
6608 nla_get_u64(stats
[NL80211_STA_INFO_TX_BYTES64
]);
6609 data
->bytes_64bit
= 1;
6611 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
6613 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
6614 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
6616 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
6617 if (stats
[NL80211_STA_INFO_RX_DURATION
])
6619 nla_get_u64(stats
[NL80211_STA_INFO_RX_DURATION
]);
6620 if (stats
[NL80211_STA_INFO_TX_DURATION
])
6622 nla_get_u64(stats
[NL80211_STA_INFO_TX_DURATION
]);
6623 if (stats
[NL80211_STA_INFO_TX_FAILED
])
6624 data
->tx_retry_failed
=
6625 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
6626 if (stats
[NL80211_STA_INFO_SIGNAL
])
6627 data
->signal
= nla_get_u8(stats
[NL80211_STA_INFO_SIGNAL
]);
6628 if (stats
[NL80211_STA_INFO_ACK_SIGNAL
]) {
6629 data
->last_ack_rssi
=
6630 nla_get_u8(stats
[NL80211_STA_INFO_ACK_SIGNAL
]);
6631 data
->flags
|= STA_DRV_DATA_LAST_ACK_RSSI
;
6634 if (stats
[NL80211_STA_INFO_TX_BITRATE
] &&
6635 nla_parse_nested(rate
, NL80211_RATE_INFO_MAX
,
6636 stats
[NL80211_STA_INFO_TX_BITRATE
],
6637 rate_policy
) == 0) {
6638 if (rate
[NL80211_RATE_INFO_BITRATE32
])
6639 data
->current_tx_rate
=
6640 nla_get_u32(rate
[NL80211_RATE_INFO_BITRATE32
]);
6641 else if (rate
[NL80211_RATE_INFO_BITRATE
])
6642 data
->current_tx_rate
=
6643 nla_get_u16(rate
[NL80211_RATE_INFO_BITRATE
]);
6645 if (rate
[NL80211_RATE_INFO_MCS
]) {
6646 data
->tx_mcs
= nla_get_u8(rate
[NL80211_RATE_INFO_MCS
]);
6647 data
->flags
|= STA_DRV_DATA_TX_MCS
;
6649 if (rate
[NL80211_RATE_INFO_VHT_MCS
]) {
6651 nla_get_u8(rate
[NL80211_RATE_INFO_VHT_MCS
]);
6652 data
->flags
|= STA_DRV_DATA_TX_VHT_MCS
;
6654 if (rate
[NL80211_RATE_INFO_SHORT_GI
])
6655 data
->flags
|= STA_DRV_DATA_TX_SHORT_GI
;
6656 if (rate
[NL80211_RATE_INFO_VHT_NSS
]) {
6658 nla_get_u8(rate
[NL80211_RATE_INFO_VHT_NSS
]);
6659 data
->flags
|= STA_DRV_DATA_TX_VHT_NSS
;
6663 if (stats
[NL80211_STA_INFO_RX_BITRATE
] &&
6664 nla_parse_nested(rate
, NL80211_RATE_INFO_MAX
,
6665 stats
[NL80211_STA_INFO_RX_BITRATE
],
6666 rate_policy
) == 0) {
6667 if (rate
[NL80211_RATE_INFO_BITRATE32
])
6668 data
->current_rx_rate
=
6669 nla_get_u32(rate
[NL80211_RATE_INFO_BITRATE32
]);
6670 else if (rate
[NL80211_RATE_INFO_BITRATE
])
6671 data
->current_rx_rate
=
6672 nla_get_u16(rate
[NL80211_RATE_INFO_BITRATE
]);
6674 if (rate
[NL80211_RATE_INFO_MCS
]) {
6676 nla_get_u8(rate
[NL80211_RATE_INFO_MCS
]);
6677 data
->flags
|= STA_DRV_DATA_RX_MCS
;
6679 if (rate
[NL80211_RATE_INFO_VHT_MCS
]) {
6681 nla_get_u8(rate
[NL80211_RATE_INFO_VHT_MCS
]);
6682 data
->flags
|= STA_DRV_DATA_RX_VHT_MCS
;
6684 if (rate
[NL80211_RATE_INFO_SHORT_GI
])
6685 data
->flags
|= STA_DRV_DATA_RX_SHORT_GI
;
6686 if (rate
[NL80211_RATE_INFO_VHT_NSS
]) {
6688 nla_get_u8(rate
[NL80211_RATE_INFO_VHT_NSS
]);
6689 data
->flags
|= STA_DRV_DATA_RX_VHT_NSS
;
6693 if (stats
[NL80211_STA_INFO_TID_STATS
])
6694 get_sta_tid_stats(data
, stats
[NL80211_STA_INFO_TID_STATS
]);
6699 static int i802_read_sta_data(struct i802_bss
*bss
,
6700 struct hostap_sta_driver_data
*data
,
6705 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_GET_STATION
)) ||
6706 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
6711 return send_and_recv_msgs(bss
->drv
, msg
, get_sta_handler
, data
);
6715 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
6716 int cw_min
, int cw_max
, int burst_time
)
6718 struct i802_bss
*bss
= priv
;
6719 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6721 struct nlattr
*txq
, *params
;
6724 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_WIPHY
);
6728 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
6732 /* We are only sending parameters for a single TXQ at a time */
6733 params
= nla_nest_start(msg
, 1);
6739 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
))
6743 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
))
6747 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
))
6751 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
))
6755 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
6756 * 32 usec, so need to convert the value here. */
6757 if (nla_put_u16(msg
, NL80211_TXQ_ATTR_TXOP
,
6758 (burst_time
* 100 + 16) / 32) ||
6759 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
) ||
6760 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
) ||
6761 nla_put_u8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
))
6764 nla_nest_end(msg
, params
);
6766 nla_nest_end(msg
, txq
);
6768 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6769 wpa_printf(MSG_DEBUG
,
6770 "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d",
6771 queue
, aifs
, cw_min
, cw_max
, burst_time
, res
);
6781 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
6782 const char *ifname
, int vlan_id
)
6784 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6788 wpa_printf(MSG_DEBUG
, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
6789 ", ifname=%s[%d], vlan_id=%d)",
6790 bss
->ifname
, if_nametoindex(bss
->ifname
),
6791 MAC2STR(addr
), ifname
, if_nametoindex(ifname
), vlan_id
);
6792 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
6793 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
6794 ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_VLAN_OFFLOAD
) &&
6795 nla_put_u16(msg
, NL80211_ATTR_VLAN_ID
, vlan_id
)) ||
6796 nla_put_u32(msg
, NL80211_ATTR_STA_VLAN
, if_nametoindex(ifname
))) {
6801 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6803 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
6804 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
6805 MAC2STR(addr
), ifname
, vlan_id
, ret
,
6812 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
6814 struct hostap_sta_driver_data data
;
6817 os_memset(&data
, 0, sizeof(data
));
6818 data
.inactive_msec
= (unsigned long) -1;
6819 ret
= i802_read_sta_data(priv
, &data
, addr
);
6822 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
6824 return data
.inactive_msec
/ 1000;
6828 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
6837 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
6840 struct i802_bss
*bss
= priv
;
6841 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6842 struct ieee80211_mgmt mgmt
;
6845 if (ieee80211_freq_to_chan(bss
->freq
, &channel
) ==
6846 HOSTAPD_MODE_IEEE80211AD
) {
6847 /* Deauthentication is not used in DMG/IEEE 802.11ad;
6848 * disassociate the STA instead. */
6849 return i802_sta_disassoc(priv
, own_addr
, addr
, reason
);
6852 if (is_mesh_interface(drv
->nlmode
))
6855 if (drv
->device_ap_sme
)
6856 return wpa_driver_nl80211_sta_remove(bss
, addr
, 1, reason
);
6858 memset(&mgmt
, 0, sizeof(mgmt
));
6859 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6860 WLAN_FC_STYPE_DEAUTH
);
6861 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6862 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6863 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6864 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
6865 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6867 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
6872 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
6875 struct i802_bss
*bss
= priv
;
6876 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6877 struct ieee80211_mgmt mgmt
;
6879 if (is_mesh_interface(drv
->nlmode
))
6882 if (drv
->device_ap_sme
)
6883 return wpa_driver_nl80211_sta_remove(bss
, addr
, 0, reason
);
6885 memset(&mgmt
, 0, sizeof(mgmt
));
6886 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6887 WLAN_FC_STYPE_DISASSOC
);
6888 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6889 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6890 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6891 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
6892 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6894 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
6899 static void dump_ifidx(struct wpa_driver_nl80211_data
*drv
)
6901 char buf
[200], *pos
, *end
;
6905 end
= pos
+ sizeof(buf
);
6907 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6908 if (!drv
->if_indices
[i
].ifindex
)
6910 res
= os_snprintf(pos
, end
- pos
, " %d(%d)",
6911 drv
->if_indices
[i
].ifindex
,
6912 drv
->if_indices
[i
].reason
);
6913 if (os_snprintf_error(end
- pos
, res
))
6919 wpa_printf(MSG_DEBUG
, "nl80211: if_indices[%d]:%s",
6920 drv
->num_if_indices
, buf
);
6924 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6928 struct drv_nl80211_if_info
*old
;
6930 wpa_printf(MSG_DEBUG
,
6931 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
6932 ifidx
, ifidx_reason
);
6933 if (have_ifidx(drv
, ifidx
, ifidx_reason
)) {
6934 wpa_printf(MSG_DEBUG
, "nl80211: ifindex %d already in the list",
6938 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6939 if (drv
->if_indices
[i
].ifindex
== 0) {
6940 drv
->if_indices
[i
].ifindex
= ifidx
;
6941 drv
->if_indices
[i
].reason
= ifidx_reason
;
6947 if (drv
->if_indices
!= drv
->default_if_indices
)
6948 old
= drv
->if_indices
;
6952 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
6954 if (!drv
->if_indices
) {
6956 drv
->if_indices
= drv
->default_if_indices
;
6958 drv
->if_indices
= old
;
6959 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
6961 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
6965 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
6966 sizeof(drv
->default_if_indices
));
6967 drv
->if_indices
[drv
->num_if_indices
].ifindex
= ifidx
;
6968 drv
->if_indices
[drv
->num_if_indices
].reason
= ifidx_reason
;
6969 drv
->num_if_indices
++;
6974 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6979 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6980 if ((drv
->if_indices
[i
].ifindex
== ifidx
||
6981 ifidx
== IFIDX_ANY
) &&
6982 (drv
->if_indices
[i
].reason
== ifidx_reason
||
6983 ifidx_reason
== IFIDX_ANY
)) {
6984 drv
->if_indices
[i
].ifindex
= 0;
6985 drv
->if_indices
[i
].reason
= 0;
6993 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6998 for (i
= 0; i
< drv
->num_if_indices
; i
++)
6999 if (drv
->if_indices
[i
].ifindex
== ifidx
&&
7000 (drv
->if_indices
[i
].reason
== ifidx_reason
||
7001 ifidx_reason
== IFIDX_ANY
))
7008 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
7009 const char *bridge_ifname
, char *ifname_wds
)
7011 struct i802_bss
*bss
= priv
;
7012 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7013 char name
[IFNAMSIZ
+ 1];
7014 union wpa_event_data event
;
7017 ret
= os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
7018 if (ret
>= (int) sizeof(name
))
7019 wpa_printf(MSG_WARNING
,
7020 "nl80211: WDS interface name was truncated");
7025 os_strlcpy(ifname_wds
, name
, IFNAMSIZ
+ 1);
7027 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
7028 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
7030 if (!if_nametoindex(name
)) {
7031 if (nl80211_create_iface(drv
, name
,
7032 NL80211_IFTYPE_AP_VLAN
,
7033 bss
->addr
, 1, NULL
, NULL
, 0) <
7036 if (bridge_ifname
&&
7037 linux_br_add_if(drv
->global
->ioctl_sock
,
7038 bridge_ifname
, name
) < 0)
7041 os_memset(&event
, 0, sizeof(event
));
7042 event
.wds_sta_interface
.sta_addr
= addr
;
7043 event
.wds_sta_interface
.ifname
= name
;
7044 event
.wds_sta_interface
.istatus
= INTERFACE_ADDED
;
7045 wpa_supplicant_event(bss
->ctx
,
7046 EVENT_WDS_STA_INTERFACE_STATUS
,
7049 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
7050 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
7051 "interface %s up", name
);
7053 return i802_set_sta_vlan(priv
, addr
, name
, 0);
7055 if (bridge_ifname
&&
7056 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
7058 wpa_printf(MSG_INFO
,
7059 "nl80211: Failed to remove interface %s from bridge %s: %s",
7060 name
, bridge_ifname
, strerror(errno
));
7062 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
7063 nl80211_remove_iface(drv
, if_nametoindex(name
));
7064 os_memset(&event
, 0, sizeof(event
));
7065 event
.wds_sta_interface
.sta_addr
= addr
;
7066 event
.wds_sta_interface
.ifname
= name
;
7067 event
.wds_sta_interface
.istatus
= INTERFACE_REMOVED
;
7068 wpa_supplicant_event(bss
->ctx
, EVENT_WDS_STA_INTERFACE_STATUS
,
7075 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
7077 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
7078 struct sockaddr_ll lladdr
;
7079 unsigned char buf
[3000];
7081 socklen_t fromlen
= sizeof(lladdr
);
7083 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
7084 (struct sockaddr
*)&lladdr
, &fromlen
);
7086 wpa_printf(MSG_ERROR
, "nl80211: EAPOL recv failed: %s",
7091 if (have_ifidx(drv
, lladdr
.sll_ifindex
, IFIDX_ANY
))
7092 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
7096 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
7097 struct i802_bss
*bss
,
7098 const char *brname
, const char *ifname
)
7101 char in_br
[IFNAMSIZ
];
7103 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
7104 br_ifindex
= if_nametoindex(brname
);
7105 if (br_ifindex
== 0) {
7107 * Bridge was configured, but the bridge device does
7108 * not exist. Try to add it now.
7110 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
7111 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
7112 "bridge interface %s: %s",
7113 brname
, strerror(errno
));
7116 bss
->added_bridge
= 1;
7117 br_ifindex
= if_nametoindex(brname
);
7118 add_ifidx(drv
, br_ifindex
, drv
->ifindex
);
7120 bss
->br_ifindex
= br_ifindex
;
7122 if (linux_br_get(in_br
, ifname
) == 0) {
7123 if (os_strcmp(in_br
, brname
) == 0) {
7124 bss
->already_in_bridge
= 1;
7125 return 0; /* already in the bridge */
7128 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
7129 "bridge %s", ifname
, in_br
);
7130 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
7132 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
7133 "remove interface %s from bridge "
7135 ifname
, in_br
, strerror(errno
));
7140 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
7142 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
7143 wpa_printf(MSG_WARNING
,
7144 "nl80211: Failed to add interface %s into bridge %s: %s",
7145 ifname
, brname
, strerror(errno
));
7146 /* Try to continue without the interface being in a bridge. This
7147 * may be needed for some cases, e.g., with Open vSwitch, where
7148 * an external component will need to handle bridge
7152 bss
->added_if_into_bridge
= 1;
7158 static void *i802_init(struct hostapd_data
*hapd
,
7159 struct wpa_init_params
*params
)
7161 struct wpa_driver_nl80211_data
*drv
;
7162 struct i802_bss
*bss
;
7164 char master_ifname
[IFNAMSIZ
];
7165 int ifindex
, br_ifindex
= 0;
7168 bss
= wpa_driver_nl80211_drv_init(hapd
, params
->ifname
,
7169 params
->global_priv
, 1,
7170 params
->bssid
, params
->driver_params
);
7176 if (linux_br_get(master_ifname
, params
->ifname
) == 0) {
7177 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
7178 params
->ifname
, master_ifname
);
7179 br_ifindex
= if_nametoindex(master_ifname
);
7180 os_strlcpy(bss
->brname
, master_ifname
, IFNAMSIZ
);
7181 } else if ((params
->num_bridge
== 0 || !params
->bridge
[0]) &&
7182 linux_master_get(master_ifname
, params
->ifname
) == 0) {
7183 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in master %s",
7184 params
->ifname
, master_ifname
);
7185 /* start listening for EAPOL on the master interface */
7186 add_ifidx(drv
, if_nametoindex(master_ifname
), drv
->ifindex
);
7188 /* check if master itself is under bridge */
7189 if (linux_br_get(master_ifname
, master_ifname
) == 0) {
7190 wpa_printf(MSG_DEBUG
, "nl80211: which is in bridge %s",
7192 br_ifindex
= if_nametoindex(master_ifname
);
7193 os_strlcpy(bss
->brname
, master_ifname
, IFNAMSIZ
);
7196 master_ifname
[0] = '\0';
7199 bss
->br_ifindex
= br_ifindex
;
7201 for (i
= 0; i
< params
->num_bridge
; i
++) {
7202 if (params
->bridge
[i
]) {
7203 ifindex
= if_nametoindex(params
->bridge
[i
]);
7205 add_ifidx(drv
, ifindex
, drv
->ifindex
);
7206 if (ifindex
== br_ifindex
)
7211 /* start listening for EAPOL on the default AP interface */
7212 add_ifidx(drv
, drv
->ifindex
, IFIDX_ANY
);
7214 if (params
->num_bridge
&& params
->bridge
[0]) {
7215 if (i802_check_bridge(drv
, bss
, params
->bridge
[0],
7216 params
->ifname
) < 0)
7218 if (os_strcmp(params
->bridge
[0], master_ifname
) != 0)
7222 if (!br_added
&& br_ifindex
&&
7223 (params
->num_bridge
== 0 || !params
->bridge
[0]))
7224 add_ifidx(drv
, br_ifindex
, drv
->ifindex
);
7226 #ifdef CONFIG_LIBNL3_ROUTE
7227 if (bss
->added_if_into_bridge
|| bss
->already_in_bridge
) {
7230 drv
->rtnl_sk
= nl_socket_alloc();
7231 if (drv
->rtnl_sk
== NULL
) {
7232 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate nl_sock");
7236 err
= nl_connect(drv
->rtnl_sk
, NETLINK_ROUTE
);
7238 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
7243 #endif /* CONFIG_LIBNL3_ROUTE */
7245 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
7246 if (drv
->eapol_sock
< 0) {
7247 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
7252 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
7254 wpa_printf(MSG_INFO
, "nl80211: Could not register read socket for eapol");
7258 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
7261 os_memcpy(drv
->perm_addr
, params
->own_addr
, ETH_ALEN
);
7263 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
7268 wpa_driver_nl80211_deinit(bss
);
7273 static void i802_deinit(void *priv
)
7275 struct i802_bss
*bss
= priv
;
7276 wpa_driver_nl80211_deinit(bss
);
7280 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
7281 enum wpa_driver_if_type type
)
7284 case WPA_IF_STATION
:
7285 return NL80211_IFTYPE_STATION
;
7286 case WPA_IF_P2P_CLIENT
:
7287 case WPA_IF_P2P_GROUP
:
7288 return NL80211_IFTYPE_P2P_CLIENT
;
7289 case WPA_IF_AP_VLAN
:
7290 return NL80211_IFTYPE_AP_VLAN
;
7292 return NL80211_IFTYPE_AP
;
7294 return NL80211_IFTYPE_P2P_GO
;
7295 case WPA_IF_P2P_DEVICE
:
7296 return NL80211_IFTYPE_P2P_DEVICE
;
7298 return NL80211_IFTYPE_MESH_POINT
;
7305 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
7307 struct wpa_driver_nl80211_data
*drv
;
7308 dl_list_for_each(drv
, &global
->interfaces
,
7309 struct wpa_driver_nl80211_data
, list
) {
7310 if (os_memcmp(addr
, drv
->first_bss
->addr
, ETH_ALEN
) == 0)
7317 static int nl80211_vif_addr(struct wpa_driver_nl80211_data
*drv
, u8
*new_addr
)
7324 os_memcpy(new_addr
, drv
->first_bss
->addr
, ETH_ALEN
);
7325 for (idx
= 0; idx
< 64; idx
++) {
7326 new_addr
[0] = drv
->first_bss
->addr
[0] | 0x02;
7327 new_addr
[0] ^= idx
<< 2;
7328 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
7334 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new virtual interface address "
7335 MACSTR
, MAC2STR(new_addr
));
7344 u8 macaddr
[ETH_ALEN
];
7347 static int nl80211_wdev_handler(struct nl_msg
*msg
, void *arg
)
7349 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7350 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7351 struct wdev_info
*wi
= arg
;
7353 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7354 genlmsg_attrlen(gnlh
, 0), NULL
);
7355 if (tb
[NL80211_ATTR_WDEV
]) {
7356 wi
->wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
7357 wi
->wdev_id_set
= 1;
7360 if (tb
[NL80211_ATTR_MAC
])
7361 os_memcpy(wi
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
7368 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
7369 const char *ifname
, const u8
*addr
,
7370 void *bss_ctx
, void **drv_priv
,
7371 char *force_ifname
, u8
*if_addr
,
7372 const char *bridge
, int use_existing
,
7375 enum nl80211_iftype nlmode
;
7376 struct i802_bss
*bss
= priv
;
7377 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7382 os_memcpy(if_addr
, addr
, ETH_ALEN
);
7383 nlmode
= wpa_driver_nl80211_if_type(type
);
7384 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
7385 struct wdev_info p2pdev_info
;
7387 os_memset(&p2pdev_info
, 0, sizeof(p2pdev_info
));
7388 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
7389 0, nl80211_wdev_handler
,
7390 &p2pdev_info
, use_existing
);
7391 if (!p2pdev_info
.wdev_id_set
|| ifidx
!= 0) {
7392 wpa_printf(MSG_ERROR
, "nl80211: Failed to create a P2P Device interface %s",
7397 drv
->global
->if_add_wdevid
= p2pdev_info
.wdev_id
;
7398 drv
->global
->if_add_wdevid_set
= p2pdev_info
.wdev_id_set
;
7399 if (!is_zero_ether_addr(p2pdev_info
.macaddr
))
7400 os_memcpy(if_addr
, p2pdev_info
.macaddr
, ETH_ALEN
);
7401 wpa_printf(MSG_DEBUG
, "nl80211: New P2P Device interface %s (0x%llx) created",
7403 (long long unsigned int) p2pdev_info
.wdev_id
);
7405 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
7406 0, NULL
, NULL
, use_existing
);
7407 if (use_existing
&& ifidx
== -ENFILE
) {
7409 ifidx
= if_nametoindex(ifname
);
7410 } else if (ifidx
< 0) {
7416 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
7417 os_memcpy(if_addr
, bss
->addr
, ETH_ALEN
);
7418 else if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
7419 ifname
, if_addr
) < 0) {
7421 nl80211_remove_iface(drv
, ifidx
);
7427 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
7428 type
== WPA_IF_P2P_GO
|| type
== WPA_IF_MESH
||
7429 type
== WPA_IF_STATION
)) {
7430 /* Enforce unique address */
7431 u8 new_addr
[ETH_ALEN
];
7433 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
7436 nl80211_remove_iface(drv
, ifidx
);
7439 if (nl80211_addr_in_use(drv
->global
, new_addr
)) {
7440 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
7441 "for interface %s type %d", ifname
, type
);
7442 if (nl80211_vif_addr(drv
, new_addr
) < 0) {
7444 nl80211_remove_iface(drv
, ifidx
);
7447 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
7450 nl80211_remove_iface(drv
, ifidx
);
7454 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
7457 if (type
== WPA_IF_AP_BSS
&& setup_ap
) {
7458 struct i802_bss
*new_bss
= os_zalloc(sizeof(*new_bss
));
7459 if (new_bss
== NULL
) {
7461 nl80211_remove_iface(drv
, ifidx
);
7466 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
7467 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
7468 "interface %s to a bridge %s",
7471 nl80211_remove_iface(drv
, ifidx
);
7476 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
7479 nl80211_remove_iface(drv
, ifidx
);
7483 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
7484 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
7485 new_bss
->ifindex
= ifidx
;
7487 new_bss
->next
= drv
->first_bss
->next
;
7488 new_bss
->freq
= drv
->first_bss
->freq
;
7489 new_bss
->ctx
= bss_ctx
;
7490 new_bss
->added_if
= added
;
7491 drv
->first_bss
->next
= new_bss
;
7493 *drv_priv
= new_bss
;
7494 nl80211_init_bss(new_bss
);
7496 /* Subscribe management frames for this WPA_IF_AP_BSS */
7497 if (nl80211_setup_ap(new_bss
))
7502 drv
->global
->if_add_ifindex
= ifidx
;
7505 * Some virtual interfaces need to process EAPOL packets and events on
7506 * the parent interface. This is used mainly with hostapd.
7510 nlmode
== NL80211_IFTYPE_AP_VLAN
||
7511 nlmode
== NL80211_IFTYPE_WDS
||
7512 nlmode
== NL80211_IFTYPE_MONITOR
))
7513 add_ifidx(drv
, ifidx
, IFIDX_ANY
);
7519 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
7520 enum wpa_driver_if_type type
,
7523 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7524 int ifindex
= if_nametoindex(ifname
);
7526 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
7527 __func__
, type
, ifname
, ifindex
, bss
->added_if
);
7528 if (ifindex
> 0 && (bss
->added_if
|| bss
->ifindex
!= ifindex
))
7529 nl80211_remove_iface(drv
, ifindex
);
7530 else if (ifindex
> 0 && !bss
->added_if
) {
7531 struct wpa_driver_nl80211_data
*drv2
;
7532 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
7533 struct wpa_driver_nl80211_data
, list
) {
7534 del_ifidx(drv2
, ifindex
, IFIDX_ANY
);
7535 del_ifidx(drv2
, IFIDX_ANY
, ifindex
);
7539 if (type
!= WPA_IF_AP_BSS
)
7542 if (bss
->added_if_into_bridge
) {
7543 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
7545 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
7546 "interface %s from bridge %s: %s",
7547 bss
->ifname
, bss
->brname
, strerror(errno
));
7549 if (bss
->added_bridge
) {
7550 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
7551 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
7553 bss
->brname
, strerror(errno
));
7556 if (bss
!= drv
->first_bss
) {
7557 struct i802_bss
*tbss
;
7559 wpa_printf(MSG_DEBUG
, "nl80211: Not the first BSS - remove it");
7560 for (tbss
= drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
7561 if (tbss
->next
== bss
) {
7562 tbss
->next
= bss
->next
;
7563 /* Unsubscribe management frames */
7564 nl80211_teardown_ap(bss
);
7565 nl80211_destroy_bss(bss
);
7567 i802_set_iface_flags(bss
, 0);
7574 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
7575 "BSS %p in the list", __func__
, bss
);
7577 wpa_printf(MSG_DEBUG
, "nl80211: First BSS - reassign context");
7578 nl80211_teardown_ap(bss
);
7579 if (!bss
->added_if
&& !drv
->first_bss
->next
)
7580 wpa_driver_nl80211_del_beacon(bss
);
7581 nl80211_destroy_bss(bss
);
7583 i802_set_iface_flags(bss
, 0);
7584 if (drv
->first_bss
->next
) {
7585 drv
->first_bss
= drv
->first_bss
->next
;
7586 drv
->ctx
= drv
->first_bss
->ctx
;
7589 wpa_printf(MSG_DEBUG
, "nl80211: No second BSS to reassign context to");
7597 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
7599 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7600 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7602 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7603 genlmsg_attrlen(gnlh
, 0), NULL
);
7604 if (tb
[NL80211_ATTR_COOKIE
])
7605 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
7610 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
7611 unsigned int freq
, unsigned int wait
,
7612 const u8
*buf
, size_t buf_len
,
7613 int save_cookie
, int no_cck
, int no_ack
,
7614 int offchanok
, const u16
*csa_offs
,
7615 size_t csa_offs_len
)
7617 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7622 wpa_printf(MSG_MSGDUMP
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
7623 "no_ack=%d offchanok=%d",
7624 freq
, wait
, no_cck
, no_ack
, offchanok
);
7625 wpa_hexdump(MSG_MSGDUMP
, "CMD_FRAME", buf
, buf_len
);
7627 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME
)) ||
7628 (freq
&& nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
7629 (wait
&& nla_put_u32(msg
, NL80211_ATTR_DURATION
, wait
)) ||
7630 (offchanok
&& ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
7631 drv
->test_use_roc_tx
) &&
7632 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
)) ||
7633 (no_cck
&& nla_put_flag(msg
, NL80211_ATTR_TX_NO_CCK_RATE
)) ||
7634 (no_ack
&& nla_put_flag(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
)) ||
7635 (csa_offs
&& nla_put(msg
, NL80211_ATTR_CSA_C_OFFSETS_TX
,
7636 csa_offs_len
* sizeof(u16
), csa_offs
)) ||
7637 nla_put(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
))
7641 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
7644 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
7645 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
7648 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame TX command accepted%s; "
7649 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
7650 (long long unsigned int) cookie
);
7653 drv
->send_frame_cookie
= no_ack
? (u64
) -1 : cookie
;
7655 if (drv
->num_send_frame_cookies
== MAX_SEND_FRAME_COOKIES
) {
7656 wpa_printf(MSG_DEBUG
,
7657 "nl80211: Drop oldest pending send frame cookie 0x%llx",
7658 (long long unsigned int)
7659 drv
->send_frame_cookies
[0]);
7660 os_memmove(&drv
->send_frame_cookies
[0],
7661 &drv
->send_frame_cookies
[1],
7662 (MAX_SEND_FRAME_COOKIES
- 1) *
7664 drv
->num_send_frame_cookies
--;
7666 drv
->send_frame_cookies
[drv
->num_send_frame_cookies
] = cookie
;
7667 drv
->num_send_frame_cookies
++;
7676 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
7678 unsigned int wait_time
,
7679 const u8
*dst
, const u8
*src
,
7681 const u8
*data
, size_t data_len
,
7684 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7687 struct ieee80211_hdr
*hdr
;
7690 if (is_ap_interface(drv
->nlmode
) && (int) freq
== bss
->freq
)
7693 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
7694 "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)",
7695 drv
->ifindex
, freq
, wait_time
, no_cck
, offchanok
);
7697 buf
= os_zalloc(24 + data_len
);
7700 os_memcpy(buf
+ 24, data
, data_len
);
7701 hdr
= (struct ieee80211_hdr
*) buf
;
7702 hdr
->frame_control
=
7703 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
7704 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
7705 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
7706 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
7708 if (os_memcmp(bss
->addr
, src
, ETH_ALEN
) != 0) {
7709 wpa_printf(MSG_DEBUG
, "nl80211: Use random TA " MACSTR
,
7711 os_memcpy(bss
->rand_addr
, src
, ETH_ALEN
);
7713 os_memset(bss
->rand_addr
, 0, ETH_ALEN
);
7716 if (is_ap_interface(drv
->nlmode
) &&
7717 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
7718 (int) freq
== bss
->freq
|| drv
->device_ap_sme
||
7720 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
7721 0, freq
, no_cck
, offchanok
,
7722 wait_time
, NULL
, 0, 0);
7724 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
7726 1, no_cck
, 0, offchanok
, NULL
, 0);
7733 static void nl80211_frame_wait_cancel(struct i802_bss
*bss
, u64 cookie
)
7735 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7739 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
7740 (long long unsigned int) cookie
);
7741 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
)) ||
7742 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
)) {
7747 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7749 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
7750 "(%s)", ret
, strerror(-ret
));
7754 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
7756 struct i802_bss
*bss
= priv
;
7757 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7761 /* Cancel the last pending TX cookie */
7762 nl80211_frame_wait_cancel(bss
, drv
->send_frame_cookie
);
7765 * Cancel the other pending TX cookies, if any. This is needed since
7766 * the driver may keep a list of all pending offchannel TX operations
7767 * and free up the radio only once they have expired or cancelled.
7769 for (i
= drv
->num_send_frame_cookies
; i
> 0; i
--) {
7770 cookie
= drv
->send_frame_cookies
[i
- 1];
7771 if (cookie
!= drv
->send_frame_cookie
)
7772 nl80211_frame_wait_cancel(bss
, cookie
);
7774 drv
->num_send_frame_cookies
= 0;
7778 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
7779 unsigned int duration
)
7781 struct i802_bss
*bss
= priv
;
7782 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7787 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
)) ||
7788 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
7789 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
)) {
7795 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
7797 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
7798 "0x%llx for freq=%u MHz duration=%u",
7799 (long long unsigned int) cookie
, freq
, duration
);
7800 drv
->remain_on_chan_cookie
= cookie
;
7801 drv
->pending_remain_on_chan
= 1;
7804 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
7805 "(freq=%d duration=%u): %d (%s)",
7806 freq
, duration
, ret
, strerror(-ret
));
7811 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
7813 struct i802_bss
*bss
= priv
;
7814 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7818 if (!drv
->pending_remain_on_chan
) {
7819 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
7824 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
7826 (long long unsigned int) drv
->remain_on_chan_cookie
);
7828 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
7830 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
)) {
7835 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7838 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
7839 "%d (%s)", ret
, strerror(-ret
));
7844 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
7846 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7849 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
7850 is_ap_interface(drv
->nlmode
) && !bss
->in_deinit
&&
7853 * Do not disable Probe Request reporting that was
7854 * enabled in nl80211_setup_ap().
7856 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
7857 "Probe Request reporting nl_preq=%p while "
7858 "in AP mode", bss
->nl_preq
);
7859 } else if (bss
->nl_preq
) {
7860 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
7861 "reporting nl_preq=%p", bss
->nl_preq
);
7862 nl80211_destroy_eloop_handle(&bss
->nl_preq
, 0);
7868 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
7869 "already on! nl_preq=%p", bss
->nl_preq
);
7873 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
7874 if (bss
->nl_preq
== NULL
)
7876 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
7877 "reporting nl_preq=%p", bss
->nl_preq
);
7879 if (nl80211_register_frame(bss
, bss
->nl_preq
,
7880 (WLAN_FC_TYPE_MGMT
<< 2) |
7881 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
7885 nl80211_register_eloop_read(&bss
->nl_preq
,
7886 wpa_driver_nl80211_event_receive
,
7892 nl_destroy_handles(&bss
->nl_preq
);
7897 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
7898 int ifindex
, int disabled
)
7901 struct nlattr
*bands
, *band
;
7904 wpa_printf(MSG_DEBUG
,
7905 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
7906 ifindex
, disabled
? "NL80211_TXRATE_LEGACY=OFDM-only" :
7907 "no NL80211_TXRATE_LEGACY constraint");
7909 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0,
7910 NL80211_CMD_SET_TX_BITRATE_MASK
);
7914 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
7919 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
7920 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
7921 * rates. All 5 GHz rates are left enabled.
7923 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
7925 (disabled
&& nla_put(msg
, NL80211_TXRATE_LEGACY
, 8,
7926 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
7928 nla_nest_end(msg
, band
);
7930 nla_nest_end(msg
, bands
);
7932 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7934 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
7935 "(%s)", ret
, strerror(-ret
));
7937 drv
->disabled_11b_rates
= disabled
;
7947 static int wpa_driver_nl80211_deinit_ap(void *priv
)
7949 struct i802_bss
*bss
= priv
;
7950 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7951 if (!is_ap_interface(drv
->nlmode
))
7953 wpa_driver_nl80211_del_beacon(bss
);
7954 bss
->beacon_set
= 0;
7957 * If the P2P GO interface was dynamically added, then it is
7958 * possible that the interface change to station is not possible.
7960 if (drv
->nlmode
== NL80211_IFTYPE_P2P_GO
&& bss
->if_dynamic
)
7963 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
7967 static int wpa_driver_nl80211_stop_ap(void *priv
)
7969 struct i802_bss
*bss
= priv
;
7970 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7971 if (!is_ap_interface(drv
->nlmode
))
7973 wpa_driver_nl80211_del_beacon(bss
);
7974 bss
->beacon_set
= 0;
7979 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
7981 struct i802_bss
*bss
= priv
;
7982 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7983 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
7987 * If the P2P Client interface was dynamically added, then it is
7988 * possible that the interface change to station is not possible.
7990 if (bss
->if_dynamic
)
7993 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
7997 static void wpa_driver_nl80211_resume(void *priv
)
7999 struct i802_bss
*bss
= priv
;
8000 enum nl80211_iftype nlmode
= nl80211_get_ifmode(bss
);
8002 if (i802_set_iface_flags(bss
, 1))
8003 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on resume event");
8005 if (is_p2p_net_interface(nlmode
))
8006 nl80211_disable_11b_rates(bss
->drv
, bss
->drv
->ifindex
, 1);
8010 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
8012 struct i802_bss
*bss
= priv
;
8013 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8017 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
8018 "hysteresis=%d", threshold
, hysteresis
);
8020 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_CQM
)) ||
8021 !(cqm
= nla_nest_start(msg
, NL80211_ATTR_CQM
)) ||
8022 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
) ||
8023 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
)) {
8027 nla_nest_end(msg
, cqm
);
8029 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8033 static int get_channel_width(struct nl_msg
*msg
, void *arg
)
8035 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8036 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8037 struct wpa_signal_info
*sig_change
= arg
;
8039 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8040 genlmsg_attrlen(gnlh
, 0), NULL
);
8042 sig_change
->center_frq1
= -1;
8043 sig_change
->center_frq2
= -1;
8044 sig_change
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
8046 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
]) {
8047 sig_change
->chanwidth
= convert2width(
8048 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
8049 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
8050 sig_change
->center_frq1
=
8051 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
8052 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
8053 sig_change
->center_frq2
=
8054 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
8061 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data
*drv
,
8062 struct wpa_signal_info
*sig
)
8066 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_INTERFACE
);
8067 return send_and_recv_msgs(drv
, msg
, get_channel_width
, sig
);
8071 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
8073 struct i802_bss
*bss
= priv
;
8074 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8077 os_memset(si
, 0, sizeof(*si
));
8078 res
= nl80211_get_link_signal(drv
, si
);
8080 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
&&
8081 drv
->nlmode
!= NL80211_IFTYPE_MESH_POINT
)
8083 si
->current_signal
= 0;
8086 res
= nl80211_get_channel_width(drv
, si
);
8090 return nl80211_get_link_noise(drv
, si
);
8094 static int nl80211_set_param(void *priv
, const char *param
)
8096 struct i802_bss
*bss
= priv
;
8097 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8101 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
8104 if (os_strstr(param
, "use_p2p_group_interface=1")) {
8105 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
8107 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
8108 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
8110 #endif /* CONFIG_P2P */
8112 if (os_strstr(param
, "use_monitor=1"))
8113 drv
->use_monitor
= 1;
8115 if (os_strstr(param
, "force_connect_cmd=1")) {
8116 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_SME
;
8117 drv
->force_connect_cmd
= 1;
8120 if (os_strstr(param
, "force_bss_selection=1"))
8121 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
8123 if (os_strstr(param
, "no_offchannel_tx=1")) {
8124 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
8125 drv
->test_use_roc_tx
= 1;
8128 if (os_strstr(param
, "control_port=0"))
8129 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_CONTROL_PORT
;
8135 static void * nl80211_global_init(void *ctx
)
8137 struct nl80211_global
*global
;
8138 struct netlink_config
*cfg
;
8140 global
= os_zalloc(sizeof(*global
));
8144 global
->ioctl_sock
= -1;
8145 dl_list_init(&global
->interfaces
);
8146 global
->if_add_ifindex
= -1;
8148 cfg
= os_zalloc(sizeof(*cfg
));
8153 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
8154 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
8155 global
->netlink
= netlink_init(cfg
);
8156 if (global
->netlink
== NULL
) {
8161 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
8164 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
8165 if (global
->ioctl_sock
< 0) {
8166 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
8174 nl80211_global_deinit(global
);
8179 static void nl80211_global_deinit(void *priv
)
8181 struct nl80211_global
*global
= priv
;
8184 if (!dl_list_empty(&global
->interfaces
)) {
8185 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
8186 "nl80211_global_deinit",
8187 dl_list_len(&global
->interfaces
));
8190 if (global
->netlink
)
8191 netlink_deinit(global
->netlink
);
8193 nl_destroy_handles(&global
->nl
);
8195 if (global
->nl_event
)
8196 nl80211_destroy_eloop_handle(&global
->nl_event
, 0);
8198 nl_cb_put(global
->nl_cb
);
8200 if (global
->ioctl_sock
>= 0)
8201 close(global
->ioctl_sock
);
8207 static const char * nl80211_get_radio_name(void *priv
)
8209 struct i802_bss
*bss
= priv
;
8210 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8211 return drv
->phyname
;
8215 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
,
8216 struct wpa_pmkid_params
*params
)
8219 const size_t PMK_MAX_LEN
= 48; /* current cfg80211 limit */
8221 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
8223 nla_put(msg
, NL80211_ATTR_PMKID
, 16, params
->pmkid
)) ||
8225 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
)) ||
8226 (params
->ssid_len
&&
8227 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
)) ||
8228 (params
->fils_cache_id
&&
8229 nla_put(msg
, NL80211_ATTR_FILS_CACHE_ID
, 2,
8230 params
->fils_cache_id
)) ||
8231 (cmd
!= NL80211_CMD_DEL_PMKSA
&&
8232 params
->pmk_len
&& params
->pmk_len
<= PMK_MAX_LEN
&&
8233 nla_put(msg
, NL80211_ATTR_PMK
, params
->pmk_len
, params
->pmk
))) {
8234 nl80211_nlmsg_clear(msg
);
8239 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, (void *) -1);
8243 static int nl80211_add_pmkid(void *priv
, struct wpa_pmkid_params
*params
)
8245 struct i802_bss
*bss
= priv
;
8249 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
,
8250 MAC2STR(params
->bssid
));
8251 else if (params
->fils_cache_id
&& params
->ssid_len
) {
8252 wpa_printf(MSG_DEBUG
,
8253 "nl80211: Add PMKSA for cache id %02x%02x SSID %s",
8254 params
->fils_cache_id
[0], params
->fils_cache_id
[1],
8255 wpa_ssid_txt(params
->ssid
, params
->ssid_len
));
8258 ret
= nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, params
);
8260 wpa_printf(MSG_DEBUG
,
8261 "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)",
8262 ret
, strerror(-ret
));
8269 static int nl80211_remove_pmkid(void *priv
, struct wpa_pmkid_params
*params
)
8271 struct i802_bss
*bss
= priv
;
8275 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
8276 MAC2STR(params
->bssid
));
8277 else if (params
->fils_cache_id
&& params
->ssid_len
) {
8278 wpa_printf(MSG_DEBUG
,
8279 "nl80211: Delete PMKSA for cache id %02x%02x SSID %s",
8280 params
->fils_cache_id
[0], params
->fils_cache_id
[1],
8281 wpa_ssid_txt(params
->ssid
, params
->ssid_len
));
8284 ret
= nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, params
);
8286 wpa_printf(MSG_DEBUG
,
8287 "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)",
8288 ret
, strerror(-ret
));
8295 static int nl80211_flush_pmkid(void *priv
)
8297 struct i802_bss
*bss
= priv
;
8300 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
8301 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_FLUSH_PMKSA
);
8304 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8308 static void clean_survey_results(struct survey_results
*survey_results
)
8310 struct freq_survey
*survey
, *tmp
;
8312 if (dl_list_empty(&survey_results
->survey_list
))
8315 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
8316 struct freq_survey
, list
) {
8317 dl_list_del(&survey
->list
);
8323 static void add_survey(struct nlattr
**sinfo
, u32 ifidx
,
8324 struct dl_list
*survey_list
)
8326 struct freq_survey
*survey
;
8328 survey
= os_zalloc(sizeof(struct freq_survey
));
8332 survey
->ifidx
= ifidx
;
8333 survey
->freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
8336 if (sinfo
[NL80211_SURVEY_INFO_NOISE
]) {
8337 survey
->nf
= (int8_t)
8338 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
8339 survey
->filled
|= SURVEY_HAS_NF
;
8342 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]) {
8343 survey
->channel_time
=
8344 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]);
8345 survey
->filled
|= SURVEY_HAS_CHAN_TIME
;
8348 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]) {
8349 survey
->channel_time_busy
=
8350 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]);
8351 survey
->filled
|= SURVEY_HAS_CHAN_TIME_BUSY
;
8354 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]) {
8355 survey
->channel_time_rx
=
8356 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]);
8357 survey
->filled
|= SURVEY_HAS_CHAN_TIME_RX
;
8360 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]) {
8361 survey
->channel_time_tx
=
8362 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]);
8363 survey
->filled
|= SURVEY_HAS_CHAN_TIME_TX
;
8366 wpa_printf(MSG_DEBUG
, "nl80211: Freq survey dump event (freq=%d MHz noise=%d channel_time=%ld busy_time=%ld tx_time=%ld rx_time=%ld filled=%04x)",
8369 (unsigned long int) survey
->channel_time
,
8370 (unsigned long int) survey
->channel_time_busy
,
8371 (unsigned long int) survey
->channel_time_tx
,
8372 (unsigned long int) survey
->channel_time_rx
,
8375 dl_list_add_tail(survey_list
, &survey
->list
);
8379 static int check_survey_ok(struct nlattr
**sinfo
, u32 surveyed_freq
,
8380 unsigned int freq_filter
)
8385 return freq_filter
== surveyed_freq
;
8389 static int survey_handler(struct nl_msg
*msg
, void *arg
)
8391 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8392 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8393 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
8394 struct survey_results
*survey_results
;
8395 u32 surveyed_freq
= 0;
8398 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
8399 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
8400 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
8403 survey_results
= (struct survey_results
*) arg
;
8405 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8406 genlmsg_attrlen(gnlh
, 0), NULL
);
8408 if (!tb
[NL80211_ATTR_IFINDEX
])
8411 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
8413 if (!tb
[NL80211_ATTR_SURVEY_INFO
])
8416 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
8417 tb
[NL80211_ATTR_SURVEY_INFO
],
8421 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) {
8422 wpa_printf(MSG_ERROR
, "nl80211: Invalid survey data");
8426 surveyed_freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
8428 if (!check_survey_ok(sinfo
, surveyed_freq
,
8429 survey_results
->freq_filter
))
8432 if (survey_results
->freq_filter
&&
8433 survey_results
->freq_filter
!= surveyed_freq
) {
8434 wpa_printf(MSG_EXCESSIVE
, "nl80211: Ignoring survey data for freq %d MHz",
8439 add_survey(sinfo
, ifidx
, &survey_results
->survey_list
);
8445 static int wpa_driver_nl80211_get_survey(void *priv
, unsigned int freq
)
8447 struct i802_bss
*bss
= priv
;
8448 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8451 union wpa_event_data data
;
8452 struct survey_results
*survey_results
;
8454 os_memset(&data
, 0, sizeof(data
));
8455 survey_results
= &data
.survey_results
;
8457 dl_list_init(&survey_results
->survey_list
);
8459 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
8464 data
.survey_results
.freq_filter
= freq
;
8467 wpa_printf(MSG_DEBUG
, "nl80211: Fetch survey data");
8468 err
= send_and_recv_msgs(drv
, msg
, survey_handler
,
8473 wpa_printf(MSG_ERROR
, "nl80211: Failed to process survey data");
8475 wpa_supplicant_event(drv
->ctx
, EVENT_SURVEY
, &data
);
8477 clean_survey_results(survey_results
);
8482 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, size_t kek_len
,
8483 const u8
*kck
, size_t kck_len
,
8484 const u8
*replay_ctr
)
8486 struct i802_bss
*bss
= priv
;
8487 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8488 struct nlattr
*replay_nested
;
8492 if (!drv
->set_rekey_offload
)
8495 wpa_printf(MSG_DEBUG
, "nl80211: Set rekey offload");
8496 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
)) ||
8497 !(replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
)) ||
8498 nla_put(msg
, NL80211_REKEY_DATA_KEK
, kek_len
, kek
) ||
8499 (kck_len
&& nla_put(msg
, NL80211_REKEY_DATA_KCK
, kck_len
, kck
)) ||
8500 nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
8502 nl80211_nlmsg_clear(msg
);
8507 nla_nest_end(msg
, replay_nested
);
8509 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
8510 if (ret
== -EOPNOTSUPP
) {
8511 wpa_printf(MSG_DEBUG
,
8512 "nl80211: Driver does not support rekey offload");
8513 drv
->set_rekey_offload
= 0;
8518 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
8519 const u8
*addr
, int qos
)
8521 /* send data frame to poll STA and check whether
8522 * this frame is ACKed */
8524 struct ieee80211_hdr hdr
;
8526 } STRUCT_PACKED nulldata
;
8529 /* Send data frame to poll STA and check whether this frame is ACKed */
8531 os_memset(&nulldata
, 0, sizeof(nulldata
));
8534 nulldata
.hdr
.frame_control
=
8535 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
8536 WLAN_FC_STYPE_QOS_NULL
);
8537 size
= sizeof(nulldata
);
8539 nulldata
.hdr
.frame_control
=
8540 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
8541 WLAN_FC_STYPE_NULLFUNC
);
8542 size
= sizeof(struct ieee80211_hdr
);
8545 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
8546 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
8547 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
8548 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
8550 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
8551 0, 0, NULL
, 0, 0) < 0)
8552 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
8556 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
8559 struct i802_bss
*bss
= priv
;
8560 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8565 if (!drv
->poll_command_supported
) {
8566 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
8570 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_PROBE_CLIENT
)) ||
8571 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
8576 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
8578 wpa_printf(MSG_DEBUG
, "nl80211: Client probe request for "
8579 MACSTR
" failed: ret=%d (%s)",
8580 MAC2STR(addr
), ret
, strerror(-ret
));
8582 wpa_printf(MSG_DEBUG
,
8583 "nl80211: Client probe request addr=" MACSTR
8584 " cookie=%llu", MAC2STR(addr
),
8585 (long long unsigned int) cookie
);
8590 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
8595 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_POWER_SAVE
)) ||
8596 nla_put_u32(msg
, NL80211_ATTR_PS_STATE
,
8597 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
)) {
8602 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8604 wpa_printf(MSG_DEBUG
,
8605 "nl80211: Setting PS state %s failed: %d (%s)",
8606 enabled
? "enabled" : "disabled",
8607 ret
, strerror(-ret
));
8613 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
8616 struct i802_bss
*bss
= priv
;
8618 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
8619 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
8621 if (opp_ps
!= -1 || ctwindow
!= -1) {
8623 wpa_driver_set_p2p_ps(priv
, legacy_ps
, opp_ps
, ctwindow
);
8624 #else /* ANDROID_P2P */
8625 return -1; /* Not yet supported */
8626 #endif /* ANDROID_P2P */
8629 if (legacy_ps
== -1)
8631 if (legacy_ps
!= 0 && legacy_ps
!= 1)
8632 return -1; /* Not yet supported */
8634 return nl80211_set_power_save(bss
, legacy_ps
);
8638 static int nl80211_start_radar_detection(void *priv
,
8639 struct hostapd_freq_params
*freq
)
8641 struct i802_bss
*bss
= priv
;
8642 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8646 wpa_printf(MSG_DEBUG
, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
8647 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
, freq
->he_enabled
,
8648 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
8650 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_RADAR
)) {
8651 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support radar "
8656 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_RADAR_DETECT
)) ||
8657 nl80211_put_freq_params(msg
, freq
) < 0) {
8662 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8665 wpa_printf(MSG_DEBUG
, "nl80211: Failed to start radar detection: "
8666 "%d (%s)", ret
, strerror(-ret
));
8672 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
8673 u8 dialog_token
, u16 status_code
,
8674 u32 peer_capab
, int initiator
, const u8
*buf
,
8677 struct i802_bss
*bss
= priv
;
8678 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8681 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8687 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_MGMT
)) ||
8688 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
8689 nla_put_u8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
) ||
8690 nla_put_u8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
) ||
8691 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
))
8695 * The internal enum tdls_peer_capability definition is
8696 * currently identical with the nl80211 enum
8697 * nl80211_tdls_peer_capability, so no conversion is needed
8700 if (nla_put_u32(msg
, NL80211_ATTR_TDLS_PEER_CAPABILITY
,
8705 nla_put_flag(msg
, NL80211_ATTR_TDLS_INITIATOR
)) ||
8706 nla_put(msg
, NL80211_ATTR_IE
, len
, buf
))
8709 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8717 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
8719 struct i802_bss
*bss
= priv
;
8720 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8722 enum nl80211_tdls_operation nl80211_oper
;
8725 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8729 case TDLS_DISCOVERY_REQ
:
8730 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
8733 nl80211_oper
= NL80211_TDLS_SETUP
;
8736 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
8738 case TDLS_ENABLE_LINK
:
8739 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
8741 case TDLS_DISABLE_LINK
:
8742 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
8752 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_OPER
)) ||
8753 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
) ||
8754 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
)) {
8759 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8760 wpa_printf(MSG_DEBUG
, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR
8761 " --> res=%d (%s)", nl80211_oper
, MAC2STR(peer
), res
,
8768 nl80211_tdls_enable_channel_switch(void *priv
, const u8
*addr
, u8 oper_class
,
8769 const struct hostapd_freq_params
*params
)
8771 struct i802_bss
*bss
= priv
;
8772 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8776 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
8777 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
8780 wpa_printf(MSG_DEBUG
, "nl80211: Enable TDLS channel switch " MACSTR
8781 " oper_class=%u freq=%u",
8782 MAC2STR(addr
), oper_class
, params
->freq
);
8783 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH
);
8785 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8786 nla_put_u8(msg
, NL80211_ATTR_OPER_CLASS
, oper_class
) ||
8787 (ret
= nl80211_put_freq_params(msg
, params
))) {
8789 wpa_printf(MSG_DEBUG
, "nl80211: Could not build TDLS chan switch");
8793 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8798 nl80211_tdls_disable_channel_switch(void *priv
, const u8
*addr
)
8800 struct i802_bss
*bss
= priv
;
8801 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8804 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
8805 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
8808 wpa_printf(MSG_DEBUG
, "nl80211: Disable TDLS channel switch " MACSTR
,
8810 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
);
8812 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
8814 wpa_printf(MSG_DEBUG
,
8815 "nl80211: Could not build TDLS cancel chan switch");
8819 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8822 #endif /* CONFIG TDLS */
8825 static int driver_nl80211_set_key(void *priv
,
8826 struct wpa_driver_set_key_params
*params
)
8828 struct i802_bss
*bss
= priv
;
8830 return wpa_driver_nl80211_set_key(bss
, params
);
8834 static int driver_nl80211_scan2(void *priv
,
8835 struct wpa_driver_scan_params
*params
)
8837 struct i802_bss
*bss
= priv
;
8838 #ifdef CONFIG_DRIVER_NL80211_QCA
8839 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8842 * Do a vendor specific scan if possible. If only_new_results is
8843 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
8844 * cannot be achieved through a vendor scan. The below condition may
8845 * need to be modified if new scan flags are added in the future whose
8846 * functionality can only be achieved through a normal scan.
8848 if (drv
->scan_vendor_cmd_avail
&& !params
->only_new_results
)
8849 return wpa_driver_nl80211_vendor_scan(bss
, params
);
8850 #endif /* CONFIG_DRIVER_NL80211_QCA */
8851 return wpa_driver_nl80211_scan(bss
, params
);
8855 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
8858 struct i802_bss
*bss
= priv
;
8859 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
8863 static int driver_nl80211_authenticate(void *priv
,
8864 struct wpa_driver_auth_params
*params
)
8866 struct i802_bss
*bss
= priv
;
8867 return wpa_driver_nl80211_authenticate(bss
, params
);
8871 static void driver_nl80211_deinit(void *priv
)
8873 struct i802_bss
*bss
= priv
;
8874 wpa_driver_nl80211_deinit(bss
);
8878 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
8881 struct i802_bss
*bss
= priv
;
8882 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
8886 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
8887 size_t data_len
, int noack
,
8889 const u16
*csa_offs
, size_t csa_offs_len
,
8890 int no_encrypt
, unsigned int wait
)
8892 struct i802_bss
*bss
= priv
;
8893 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
8894 freq
, 0, 0, wait
, csa_offs
,
8895 csa_offs_len
, no_encrypt
);
8899 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
8901 struct i802_bss
*bss
= priv
;
8902 return wpa_driver_nl80211_sta_remove(bss
, addr
, -1, 0);
8906 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
8907 const char *ifname
, int vlan_id
)
8909 struct i802_bss
*bss
= priv
;
8910 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
8914 static int driver_nl80211_read_sta_data(void *priv
,
8915 struct hostap_sta_driver_data
*data
,
8918 struct i802_bss
*bss
= priv
;
8920 os_memset(data
, 0, sizeof(*data
));
8921 return i802_read_sta_data(bss
, data
, addr
);
8925 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
8926 unsigned int wait_time
,
8927 const u8
*dst
, const u8
*src
,
8929 const u8
*data
, size_t data_len
,
8932 struct i802_bss
*bss
= priv
;
8933 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
8934 bssid
, data
, data_len
, no_cck
);
8938 static int driver_nl80211_probe_req_report(void *priv
, int report
)
8940 struct i802_bss
*bss
= priv
;
8941 return wpa_driver_nl80211_probe_req_report(bss
, report
);
8945 static int wpa_driver_nl80211_update_ft_ies(void *priv
, const u8
*md
,
8946 const u8
*ies
, size_t ies_len
)
8950 struct i802_bss
*bss
= priv
;
8951 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8952 u16 mdid
= WPA_GET_LE16(md
);
8954 wpa_printf(MSG_DEBUG
, "nl80211: Updating FT IEs");
8955 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_UPDATE_FT_IES
)) ||
8956 nla_put(msg
, NL80211_ATTR_IE
, ies_len
, ies
) ||
8957 nla_put_u16(msg
, NL80211_ATTR_MDID
, mdid
)) {
8962 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8964 wpa_printf(MSG_DEBUG
, "nl80211: update_ft_ies failed "
8965 "err=%d (%s)", ret
, strerror(-ret
));
8972 static int nl80211_update_dh_ie(void *priv
, const u8
*peer_mac
,
8973 u16 reason_code
, const u8
*ie
, size_t ie_len
)
8977 struct i802_bss
*bss
= priv
;
8978 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8980 wpa_printf(MSG_DEBUG
, "nl80211: Updating DH IE peer: " MACSTR
8981 " reason %u", MAC2STR(peer_mac
), reason_code
);
8982 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_UPDATE_OWE_INFO
)) ||
8983 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer_mac
) ||
8984 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, reason_code
) ||
8985 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
))) {
8990 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8992 wpa_printf(MSG_DEBUG
,
8993 "nl80211: update_dh_ie failed err=%d (%s)",
8994 ret
, strerror(-ret
));
9001 static const u8
* wpa_driver_nl80211_get_macaddr(void *priv
)
9003 struct i802_bss
*bss
= priv
;
9004 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9006 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
9013 static const char * scan_state_str(enum scan_states scan_state
)
9015 switch (scan_state
) {
9018 case SCAN_REQUESTED
:
9019 return "SCAN_REQUESTED";
9021 return "SCAN_STARTED";
9022 case SCAN_COMPLETED
:
9023 return "SCAN_COMPLETED";
9025 return "SCAN_ABORTED";
9026 case SCHED_SCAN_STARTED
:
9027 return "SCHED_SCAN_STARTED";
9028 case SCHED_SCAN_STOPPED
:
9029 return "SCHED_SCAN_STOPPED";
9030 case SCHED_SCAN_RESULTS
:
9031 return "SCHED_SCAN_RESULTS";
9038 static int wpa_driver_nl80211_status(void *priv
, char *buf
, size_t buflen
)
9040 struct i802_bss
*bss
= priv
;
9041 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9045 char alpha2
[3] = { 0, 0, 0 };
9050 res
= os_snprintf(pos
, end
- pos
,
9062 bss
->beacon_set
? "beacon_set=1\n" : "",
9063 bss
->added_if_into_bridge
?
9064 "added_if_into_bridge=1\n" : "",
9065 bss
->already_in_bridge
? "already_in_bridge=1\n" : "",
9066 bss
->added_bridge
? "added_bridge=1\n" : "",
9067 bss
->in_deinit
? "in_deinit=1\n" : "",
9068 bss
->if_dynamic
? "if_dynamic=1\n" : "");
9069 if (os_snprintf_error(end
- pos
, res
))
9073 if (bss
->wdev_id_set
) {
9074 res
= os_snprintf(pos
, end
- pos
, "wdev_id=%llu\n",
9075 (unsigned long long) bss
->wdev_id
);
9076 if (os_snprintf_error(end
- pos
, res
))
9081 res
= os_snprintf(pos
, end
- pos
,
9083 "perm_addr=" MACSTR
"\n"
9087 "auth_bssid=" MACSTR
"\n"
9088 "auth_attempt_bssid=" MACSTR
"\n"
9089 "bssid=" MACSTR
"\n"
9090 "prev_bssid=" MACSTR
"\n"
9094 "monitor_ifidx=%d\n"
9095 "monitor_refcount=%d\n"
9096 "last_mgmt_freq=%u\n"
9097 "eapol_tx_sock=%d\n"
9098 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
9100 MAC2STR(drv
->perm_addr
),
9103 scan_state_str(drv
->scan_state
),
9104 MAC2STR(drv
->auth_bssid
),
9105 MAC2STR(drv
->auth_attempt_bssid
),
9106 MAC2STR(drv
->bssid
),
9107 MAC2STR(drv
->prev_bssid
),
9112 drv
->monitor_refcount
,
9113 drv
->last_mgmt_freq
,
9115 drv
->ignore_if_down_event
?
9116 "ignore_if_down_event=1\n" : "",
9117 drv
->scan_complete_events
?
9118 "scan_complete_events=1\n" : "",
9119 drv
->disabled_11b_rates
?
9120 "disabled_11b_rates=1\n" : "",
9121 drv
->pending_remain_on_chan
?
9122 "pending_remain_on_chan=1\n" : "",
9123 drv
->in_interface_list
? "in_interface_list=1\n" : "",
9124 drv
->device_ap_sme
? "device_ap_sme=1\n" : "",
9125 drv
->poll_command_supported
?
9126 "poll_command_supported=1\n" : "",
9127 drv
->data_tx_status
? "data_tx_status=1\n" : "",
9128 drv
->scan_for_auth
? "scan_for_auth=1\n" : "",
9129 drv
->retry_auth
? "retry_auth=1\n" : "",
9130 drv
->use_monitor
? "use_monitor=1\n" : "",
9131 drv
->ignore_next_local_disconnect
?
9132 "ignore_next_local_disconnect=1\n" : "",
9133 drv
->ignore_next_local_deauth
?
9134 "ignore_next_local_deauth=1\n" : "");
9135 if (os_snprintf_error(end
- pos
, res
))
9139 if (drv
->has_capability
) {
9140 res
= os_snprintf(pos
, end
- pos
,
9141 "capa.key_mgmt=0x%x\n"
9144 "capa.flags=0x%llx\n"
9145 "capa.rrm_flags=0x%x\n"
9146 "capa.max_scan_ssids=%d\n"
9147 "capa.max_sched_scan_ssids=%d\n"
9148 "capa.sched_scan_supported=%d\n"
9149 "capa.max_match_sets=%d\n"
9150 "capa.max_remain_on_chan=%u\n"
9151 "capa.max_stations=%u\n"
9152 "capa.probe_resp_offloads=0x%x\n"
9153 "capa.max_acl_mac_addrs=%u\n"
9154 "capa.num_multichan_concurrent=%u\n"
9155 "capa.mac_addr_rand_sched_scan_supported=%d\n"
9156 "capa.mac_addr_rand_scan_supported=%d\n"
9157 "capa.conc_capab=%u\n"
9158 "capa.max_conc_chan_2_4=%u\n"
9159 "capa.max_conc_chan_5_0=%u\n"
9160 "capa.max_sched_scan_plans=%u\n"
9161 "capa.max_sched_scan_plan_interval=%u\n"
9162 "capa.max_sched_scan_plan_iterations=%u\n",
9166 (unsigned long long) drv
->capa
.flags
,
9167 drv
->capa
.rrm_flags
,
9168 drv
->capa
.max_scan_ssids
,
9169 drv
->capa
.max_sched_scan_ssids
,
9170 drv
->capa
.sched_scan_supported
,
9171 drv
->capa
.max_match_sets
,
9172 drv
->capa
.max_remain_on_chan
,
9173 drv
->capa
.max_stations
,
9174 drv
->capa
.probe_resp_offloads
,
9175 drv
->capa
.max_acl_mac_addrs
,
9176 drv
->capa
.num_multichan_concurrent
,
9177 drv
->capa
.mac_addr_rand_sched_scan_supported
,
9178 drv
->capa
.mac_addr_rand_scan_supported
,
9179 drv
->capa
.conc_capab
,
9180 drv
->capa
.max_conc_chan_2_4
,
9181 drv
->capa
.max_conc_chan_5_0
,
9182 drv
->capa
.max_sched_scan_plans
,
9183 drv
->capa
.max_sched_scan_plan_interval
,
9184 drv
->capa
.max_sched_scan_plan_iterations
);
9185 if (os_snprintf_error(end
- pos
, res
))
9190 msg
= nlmsg_alloc();
9192 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
) &&
9193 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, drv
->wiphy_idx
) == 0) {
9194 if (send_and_recv_msgs(drv
, msg
, nl80211_get_country
,
9197 res
= os_snprintf(pos
, end
- pos
, "country=%s\n",
9199 if (os_snprintf_error(end
- pos
, res
))
9211 static int set_beacon_data(struct nl_msg
*msg
, struct beacon_data
*settings
)
9213 if ((settings
->head
&&
9214 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
,
9215 settings
->head_len
, settings
->head
)) ||
9217 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
,
9218 settings
->tail_len
, settings
->tail
)) ||
9219 (settings
->beacon_ies
&&
9220 nla_put(msg
, NL80211_ATTR_IE
,
9221 settings
->beacon_ies_len
, settings
->beacon_ies
)) ||
9222 (settings
->proberesp_ies
&&
9223 nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
9224 settings
->proberesp_ies_len
, settings
->proberesp_ies
)) ||
9225 (settings
->assocresp_ies
&&
9226 nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
9227 settings
->assocresp_ies_len
, settings
->assocresp_ies
)) ||
9228 (settings
->probe_resp
&&
9229 nla_put(msg
, NL80211_ATTR_PROBE_RESP
,
9230 settings
->probe_resp_len
, settings
->probe_resp
)))
9237 static int nl80211_switch_channel(void *priv
, struct csa_settings
*settings
)
9240 struct i802_bss
*bss
= priv
;
9241 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9242 struct nlattr
*beacon_csa
;
9244 int csa_off_len
= 0;
9247 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
9248 settings
->cs_count
, settings
->block_tx
,
9249 settings
->freq_params
.freq
, settings
->freq_params
.bandwidth
,
9250 settings
->freq_params
.center_freq1
,
9251 settings
->freq_params
.center_freq2
);
9253 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
9254 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support channel switch command");
9258 if (drv
->nlmode
!= NL80211_IFTYPE_AP
&&
9259 drv
->nlmode
!= NL80211_IFTYPE_P2P_GO
&&
9260 drv
->nlmode
!= NL80211_IFTYPE_MESH_POINT
)
9264 * Remove empty counters, assuming Probe Response and Beacon frame
9265 * counters match. This implementation assumes that there are only two
9268 if (settings
->counter_offset_beacon
[0] &&
9269 !settings
->counter_offset_beacon
[1]) {
9271 } else if (settings
->counter_offset_beacon
[1] &&
9272 !settings
->counter_offset_beacon
[0]) {
9274 settings
->counter_offset_beacon
[0] =
9275 settings
->counter_offset_beacon
[1];
9276 settings
->counter_offset_presp
[0] =
9277 settings
->counter_offset_presp
[1];
9278 } else if (settings
->counter_offset_beacon
[1] &&
9279 settings
->counter_offset_beacon
[0]) {
9282 wpa_printf(MSG_ERROR
, "nl80211: No CSA counters provided");
9286 /* Check CSA counters validity */
9287 if (drv
->capa
.max_csa_counters
&&
9288 csa_off_len
> drv
->capa
.max_csa_counters
) {
9289 wpa_printf(MSG_ERROR
,
9290 "nl80211: Too many CSA counters provided");
9294 if (!settings
->beacon_csa
.tail
)
9297 for (i
= 0; i
< csa_off_len
; i
++) {
9298 u16 csa_c_off_bcn
= settings
->counter_offset_beacon
[i
];
9299 u16 csa_c_off_presp
= settings
->counter_offset_presp
[i
];
9301 if ((settings
->beacon_csa
.tail_len
<= csa_c_off_bcn
) ||
9302 (settings
->beacon_csa
.tail
[csa_c_off_bcn
] !=
9303 settings
->cs_count
))
9306 if (settings
->beacon_csa
.probe_resp
&&
9307 ((settings
->beacon_csa
.probe_resp_len
<=
9309 (settings
->beacon_csa
.probe_resp
[csa_c_off_presp
] !=
9310 settings
->cs_count
)))
9314 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_CHANNEL_SWITCH
)) ||
9315 nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
,
9316 settings
->cs_count
) ||
9317 (ret
= nl80211_put_freq_params(msg
, &settings
->freq_params
)) ||
9318 (settings
->block_tx
&&
9319 nla_put_flag(msg
, NL80211_ATTR_CH_SWITCH_BLOCK_TX
)))
9322 /* beacon_after params */
9323 ret
= set_beacon_data(msg
, &settings
->beacon_after
);
9327 /* beacon_csa params */
9328 beacon_csa
= nla_nest_start(msg
, NL80211_ATTR_CSA_IES
);
9332 ret
= set_beacon_data(msg
, &settings
->beacon_csa
);
9336 if (nla_put(msg
, NL80211_ATTR_CSA_C_OFF_BEACON
,
9337 csa_off_len
* sizeof(u16
),
9338 settings
->counter_offset_beacon
) ||
9339 (settings
->beacon_csa
.probe_resp
&&
9340 nla_put(msg
, NL80211_ATTR_CSA_C_OFF_PRESP
,
9341 csa_off_len
* sizeof(u16
),
9342 settings
->counter_offset_presp
)))
9345 nla_nest_end(msg
, beacon_csa
);
9346 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9348 wpa_printf(MSG_DEBUG
, "nl80211: switch_channel failed err=%d (%s)",
9349 ret
, strerror(-ret
));
9357 wpa_printf(MSG_DEBUG
, "nl80211: Could not build channel switch request");
9362 static int nl80211_add_ts(void *priv
, u8 tsid
, const u8
*addr
,
9363 u8 user_priority
, u16 admitted_time
)
9365 struct i802_bss
*bss
= priv
;
9366 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9370 wpa_printf(MSG_DEBUG
,
9371 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
9372 tsid
, admitted_time
, user_priority
);
9374 if (!is_sta_interface(drv
->nlmode
))
9377 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_ADD_TX_TS
);
9379 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
9380 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9381 nla_put_u8(msg
, NL80211_ATTR_USER_PRIO
, user_priority
) ||
9382 nla_put_u16(msg
, NL80211_ATTR_ADMITTED_TIME
, admitted_time
)) {
9387 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9389 wpa_printf(MSG_DEBUG
, "nl80211: add_ts failed err=%d (%s)",
9390 ret
, strerror(-ret
));
9395 static int nl80211_del_ts(void *priv
, u8 tsid
, const u8
*addr
)
9397 struct i802_bss
*bss
= priv
;
9398 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9402 wpa_printf(MSG_DEBUG
, "nl80211: del_ts request: tsid=%u", tsid
);
9404 if (!is_sta_interface(drv
->nlmode
))
9407 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_TX_TS
)) ||
9408 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
9409 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
9414 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9416 wpa_printf(MSG_DEBUG
, "nl80211: del_ts failed err=%d (%s)",
9417 ret
, strerror(-ret
));
9422 #ifdef CONFIG_TESTING_OPTIONS
9423 static int cmd_reply_handler(struct nl_msg
*msg
, void *arg
)
9425 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9426 struct wpabuf
*buf
= arg
;
9431 if ((size_t) genlmsg_attrlen(gnlh
, 0) > wpabuf_tailroom(buf
)) {
9432 wpa_printf(MSG_INFO
, "nl80211: insufficient buffer space for reply");
9436 wpabuf_put_data(buf
, genlmsg_attrdata(gnlh
, 0),
9437 genlmsg_attrlen(gnlh
, 0));
9441 #endif /* CONFIG_TESTING_OPTIONS */
9444 static int vendor_reply_handler(struct nl_msg
*msg
, void *arg
)
9446 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9447 struct nlattr
*nl_vendor_reply
, *nl
;
9448 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9449 struct wpabuf
*buf
= arg
;
9455 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9456 genlmsg_attrlen(gnlh
, 0), NULL
);
9457 nl_vendor_reply
= tb
[NL80211_ATTR_VENDOR_DATA
];
9459 if (!nl_vendor_reply
)
9462 if ((size_t) nla_len(nl_vendor_reply
) > wpabuf_tailroom(buf
)) {
9463 wpa_printf(MSG_INFO
, "nl80211: Vendor command: insufficient buffer space for reply");
9467 nla_for_each_nested(nl
, nl_vendor_reply
, rem
) {
9468 wpabuf_put_data(buf
, nla_data(nl
), nla_len(nl
));
9475 static int nl80211_vendor_cmd(void *priv
, unsigned int vendor_id
,
9476 unsigned int subcmd
, const u8
*data
,
9477 size_t data_len
, struct wpabuf
*buf
)
9479 struct i802_bss
*bss
= priv
;
9480 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9484 #ifdef CONFIG_TESTING_OPTIONS
9485 if (vendor_id
== 0xffffffff) {
9486 msg
= nlmsg_alloc();
9490 nl80211_cmd(drv
, msg
, 0, subcmd
);
9491 if (nlmsg_append(msg
, (void *) data
, data_len
, NLMSG_ALIGNTO
) <
9494 ret
= send_and_recv_msgs(drv
, msg
, cmd_reply_handler
, buf
);
9496 wpa_printf(MSG_DEBUG
, "nl80211: command failed err=%d",
9500 #endif /* CONFIG_TESTING_OPTIONS */
9502 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_VENDOR
)) ||
9503 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, vendor_id
) ||
9504 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
, subcmd
) ||
9506 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, data_len
, data
)))
9509 ret
= send_and_recv_msgs(drv
, msg
, vendor_reply_handler
, buf
);
9511 wpa_printf(MSG_DEBUG
, "nl80211: vendor command failed err=%d",
9521 static int nl80211_set_qos_map(void *priv
, const u8
*qos_map_set
,
9524 struct i802_bss
*bss
= priv
;
9525 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9529 wpa_hexdump(MSG_DEBUG
, "nl80211: Setting QoS Map",
9530 qos_map_set
, qos_map_set_len
);
9532 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_QOS_MAP
)) ||
9533 nla_put(msg
, NL80211_ATTR_QOS_MAP
, qos_map_set_len
, qos_map_set
)) {
9538 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9540 wpa_printf(MSG_DEBUG
, "nl80211: Setting QoS Map failed");
9546 static int get_wowlan_handler(struct nl_msg
*msg
, void *arg
)
9548 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9549 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9550 int *wowlan_enabled
= arg
;
9552 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9553 genlmsg_attrlen(gnlh
, 0), NULL
);
9555 *wowlan_enabled
= !!tb
[NL80211_ATTR_WOWLAN_TRIGGERS
];
9561 static int nl80211_get_wowlan(void *priv
)
9563 struct i802_bss
*bss
= priv
;
9564 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9569 wpa_printf(MSG_DEBUG
, "nl80211: Getting wowlan status");
9571 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_WOWLAN
);
9573 ret
= send_and_recv_msgs(drv
, msg
, get_wowlan_handler
, &wowlan_enabled
);
9575 wpa_printf(MSG_DEBUG
, "nl80211: Getting wowlan status failed");
9579 wpa_printf(MSG_DEBUG
, "nl80211: wowlan is %s",
9580 wowlan_enabled
? "enabled" : "disabled");
9582 return wowlan_enabled
;
9586 static int nl80211_set_wowlan(void *priv
,
9587 const struct wowlan_triggers
*triggers
)
9589 struct i802_bss
*bss
= priv
;
9590 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9592 struct nlattr
*wowlan_triggers
;
9595 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan");
9597 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_SET_WOWLAN
)) ||
9598 !(wowlan_triggers
= nla_nest_start(msg
,
9599 NL80211_ATTR_WOWLAN_TRIGGERS
)) ||
9601 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
9602 (triggers
->disconnect
&&
9603 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
9604 (triggers
->magic_pkt
&&
9605 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
9606 (triggers
->gtk_rekey_failure
&&
9607 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
9608 (triggers
->eap_identity_req
&&
9609 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
9610 (triggers
->four_way_handshake
&&
9611 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
9612 (triggers
->rfkill_release
&&
9613 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))) {
9618 nla_nest_end(msg
, wowlan_triggers
);
9620 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9622 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan failed");
9628 #ifdef CONFIG_DRIVER_NL80211_QCA
9629 static int nl80211_roaming(void *priv
, int allowed
, const u8
*bssid
)
9631 struct i802_bss
*bss
= priv
;
9632 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9634 struct nlattr
*params
;
9636 wpa_printf(MSG_DEBUG
, "nl80211: Roaming policy: allowed=%d", allowed
);
9638 if (!drv
->roaming_vendor_cmd_avail
) {
9639 wpa_printf(MSG_DEBUG
,
9640 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
9644 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9645 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9646 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9647 QCA_NL80211_VENDOR_SUBCMD_ROAMING
) ||
9648 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9649 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY
,
9650 allowed
? QCA_ROAMING_ALLOWED_WITHIN_ESS
:
9651 QCA_ROAMING_NOT_ALLOWED
) ||
9653 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_MAC_ADDR
, ETH_ALEN
, bssid
))) {
9657 nla_nest_end(msg
, params
);
9659 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9663 static int nl80211_disable_fils(void *priv
, int disable
)
9665 struct i802_bss
*bss
= priv
;
9666 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9668 struct nlattr
*params
;
9670 wpa_printf(MSG_DEBUG
, "nl80211: Disable FILS=%d", disable
);
9672 if (!drv
->set_wifi_conf_vendor_cmd_avail
)
9675 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9676 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9677 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9678 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION
) ||
9679 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9680 nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS
,
9685 nla_nest_end(msg
, params
);
9687 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9691 /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */
9692 #define WPA_SUPPLICANT_CLIENT_ID 1
9694 static int nl80211_set_bssid_blacklist(void *priv
, unsigned int num_bssid
,
9697 struct i802_bss
*bss
= priv
;
9698 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9700 struct nlattr
*params
, *nlbssids
, *attr
;
9703 wpa_printf(MSG_DEBUG
, "nl80211: Set blacklist BSSID (num=%u)",
9706 if (!drv
->roam_vendor_cmd_avail
)
9709 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9710 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9711 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9712 QCA_NL80211_VENDOR_SUBCMD_ROAM
) ||
9713 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9714 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD
,
9715 QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID
) ||
9716 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID
,
9717 WPA_SUPPLICANT_CLIENT_ID
) ||
9719 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID
,
9723 nlbssids
= nla_nest_start(
9724 msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS
);
9728 for (i
= 0; i
< num_bssid
; i
++) {
9729 attr
= nla_nest_start(msg
, i
);
9733 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID
,
9734 ETH_ALEN
, &bssid
[i
* ETH_ALEN
]))
9736 wpa_printf(MSG_DEBUG
, "nl80211: BSSID[%u]: " MACSTR
, i
,
9737 MAC2STR(&bssid
[i
* ETH_ALEN
]));
9738 nla_nest_end(msg
, attr
);
9740 nla_nest_end(msg
, nlbssids
);
9741 nla_nest_end(msg
, params
);
9743 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9751 static int nl80211_add_sta_node(void *priv
, const u8
*addr
, u16 auth_alg
)
9753 struct i802_bss
*bss
= priv
;
9754 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9756 struct nlattr
*params
;
9758 if (!drv
->add_sta_node_vendor_cmd_avail
)
9761 wpa_printf(MSG_DEBUG
, "nl80211: Add STA node");
9763 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9764 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9765 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9766 QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE
) ||
9767 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9769 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR
, ETH_ALEN
,
9771 nla_put_u16(msg
, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO
,
9774 wpa_printf(MSG_ERROR
,
9775 "%s: err in adding vendor_cmd and vendor_data",
9779 nla_nest_end(msg
, params
);
9781 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9784 #endif /* CONFIG_DRIVER_NL80211_QCA */
9787 static int nl80211_set_mac_addr(void *priv
, const u8
*addr
)
9789 struct i802_bss
*bss
= priv
;
9790 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9791 int new_addr
= addr
!= NULL
;
9797 addr
= drv
->perm_addr
;
9799 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) < 0)
9802 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
, addr
) < 0)
9804 wpa_printf(MSG_DEBUG
,
9805 "nl80211: failed to set_mac_addr for %s to " MACSTR
,
9806 bss
->ifname
, MAC2STR(addr
));
9807 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
9809 wpa_printf(MSG_DEBUG
,
9810 "nl80211: Could not restore interface UP after failed set_mac_addr");
9815 wpa_printf(MSG_DEBUG
, "nl80211: set_mac_addr for %s to " MACSTR
,
9816 bss
->ifname
, MAC2STR(addr
));
9817 drv
->addr_changed
= new_addr
;
9818 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
9820 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1) < 0)
9822 wpa_printf(MSG_DEBUG
,
9823 "nl80211: Could not restore interface UP after set_mac_addr");
9832 static int wpa_driver_nl80211_init_mesh(void *priv
)
9834 if (wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_MESH_POINT
)) {
9835 wpa_printf(MSG_INFO
,
9836 "nl80211: Failed to set interface into mesh mode");
9843 static int nl80211_put_mesh_id(struct nl_msg
*msg
, const u8
*mesh_id
,
9847 wpa_printf(MSG_DEBUG
, " * Mesh ID (SSID)=%s",
9848 wpa_ssid_txt(mesh_id
, mesh_id_len
));
9849 return nla_put(msg
, NL80211_ATTR_MESH_ID
, mesh_id_len
, mesh_id
);
9856 static int nl80211_put_mesh_config(struct nl_msg
*msg
,
9857 struct wpa_driver_mesh_bss_params
*params
)
9859 struct nlattr
*container
;
9861 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
9865 if (((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS
) &&
9866 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
9867 params
->auto_plinks
)) ||
9868 ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS
) &&
9869 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
9870 params
->max_peer_links
)) ||
9871 ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD
) &&
9872 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
9873 params
->rssi_threshold
)))
9877 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
9878 * the timer could disconnect stations even in that case.
9880 if ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT
) &&
9881 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
9882 params
->peer_link_timeout
)) {
9883 wpa_printf(MSG_ERROR
, "nl80211: Failed to set PLINK_TIMEOUT");
9887 if ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE
) &&
9888 nla_put_u16(msg
, NL80211_MESHCONF_HT_OPMODE
, params
->ht_opmode
)) {
9889 wpa_printf(MSG_ERROR
, "nl80211: Failed to set HT_OP_MODE");
9893 nla_nest_end(msg
, container
);
9899 static int nl80211_join_mesh(struct i802_bss
*bss
,
9900 struct wpa_driver_mesh_join_params
*params
)
9902 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9904 struct nlattr
*container
;
9907 wpa_printf(MSG_DEBUG
, "nl80211: mesh join (ifindex=%d)", drv
->ifindex
);
9908 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_MESH
);
9910 nl80211_put_freq_params(msg
, ¶ms
->freq
) ||
9911 nl80211_put_basic_rates(msg
, params
->basic_rates
) ||
9912 nl80211_put_mesh_id(msg
, params
->meshid
, params
->meshid_len
) ||
9913 nl80211_put_beacon_int(msg
, params
->beacon_int
) ||
9914 nl80211_put_dtim_period(msg
, params
->dtim_period
))
9917 wpa_printf(MSG_DEBUG
, " * flags=%08X", params
->flags
);
9919 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_SETUP
);
9924 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ies
, params
->ie_len
);
9925 if (nla_put(msg
, NL80211_MESH_SETUP_IE
, params
->ie_len
,
9929 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
9930 if (params
->flags
& WPA_DRIVER_MESH_FLAG_SAE_AUTH
) {
9931 if (nla_put_u8(msg
, NL80211_MESH_SETUP_AUTH_PROTOCOL
, 0x1) ||
9932 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AUTH
))
9935 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_AMPE
) &&
9936 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AMPE
))
9938 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
) &&
9939 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_MPM
))
9941 nla_nest_end(msg
, container
);
9943 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS
;
9944 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT
;
9945 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS
;
9946 if (nl80211_put_mesh_config(msg
, ¶ms
->conf
) < 0)
9949 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9952 wpa_printf(MSG_DEBUG
, "nl80211: mesh join failed: ret=%d (%s)",
9953 ret
, strerror(-ret
));
9957 drv
->assoc_freq
= bss
->freq
= params
->freq
.freq
;
9958 wpa_printf(MSG_DEBUG
, "nl80211: mesh join request send successfully");
9967 wpa_driver_nl80211_join_mesh(void *priv
,
9968 struct wpa_driver_mesh_join_params
*params
)
9970 struct i802_bss
*bss
= priv
;
9973 timeout
= params
->conf
.peer_link_timeout
;
9975 /* Disable kernel inactivity timer */
9976 if (params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
)
9977 params
->conf
.peer_link_timeout
= 0;
9979 ret
= nl80211_join_mesh(bss
, params
);
9980 if (ret
== -EINVAL
&& params
->conf
.peer_link_timeout
== 0) {
9981 wpa_printf(MSG_DEBUG
,
9982 "nl80211: Mesh join retry for peer_link_timeout");
9984 * Old kernel does not support setting
9985 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
9986 * into future from peer_link_timeout.
9988 params
->conf
.peer_link_timeout
= timeout
+ 60;
9989 ret
= nl80211_join_mesh(priv
, params
);
9992 params
->conf
.peer_link_timeout
= timeout
;
9997 static int wpa_driver_nl80211_leave_mesh(void *priv
)
9999 struct i802_bss
*bss
= priv
;
10000 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10001 struct nl_msg
*msg
;
10004 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave (ifindex=%d)", drv
->ifindex
);
10005 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_MESH
);
10006 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10008 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave failed: ret=%d (%s)",
10009 ret
, strerror(-ret
));
10011 wpa_printf(MSG_DEBUG
,
10012 "nl80211: mesh leave request send successfully");
10015 if (wpa_driver_nl80211_set_mode(drv
->first_bss
,
10016 NL80211_IFTYPE_STATION
)) {
10017 wpa_printf(MSG_INFO
,
10018 "nl80211: Failed to set interface into station mode");
10024 static int nl80211_probe_mesh_link(void *priv
, const u8
*addr
, const u8
*eth
,
10027 struct i802_bss
*bss
= priv
;
10028 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10029 struct nl_msg
*msg
;
10032 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_PROBE_MESH_LINK
);
10034 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10035 nla_put(msg
, NL80211_ATTR_FRAME
, len
, eth
)) {
10040 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10042 wpa_printf(MSG_DEBUG
, "nl80211: mesh link probe to " MACSTR
10043 " failed: ret=%d (%s)",
10044 MAC2STR(addr
), ret
, strerror(-ret
));
10046 wpa_printf(MSG_DEBUG
, "nl80211: Mesh link to " MACSTR
10047 " probed successfully", MAC2STR(addr
));
10053 #endif /* CONFIG_MESH */
10056 static int wpa_driver_br_add_ip_neigh(void *priv
, u8 version
,
10057 const u8
*ipaddr
, int prefixlen
,
10060 #ifdef CONFIG_LIBNL3_ROUTE
10061 struct i802_bss
*bss
= priv
;
10062 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10063 struct rtnl_neigh
*rn
;
10064 struct nl_addr
*nl_ipaddr
= NULL
;
10065 struct nl_addr
*nl_lladdr
= NULL
;
10066 int family
, addrsize
;
10069 if (!ipaddr
|| prefixlen
== 0 || !addr
)
10072 if (bss
->br_ifindex
== 0) {
10073 wpa_printf(MSG_DEBUG
,
10074 "nl80211: bridge must be set before adding an ip neigh to it");
10078 if (!drv
->rtnl_sk
) {
10079 wpa_printf(MSG_DEBUG
,
10080 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
10084 if (version
== 4) {
10087 } else if (version
== 6) {
10094 rn
= rtnl_neigh_alloc();
10098 /* set the destination ip address for neigh */
10099 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
10100 if (nl_ipaddr
== NULL
) {
10101 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
10105 nl_addr_set_prefixlen(nl_ipaddr
, prefixlen
);
10106 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
10108 wpa_printf(MSG_DEBUG
,
10109 "nl80211: neigh set destination addr failed");
10113 /* set the corresponding lladdr for neigh */
10114 nl_lladdr
= nl_addr_build(AF_BRIDGE
, (u8
*) addr
, ETH_ALEN
);
10115 if (nl_lladdr
== NULL
) {
10116 wpa_printf(MSG_DEBUG
, "nl80211: neigh set lladdr failed");
10120 rtnl_neigh_set_lladdr(rn
, nl_lladdr
);
10122 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
10123 rtnl_neigh_set_state(rn
, NUD_PERMANENT
);
10125 res
= rtnl_neigh_add(drv
->rtnl_sk
, rn
, NLM_F_CREATE
);
10127 wpa_printf(MSG_DEBUG
,
10128 "nl80211: Adding bridge ip neigh failed: %s",
10133 nl_addr_put(nl_lladdr
);
10135 nl_addr_put(nl_ipaddr
);
10137 rtnl_neigh_put(rn
);
10139 #else /* CONFIG_LIBNL3_ROUTE */
10141 #endif /* CONFIG_LIBNL3_ROUTE */
10145 static int wpa_driver_br_delete_ip_neigh(void *priv
, u8 version
,
10148 #ifdef CONFIG_LIBNL3_ROUTE
10149 struct i802_bss
*bss
= priv
;
10150 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10151 struct rtnl_neigh
*rn
;
10152 struct nl_addr
*nl_ipaddr
;
10153 int family
, addrsize
;
10159 if (version
== 4) {
10162 } else if (version
== 6) {
10169 if (bss
->br_ifindex
== 0) {
10170 wpa_printf(MSG_DEBUG
,
10171 "nl80211: bridge must be set to delete an ip neigh");
10175 if (!drv
->rtnl_sk
) {
10176 wpa_printf(MSG_DEBUG
,
10177 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
10181 rn
= rtnl_neigh_alloc();
10185 /* set the destination ip address for neigh */
10186 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
10187 if (nl_ipaddr
== NULL
) {
10188 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
10192 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
10194 wpa_printf(MSG_DEBUG
,
10195 "nl80211: neigh set destination addr failed");
10199 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
10201 res
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
10203 wpa_printf(MSG_DEBUG
,
10204 "nl80211: Deleting bridge ip neigh failed: %s",
10209 nl_addr_put(nl_ipaddr
);
10211 rtnl_neigh_put(rn
);
10213 #else /* CONFIG_LIBNL3_ROUTE */
10215 #endif /* CONFIG_LIBNL3_ROUTE */
10219 static int linux_write_system_file(const char *path
, unsigned int val
)
10224 len
= os_snprintf(buf
, sizeof(buf
), "%u\n", val
);
10225 if (os_snprintf_error(sizeof(buf
), len
))
10228 fd
= open(path
, O_WRONLY
);
10232 if (write(fd
, buf
, len
) < 0) {
10233 wpa_printf(MSG_DEBUG
,
10234 "nl80211: Failed to write Linux system file: %s with the value of %d",
10245 static const char * drv_br_port_attr_str(enum drv_br_port_attr attr
)
10248 case DRV_BR_PORT_ATTR_PROXYARP
:
10249 return "proxyarp_wifi";
10250 case DRV_BR_PORT_ATTR_HAIRPIN_MODE
:
10251 return "hairpin_mode";
10258 static int wpa_driver_br_port_set_attr(void *priv
, enum drv_br_port_attr attr
,
10261 struct i802_bss
*bss
= priv
;
10263 const char *attr_txt
;
10265 attr_txt
= drv_br_port_attr_str(attr
);
10266 if (attr_txt
== NULL
)
10269 os_snprintf(path
, sizeof(path
), "/sys/class/net/%s/brport/%s",
10270 bss
->ifname
, attr_txt
);
10272 if (linux_write_system_file(path
, val
))
10279 static const char * drv_br_net_param_str(enum drv_br_net_param param
)
10282 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
10283 return "arp_accept";
10290 static int wpa_driver_br_set_net_param(void *priv
, enum drv_br_net_param param
,
10293 struct i802_bss
*bss
= priv
;
10295 const char *param_txt
;
10296 int ip_version
= 4;
10298 if (param
== DRV_BR_MULTICAST_SNOOPING
) {
10299 os_snprintf(path
, sizeof(path
),
10300 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
10305 param_txt
= drv_br_net_param_str(param
);
10306 if (param_txt
== NULL
)
10310 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
10317 os_snprintf(path
, sizeof(path
), "/proc/sys/net/ipv%d/conf/%s/%s",
10318 ip_version
, bss
->brname
, param_txt
);
10321 if (linux_write_system_file(path
, val
))
10328 #ifdef CONFIG_DRIVER_NL80211_QCA
10330 static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode
)
10333 case HOSTAPD_MODE_IEEE80211B
:
10334 return QCA_ACS_MODE_IEEE80211B
;
10335 case HOSTAPD_MODE_IEEE80211G
:
10336 return QCA_ACS_MODE_IEEE80211G
;
10337 case HOSTAPD_MODE_IEEE80211A
:
10338 return QCA_ACS_MODE_IEEE80211A
;
10339 case HOSTAPD_MODE_IEEE80211AD
:
10340 return QCA_ACS_MODE_IEEE80211AD
;
10341 case HOSTAPD_MODE_IEEE80211ANY
:
10342 return QCA_ACS_MODE_IEEE80211ANY
;
10349 static int add_acs_ch_list(struct nl_msg
*msg
, const int *freq_list
)
10351 int num_channels
= 0, num_freqs
;
10353 enum hostapd_hw_mode hw_mode
;
10360 num_freqs
= int_array_len(freq_list
);
10361 ch_list
= os_malloc(sizeof(u8
) * num_freqs
);
10365 for (i
= 0; i
< num_freqs
; i
++) {
10366 const int freq
= freq_list
[i
];
10370 /* Send 2.4 GHz and 5 GHz channels with
10371 * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards
10374 if (!(freq
>= 2412 && freq
<= 2484) &&
10375 !(freq
>= 5180 && freq
<= 5900))
10377 hw_mode
= ieee80211_freq_to_chan(freq
, &ch_list
[num_channels
]);
10378 if (hw_mode
!= NUM_HOSTAPD_MODES
)
10383 ret
= nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST
,
10384 num_channels
, ch_list
);
10391 static int add_acs_freq_list(struct nl_msg
*msg
, const int *freq_list
)
10398 len
= int_array_len(freq_list
);
10399 freqs
= os_malloc(sizeof(u32
) * len
);
10402 for (i
= 0; i
< len
; i
++)
10403 freqs
[i
] = freq_list
[i
];
10404 ret
= nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST
,
10405 sizeof(u32
) * len
, freqs
);
10411 static int wpa_driver_do_acs(void *priv
, struct drv_acs_params
*params
)
10413 struct i802_bss
*bss
= priv
;
10414 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10415 struct nl_msg
*msg
;
10416 struct nlattr
*data
;
10420 mode
= hw_mode_to_qca_acs(params
->hw_mode
);
10424 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10425 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10426 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10427 QCA_NL80211_VENDOR_SUBCMD_DO_ACS
) ||
10428 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
10429 nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE
, mode
) ||
10430 (params
->ht_enabled
&&
10431 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED
)) ||
10432 (params
->ht40_enabled
&&
10433 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED
)) ||
10434 (params
->vht_enabled
&&
10435 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED
)) ||
10436 nla_put_u16(msg
, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH
,
10437 params
->ch_width
) ||
10438 add_acs_ch_list(msg
, params
->freq_list
) ||
10439 add_acs_freq_list(msg
, params
->freq_list
)) {
10443 nla_nest_end(msg
, data
);
10445 wpa_printf(MSG_DEBUG
,
10446 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d",
10447 params
->hw_mode
, params
->ht_enabled
, params
->ht40_enabled
,
10448 params
->vht_enabled
, params
->ch_width
);
10450 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10452 wpa_printf(MSG_DEBUG
,
10453 "nl80211: Failed to invoke driver ACS function: %s",
10460 static int nl80211_set_band(void *priv
, enum set_band band
)
10462 struct i802_bss
*bss
= priv
;
10463 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10464 struct nl_msg
*msg
;
10465 struct nlattr
*data
;
10467 enum qca_set_band qca_band
;
10469 if (!drv
->setband_vendor_cmd_avail
)
10473 case WPA_SETBAND_AUTO
:
10474 qca_band
= QCA_SETBAND_AUTO
;
10476 case WPA_SETBAND_5G
:
10477 qca_band
= QCA_SETBAND_5G
;
10479 case WPA_SETBAND_2G
:
10480 qca_band
= QCA_SETBAND_2G
;
10486 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10487 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10488 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10489 QCA_NL80211_VENDOR_SUBCMD_SETBAND
) ||
10490 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
10491 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE
, qca_band
)) {
10495 nla_nest_end(msg
, data
);
10497 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10499 wpa_printf(MSG_DEBUG
,
10500 "nl80211: Driver setband function failed: %s",
10507 struct nl80211_pcl
{
10509 unsigned int *freq_list
;
10512 static int preferred_freq_info_handler(struct nl_msg
*msg
, void *arg
)
10514 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
10515 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
10516 struct nl80211_pcl
*param
= arg
;
10517 struct nlattr
*nl_vend
, *attr
;
10518 enum qca_iface_type iface_type
;
10519 struct nlattr
*tb_vendor
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
10520 unsigned int num
, max_num
;
10523 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
10524 genlmsg_attrlen(gnlh
, 0), NULL
);
10526 nl_vend
= tb
[NL80211_ATTR_VENDOR_DATA
];
10530 nla_parse(tb_vendor
, QCA_WLAN_VENDOR_ATTR_MAX
,
10531 nla_data(nl_vend
), nla_len(nl_vend
), NULL
);
10534 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE
];
10536 wpa_printf(MSG_ERROR
, "nl80211: iface_type couldn't be found");
10541 iface_type
= (enum qca_iface_type
) nla_get_u32(attr
);
10542 wpa_printf(MSG_DEBUG
, "nl80211: Driver returned iface_type=%d",
10545 attr
= tb_vendor
[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST
];
10547 wpa_printf(MSG_ERROR
,
10548 "nl80211: preferred_freq_list couldn't be found");
10554 * param->num has the maximum number of entries for which there
10555 * is room in the freq_list provided by the caller.
10557 freqs
= nla_data(attr
);
10558 max_num
= nla_len(attr
) / sizeof(u32
);
10559 if (max_num
> param
->num
)
10560 max_num
= param
->num
;
10561 for (num
= 0; num
< max_num
; num
++)
10562 param
->freq_list
[num
] = freqs
[num
];
10569 static int nl80211_get_pref_freq_list(void *priv
,
10570 enum wpa_driver_if_type if_type
,
10572 unsigned int *freq_list
)
10574 struct i802_bss
*bss
= priv
;
10575 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10576 struct nl_msg
*msg
;
10579 struct nlattr
*params
;
10580 struct nl80211_pcl param
;
10581 enum qca_iface_type iface_type
;
10583 if (!drv
->get_pref_freq_list
)
10587 case WPA_IF_STATION
:
10588 iface_type
= QCA_IFACE_TYPE_STA
;
10590 case WPA_IF_AP_BSS
:
10591 iface_type
= QCA_IFACE_TYPE_AP
;
10593 case WPA_IF_P2P_GO
:
10594 iface_type
= QCA_IFACE_TYPE_P2P_GO
;
10596 case WPA_IF_P2P_CLIENT
:
10597 iface_type
= QCA_IFACE_TYPE_P2P_CLIENT
;
10600 iface_type
= QCA_IFACE_TYPE_IBSS
;
10603 iface_type
= QCA_IFACE_TYPE_TDLS
;
10610 param
.freq_list
= freq_list
;
10612 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10613 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
) ||
10614 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10615 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10616 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST
) ||
10617 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
10619 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE
,
10621 wpa_printf(MSG_ERROR
,
10622 "%s: err in adding vendor_cmd and vendor_data",
10627 nla_nest_end(msg
, params
);
10629 os_memset(freq_list
, 0, *num
* sizeof(freq_list
[0]));
10630 ret
= send_and_recv_msgs(drv
, msg
, preferred_freq_info_handler
, ¶m
);
10632 wpa_printf(MSG_ERROR
,
10633 "%s: err in send_and_recv_msgs", __func__
);
10639 for (i
= 0; i
< *num
; i
++) {
10640 wpa_printf(MSG_DEBUG
, "nl80211: preferred_channel_list[%d]=%d",
10648 static int nl80211_set_prob_oper_freq(void *priv
, unsigned int freq
)
10650 struct i802_bss
*bss
= priv
;
10651 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10652 struct nl_msg
*msg
;
10654 struct nlattr
*params
;
10656 if (!drv
->set_prob_oper_freq
)
10659 wpa_printf(MSG_DEBUG
,
10660 "nl80211: Set P2P probable operating freq %u for ifindex %d",
10661 freq
, bss
->ifindex
);
10663 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10664 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10665 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10666 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL
) ||
10667 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
10669 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE
,
10670 QCA_IFACE_TYPE_P2P_CLIENT
) ||
10672 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ
,
10674 wpa_printf(MSG_ERROR
,
10675 "%s: err in adding vendor_cmd and vendor_data",
10680 nla_nest_end(msg
, params
);
10682 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10685 wpa_printf(MSG_ERROR
, "%s: err in send_and_recv_msgs",
10694 static int nl80211_p2p_lo_start(void *priv
, unsigned int freq
,
10695 unsigned int period
, unsigned int interval
,
10696 unsigned int count
, const u8
*device_types
,
10697 size_t dev_types_len
,
10698 const u8
*ies
, size_t ies_len
)
10700 struct i802_bss
*bss
= priv
;
10701 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10702 struct nl_msg
*msg
;
10703 struct nlattr
*container
;
10706 wpa_printf(MSG_DEBUG
,
10707 "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u",
10708 freq
, period
, interval
, count
);
10710 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD
))
10713 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10714 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10715 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10716 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START
))
10719 container
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
10723 if (nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL
,
10725 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD
,
10727 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL
,
10729 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT
,
10731 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES
,
10732 dev_types_len
, device_types
) ||
10733 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE
,
10737 nla_nest_end(msg
, container
);
10738 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10741 wpa_printf(MSG_DEBUG
,
10742 "nl80211: Failed to send P2P Listen offload vendor command");
10754 static int nl80211_p2p_lo_stop(void *priv
)
10756 struct i802_bss
*bss
= priv
;
10757 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10758 struct nl_msg
*msg
;
10760 wpa_printf(MSG_DEBUG
, "nl80211: Stop P2P Listen offload");
10762 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD
))
10765 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10766 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10767 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10768 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP
)) {
10773 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10777 static int nl80211_set_tdls_mode(void *priv
, int tdls_external_control
)
10779 struct i802_bss
*bss
= priv
;
10780 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10781 struct nl_msg
*msg
;
10782 struct nlattr
*params
;
10786 wpa_printf(MSG_DEBUG
,
10787 "nl80211: Set TDKS mode: tdls_external_control=%d",
10788 tdls_external_control
);
10790 if (tdls_external_control
== 1)
10791 tdls_mode
= QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT
|
10792 QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL
;
10794 tdls_mode
= QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT
;
10796 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10797 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10798 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10799 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS
))
10802 params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
10806 if (nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE
,
10810 nla_nest_end(msg
, params
);
10812 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10815 wpa_printf(MSG_ERROR
,
10816 "nl80211: Set TDLS mode failed: ret=%d (%s)",
10817 ret
, strerror(-ret
));
10829 static enum mbo_transition_reject_reason
10830 nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status
)
10833 case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED
:
10834 return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS
;
10835 case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED
:
10836 return MBO_TRANSITION_REJECT_REASON_DELAY
;
10837 case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY
:
10838 return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY
;
10839 case QCA_STATUS_REJECT_LOW_RSSI
:
10840 return MBO_TRANSITION_REJECT_REASON_RSSI
;
10841 case QCA_STATUS_REJECT_HIGH_INTERFERENCE
:
10842 return MBO_TRANSITION_REJECT_REASON_INTERFERENCE
;
10843 case QCA_STATUS_REJECT_UNKNOWN
:
10845 return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED
;
10850 static void nl80211_parse_btm_candidate_info(struct candidate_list
*candidate
,
10851 struct nlattr
*tb
[], int num
)
10853 enum qca_wlan_btm_candidate_status status
;
10856 os_memcpy(candidate
->bssid
,
10857 nla_data(tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID
]),
10860 status
= nla_get_u32(
10861 tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS
]);
10862 candidate
->is_accept
= status
== QCA_STATUS_ACCEPT
;
10863 candidate
->reject_reason
= nl80211_mbo_reject_reason_mapping(status
);
10865 if (candidate
->is_accept
)
10866 os_snprintf(buf
, sizeof(buf
), "Accepted");
10868 os_snprintf(buf
, sizeof(buf
),
10869 "Rejected, Reject_reason: %d",
10870 candidate
->reject_reason
);
10871 wpa_printf(MSG_DEBUG
, "nl80211: BSSID[%d]: " MACSTR
" %s",
10872 num
, MAC2STR(candidate
->bssid
), buf
);
10877 nl80211_get_bss_transition_status_handler(struct nl_msg
*msg
, void *arg
)
10879 struct wpa_bss_candidate_info
*info
= arg
;
10880 struct candidate_list
*candidate
= info
->candidates
;
10881 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
10882 struct nlattr
*tb_vendor
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
10883 struct nlattr
*tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX
+ 1];
10884 static struct nla_policy policy
[
10885 QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX
+ 1] = {
10886 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID
] = {
10889 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS
] = {
10893 struct nlattr
*attr
;
10895 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
10898 num
= info
->num
; /* number of candidates sent to driver */
10900 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
10901 genlmsg_attrlen(gnlh
, 0), NULL
);
10903 if (!tb_msg
[NL80211_ATTR_VENDOR_DATA
] ||
10904 nla_parse_nested(tb_vendor
, QCA_WLAN_VENDOR_ATTR_MAX
,
10905 tb_msg
[NL80211_ATTR_VENDOR_DATA
], NULL
) ||
10906 !tb_vendor
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO
])
10909 wpa_printf(MSG_DEBUG
,
10910 "nl80211: WNM Candidate list received from driver");
10911 nla_for_each_nested(attr
,
10912 tb_vendor
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO
],
10914 if (info
->num
>= num
||
10916 tb
, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX
,
10918 !tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID
] ||
10919 !tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS
])
10922 nl80211_parse_btm_candidate_info(candidate
, tb
, info
->num
);
10932 static struct wpa_bss_candidate_info
*
10933 nl80211_get_bss_transition_status(void *priv
, struct wpa_bss_trans_info
*params
)
10935 struct i802_bss
*bss
= priv
;
10936 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10937 struct nl_msg
*msg
;
10938 struct nlattr
*attr
, *attr1
, *attr2
;
10939 struct wpa_bss_candidate_info
*info
;
10944 if (!drv
->fetch_bss_trans_status
)
10947 info
= os_zalloc(sizeof(*info
));
10950 /* Allocate memory for number of candidates sent to driver */
10951 info
->candidates
= os_calloc(params
->n_candidates
,
10952 sizeof(*info
->candidates
));
10953 if (!info
->candidates
) {
10958 /* Copy the number of candidates being sent to driver. This is used in
10959 * nl80211_get_bss_transition_status_handler() to limit the number of
10960 * candidates that can be populated in info->candidates and will be
10961 * later overwritten with the actual number of candidates received from
10964 info
->num
= params
->n_candidates
;
10966 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10967 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10968 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10969 QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS
))
10972 attr
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
10976 if (nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON
,
10977 params
->mbo_transition_reason
))
10980 attr1
= nla_nest_start(msg
, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO
);
10984 wpa_printf(MSG_DEBUG
,
10985 "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d",
10986 params
->mbo_transition_reason
, params
->n_candidates
);
10987 pos
= params
->bssid
;
10988 for (i
= 0; i
< params
->n_candidates
; i
++) {
10989 wpa_printf(MSG_DEBUG
, "nl80211: BSSID[%d]: " MACSTR
, i
,
10991 attr2
= nla_nest_start(msg
, i
);
10993 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID
,
10997 nla_nest_end(msg
, attr2
);
11000 nla_nest_end(msg
, attr1
);
11001 nla_nest_end(msg
, attr
);
11003 ret
= send_and_recv_msgs(drv
, msg
,
11004 nl80211_get_bss_transition_status_handler
,
11008 wpa_printf(MSG_ERROR
,
11009 "nl80211: WNM Get BSS transition status failed: ret=%d (%s)",
11010 ret
, strerror(-ret
));
11017 os_free(info
->candidates
);
11024 * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow
11025 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
11026 * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore
11027 * Returns: 0 on success, -1 on failure
11029 static int nl80211_ignore_assoc_disallow(void *priv
, int ignore_disallow
)
11031 struct i802_bss
*bss
= priv
;
11032 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11033 struct nl_msg
*msg
;
11034 struct nlattr
*attr
;
11037 if (!drv
->set_wifi_conf_vendor_cmd_avail
)
11040 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
11041 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
11042 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
11043 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION
))
11046 attr
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
11050 wpa_printf(MSG_DEBUG
, "nl80211: Set ignore_assoc_disallow %d",
11052 if (nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED
,
11056 nla_nest_end(msg
, attr
);
11058 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
11061 wpa_printf(MSG_ERROR
,
11062 "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)",
11063 ret
, strerror(-ret
));
11072 #endif /* CONFIG_MBO */
11074 #endif /* CONFIG_DRIVER_NL80211_QCA */
11077 static int nl80211_write_to_file(const char *name
, unsigned int val
)
11083 fd
= open(name
, O_RDWR
);
11087 * Flags may not exist on older kernels, or while we're tearing
11088 * down a disappearing device.
11090 if (errno
== ENOENT
) {
11097 wpa_printf(level
, "nl80211: Failed to open %s: %s",
11098 name
, strerror(errno
));
11102 len
= os_snprintf(tmp
, sizeof(tmp
), "%u\n", val
);
11103 len
= write(fd
, tmp
, len
);
11106 wpa_printf(MSG_ERROR
, "nl80211: Failed to write to %s: %s",
11107 name
, strerror(errno
));
11115 static int nl80211_configure_data_frame_filters(void *priv
, u32 filter_flags
)
11117 struct i802_bss
*bss
= priv
;
11121 wpa_printf(MSG_DEBUG
, "nl80211: Data frame filter flags=0x%x",
11124 /* Configure filtering of unicast frame encrypted using GTK */
11125 ret
= os_snprintf(path
, sizeof(path
),
11126 "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast",
11128 if (os_snprintf_error(sizeof(path
), ret
))
11131 ret
= nl80211_write_to_file(path
,
11133 WPA_DATA_FRAME_FILTER_FLAG_GTK
));
11135 wpa_printf(MSG_ERROR
,
11136 "nl80211: Failed to set IPv4 unicast in multicast filter");
11140 os_snprintf(path
, sizeof(path
),
11141 "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast",
11143 ret
= nl80211_write_to_file(path
,
11145 WPA_DATA_FRAME_FILTER_FLAG_GTK
));
11148 wpa_printf(MSG_ERROR
,
11149 "nl80211: Failed to set IPv6 unicast in multicast filter");
11153 /* Configure filtering of unicast frame encrypted using GTK */
11154 os_snprintf(path
, sizeof(path
),
11155 "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp",
11157 ret
= nl80211_write_to_file(path
,
11159 WPA_DATA_FRAME_FILTER_FLAG_ARP
));
11161 wpa_printf(MSG_ERROR
,
11162 "nl80211: Failed set gratuitous ARP filter");
11166 /* Configure filtering of IPv6 NA frames */
11167 os_snprintf(path
, sizeof(path
),
11168 "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na",
11170 ret
= nl80211_write_to_file(path
,
11172 WPA_DATA_FRAME_FILTER_FLAG_NA
));
11174 wpa_printf(MSG_ERROR
,
11175 "nl80211: Failed to set unsolicited NA filter");
11183 static int nl80211_get_ext_capab(void *priv
, enum wpa_driver_if_type type
,
11184 const u8
**ext_capa
, const u8
**ext_capa_mask
,
11185 unsigned int *ext_capa_len
)
11187 struct i802_bss
*bss
= priv
;
11188 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11189 enum nl80211_iftype nlmode
;
11192 if (!ext_capa
|| !ext_capa_mask
|| !ext_capa_len
)
11195 nlmode
= wpa_driver_nl80211_if_type(type
);
11197 /* By default, use the per-radio values */
11198 *ext_capa
= drv
->extended_capa
;
11199 *ext_capa_mask
= drv
->extended_capa_mask
;
11200 *ext_capa_len
= drv
->extended_capa_len
;
11202 /* Replace the default value if a per-interface type value exists */
11203 for (i
= 0; i
< drv
->num_iface_ext_capa
; i
++) {
11204 if (nlmode
== drv
->iface_ext_capa
[i
].iftype
) {
11205 *ext_capa
= drv
->iface_ext_capa
[i
].ext_capa
;
11206 *ext_capa_mask
= drv
->iface_ext_capa
[i
].ext_capa_mask
;
11207 *ext_capa_len
= drv
->iface_ext_capa
[i
].ext_capa_len
;
11216 static int nl80211_update_connection_params(
11217 void *priv
, struct wpa_driver_associate_params
*params
,
11218 enum wpa_drv_update_connect_params_mask mask
)
11220 struct i802_bss
*bss
= priv
;
11221 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11222 struct nl_msg
*msg
;
11224 enum nl80211_auth_type type
;
11226 /* Update Connection Params is intended for drivers that implement
11227 * internal SME and expect these updated connection params from
11228 * wpa_supplicant. Do not send this request for the drivers using
11229 * SME from wpa_supplicant.
11231 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)
11234 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS
);
11238 wpa_printf(MSG_DEBUG
, "nl80211: Update connection params (ifindex=%d)",
11241 if ((mask
& WPA_DRV_UPDATE_ASSOC_IES
) && params
->wpa_ie
) {
11242 if (nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
11245 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
,
11246 params
->wpa_ie_len
);
11249 if (mask
& WPA_DRV_UPDATE_AUTH_TYPE
) {
11250 type
= get_nl_auth_type(params
->auth_alg
);
11251 if (type
== NL80211_AUTHTYPE_MAX
||
11252 nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
11254 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
11257 if ((mask
& WPA_DRV_UPDATE_FILS_ERP_INFO
) &&
11258 nl80211_put_fils_connect_params(drv
, params
, msg
))
11261 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
11264 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
11265 "nl80211: Update connect params command failed: ret=%d (%s)",
11266 ret
, strerror(-ret
));
11274 static int nl80211_send_external_auth_status(void *priv
,
11275 struct external_auth
*params
)
11277 struct i802_bss
*bss
= priv
;
11278 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11279 struct nl_msg
*msg
= NULL
;
11282 /* External auth command/status is intended for drivers that implement
11283 * internal SME but want to offload authentication processing (e.g.,
11284 * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers
11285 * which do not support AP SME or use wpa_supplicant/hostapd SME.
11287 if ((is_ap_interface(drv
->nlmode
) && !bss
->drv
->device_ap_sme
) ||
11288 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
11291 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
11292 "nl80211: External auth status: %u", params
->status
);
11294 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_EXTERNAL_AUTH
);
11296 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, params
->status
) ||
11297 (params
->ssid
&& params
->ssid_len
&&
11298 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
)) ||
11300 nla_put(msg
, NL80211_ATTR_PMKID
, PMKID_LEN
, params
->pmkid
)) ||
11302 nla_put(msg
, NL80211_ATTR_BSSID
, ETH_ALEN
, params
->bssid
)))
11304 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
11307 wpa_printf(MSG_DEBUG
,
11308 "nl80211: External Auth status update failed: ret=%d (%s)",
11309 ret
, strerror(-ret
));
11318 static int nl80211_set_4addr_mode(void *priv
, const char *bridge_ifname
,
11321 struct i802_bss
*bss
= priv
;
11322 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11323 struct nl_msg
*msg
;
11324 int ret
= -ENOBUFS
;
11326 wpa_printf(MSG_DEBUG
, "nl80211: %s 4addr mode (bridge_ifname: %s)",
11327 val
? "Enable" : "Disable", bridge_ifname
);
11329 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_SET_INTERFACE
);
11330 if (!msg
|| nla_put_u8(msg
, NL80211_ATTR_4ADDR
, val
))
11333 if (bridge_ifname
[0] && bss
->added_if_into_bridge
&& !val
) {
11334 if (linux_br_del_if(drv
->global
->ioctl_sock
,
11335 bridge_ifname
, bss
->ifname
)) {
11336 wpa_printf(MSG_ERROR
,
11337 "nl80211: Failed to remove interface %s from bridge %s",
11338 bss
->ifname
, bridge_ifname
);
11341 bss
->added_if_into_bridge
= 0;
11344 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
11347 if (bridge_ifname
[0] && val
&&
11348 i802_check_bridge(drv
, bss
, bridge_ifname
, bss
->ifname
) < 0)
11355 wpa_printf(MSG_ERROR
, "nl80211: Failed to enable/disable 4addr");
11361 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
11363 .desc
= "Linux nl80211/cfg80211",
11364 .get_bssid
= wpa_driver_nl80211_get_bssid
,
11365 .get_ssid
= wpa_driver_nl80211_get_ssid
,
11366 .set_key
= driver_nl80211_set_key
,
11367 .scan2
= driver_nl80211_scan2
,
11368 .sched_scan
= wpa_driver_nl80211_sched_scan
,
11369 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
11370 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
11371 .abort_scan
= wpa_driver_nl80211_abort_scan
,
11372 .deauthenticate
= driver_nl80211_deauthenticate
,
11373 .authenticate
= driver_nl80211_authenticate
,
11374 .associate
= wpa_driver_nl80211_associate
,
11375 .global_init
= nl80211_global_init
,
11376 .global_deinit
= nl80211_global_deinit
,
11377 .init2
= wpa_driver_nl80211_init
,
11378 .deinit
= driver_nl80211_deinit
,
11379 .get_capa
= wpa_driver_nl80211_get_capa
,
11380 .set_operstate
= wpa_driver_nl80211_set_operstate
,
11381 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
11382 .set_country
= wpa_driver_nl80211_set_country
,
11383 .get_country
= wpa_driver_nl80211_get_country
,
11384 .set_ap
= wpa_driver_nl80211_set_ap
,
11385 .set_acl
= wpa_driver_nl80211_set_acl
,
11386 .if_add
= wpa_driver_nl80211_if_add
,
11387 .if_remove
= driver_nl80211_if_remove
,
11388 .send_mlme
= driver_nl80211_send_mlme
,
11389 .get_hw_feature_data
= nl80211_get_hw_feature_data
,
11390 .sta_add
= wpa_driver_nl80211_sta_add
,
11391 .sta_remove
= driver_nl80211_sta_remove
,
11392 .tx_control_port
= nl80211_tx_control_port
,
11393 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
11394 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
11395 .sta_set_airtime_weight
= driver_nl80211_sta_set_airtime_weight
,
11396 .hapd_init
= i802_init
,
11397 .hapd_deinit
= i802_deinit
,
11398 .set_wds_sta
= i802_set_wds_sta
,
11399 .get_seqnum
= i802_get_seqnum
,
11400 .flush
= i802_flush
,
11401 .get_inact_sec
= i802_get_inact_sec
,
11402 .sta_clear_stats
= i802_sta_clear_stats
,
11403 .set_rts
= i802_set_rts
,
11404 .set_frag
= i802_set_frag
,
11405 .set_tx_queue_params
= i802_set_tx_queue_params
,
11406 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
11407 .sta_deauth
= i802_sta_deauth
,
11408 .sta_disassoc
= i802_sta_disassoc
,
11409 .read_sta_data
= driver_nl80211_read_sta_data
,
11410 .set_freq
= i802_set_freq
,
11411 .send_action
= driver_nl80211_send_action
,
11412 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
11413 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
11414 .cancel_remain_on_channel
=
11415 wpa_driver_nl80211_cancel_remain_on_channel
,
11416 .probe_req_report
= driver_nl80211_probe_req_report
,
11417 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
11418 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
11419 .resume
= wpa_driver_nl80211_resume
,
11420 .signal_monitor
= nl80211_signal_monitor
,
11421 .signal_poll
= nl80211_signal_poll
,
11422 .channel_info
= nl80211_channel_info
,
11423 .set_param
= nl80211_set_param
,
11424 .get_radio_name
= nl80211_get_radio_name
,
11425 .add_pmkid
= nl80211_add_pmkid
,
11426 .remove_pmkid
= nl80211_remove_pmkid
,
11427 .flush_pmkid
= nl80211_flush_pmkid
,
11428 .set_rekey_info
= nl80211_set_rekey_info
,
11429 .poll_client
= nl80211_poll_client
,
11430 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
11431 .start_dfs_cac
= nl80211_start_radar_detection
,
11432 .stop_ap
= wpa_driver_nl80211_stop_ap
,
11434 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
11435 .tdls_oper
= nl80211_tdls_oper
,
11436 .tdls_enable_channel_switch
= nl80211_tdls_enable_channel_switch
,
11437 .tdls_disable_channel_switch
= nl80211_tdls_disable_channel_switch
,
11438 #endif /* CONFIG_TDLS */
11439 .update_ft_ies
= wpa_driver_nl80211_update_ft_ies
,
11440 .update_dh_ie
= nl80211_update_dh_ie
,
11441 .get_mac_addr
= wpa_driver_nl80211_get_macaddr
,
11442 .get_survey
= wpa_driver_nl80211_get_survey
,
11443 .status
= wpa_driver_nl80211_status
,
11444 .switch_channel
= nl80211_switch_channel
,
11446 .set_noa
= wpa_driver_set_p2p_noa
,
11447 .get_noa
= wpa_driver_get_p2p_noa
,
11448 .set_ap_wps_ie
= wpa_driver_set_ap_wps_p2p_ie
,
11449 #endif /* ANDROID_P2P */
11451 #ifndef ANDROID_LIB_STUB
11452 .driver_cmd
= wpa_driver_nl80211_driver_cmd
,
11453 #endif /* !ANDROID_LIB_STUB */
11454 #endif /* ANDROID */
11455 .vendor_cmd
= nl80211_vendor_cmd
,
11456 .set_qos_map
= nl80211_set_qos_map
,
11457 .get_wowlan
= nl80211_get_wowlan
,
11458 .set_wowlan
= nl80211_set_wowlan
,
11459 .set_mac_addr
= nl80211_set_mac_addr
,
11461 .init_mesh
= wpa_driver_nl80211_init_mesh
,
11462 .join_mesh
= wpa_driver_nl80211_join_mesh
,
11463 .leave_mesh
= wpa_driver_nl80211_leave_mesh
,
11464 .probe_mesh_link
= nl80211_probe_mesh_link
,
11465 #endif /* CONFIG_MESH */
11466 .br_add_ip_neigh
= wpa_driver_br_add_ip_neigh
,
11467 .br_delete_ip_neigh
= wpa_driver_br_delete_ip_neigh
,
11468 .br_port_set_attr
= wpa_driver_br_port_set_attr
,
11469 .br_set_net_param
= wpa_driver_br_set_net_param
,
11470 .add_tx_ts
= nl80211_add_ts
,
11471 .del_tx_ts
= nl80211_del_ts
,
11472 .get_ifindex
= nl80211_get_ifindex
,
11473 #ifdef CONFIG_DRIVER_NL80211_QCA
11474 .roaming
= nl80211_roaming
,
11475 .disable_fils
= nl80211_disable_fils
,
11476 .do_acs
= wpa_driver_do_acs
,
11477 .set_band
= nl80211_set_band
,
11478 .get_pref_freq_list
= nl80211_get_pref_freq_list
,
11479 .set_prob_oper_freq
= nl80211_set_prob_oper_freq
,
11480 .p2p_lo_start
= nl80211_p2p_lo_start
,
11481 .p2p_lo_stop
= nl80211_p2p_lo_stop
,
11482 .set_default_scan_ies
= nl80211_set_default_scan_ies
,
11483 .set_tdls_mode
= nl80211_set_tdls_mode
,
11485 .get_bss_transition_status
= nl80211_get_bss_transition_status
,
11486 .ignore_assoc_disallow
= nl80211_ignore_assoc_disallow
,
11487 #endif /* CONFIG_MBO */
11488 .set_bssid_blacklist
= nl80211_set_bssid_blacklist
,
11489 .add_sta_node
= nl80211_add_sta_node
,
11490 #endif /* CONFIG_DRIVER_NL80211_QCA */
11491 .configure_data_frame_filters
= nl80211_configure_data_frame_filters
,
11492 .get_ext_capab
= nl80211_get_ext_capab
,
11493 .update_connect_params
= nl80211_update_connection_params
,
11494 .send_external_auth_status
= nl80211_send_external_auth_status
,
11495 .set_4addr_mode
= nl80211_set_4addr_mode
,