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 CONFIG_LIBNL20
45 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
46 * but when you free a socket again it will mess up its bitmap and
47 * and use the wrong number the next time it needs a socket ID.
48 * Therefore, we wrap the handle alloc/destroy and add our own pid
51 static uint32_t port_bitmap
[32] = { 0 };
53 static struct nl_handle
*nl80211_handle_alloc(void *cb
)
55 struct nl_handle
*handle
;
56 uint32_t pid
= getpid() & 0x3FFFFF;
59 handle
= nl_handle_alloc_cb(cb
);
61 for (i
= 0; i
< 1024; i
++) {
62 if (port_bitmap
[i
/ 32] & (1 << (i
% 32)))
64 port_bitmap
[i
/ 32] |= 1 << (i
% 32);
69 nl_socket_set_local_port(handle
, pid
);
74 static void nl80211_handle_destroy(struct nl_handle
*handle
)
76 uint32_t port
= nl_socket_get_local_port(handle
);
79 port_bitmap
[port
/ 32] &= ~(1 << (port
% 32));
81 nl_handle_destroy(handle
);
83 #endif /* CONFIG_LIBNL20 */
87 /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
88 #undef nl_socket_set_nonblocking
89 #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
94 static struct nl_handle
* nl_create_handle(struct nl_cb
*cb
, const char *dbg
)
96 struct nl_handle
*handle
;
98 handle
= nl80211_handle_alloc(cb
);
100 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
101 "callbacks (%s)", dbg
);
105 if (genl_connect(handle
)) {
106 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect to generic "
107 "netlink (%s)", dbg
);
108 nl80211_handle_destroy(handle
);
116 static void nl_destroy_handles(struct nl_handle
**handle
)
120 nl80211_handle_destroy(*handle
);
126 #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
128 #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
131 static void nl80211_register_eloop_read(struct nl_handle
**handle
,
132 eloop_sock_handler handler
,
133 void *eloop_data
, int persist
)
135 #ifdef CONFIG_LIBNL20
137 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
138 * by default. It is possible to hit that limit in some cases where
139 * operations are blocked, e.g., with a burst of Deauthentication frames
140 * to hostapd and STA entry deletion. Try to increase the buffer to make
141 * this less likely to occur.
143 if (nl_socket_set_buffer_size(*handle
, 262144, 0) < 0) {
144 wpa_printf(MSG_DEBUG
,
145 "nl80211: Could not set nl_socket RX buffer size: %s",
147 /* continue anyway with the default (smaller) buffer */
149 #endif /* CONFIG_LIBNL20 */
151 nl_socket_set_nonblocking(*handle
);
152 eloop_register_read_sock(nl_socket_get_fd(*handle
), handler
,
153 eloop_data
, *handle
);
155 *handle
= (void *) (((intptr_t) *handle
) ^
156 ELOOP_SOCKET_INVALID
);
160 static void nl80211_destroy_eloop_handle(struct nl_handle
**handle
, int persist
)
163 *handle
= (void *) (((intptr_t) *handle
) ^
164 ELOOP_SOCKET_INVALID
);
165 eloop_unregister_read_sock(nl_socket_get_fd(*handle
));
166 nl_destroy_handles(handle
);
170 static void nl80211_global_deinit(void *priv
);
171 static void nl80211_check_global(struct nl80211_global
*global
);
173 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
);
174 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
175 struct hostapd_freq_params
*freq
);
178 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
179 const u8
*set_addr
, int first
,
180 const char *driver_params
);
181 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
182 unsigned int freq
, unsigned int wait
,
183 const u8
*buf
, size_t buf_len
, u64
*cookie
,
184 int no_cck
, int no_ack
, int offchanok
,
185 const u16
*csa_offs
, size_t csa_offs_len
);
186 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
,
191 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
193 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
195 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
198 static int nl80211_set_channel(struct i802_bss
*bss
,
199 struct hostapd_freq_params
*freq
, int set_chan
);
200 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
201 int ifindex
, int disabled
);
203 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
206 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
);
207 static int nl80211_set_param(void *priv
, const char *param
);
209 static int nl80211_put_mesh_config(struct nl_msg
*msg
,
210 struct wpa_driver_mesh_bss_params
*params
);
211 #endif /* CONFIG_MESH */
212 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
216 /* Converts nl80211_chan_width to a common format */
217 enum chan_width
convert2width(int width
)
220 case NL80211_CHAN_WIDTH_20_NOHT
:
221 return CHAN_WIDTH_20_NOHT
;
222 case NL80211_CHAN_WIDTH_20
:
223 return CHAN_WIDTH_20
;
224 case NL80211_CHAN_WIDTH_40
:
225 return CHAN_WIDTH_40
;
226 case NL80211_CHAN_WIDTH_80
:
227 return CHAN_WIDTH_80
;
228 case NL80211_CHAN_WIDTH_80P80
:
229 return CHAN_WIDTH_80P80
;
230 case NL80211_CHAN_WIDTH_160
:
231 return CHAN_WIDTH_160
;
233 return CHAN_WIDTH_UNKNOWN
;
237 int is_ap_interface(enum nl80211_iftype nlmode
)
239 return nlmode
== NL80211_IFTYPE_AP
||
240 nlmode
== NL80211_IFTYPE_P2P_GO
;
244 int is_sta_interface(enum nl80211_iftype nlmode
)
246 return nlmode
== NL80211_IFTYPE_STATION
||
247 nlmode
== NL80211_IFTYPE_P2P_CLIENT
;
251 static int is_p2p_net_interface(enum nl80211_iftype nlmode
)
253 return nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
254 nlmode
== NL80211_IFTYPE_P2P_GO
;
258 struct i802_bss
* get_bss_ifindex(struct wpa_driver_nl80211_data
*drv
,
261 struct i802_bss
*bss
;
263 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
264 if (bss
->ifindex
== ifindex
)
272 static int is_mesh_interface(enum nl80211_iftype nlmode
)
274 return nlmode
== NL80211_IFTYPE_MESH_POINT
;
278 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data
*drv
)
281 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
283 os_memset(drv
->bssid
, 0, ETH_ALEN
);
288 static int ack_handler(struct nl_msg
*msg
, void *arg
)
295 static int finish_handler(struct nl_msg
*msg
, void *arg
)
302 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
311 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
317 static void nl80211_nlmsg_clear(struct nl_msg
*msg
)
320 * Clear nlmsg data, e.g., to make sure key material is not left in
321 * heap memory for unnecessarily long time.
324 struct nlmsghdr
*hdr
= nlmsg_hdr(msg
);
325 void *data
= nlmsg_data(hdr
);
327 * This would use nlmsg_datalen() or the older nlmsg_len() if
328 * only libnl were to maintain a stable API.. Neither will work
329 * with all released versions, so just calculate the length
332 int len
= hdr
->nlmsg_len
- NLMSG_HDRLEN
;
334 os_memset(data
, 0, len
);
339 static int send_and_recv(struct nl80211_global
*global
,
340 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
341 int (*valid_handler
)(struct nl_msg
*, void *),
350 cb
= nl_cb_clone(global
->nl_cb
);
354 err
= nl_send_auto_complete(nl_handle
, msg
);
360 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
361 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
362 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
365 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
366 valid_handler
, valid_data
);
369 int res
= nl_recvmsgs(nl_handle
, cb
);
372 "nl80211: %s->nl_recvmsgs failed: %d",
378 if (!valid_handler
&& valid_data
== (void *) -1)
379 nl80211_nlmsg_clear(msg
);
385 int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
387 int (*valid_handler
)(struct nl_msg
*, void *),
390 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
391 valid_handler
, valid_data
);
401 static int family_handler(struct nl_msg
*msg
, void *arg
)
403 struct family_data
*res
= arg
;
404 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
405 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
406 struct nlattr
*mcgrp
;
409 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
410 genlmsg_attrlen(gnlh
, 0), NULL
);
411 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
414 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
415 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
416 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
417 nla_len(mcgrp
), NULL
);
418 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
419 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
420 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
422 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
424 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
432 static int nl_get_multicast_id(struct nl80211_global
*global
,
433 const char *family
, const char *group
)
437 struct family_data res
= { group
, -ENOENT
};
442 if (!genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
443 0, 0, CTRL_CMD_GETFAMILY
, 0) ||
444 nla_put_string(msg
, CTRL_ATTR_FAMILY_NAME
, family
)) {
449 ret
= send_and_recv(global
, global
->nl
, msg
, family_handler
, &res
);
456 void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
457 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
461 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
466 static int nl80211_set_iface_id(struct nl_msg
*msg
, struct i802_bss
*bss
)
468 if (bss
->wdev_id_set
)
469 return nla_put_u64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
470 return nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
474 struct nl_msg
* nl80211_cmd_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
482 if (!nl80211_cmd(bss
->drv
, msg
, flags
, cmd
) ||
483 nl80211_set_iface_id(msg
, bss
) < 0) {
492 static struct nl_msg
*
493 nl80211_ifindex_msg(struct wpa_driver_nl80211_data
*drv
, int ifindex
,
494 int flags
, uint8_t cmd
)
502 if (!nl80211_cmd(drv
, msg
, flags
, cmd
) ||
503 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, ifindex
)) {
512 struct nl_msg
* nl80211_drv_msg(struct wpa_driver_nl80211_data
*drv
, int flags
,
515 return nl80211_ifindex_msg(drv
, drv
->ifindex
, flags
, cmd
);
519 struct nl_msg
* nl80211_bss_msg(struct i802_bss
*bss
, int flags
, uint8_t cmd
)
521 return nl80211_ifindex_msg(bss
->drv
, bss
->ifindex
, flags
, cmd
);
525 struct wiphy_idx_data
{
527 enum nl80211_iftype nlmode
;
532 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
534 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
535 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
536 struct wiphy_idx_data
*info
= arg
;
538 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
539 genlmsg_attrlen(gnlh
, 0), NULL
);
541 if (tb
[NL80211_ATTR_WIPHY
])
542 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
544 if (tb
[NL80211_ATTR_IFTYPE
])
545 info
->nlmode
= nla_get_u32(tb
[NL80211_ATTR_IFTYPE
]);
547 if (tb
[NL80211_ATTR_MAC
] && info
->macaddr
)
548 os_memcpy(info
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
555 int nl80211_get_wiphy_index(struct i802_bss
*bss
)
558 struct wiphy_idx_data data
= {
563 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
566 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
567 return data
.wiphy_idx
;
572 static enum nl80211_iftype
nl80211_get_ifmode(struct i802_bss
*bss
)
575 struct wiphy_idx_data data
= {
576 .nlmode
= NL80211_IFTYPE_UNSPECIFIED
,
580 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
581 return NL80211_IFTYPE_UNSPECIFIED
;
583 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
585 return NL80211_IFTYPE_UNSPECIFIED
;
589 static int nl80211_get_macaddr(struct i802_bss
*bss
)
592 struct wiphy_idx_data data
= {
593 .macaddr
= bss
->addr
,
596 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_GET_INTERFACE
)))
599 return send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
);
603 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
604 struct nl80211_wiphy_data
*w
)
613 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
) ||
614 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
)) {
619 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
621 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
622 "failed: ret=%d (%s)",
623 ret
, strerror(-ret
));
629 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
631 struct nl80211_wiphy_data
*w
= eloop_ctx
;
634 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
636 res
= nl_recvmsgs(handle
, w
->nl_cb
);
638 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
644 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
646 struct nl80211_wiphy_data
*w
= arg
;
647 struct wpa_driver_nl80211_data
*drv
;
648 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
649 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
650 union wpa_event_data event
;
652 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
653 genlmsg_attrlen(gnlh
, 0), NULL
);
655 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
656 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
661 if (!tb
[NL80211_ATTR_FRAME
])
664 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
666 os_memset(&event
, 0, sizeof(event
));
667 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
668 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
669 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
676 static struct nl80211_wiphy_data
*
677 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
679 static DEFINE_DL_LIST(nl80211_wiphys
);
680 struct nl80211_wiphy_data
*w
;
681 int wiphy_idx
, found
= 0;
682 struct i802_bss
*tmp_bss
;
685 if (bss
->wiphy_data
!= NULL
)
686 return bss
->wiphy_data
;
688 wiphy_idx
= nl80211_get_wiphy_index(bss
);
690 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
691 if (w
->wiphy_idx
== wiphy_idx
)
696 w
= os_zalloc(sizeof(*w
));
699 w
->wiphy_idx
= wiphy_idx
;
700 dl_list_init(&w
->bsss
);
701 dl_list_init(&w
->drvs
);
703 /* Beacon frames not supported in IEEE 802.11ad */
704 if (ieee80211_freq_to_chan(bss
->freq
, &channel
) !=
705 HOSTAPD_MODE_IEEE80211AD
) {
706 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
711 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
713 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
714 process_beacon_event
, w
);
716 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
718 if (w
->nl_beacons
== NULL
) {
723 if (nl80211_register_beacons(bss
->drv
, w
)) {
724 nl_destroy_handles(&w
->nl_beacons
);
729 nl80211_register_eloop_read(&w
->nl_beacons
,
730 nl80211_recv_beacons
, w
, 0);
733 dl_list_add(&nl80211_wiphys
, &w
->list
);
736 /* drv entry for this bss already there? */
737 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
738 if (tmp_bss
->drv
== bss
->drv
) {
745 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
747 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
753 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
755 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
756 struct i802_bss
*tmp_bss
;
761 bss
->wiphy_data
= NULL
;
762 dl_list_del(&bss
->wiphy_list
);
764 /* still any for this drv present? */
765 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
766 if (tmp_bss
->drv
== bss
->drv
) {
771 /* if not remove it */
773 dl_list_del(&bss
->drv
->wiphy_list
);
775 if (!dl_list_empty(&w
->bsss
))
779 nl80211_destroy_eloop_handle(&w
->nl_beacons
, 0);
782 dl_list_del(&w
->list
);
787 static unsigned int nl80211_get_ifindex(void *priv
)
789 struct i802_bss
*bss
= priv
;
790 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
796 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
798 struct i802_bss
*bss
= priv
;
799 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
800 if (!drv
->associated
)
802 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
807 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
809 struct i802_bss
*bss
= priv
;
810 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
811 if (!drv
->associated
)
813 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
814 return drv
->ssid_len
;
818 static void wpa_driver_nl80211_event_newlink(
819 struct nl80211_global
*global
, struct wpa_driver_nl80211_data
*drv
,
820 int ifindex
, const char *ifname
)
822 union wpa_event_data event
;
824 if (drv
&& os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
825 if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
826 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
827 drv
->first_bss
->ifname
);
830 if (!drv
->if_removed
)
832 wpa_printf(MSG_DEBUG
, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
833 drv
->first_bss
->ifname
);
837 os_memset(&event
, 0, sizeof(event
));
838 event
.interface_status
.ifindex
= ifindex
;
839 os_strlcpy(event
.interface_status
.ifname
, ifname
,
840 sizeof(event
.interface_status
.ifname
));
841 event
.interface_status
.ievent
= EVENT_INTERFACE_ADDED
;
843 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
845 wpa_supplicant_event_global(global
->ctx
, EVENT_INTERFACE_STATUS
,
850 static void wpa_driver_nl80211_event_dellink(
851 struct nl80211_global
*global
, struct wpa_driver_nl80211_data
*drv
,
852 int ifindex
, const char *ifname
)
854 union wpa_event_data event
;
856 if (drv
&& os_strcmp(drv
->first_bss
->ifname
, ifname
) == 0) {
857 if (drv
->if_removed
) {
858 wpa_printf(MSG_DEBUG
, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
862 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
866 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: Interface '%s' removed",
870 os_memset(&event
, 0, sizeof(event
));
871 event
.interface_status
.ifindex
= ifindex
;
872 os_strlcpy(event
.interface_status
.ifname
, ifname
,
873 sizeof(event
.interface_status
.ifname
));
874 event
.interface_status
.ievent
= EVENT_INTERFACE_REMOVED
;
876 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
878 wpa_supplicant_event_global(global
->ctx
, EVENT_INTERFACE_STATUS
,
883 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
886 int attrlen
, rta_len
;
890 attr
= (struct rtattr
*) buf
;
892 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
893 while (RTA_OK(attr
, attrlen
)) {
894 if (attr
->rta_type
== IFLA_IFNAME
) {
895 if (os_strcmp(((char *) attr
) + rta_len
,
896 drv
->first_bss
->ifname
) == 0)
901 attr
= RTA_NEXT(attr
, attrlen
);
908 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
909 int ifindex
, u8
*buf
, size_t len
)
911 if (drv
->ifindex
== ifindex
)
914 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
915 nl80211_check_global(drv
->global
);
916 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
918 if (wpa_driver_nl80211_finish_drv_init(drv
, NULL
, 0, NULL
) < 0)
927 static struct wpa_driver_nl80211_data
*
928 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
,
931 struct wpa_driver_nl80211_data
*drv
;
936 dl_list_for_each(drv
, &global
->interfaces
,
937 struct wpa_driver_nl80211_data
, list
) {
938 res
= wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
);
940 wpa_printf(MSG_DEBUG
,
941 "nl80211: Found matching own interface, but failed to complete reinitialization");
946 if (res
> 0 || have_ifidx(drv
, idx
, IFIDX_ANY
))
953 static void nl80211_refresh_mac(struct wpa_driver_nl80211_data
*drv
,
956 struct i802_bss
*bss
;
959 bss
= get_bss_ifindex(drv
, ifindex
);
961 linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
962 bss
->ifname
, addr
) < 0) {
963 wpa_printf(MSG_DEBUG
,
964 "nl80211: %s: failed to re-read MAC address",
966 } else if (bss
&& os_memcmp(addr
, bss
->addr
, ETH_ALEN
) != 0) {
967 wpa_printf(MSG_DEBUG
,
968 "nl80211: Own MAC address on ifindex %d (%s) changed from "
969 MACSTR
" to " MACSTR
,
970 ifindex
, bss
->ifname
,
971 MAC2STR(bss
->addr
), MAC2STR(addr
));
972 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
977 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
978 struct ifinfomsg
*ifi
,
981 struct nl80211_global
*global
= ctx
;
982 struct wpa_driver_nl80211_data
*drv
;
986 char namebuf
[IFNAMSIZ
];
987 char ifname
[IFNAMSIZ
+ 1];
988 char extra
[100], *pos
, *end
;
993 end
= pos
+ sizeof(extra
);
997 attr
= (struct rtattr
*) buf
;
998 while (RTA_OK(attr
, attrlen
)) {
999 switch (attr
->rta_type
) {
1001 if (RTA_PAYLOAD(attr
) >= IFNAMSIZ
)
1003 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
1004 ifname
[RTA_PAYLOAD(attr
)] = '\0';
1007 brid
= nla_get_u32((struct nlattr
*) attr
);
1008 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
1011 pos
+= os_snprintf(pos
, end
- pos
, " wext");
1013 case IFLA_OPERSTATE
:
1014 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
1015 nla_get_u32((struct nlattr
*) attr
));
1018 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
1019 nla_get_u32((struct nlattr
*) attr
));
1022 attr
= RTA_NEXT(attr
, attrlen
);
1024 extra
[sizeof(extra
) - 1] = '\0';
1026 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1027 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
1029 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1030 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1031 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1032 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1034 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
, &init_failed
);
1038 return; /* do not update interface state */
1040 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
1042 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1043 linux_iface_up(drv
->global
->ioctl_sock
, namebuf
) > 0) {
1044 /* Re-read MAC address as it may have changed */
1045 nl80211_refresh_mac(drv
, ifi
->ifi_index
);
1046 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1047 "event since interface %s is up", namebuf
);
1048 drv
->ignore_if_down_event
= 0;
1051 wpa_printf(MSG_DEBUG
, "nl80211: Interface down (%s/%s)",
1053 if (os_strcmp(drv
->first_bss
->ifname
, ifname
) != 0) {
1054 wpa_printf(MSG_DEBUG
,
1055 "nl80211: Not the main interface (%s) - do not indicate interface down",
1056 drv
->first_bss
->ifname
);
1057 } else if (drv
->ignore_if_down_event
) {
1058 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1059 "event generated by mode change");
1060 drv
->ignore_if_down_event
= 0;
1062 drv
->if_disabled
= 1;
1063 wpa_supplicant_event(drv
->ctx
,
1064 EVENT_INTERFACE_DISABLED
, NULL
);
1067 * Try to get drv again, since it may be removed as
1068 * part of the EVENT_INTERFACE_DISABLED handling for
1069 * dynamic interfaces
1071 drv
= nl80211_find_drv(global
, ifi
->ifi_index
,
1078 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
1079 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1080 linux_iface_up(drv
->global
->ioctl_sock
, namebuf
) == 0) {
1081 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1082 "event since interface %s is down",
1084 } else if (if_nametoindex(drv
->first_bss
->ifname
) == 0) {
1085 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1086 "event since interface %s does not exist",
1087 drv
->first_bss
->ifname
);
1088 } else if (drv
->if_removed
) {
1089 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1090 "event since interface %s is marked "
1091 "removed", drv
->first_bss
->ifname
);
1093 /* Re-read MAC address as it may have changed */
1094 nl80211_refresh_mac(drv
, ifi
->ifi_index
);
1096 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
1097 drv
->if_disabled
= 0;
1098 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
1104 * Some drivers send the association event before the operup event--in
1105 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1106 * fails. This will hit us when wpa_supplicant does not need to do
1107 * IEEE 802.1X authentication
1109 if (drv
->operstate
== 1 &&
1110 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
1111 !(ifi
->ifi_flags
& IFF_RUNNING
)) {
1112 wpa_printf(MSG_DEBUG
, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
1113 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
1119 wpa_driver_nl80211_event_newlink(global
, drv
, ifi
->ifi_index
,
1122 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
&& drv
) {
1123 struct i802_bss
*bss
;
1125 /* device has been added to bridge */
1126 if (!if_indextoname(brid
, namebuf
)) {
1127 wpa_printf(MSG_DEBUG
,
1128 "nl80211: Could not find bridge ifname for ifindex %u",
1132 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
1134 add_ifidx(drv
, brid
, ifi
->ifi_index
);
1136 for (bss
= drv
->first_bss
; bss
; bss
= bss
->next
) {
1137 if (os_strcmp(ifname
, bss
->ifname
) == 0) {
1138 os_strlcpy(bss
->brname
, namebuf
, IFNAMSIZ
);
1146 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
1147 struct ifinfomsg
*ifi
,
1148 u8
*buf
, size_t len
)
1150 struct nl80211_global
*global
= ctx
;
1151 struct wpa_driver_nl80211_data
*drv
;
1153 struct rtattr
*attr
;
1155 char ifname
[IFNAMSIZ
+ 1];
1156 char extra
[100], *pos
, *end
;
1160 end
= pos
+ sizeof(extra
);
1164 attr
= (struct rtattr
*) buf
;
1165 while (RTA_OK(attr
, attrlen
)) {
1166 switch (attr
->rta_type
) {
1168 if (RTA_PAYLOAD(attr
) >= IFNAMSIZ
)
1170 os_memcpy(ifname
, RTA_DATA(attr
), RTA_PAYLOAD(attr
));
1171 ifname
[RTA_PAYLOAD(attr
)] = '\0';
1174 brid
= nla_get_u32((struct nlattr
*) attr
);
1175 pos
+= os_snprintf(pos
, end
- pos
, " master=%u", brid
);
1177 case IFLA_OPERSTATE
:
1178 pos
+= os_snprintf(pos
, end
- pos
, " operstate=%u",
1179 nla_get_u32((struct nlattr
*) attr
));
1182 pos
+= os_snprintf(pos
, end
- pos
, " linkmode=%u",
1183 nla_get_u32((struct nlattr
*) attr
));
1186 attr
= RTA_NEXT(attr
, attrlen
);
1188 extra
[sizeof(extra
) - 1] = '\0';
1190 wpa_printf(MSG_DEBUG
, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1191 ifi
->ifi_index
, ifname
, extra
, ifi
->ifi_family
,
1193 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1194 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1195 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1196 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1198 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
, NULL
);
1200 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
&& drv
) {
1201 /* device has been removed from bridge */
1202 char namebuf
[IFNAMSIZ
];
1204 if (!if_indextoname(brid
, namebuf
)) {
1205 wpa_printf(MSG_DEBUG
,
1206 "nl80211: Could not find bridge ifname for ifindex %u",
1209 wpa_printf(MSG_DEBUG
,
1210 "nl80211: Remove ifindex %u for bridge %s",
1213 del_ifidx(drv
, brid
, ifi
->ifi_index
);
1216 if (ifi
->ifi_family
!= AF_BRIDGE
|| !brid
)
1217 wpa_driver_nl80211_event_dellink(global
, drv
, ifi
->ifi_index
,
1222 struct nl80211_get_assoc_freq_arg
{
1223 struct wpa_driver_nl80211_data
*drv
;
1224 unsigned int assoc_freq
;
1225 unsigned int ibss_freq
;
1226 u8 assoc_bssid
[ETH_ALEN
];
1227 u8 assoc_ssid
[SSID_MAX_LEN
];
1231 static int nl80211_get_assoc_freq_handler(struct nl_msg
*msg
, void *arg
)
1233 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1234 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1235 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
1236 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
1237 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
1238 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
1239 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
1240 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
1242 struct nl80211_get_assoc_freq_arg
*ctx
= arg
;
1243 enum nl80211_bss_status status
;
1245 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1246 genlmsg_attrlen(gnlh
, 0), NULL
);
1247 if (!tb
[NL80211_ATTR_BSS
] ||
1248 nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
1250 !bss
[NL80211_BSS_STATUS
])
1253 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
1254 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1255 bss
[NL80211_BSS_FREQUENCY
]) {
1256 ctx
->assoc_freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
1257 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
1260 if (status
== NL80211_BSS_STATUS_IBSS_JOINED
&&
1261 bss
[NL80211_BSS_FREQUENCY
]) {
1262 ctx
->ibss_freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
1263 wpa_printf(MSG_DEBUG
, "nl80211: IBSS-joined on %u MHz",
1266 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1267 bss
[NL80211_BSS_BSSID
]) {
1268 os_memcpy(ctx
->assoc_bssid
,
1269 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
1270 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
1271 MACSTR
, MAC2STR(ctx
->assoc_bssid
));
1274 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
1275 bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
1276 const u8
*ie
, *ssid
;
1279 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
1280 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
1281 ssid
= get_ie(ie
, ie_len
, WLAN_EID_SSID
);
1282 if (ssid
&& ssid
[1] > 0 && ssid
[1] <= SSID_MAX_LEN
) {
1283 ctx
->assoc_ssid_len
= ssid
[1];
1284 os_memcpy(ctx
->assoc_ssid
, ssid
+ 2, ssid
[1]);
1292 int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data
*drv
, u8
*ssid
)
1296 struct nl80211_get_assoc_freq_arg arg
;
1298 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1299 os_memset(&arg
, 0, sizeof(arg
));
1301 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_assoc_freq_handler
,
1304 os_memcpy(ssid
, arg
.assoc_ssid
, arg
.assoc_ssid_len
);
1305 return arg
.assoc_ssid_len
;
1307 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d (%s)",
1308 ret
, strerror(-ret
));
1313 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1317 struct nl80211_get_assoc_freq_arg arg
;
1319 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1320 os_memset(&arg
, 0, sizeof(arg
));
1322 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_assoc_freq_handler
,
1325 unsigned int freq
= drv
->nlmode
== NL80211_IFTYPE_ADHOC
?
1326 arg
.ibss_freq
: arg
.assoc_freq
;
1327 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1328 "associated BSS from scan results: %u MHz", freq
);
1330 drv
->assoc_freq
= freq
;
1331 return drv
->assoc_freq
;
1333 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1334 "(%s)", ret
, strerror(-ret
));
1335 return drv
->assoc_freq
;
1339 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1341 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1342 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1343 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1344 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1345 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1346 [NL80211_STA_INFO_SIGNAL_AVG
] = { .type
= NLA_U8
},
1347 [NL80211_STA_INFO_BEACON_SIGNAL_AVG
] = { .type
= NLA_U8
},
1349 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1350 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1351 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1352 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1353 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1354 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1356 struct wpa_signal_info
*sig_change
= arg
;
1358 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1359 genlmsg_attrlen(gnlh
, 0), NULL
);
1360 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1361 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1362 tb
[NL80211_ATTR_STA_INFO
], policy
))
1364 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1367 sig_change
->current_signal
=
1368 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1370 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
1371 sig_change
->avg_signal
=
1372 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]);
1374 sig_change
->avg_signal
= 0;
1376 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
1377 sig_change
->avg_beacon_signal
=
1379 nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]);
1381 sig_change
->avg_beacon_signal
= 0;
1383 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1384 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1385 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1387 sig_change
->current_txrate
= 0;
1389 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1390 sig_change
->current_txrate
=
1392 NL80211_RATE_INFO_BITRATE
]) * 100;
1401 int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1402 struct wpa_signal_info
*sig
)
1406 sig
->current_signal
= -9999;
1407 sig
->current_txrate
= 0;
1409 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_STATION
)) ||
1410 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
)) {
1415 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1419 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
1421 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1422 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1423 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
1424 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
1425 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
1426 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
1428 struct wpa_signal_info
*sig_change
= arg
;
1430 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1431 genlmsg_attrlen(gnlh
, 0), NULL
);
1433 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
1434 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
1438 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
1439 tb
[NL80211_ATTR_SURVEY_INFO
],
1441 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
1446 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
1449 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
1450 sig_change
->frequency
)
1453 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
1456 sig_change
->current_noise
=
1457 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
1463 int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
1464 struct wpa_signal_info
*sig_change
)
1468 sig_change
->current_noise
= 9999;
1469 sig_change
->frequency
= drv
->assoc_freq
;
1471 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
1472 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
1476 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
1479 struct nl_cb
*cb
= eloop_ctx
;
1482 wpa_printf(MSG_MSGDUMP
, "nl80211: Event message available");
1484 res
= nl_recvmsgs(handle
, cb
);
1486 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
1493 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1494 * @priv: driver_nl80211 private data
1495 * @alpha2_arg: country to which to switch to
1496 * Returns: 0 on success, -1 on failure
1498 * This asks nl80211 to set the regulatory domain for given
1499 * country ISO / IEC alpha2.
1501 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
1503 struct i802_bss
*bss
= priv
;
1504 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1508 msg
= nlmsg_alloc();
1512 alpha2
[0] = alpha2_arg
[0];
1513 alpha2
[1] = alpha2_arg
[1];
1516 if (!nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
) ||
1517 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
)) {
1521 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
1527 static int nl80211_get_country(struct nl_msg
*msg
, void *arg
)
1530 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
1531 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1533 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1534 genlmsg_attrlen(gnlh
, 0), NULL
);
1535 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
]) {
1536 wpa_printf(MSG_DEBUG
, "nl80211: No country information available");
1539 os_strlcpy(alpha2
, nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]), 3);
1544 static int wpa_driver_nl80211_get_country(void *priv
, char *alpha2
)
1546 struct i802_bss
*bss
= priv
;
1547 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1551 msg
= nlmsg_alloc();
1555 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
1557 ret
= send_and_recv_msgs(drv
, msg
, nl80211_get_country
, alpha2
);
1565 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
1569 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1570 if (global
->nl_cb
== NULL
) {
1571 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
1576 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
1577 if (global
->nl
== NULL
)
1580 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
1581 if (global
->nl80211_id
< 0) {
1582 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
1587 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
1588 if (global
->nl_event
== NULL
)
1591 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
1593 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1595 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1596 "membership for scan events: %d (%s)",
1597 ret
, strerror(-ret
));
1601 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
1603 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1605 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
1606 "membership for mlme events: %d (%s)",
1607 ret
, strerror(-ret
));
1611 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
1613 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1615 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1616 "membership for regulatory events: %d (%s)",
1617 ret
, strerror(-ret
));
1618 /* Continue without regulatory events */
1621 ret
= nl_get_multicast_id(global
, "nl80211", "vendor");
1623 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
1625 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
1626 "membership for vendor events: %d (%s)",
1627 ret
, strerror(-ret
));
1628 /* Continue without vendor events */
1631 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1632 no_seq_check
, NULL
);
1633 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1634 process_global_event
, global
);
1636 nl80211_register_eloop_read(&global
->nl_event
,
1637 wpa_driver_nl80211_event_receive
,
1643 nl_destroy_handles(&global
->nl_event
);
1644 nl_destroy_handles(&global
->nl
);
1645 nl_cb_put(global
->nl_cb
);
1646 global
->nl_cb
= NULL
;
1651 static void nl80211_check_global(struct nl80211_global
*global
)
1653 struct nl_handle
*handle
;
1654 const char *groups
[] = { "scan", "mlme", "regulatory", "vendor", NULL
};
1659 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1660 * and all registration having been cleared.
1662 handle
= (void *) (((intptr_t) global
->nl_event
) ^
1663 ELOOP_SOCKET_INVALID
);
1665 for (i
= 0; groups
[i
]; i
++) {
1666 ret
= nl_get_multicast_id(global
, "nl80211", groups
[i
]);
1668 ret
= nl_socket_add_membership(handle
, ret
);
1670 wpa_printf(MSG_INFO
,
1671 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1672 groups
[i
], ret
, strerror(-ret
));
1678 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
1680 struct wpa_driver_nl80211_data
*drv
= ctx
;
1682 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
1685 * rtnetlink ifdown handler will report interfaces other than the P2P
1686 * Device interface as disabled.
1688 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
1689 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
1693 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
1695 struct wpa_driver_nl80211_data
*drv
= ctx
;
1696 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
1697 if (i802_set_iface_flags(drv
->first_bss
, 1)) {
1698 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
1699 "after rfkill unblock");
1703 if (is_p2p_net_interface(drv
->nlmode
))
1704 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
1707 * rtnetlink ifup handler will report interfaces other than the P2P
1708 * Device interface as enabled.
1710 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
1711 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
, NULL
);
1715 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
1719 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
1724 struct cmsghdr
*cmsg
;
1725 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
1726 union wpa_event_data event
;
1728 memset(&msg
, 0, sizeof(msg
));
1729 msg
.msg_iov
= &entry
;
1731 entry
.iov_base
= data
;
1732 entry
.iov_len
= sizeof(data
);
1733 msg
.msg_control
= &control
;
1734 msg
.msg_controllen
= sizeof(control
);
1736 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
1737 /* if error or not fitting 802.3 header, return */
1741 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
1743 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
1744 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
1748 ack
= (void *)CMSG_DATA(cmsg
);
1752 if (cmsg
->cmsg_level
== SOL_PACKET
&&
1753 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
1754 struct sock_extended_err
*err
=
1755 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
1757 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
1762 if (!found_ee
|| !found_wifi
)
1765 memset(&event
, 0, sizeof(event
));
1766 event
.eapol_tx_status
.dst
= data
;
1767 event
.eapol_tx_status
.data
= data
+ 14;
1768 event
.eapol_tx_status
.data_len
= res
- 14;
1769 event
.eapol_tx_status
.ack
= acked
;
1770 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
1774 static int nl80211_init_bss(struct i802_bss
*bss
)
1776 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
1780 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
1781 no_seq_check
, NULL
);
1782 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
1783 process_bss_event
, bss
);
1789 static void nl80211_destroy_bss(struct i802_bss
*bss
)
1791 nl_cb_put(bss
->nl_cb
);
1797 wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data
*drv
)
1799 struct rfkill_config
*rcfg
;
1804 rcfg
= os_zalloc(sizeof(*rcfg
));
1810 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
1811 * not associated with a netdev, so use the name of some other interface
1812 * sharing the same wiphy as the P2P Device interface.
1814 * Note: This is valid, as a P2P Device interface is always dynamically
1815 * created and is created only once another wpa_s interface was added.
1817 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
1818 struct nl80211_global
*global
= drv
->global
;
1819 struct wpa_driver_nl80211_data
*tmp1
;
1821 dl_list_for_each(tmp1
, &global
->interfaces
,
1822 struct wpa_driver_nl80211_data
, list
) {
1823 if (drv
== tmp1
|| drv
->wiphy_idx
!= tmp1
->wiphy_idx
||
1827 wpa_printf(MSG_DEBUG
,
1828 "nl80211: Use (%s) to initialize P2P Device rfkill",
1829 tmp1
->first_bss
->ifname
);
1830 os_strlcpy(rcfg
->ifname
, tmp1
->first_bss
->ifname
,
1831 sizeof(rcfg
->ifname
));
1835 os_strlcpy(rcfg
->ifname
, drv
->first_bss
->ifname
,
1836 sizeof(rcfg
->ifname
));
1839 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
1840 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
1841 drv
->rfkill
= rfkill_init(rcfg
);
1843 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
1849 static void * wpa_driver_nl80211_drv_init(void *ctx
, const char *ifname
,
1850 void *global_priv
, int hostapd
,
1852 const char *driver_params
)
1854 struct wpa_driver_nl80211_data
*drv
;
1855 struct i802_bss
*bss
;
1857 if (global_priv
== NULL
)
1859 drv
= os_zalloc(sizeof(*drv
));
1862 drv
->global
= global_priv
;
1864 drv
->hostapd
= !!hostapd
;
1865 drv
->eapol_sock
= -1;
1868 * There is no driver capability flag for this, so assume it is
1869 * supported and disable this on first attempt to use if the driver
1870 * rejects the command due to missing support.
1872 drv
->set_rekey_offload
= 1;
1874 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
1875 drv
->if_indices
= drv
->default_if_indices
;
1876 drv
->if_indices_reason
= drv
->default_if_indices_reason
;
1878 drv
->first_bss
= os_zalloc(sizeof(*drv
->first_bss
));
1879 if (!drv
->first_bss
) {
1883 bss
= drv
->first_bss
;
1887 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
1888 drv
->monitor_ifidx
= -1;
1889 drv
->monitor_sock
= -1;
1890 drv
->eapol_tx_sock
= -1;
1891 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
1893 if (nl80211_init_bss(bss
))
1896 if (wpa_driver_nl80211_finish_drv_init(drv
, set_addr
, 1, driver_params
))
1899 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
1900 if (drv
->eapol_tx_sock
< 0)
1903 if (drv
->data_tx_status
) {
1906 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
1907 &enabled
, sizeof(enabled
)) < 0) {
1908 wpa_printf(MSG_DEBUG
,
1909 "nl80211: wifi status sockopt failed\n");
1910 drv
->data_tx_status
= 0;
1911 if (!drv
->use_monitor
)
1913 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
1915 eloop_register_read_sock(drv
->eapol_tx_sock
,
1916 wpa_driver_nl80211_handle_eapol_tx_status
,
1922 nl80211_check_global(drv
->global
);
1923 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
1924 drv
->in_interface_list
= 1;
1930 wpa_driver_nl80211_deinit(bss
);
1936 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1937 * @ctx: context to be used when calling wpa_supplicant functions,
1938 * e.g., wpa_supplicant_event()
1939 * @ifname: interface name, e.g., wlan0
1940 * @global_priv: private driver global data from global_init()
1941 * Returns: Pointer to private data, %NULL on failure
1943 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
1946 return wpa_driver_nl80211_drv_init(ctx
, ifname
, global_priv
, 0, NULL
,
1951 static int nl80211_register_frame(struct i802_bss
*bss
,
1952 struct nl_handle
*nl_handle
,
1953 u16 type
, const u8
*match
, size_t match_len
)
1955 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1961 wpa_snprintf_hex(buf
, sizeof(buf
), match
, match_len
);
1962 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1963 type
, fc2str(type
), nl_handle
, buf
);
1965 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REGISTER_ACTION
)) ||
1966 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
, type
) ||
1967 nla_put(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
)) {
1972 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
1974 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
1975 "failed (type=%u): ret=%d (%s)",
1976 type
, ret
, strerror(-ret
));
1977 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
1984 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
1987 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
1988 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
1992 bss
->nl_mgmt
= nl_create_handle(bss
->nl_cb
, "mgmt");
1993 if (bss
->nl_mgmt
== NULL
)
2000 static void nl80211_mgmt_handle_register_eloop(struct i802_bss
*bss
)
2002 nl80211_register_eloop_read(&bss
->nl_mgmt
,
2003 wpa_driver_nl80211_event_receive
,
2008 static int nl80211_register_action_frame(struct i802_bss
*bss
,
2009 const u8
*match
, size_t match_len
)
2011 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
2012 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
2013 type
, match
, match_len
);
2017 static int nl80211_init_connect_handle(struct i802_bss
*bss
)
2019 if (bss
->nl_connect
) {
2020 wpa_printf(MSG_DEBUG
,
2021 "nl80211: Connect handle already created (nl_connect=%p)",
2026 bss
->nl_connect
= nl_create_handle(bss
->nl_cb
, "connect");
2027 if (!bss
->nl_connect
)
2029 nl80211_register_eloop_read(&bss
->nl_connect
,
2030 wpa_driver_nl80211_event_receive
,
2036 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
2038 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2041 if (nl80211_alloc_mgmt_handle(bss
))
2043 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
2044 "handle %p", bss
->nl_mgmt
);
2046 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
||
2047 ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_SAE
) &&
2048 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))) {
2049 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_AUTH
<< 4);
2051 /* register for any AUTH message */
2052 nl80211_register_frame(bss
, bss
->nl_mgmt
, type
, NULL
, 0);
2055 #ifdef CONFIG_INTERWORKING
2056 /* QoS Map Configure */
2057 if (nl80211_register_action_frame(bss
, (u8
*) "\x01\x04", 2) < 0)
2059 #endif /* CONFIG_INTERWORKING */
2060 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
2061 /* GAS Initial Request */
2062 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
2064 /* GAS Initial Response */
2065 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
2067 /* GAS Comeback Request */
2068 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
2070 /* GAS Comeback Response */
2071 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
2073 /* Protected GAS Initial Request */
2074 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0a", 2) < 0)
2076 /* Protected GAS Initial Response */
2077 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0b", 2) < 0)
2079 /* Protected GAS Comeback Request */
2080 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0c", 2) < 0)
2082 /* Protected GAS Comeback Response */
2083 if (nl80211_register_action_frame(bss
, (u8
*) "\x09\x0d", 2) < 0)
2085 #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */
2087 /* P2P Public Action */
2088 if (nl80211_register_action_frame(bss
,
2089 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
2093 if (nl80211_register_action_frame(bss
,
2094 (u8
*) "\x7f\x50\x6f\x9a\x09",
2097 #endif /* CONFIG_P2P */
2099 /* DPP Public Action */
2100 if (nl80211_register_action_frame(bss
,
2101 (u8
*) "\x04\x09\x50\x6f\x9a\x1a",
2104 #endif /* CONFIG_DPP */
2105 #ifdef CONFIG_IEEE80211W
2106 /* SA Query Response */
2107 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
2109 #endif /* CONFIG_IEEE80211W */
2111 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
2112 /* TDLS Discovery Response */
2113 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
2117 #endif /* CONFIG_TDLS */
2119 /* FST Action frames */
2120 if (nl80211_register_action_frame(bss
, (u8
*) "\x12", 1) < 0)
2122 #endif /* CONFIG_FST */
2124 /* FT Action frames */
2125 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
2128 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
2129 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
2131 /* WNM - BSS Transition Management Request */
2132 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
2134 /* WNM-Sleep Mode Response */
2135 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
2139 /* WNM-Notification */
2140 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x1a", 2) < 0)
2142 #endif /* CONFIG_HS20 */
2144 /* WMM-AC ADDTS Response */
2145 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x01", 2) < 0)
2149 if (nl80211_register_action_frame(bss
, (u8
*) "\x11\x02", 2) < 0)
2152 /* Radio Measurement - Neighbor Report Response */
2153 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x05", 2) < 0)
2156 /* Radio Measurement - Radio Measurement Request */
2157 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x00", 2) < 0)
2160 /* Radio Measurement - Link Measurement Request */
2161 if ((drv
->capa
.rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
) &&
2162 (nl80211_register_action_frame(bss
, (u8
*) "\x05\x02", 2) < 0))
2165 nl80211_mgmt_handle_register_eloop(bss
);
2171 static int nl80211_mgmt_subscribe_mesh(struct i802_bss
*bss
)
2175 if (nl80211_alloc_mgmt_handle(bss
))
2178 wpa_printf(MSG_DEBUG
,
2179 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2182 /* Auth frames for mesh SAE */
2183 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
2184 (WLAN_FC_TYPE_MGMT
<< 2) |
2185 (WLAN_FC_STYPE_AUTH
<< 4),
2189 /* Mesh peering open */
2190 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x01", 2) < 0)
2192 /* Mesh peering confirm */
2193 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x02", 2) < 0)
2195 /* Mesh peering close */
2196 if (nl80211_register_action_frame(bss
, (u8
*) "\x0f\x03", 2) < 0)
2199 nl80211_mgmt_handle_register_eloop(bss
);
2205 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
2210 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
2211 ret
= send_and_recv(bss
->drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
2213 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
2214 "failed: ret=%d (%s)",
2215 ret
, strerror(-ret
));
2221 static int nl80211_action_subscribe_ap(struct i802_bss
*bss
)
2225 /* Public Action frames */
2226 if (nl80211_register_action_frame(bss
, (u8
*) "\x04", 1) < 0)
2228 /* RRM Measurement Report */
2229 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x01", 2) < 0)
2231 /* RRM Link Measurement Report */
2232 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x03", 2) < 0)
2234 /* RRM Neighbor Report Request */
2235 if (nl80211_register_action_frame(bss
, (u8
*) "\x05\x04", 2) < 0)
2237 /* FT Action frames */
2238 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
2240 #ifdef CONFIG_IEEE80211W
2242 if (nl80211_register_action_frame(bss
, (u8
*) "\x08", 1) < 0)
2244 #endif /* CONFIG_IEEE80211W */
2245 /* Protected Dual of Public Action */
2246 if (nl80211_register_action_frame(bss
, (u8
*) "\x09", 1) < 0)
2249 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a", 1) < 0)
2252 if (nl80211_register_action_frame(bss
, (u8
*) "\x11", 1) < 0)
2255 /* FST Action frames */
2256 if (nl80211_register_action_frame(bss
, (u8
*) "\x12", 1) < 0)
2258 #endif /* CONFIG_FST */
2259 /* Vendor-specific */
2260 if (nl80211_register_action_frame(bss
, (u8
*) "\x7f", 1) < 0)
2267 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
2269 static const int stypes
[] = {
2271 WLAN_FC_STYPE_ASSOC_REQ
,
2272 WLAN_FC_STYPE_REASSOC_REQ
,
2273 WLAN_FC_STYPE_DISASSOC
,
2274 WLAN_FC_STYPE_DEAUTH
,
2275 WLAN_FC_STYPE_PROBE_REQ
,
2276 /* Beacon doesn't work as mac80211 doesn't currently allow
2277 * it, but it wouldn't really be the right thing anyway as
2278 * it isn't per interface ... maybe just dump the scan
2279 * results periodically for OLBC?
2281 /* WLAN_FC_STYPE_BEACON, */
2285 if (nl80211_alloc_mgmt_handle(bss
))
2287 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
2288 "handle %p", bss
->nl_mgmt
);
2290 for (i
= 0; i
< ARRAY_SIZE(stypes
); i
++) {
2291 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
2292 (WLAN_FC_TYPE_MGMT
<< 2) |
2299 if (nl80211_action_subscribe_ap(bss
))
2302 if (nl80211_register_spurious_class3(bss
))
2305 nl80211_mgmt_handle_register_eloop(bss
);
2309 nl_destroy_handles(&bss
->nl_mgmt
);
2314 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
2316 if (nl80211_alloc_mgmt_handle(bss
))
2318 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
2319 "handle %p (device SME)", bss
->nl_mgmt
);
2321 if (nl80211_action_subscribe_ap(bss
))
2324 nl80211_mgmt_handle_register_eloop(bss
);
2328 nl_destroy_handles(&bss
->nl_mgmt
);
2333 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
2335 if (bss
->nl_mgmt
== NULL
)
2337 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
2338 "(%s)", bss
->nl_mgmt
, reason
);
2339 nl80211_destroy_eloop_handle(&bss
->nl_mgmt
, 0);
2341 nl80211_put_wiphy_data_ap(bss
);
2345 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
2347 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
2351 static void nl80211_del_p2pdev(struct i802_bss
*bss
)
2356 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_INTERFACE
);
2357 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2359 wpa_printf(MSG_DEBUG
, "nl80211: Delete P2P Device %s (0x%llx): %s",
2360 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2365 static int nl80211_set_p2pdev(struct i802_bss
*bss
, int start
)
2370 msg
= nl80211_cmd_msg(bss
, 0, start
? NL80211_CMD_START_P2P_DEVICE
:
2371 NL80211_CMD_STOP_P2P_DEVICE
);
2372 ret
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
2374 wpa_printf(MSG_DEBUG
, "nl80211: %s P2P Device %s (0x%llx): %s",
2375 start
? "Start" : "Stop",
2376 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
2382 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
)
2384 enum nl80211_iftype nlmode
;
2386 nlmode
= nl80211_get_ifmode(bss
);
2387 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2388 return linux_set_iface_flags(bss
->drv
->global
->ioctl_sock
,
2392 /* P2P Device has start/stop which is equivalent */
2393 return nl80211_set_p2pdev(bss
, up
);
2397 #ifdef CONFIG_TESTING_OPTIONS
2398 static int qca_vendor_test_cmd_handler(struct nl_msg
*msg
, void *arg
)
2400 /* struct wpa_driver_nl80211_data *drv = arg; */
2401 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2402 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2405 wpa_printf(MSG_DEBUG
,
2406 "nl80211: QCA vendor test command response received");
2408 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2409 genlmsg_attrlen(gnlh
, 0), NULL
);
2410 if (!tb
[NL80211_ATTR_VENDOR_DATA
]) {
2411 wpa_printf(MSG_DEBUG
, "nl80211: No vendor data attribute");
2415 wpa_hexdump(MSG_DEBUG
,
2416 "nl80211: Received QCA vendor test command response",
2417 nla_data(tb
[NL80211_ATTR_VENDOR_DATA
]),
2418 nla_len(tb
[NL80211_ATTR_VENDOR_DATA
]));
2422 #endif /* CONFIG_TESTING_OPTIONS */
2425 static void qca_vendor_test(struct wpa_driver_nl80211_data
*drv
)
2427 #ifdef CONFIG_TESTING_OPTIONS
2429 struct nlattr
*params
;
2432 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2433 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2434 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2435 QCA_NL80211_VENDOR_SUBCMD_TEST
) ||
2436 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
2437 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_TEST
, 123)) {
2441 nla_nest_end(msg
, params
);
2443 ret
= send_and_recv_msgs(drv
, msg
, qca_vendor_test_cmd_handler
, drv
);
2444 wpa_printf(MSG_DEBUG
,
2445 "nl80211: QCA vendor test command returned %d (%s)",
2446 ret
, strerror(-ret
));
2447 #endif /* CONFIG_TESTING_OPTIONS */
2452 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
,
2453 const u8
*set_addr
, int first
,
2454 const char *driver_params
)
2456 struct i802_bss
*bss
= drv
->first_bss
;
2457 int send_rfkill_event
= 0;
2458 enum nl80211_iftype nlmode
;
2460 drv
->ifindex
= if_nametoindex(bss
->ifname
);
2461 bss
->ifindex
= drv
->ifindex
;
2462 bss
->wdev_id
= drv
->global
->if_add_wdevid
;
2463 bss
->wdev_id_set
= drv
->global
->if_add_wdevid_set
;
2465 bss
->if_dynamic
= drv
->ifindex
== drv
->global
->if_add_ifindex
;
2466 bss
->if_dynamic
= bss
->if_dynamic
|| drv
->global
->if_add_wdevid_set
;
2467 drv
->global
->if_add_wdevid_set
= 0;
2469 if (!bss
->if_dynamic
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2473 nl80211_get_ifmode(bss
) != NL80211_IFTYPE_P2P_DEVICE
&&
2474 linux_iface_up(drv
->global
->ioctl_sock
, bss
->ifname
) > 0)
2475 drv
->start_iface_up
= 1;
2477 if (wpa_driver_nl80211_capa(drv
))
2480 if (driver_params
&& nl80211_set_param(bss
, driver_params
) < 0)
2483 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
2484 bss
->ifname
, drv
->phyname
);
2487 (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) ||
2488 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2492 if (first
&& nl80211_get_ifmode(bss
) == NL80211_IFTYPE_AP
)
2493 drv
->start_mode_ap
= 1;
2495 if (drv
->hostapd
|| bss
->static_ap
)
2496 nlmode
= NL80211_IFTYPE_AP
;
2497 else if (bss
->if_dynamic
||
2498 nl80211_get_ifmode(bss
) == NL80211_IFTYPE_MESH_POINT
)
2499 nlmode
= nl80211_get_ifmode(bss
);
2501 nlmode
= NL80211_IFTYPE_STATION
;
2503 if (wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0) {
2504 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver mode");
2508 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2509 nl80211_get_macaddr(bss
);
2511 wpa_driver_nl80211_drv_init_rfkill(drv
);
2513 if (!rfkill_is_blocked(drv
->rfkill
)) {
2514 int ret
= i802_set_iface_flags(bss
, 1);
2516 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
2517 "interface '%s' UP", bss
->ifname
);
2521 if (is_p2p_net_interface(nlmode
))
2522 nl80211_disable_11b_rates(bss
->drv
,
2523 bss
->drv
->ifindex
, 1);
2525 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2528 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
2529 "interface '%s' due to rfkill", bss
->ifname
);
2530 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
2531 drv
->if_disabled
= 1;
2533 send_rfkill_event
= 1;
2536 if (!drv
->hostapd
&& nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
2537 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
2538 1, IF_OPER_DORMANT
);
2540 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2541 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2544 os_memcpy(drv
->perm_addr
, bss
->addr
, ETH_ALEN
);
2547 if (send_rfkill_event
) {
2548 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
2552 if (drv
->vendor_cmd_test_avail
)
2553 qca_vendor_test(drv
);
2555 nl80211_init_connect_handle(bss
);
2561 static int wpa_driver_nl80211_del_beacon(struct i802_bss
*bss
)
2564 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2566 wpa_printf(MSG_DEBUG
, "nl80211: Remove beacon (ifindex=%d)",
2568 nl80211_put_wiphy_data_ap(bss
);
2569 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_DEL_BEACON
);
2570 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2575 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
2576 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
2578 * Shut down driver interface and processing of driver events. Free
2579 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2581 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
2583 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2586 wpa_printf(MSG_INFO
, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2587 bss
->ifname
, drv
->disabled_11b_rates
);
2590 if (drv
->data_tx_status
)
2591 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
2592 if (drv
->eapol_tx_sock
>= 0)
2593 close(drv
->eapol_tx_sock
);
2596 wpa_driver_nl80211_probe_req_report(bss
, 0);
2597 if (bss
->added_if_into_bridge
) {
2598 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
2600 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2601 "interface %s from bridge %s: %s",
2602 bss
->ifname
, bss
->brname
, strerror(errno
));
2604 nl80211_handle_destroy(drv
->rtnl_sk
);
2606 if (bss
->added_bridge
) {
2607 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->brname
,
2609 wpa_printf(MSG_INFO
,
2610 "nl80211: Could not set bridge %s down",
2612 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
2613 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
2615 bss
->brname
, strerror(errno
));
2618 nl80211_remove_monitor_interface(drv
);
2620 if (is_ap_interface(drv
->nlmode
))
2621 wpa_driver_nl80211_del_beacon(bss
);
2623 if (drv
->eapol_sock
>= 0) {
2624 eloop_unregister_read_sock(drv
->eapol_sock
);
2625 close(drv
->eapol_sock
);
2628 if (drv
->if_indices
!= drv
->default_if_indices
)
2629 os_free(drv
->if_indices
);
2631 if (drv
->if_indices_reason
!= drv
->default_if_indices_reason
)
2632 os_free(drv
->if_indices_reason
);
2634 if (drv
->disabled_11b_rates
)
2635 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
2637 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
2639 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill
, drv
, drv
->ctx
);
2640 rfkill_deinit(drv
->rfkill
);
2642 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
2644 if (!drv
->start_iface_up
)
2645 (void) i802_set_iface_flags(bss
, 0);
2647 if (drv
->addr_changed
) {
2648 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
2650 wpa_printf(MSG_DEBUG
,
2651 "nl80211: Could not set interface down to restore permanent MAC address");
2653 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
2654 drv
->perm_addr
) < 0) {
2655 wpa_printf(MSG_DEBUG
,
2656 "nl80211: Could not restore permanent MAC address");
2660 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
2661 if (!drv
->hostapd
|| !drv
->start_mode_ap
)
2662 wpa_driver_nl80211_set_mode(bss
,
2663 NL80211_IFTYPE_STATION
);
2664 nl80211_mgmt_unsubscribe(bss
, "deinit");
2666 nl80211_mgmt_unsubscribe(bss
, "deinit");
2667 nl80211_del_p2pdev(bss
);
2670 if (bss
->nl_connect
)
2671 nl80211_destroy_eloop_handle(&bss
->nl_connect
, 1);
2673 nl80211_destroy_bss(drv
->first_bss
);
2675 os_free(drv
->filter_ssids
);
2677 os_free(drv
->auth_ie
);
2679 if (drv
->in_interface_list
)
2680 dl_list_del(&drv
->list
);
2682 os_free(drv
->extended_capa
);
2683 os_free(drv
->extended_capa_mask
);
2684 for (i
= 0; i
< drv
->num_iface_ext_capa
; i
++) {
2685 os_free(drv
->iface_ext_capa
[i
].ext_capa
);
2686 os_free(drv
->iface_ext_capa
[i
].ext_capa_mask
);
2688 os_free(drv
->first_bss
);
2693 static u32
wpa_alg_to_cipher_suite(enum wpa_alg alg
, size_t key_len
)
2698 return RSN_CIPHER_SUITE_WEP40
;
2699 return RSN_CIPHER_SUITE_WEP104
;
2701 return RSN_CIPHER_SUITE_TKIP
;
2703 return RSN_CIPHER_SUITE_CCMP
;
2705 return RSN_CIPHER_SUITE_GCMP
;
2706 case WPA_ALG_CCMP_256
:
2707 return RSN_CIPHER_SUITE_CCMP_256
;
2708 case WPA_ALG_GCMP_256
:
2709 return RSN_CIPHER_SUITE_GCMP_256
;
2711 return RSN_CIPHER_SUITE_AES_128_CMAC
;
2712 case WPA_ALG_BIP_GMAC_128
:
2713 return RSN_CIPHER_SUITE_BIP_GMAC_128
;
2714 case WPA_ALG_BIP_GMAC_256
:
2715 return RSN_CIPHER_SUITE_BIP_GMAC_256
;
2716 case WPA_ALG_BIP_CMAC_256
:
2717 return RSN_CIPHER_SUITE_BIP_CMAC_256
;
2719 return RSN_CIPHER_SUITE_SMS4
;
2721 return RSN_CIPHER_SUITE_KRK
;
2724 wpa_printf(MSG_ERROR
, "nl80211: Unexpected encryption algorithm %d",
2729 wpa_printf(MSG_ERROR
, "nl80211: Unsupported encryption algorithm %d",
2735 static u32
wpa_cipher_to_cipher_suite(unsigned int cipher
)
2738 case WPA_CIPHER_CCMP_256
:
2739 return RSN_CIPHER_SUITE_CCMP_256
;
2740 case WPA_CIPHER_GCMP_256
:
2741 return RSN_CIPHER_SUITE_GCMP_256
;
2742 case WPA_CIPHER_CCMP
:
2743 return RSN_CIPHER_SUITE_CCMP
;
2744 case WPA_CIPHER_GCMP
:
2745 return RSN_CIPHER_SUITE_GCMP
;
2746 case WPA_CIPHER_TKIP
:
2747 return RSN_CIPHER_SUITE_TKIP
;
2748 case WPA_CIPHER_WEP104
:
2749 return RSN_CIPHER_SUITE_WEP104
;
2750 case WPA_CIPHER_WEP40
:
2751 return RSN_CIPHER_SUITE_WEP40
;
2752 case WPA_CIPHER_GTK_NOT_USED
:
2753 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED
;
2760 static int wpa_cipher_to_cipher_suites(unsigned int ciphers
, u32 suites
[],
2765 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP_256
)
2766 suites
[num_suites
++] = RSN_CIPHER_SUITE_CCMP_256
;
2767 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP_256
)
2768 suites
[num_suites
++] = RSN_CIPHER_SUITE_GCMP_256
;
2769 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_CCMP
)
2770 suites
[num_suites
++] = RSN_CIPHER_SUITE_CCMP
;
2771 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_GCMP
)
2772 suites
[num_suites
++] = RSN_CIPHER_SUITE_GCMP
;
2773 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_TKIP
)
2774 suites
[num_suites
++] = RSN_CIPHER_SUITE_TKIP
;
2775 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP104
)
2776 suites
[num_suites
++] = RSN_CIPHER_SUITE_WEP104
;
2777 if (num_suites
< max_suites
&& ciphers
& WPA_CIPHER_WEP40
)
2778 suites
[num_suites
++] = RSN_CIPHER_SUITE_WEP40
;
2784 #ifdef CONFIG_DRIVER_NL80211_QCA
2785 static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data
*drv
,
2786 const u8
*key
, size_t key_len
)
2791 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
))
2794 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
2795 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
2796 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
2797 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY
) ||
2798 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, key_len
, key
)) {
2799 nl80211_nlmsg_clear(msg
);
2803 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
2805 wpa_printf(MSG_DEBUG
,
2806 "nl80211: Key management set key failed: ret=%d (%s)",
2807 ret
, strerror(-ret
));
2812 #endif /* CONFIG_DRIVER_NL80211_QCA */
2815 static int wpa_driver_nl80211_set_key(const char *ifname
, struct i802_bss
*bss
,
2816 enum wpa_alg alg
, const u8
*addr
,
2817 int key_idx
, int set_tx
,
2818 const u8
*seq
, size_t seq_len
,
2819 const u8
*key
, size_t key_len
)
2821 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2823 struct nl_msg
*msg
= NULL
;
2827 /* Ignore for P2P Device */
2828 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
2831 ifindex
= if_nametoindex(ifname
);
2832 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
2833 "set_tx=%d seq_len=%lu key_len=%lu",
2834 __func__
, ifindex
, ifname
, alg
, addr
, key_idx
, set_tx
,
2835 (unsigned long) seq_len
, (unsigned long) key_len
);
2837 if (key_idx
== -1) {
2841 #endif /* CONFIG_TDLS */
2843 #ifdef CONFIG_DRIVER_NL80211_QCA
2844 if (alg
== WPA_ALG_PMK
&&
2845 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD
)) {
2846 wpa_printf(MSG_DEBUG
, "%s: calling issue_key_mgmt_set_key",
2848 ret
= issue_key_mgmt_set_key(drv
, key
, key_len
);
2851 #endif /* CONFIG_DRIVER_NL80211_QCA */
2853 if (alg
== WPA_ALG_NONE
) {
2854 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_DEL_KEY
);
2860 suite
= wpa_alg_to_cipher_suite(alg
, key_len
);
2863 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_NEW_KEY
);
2865 nla_put(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
) ||
2866 nla_put_u32(msg
, NL80211_ATTR_KEY_CIPHER
, suite
))
2868 wpa_hexdump_key(MSG_DEBUG
, "nl80211: KEY_DATA", key
, key_len
);
2871 if (seq
&& seq_len
) {
2872 if (nla_put(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
))
2874 wpa_hexdump(MSG_DEBUG
, "nl80211: KEY_SEQ", seq
, seq_len
);
2877 if (addr
&& !is_broadcast_ether_addr(addr
)) {
2878 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
2879 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
2882 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
2883 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
2884 if (nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
,
2885 NL80211_KEYTYPE_GROUP
))
2888 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
2889 struct nlattr
*types
;
2891 wpa_printf(MSG_DEBUG
, " broadcast key");
2893 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2895 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
2897 nla_nest_end(msg
, types
);
2899 if (nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2902 ret
= send_and_recv_msgs(drv
, msg
, NULL
, key
? (void *) -1 : NULL
);
2903 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
2906 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
2907 ret
, strerror(-ret
));
2910 * If we failed or don't need to set the default TX key (below),
2913 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
|| tdls
)
2915 if (is_ap_interface(drv
->nlmode
) && addr
&&
2916 !is_broadcast_ether_addr(addr
))
2919 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0, NL80211_CMD_SET_KEY
);
2921 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
) ||
2922 nla_put_flag(msg
, (alg
== WPA_ALG_IGTK
||
2923 alg
== WPA_ALG_BIP_GMAC_128
||
2924 alg
== WPA_ALG_BIP_GMAC_256
||
2925 alg
== WPA_ALG_BIP_CMAC_256
) ?
2926 NL80211_ATTR_KEY_DEFAULT_MGMT
:
2927 NL80211_ATTR_KEY_DEFAULT
))
2929 if (addr
&& is_broadcast_ether_addr(addr
)) {
2930 struct nlattr
*types
;
2932 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2934 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
))
2936 nla_nest_end(msg
, types
);
2938 struct nlattr
*types
;
2940 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
2942 nla_put_flag(msg
, NL80211_KEY_DEFAULT_TYPE_UNICAST
))
2944 nla_nest_end(msg
, types
);
2947 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
2951 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
2952 "err=%d %s)", ret
, strerror(-ret
));
2956 nl80211_nlmsg_clear(msg
);
2962 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
2963 int key_idx
, int defkey
,
2964 const u8
*seq
, size_t seq_len
,
2965 const u8
*key
, size_t key_len
)
2967 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
2973 suite
= wpa_alg_to_cipher_suite(alg
, key_len
);
2977 if (defkey
&& alg
== WPA_ALG_IGTK
) {
2978 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT_MGMT
))
2980 } else if (defkey
) {
2981 if (nla_put_flag(msg
, NL80211_KEY_DEFAULT
))
2985 if (nla_put_u8(msg
, NL80211_KEY_IDX
, key_idx
) ||
2986 nla_put_u32(msg
, NL80211_KEY_CIPHER
, suite
) ||
2988 nla_put(msg
, NL80211_KEY_SEQ
, seq_len
, seq
)) ||
2989 nla_put(msg
, NL80211_KEY_DATA
, key_len
, key
))
2992 nla_nest_end(msg
, key_attr
);
2998 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
3002 struct nlattr
*nl_keys
, *nl_key
;
3004 for (i
= 0; i
< 4; i
++) {
3005 if (!params
->wep_key
[i
])
3010 if (params
->wps
== WPS_MODE_PRIVACY
)
3012 if (params
->pairwise_suite
&&
3013 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
3019 if (nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
3022 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
3026 for (i
= 0; i
< 4; i
++) {
3027 if (!params
->wep_key
[i
])
3030 nl_key
= nla_nest_start(msg
, i
);
3032 nla_put(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
3033 params
->wep_key
[i
]) ||
3034 nla_put_u32(msg
, NL80211_KEY_CIPHER
,
3035 params
->wep_key_len
[i
] == 5 ?
3036 RSN_CIPHER_SUITE_WEP40
:
3037 RSN_CIPHER_SUITE_WEP104
) ||
3038 nla_put_u8(msg
, NL80211_KEY_IDX
, i
) ||
3039 (i
== params
->wep_tx_keyidx
&&
3040 nla_put_flag(msg
, NL80211_KEY_DEFAULT
)))
3043 nla_nest_end(msg
, nl_key
);
3045 nla_nest_end(msg
, nl_keys
);
3051 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
3052 const u8
*addr
, int cmd
, u16 reason_code
,
3053 int local_state_change
)
3058 if (!(msg
= nl80211_drv_msg(drv
, 0, cmd
)) ||
3059 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
) ||
3060 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
3061 (local_state_change
&&
3062 nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))) {
3067 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3069 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
3070 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
3071 reason_code
, ret
, strerror(-ret
));
3077 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
3082 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
3083 nl80211_mark_disconnected(drv
);
3084 /* Disconnect command doesn't need BSSID - it uses cached value */
3085 ret
= wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
3088 * For locally generated disconnect, supplicant already generates a
3089 * DEAUTH event, so ignore the event from NL80211.
3091 drv
->ignore_next_local_disconnect
= ret
== 0;
3097 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
3098 const u8
*addr
, int reason_code
)
3100 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3103 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3104 nl80211_mark_disconnected(drv
);
3105 return nl80211_leave_ibss(drv
, 1);
3107 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
3108 return wpa_driver_nl80211_disconnect(drv
, reason_code
);
3109 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
3110 __func__
, MAC2STR(addr
), reason_code
);
3111 nl80211_mark_disconnected(drv
);
3112 ret
= wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
3115 * For locally generated deauthenticate, supplicant already generates a
3116 * DEAUTH event, so ignore the event from NL80211.
3118 drv
->ignore_next_local_deauth
= ret
== 0;
3123 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
3124 struct wpa_driver_auth_params
*params
)
3128 drv
->auth_freq
= params
->freq
;
3129 drv
->auth_alg
= params
->auth_alg
;
3130 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
3131 drv
->auth_local_state_change
= params
->local_state_change
;
3132 drv
->auth_p2p
= params
->p2p
;
3135 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
3137 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
3140 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
3141 drv
->auth_ssid_len
= params
->ssid_len
;
3143 drv
->auth_ssid_len
= 0;
3146 os_free(drv
->auth_ie
);
3147 drv
->auth_ie
= NULL
;
3148 drv
->auth_ie_len
= 0;
3150 drv
->auth_ie
= os_malloc(params
->ie_len
);
3152 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
3153 drv
->auth_ie_len
= params
->ie_len
;
3157 for (i
= 0; i
< 4; i
++) {
3158 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
3159 params
->wep_key_len
[i
] <= 16) {
3160 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
3161 params
->wep_key_len
[i
]);
3162 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
3164 drv
->auth_wep_key_len
[i
] = 0;
3169 static void nl80211_unmask_11b_rates(struct i802_bss
*bss
)
3171 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3173 if (is_p2p_net_interface(drv
->nlmode
) || !drv
->disabled_11b_rates
)
3177 * Looks like we failed to unmask 11b rates previously. This could
3178 * happen, e.g., if the interface was down at the point in time when a
3179 * P2P group was terminated.
3181 wpa_printf(MSG_DEBUG
,
3182 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
3184 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
3188 static enum nl80211_auth_type
get_nl_auth_type(int wpa_auth_alg
)
3190 if (wpa_auth_alg
& WPA_AUTH_ALG_OPEN
)
3191 return NL80211_AUTHTYPE_OPEN_SYSTEM
;
3192 if (wpa_auth_alg
& WPA_AUTH_ALG_SHARED
)
3193 return NL80211_AUTHTYPE_SHARED_KEY
;
3194 if (wpa_auth_alg
& WPA_AUTH_ALG_LEAP
)
3195 return NL80211_AUTHTYPE_NETWORK_EAP
;
3196 if (wpa_auth_alg
& WPA_AUTH_ALG_FT
)
3197 return NL80211_AUTHTYPE_FT
;
3198 if (wpa_auth_alg
& WPA_AUTH_ALG_SAE
)
3199 return NL80211_AUTHTYPE_SAE
;
3200 if (wpa_auth_alg
& WPA_AUTH_ALG_FILS
)
3201 return NL80211_AUTHTYPE_FILS_SK
;
3202 if (wpa_auth_alg
& WPA_AUTH_ALG_FILS_SK_PFS
)
3203 return NL80211_AUTHTYPE_FILS_SK_PFS
;
3205 return NL80211_AUTHTYPE_MAX
;
3209 static int wpa_driver_nl80211_authenticate(
3210 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
3212 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3215 enum nl80211_auth_type type
;
3216 enum nl80211_iftype nlmode
;
3220 nl80211_unmask_11b_rates(bss
);
3222 is_retry
= drv
->retry_auth
;
3223 drv
->retry_auth
= 0;
3224 drv
->ignore_deauth_event
= 0;
3226 nl80211_mark_disconnected(drv
);
3227 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
3229 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
3231 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
3232 /* FIX: IBSS mode */
3233 nlmode
= params
->p2p
?
3234 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
3235 if (drv
->nlmode
!= nlmode
&&
3236 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
3240 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
3243 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_AUTHENTICATE
);
3247 for (i
= 0; i
< 4; i
++) {
3248 if (!params
->wep_key
[i
])
3250 wpa_driver_nl80211_set_key(bss
->ifname
, bss
, WPA_ALG_WEP
,
3252 i
== params
->wep_tx_keyidx
, NULL
, 0,
3254 params
->wep_key_len
[i
]);
3255 if (params
->wep_tx_keyidx
!= i
)
3257 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
3258 params
->wep_key
[i
], params
->wep_key_len
[i
]))
3262 if (params
->bssid
) {
3263 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
3264 MAC2STR(params
->bssid
));
3265 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
3269 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
3270 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
))
3274 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
3275 params
->ssid
, params
->ssid_len
);
3276 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
3280 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
3282 nla_put(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
))
3284 if (params
->auth_data
) {
3285 wpa_hexdump(MSG_DEBUG
, " * auth_data", params
->auth_data
,
3286 params
->auth_data_len
);
3287 if (nla_put(msg
, NL80211_ATTR_SAE_DATA
, params
->auth_data_len
,
3291 type
= get_nl_auth_type(params
->auth_alg
);
3292 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
3293 if (type
== NL80211_AUTHTYPE_MAX
||
3294 nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
3296 if (params
->local_state_change
) {
3297 wpa_printf(MSG_DEBUG
, " * Local state change only");
3298 if (nla_put_flag(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
))
3302 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3305 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
3306 "nl80211: MLME command failed (auth): ret=%d (%s)",
3307 ret
, strerror(-ret
));
3309 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
3310 !params
->local_state_change
) {
3312 * mac80211 does not currently accept new
3313 * authentication if we are already authenticated. As a
3314 * workaround, force deauthentication and try again.
3316 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
3317 "after forced deauthentication");
3318 drv
->ignore_deauth_event
= 1;
3319 wpa_driver_nl80211_deauthenticate(
3321 WLAN_REASON_PREV_AUTH_NOT_VALID
);
3326 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
3328 * cfg80211 has likely expired the BSS entry even
3329 * though it was previously available in our internal
3330 * BSS table. To recover quickly, start a single
3331 * channel scan on the specified channel.
3333 struct wpa_driver_scan_params scan
;
3336 os_memset(&scan
, 0, sizeof(scan
));
3339 scan
.ssids
[0].ssid
= params
->ssid
;
3340 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
3342 freqs
[0] = params
->freq
;
3345 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
3346 "channel scan to refresh cfg80211 BSS "
3348 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
3350 nl80211_copy_auth_params(drv
, params
);
3351 drv
->scan_for_auth
= 1;
3353 } else if (is_retry
) {
3355 * Need to indicate this with an event since the return
3356 * value from the retry is not delivered to core code.
3358 union wpa_event_data event
;
3359 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
3361 os_memset(&event
, 0, sizeof(event
));
3362 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
3364 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
3368 wpa_printf(MSG_DEBUG
,
3369 "nl80211: Authentication request send successfully");
3378 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data
*drv
)
3380 struct wpa_driver_auth_params params
;
3381 struct i802_bss
*bss
= drv
->first_bss
;
3384 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
3386 os_memset(¶ms
, 0, sizeof(params
));
3387 params
.freq
= drv
->auth_freq
;
3388 params
.auth_alg
= drv
->auth_alg
;
3389 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
3390 params
.local_state_change
= drv
->auth_local_state_change
;
3391 params
.p2p
= drv
->auth_p2p
;
3393 if (!is_zero_ether_addr(drv
->auth_bssid_
))
3394 params
.bssid
= drv
->auth_bssid_
;
3396 if (drv
->auth_ssid_len
) {
3397 params
.ssid
= drv
->auth_ssid
;
3398 params
.ssid_len
= drv
->auth_ssid_len
;
3401 params
.ie
= drv
->auth_ie
;
3402 params
.ie_len
= drv
->auth_ie_len
;
3404 for (i
= 0; i
< 4; i
++) {
3405 if (drv
->auth_wep_key_len
[i
]) {
3406 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
3407 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
3411 drv
->retry_auth
= 1;
3412 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
3416 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
3417 const void *data
, size_t len
,
3418 int encrypt
, int noack
,
3419 unsigned int freq
, int no_cck
,
3420 int offchanok
, unsigned int wait_time
,
3421 const u16
*csa_offs
,
3422 size_t csa_offs_len
)
3424 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3428 if (freq
== 0 && drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3429 freq
= nl80211_get_assoc_freq(drv
);
3430 wpa_printf(MSG_DEBUG
,
3431 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3435 wpa_printf(MSG_DEBUG
, "nl80211: send_frame - Use bss->freq=%u",
3440 if (drv
->use_monitor
) {
3441 wpa_printf(MSG_DEBUG
, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
3443 return nl80211_send_monitor(drv
, data
, len
, encrypt
, noack
);
3446 wpa_printf(MSG_DEBUG
, "nl80211: send_frame -> send_frame_cmd");
3447 res
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
3448 &cookie
, no_cck
, noack
, offchanok
,
3449 csa_offs
, csa_offs_len
);
3450 if (res
== 0 && !noack
) {
3451 const struct ieee80211_mgmt
*mgmt
;
3454 mgmt
= (const struct ieee80211_mgmt
*) data
;
3455 fc
= le_to_host16(mgmt
->frame_control
);
3456 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3457 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_ACTION
) {
3458 wpa_printf(MSG_MSGDUMP
,
3459 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3460 (long long unsigned int)
3461 drv
->send_action_cookie
,
3462 (long long unsigned int) cookie
);
3463 drv
->send_action_cookie
= cookie
;
3471 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
3472 size_t data_len
, int noack
,
3473 unsigned int freq
, int no_cck
,
3475 unsigned int wait_time
,
3476 const u16
*csa_offs
,
3477 size_t csa_offs_len
)
3479 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3480 struct ieee80211_mgmt
*mgmt
;
3484 mgmt
= (struct ieee80211_mgmt
*) data
;
3485 fc
= le_to_host16(mgmt
->frame_control
);
3486 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme - da= " MACSTR
3487 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3488 MAC2STR(mgmt
->da
), noack
, freq
, no_cck
, offchanok
, wait_time
,
3489 fc
, fc2str(fc
), drv
->nlmode
);
3491 if ((is_sta_interface(drv
->nlmode
) ||
3492 drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) &&
3493 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3494 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
3496 * The use of last_mgmt_freq is a bit of a hack,
3497 * but it works due to the single-threaded nature
3498 * of wpa_supplicant.
3501 wpa_printf(MSG_DEBUG
, "nl80211: Use last_mgmt_freq=%d",
3502 drv
->last_mgmt_freq
);
3503 freq
= drv
->last_mgmt_freq
;
3505 return nl80211_send_frame_cmd(bss
, freq
, 0,
3506 data
, data_len
, NULL
, 1, noack
,
3507 1, csa_offs
, csa_offs_len
);
3510 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
3512 wpa_printf(MSG_DEBUG
, "nl80211: Use bss->freq=%d",
3516 return nl80211_send_frame_cmd(bss
, freq
,
3517 (int) freq
== bss
->freq
? 0 :
3520 &drv
->send_action_cookie
,
3521 no_cck
, noack
, offchanok
,
3522 csa_offs
, csa_offs_len
);
3525 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3526 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
3528 * Only one of the authentication frame types is encrypted.
3529 * In order for static WEP encryption to work properly (i.e.,
3530 * to not encrypt the frame), we need to tell mac80211 about
3531 * the frames that must not be encrypted.
3533 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
3534 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
3535 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
3539 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme -> send_frame");
3540 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
3541 noack
, freq
, no_cck
, offchanok
,
3542 wait_time
, csa_offs
,
3547 static int nl80211_put_basic_rates(struct nl_msg
*msg
, const int *basic_rates
)
3549 u8 rates
[NL80211_MAX_SUPP_RATES
];
3556 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0; i
++)
3557 rates
[rates_len
++] = basic_rates
[i
] / 5;
3559 return nla_put(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
3563 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
3564 int slot
, int ht_opmode
, int ap_isolate
,
3565 const int *basic_rates
)
3567 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3570 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_BSS
)) ||
3572 nla_put_u8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
)) ||
3574 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
)) ||
3576 nla_put_u8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
)) ||
3578 nla_put_u16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
)) ||
3580 nla_put_u8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
)) ||
3581 nl80211_put_basic_rates(msg
, basic_rates
)) {
3586 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3590 static int wpa_driver_nl80211_set_acl(void *priv
,
3591 struct hostapd_acl_params
*params
)
3593 struct i802_bss
*bss
= priv
;
3594 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3600 if (!(drv
->capa
.max_acl_mac_addrs
))
3603 if (params
->num_mac_acl
> drv
->capa
.max_acl_mac_addrs
)
3606 wpa_printf(MSG_DEBUG
, "nl80211: Set %s ACL (num_mac_acl=%u)",
3607 params
->acl_policy
? "Accept" : "Deny", params
->num_mac_acl
);
3609 acl
= nlmsg_alloc();
3612 for (i
= 0; i
< params
->num_mac_acl
; i
++) {
3613 if (nla_put(acl
, i
+ 1, ETH_ALEN
, params
->mac_acl
[i
].addr
)) {
3619 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_MAC_ACL
)) ||
3620 nla_put_u32(msg
, NL80211_ATTR_ACL_POLICY
, params
->acl_policy
?
3621 NL80211_ACL_POLICY_DENY_UNLESS_LISTED
:
3622 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
) ||
3623 nla_put_nested(msg
, NL80211_ATTR_MAC_ADDRS
, acl
)) {
3630 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3632 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set MAC ACL: %d (%s)",
3633 ret
, strerror(-ret
));
3640 static int nl80211_put_beacon_int(struct nl_msg
*msg
, int beacon_int
)
3642 if (beacon_int
> 0) {
3643 wpa_printf(MSG_DEBUG
, " * beacon_int=%d", beacon_int
);
3644 return nla_put_u32(msg
, NL80211_ATTR_BEACON_INTERVAL
,
3652 static int nl80211_put_dtim_period(struct nl_msg
*msg
, int dtim_period
)
3654 if (dtim_period
> 0) {
3655 wpa_printf(MSG_DEBUG
, " * dtim_period=%d", dtim_period
);
3656 return nla_put_u32(msg
, NL80211_ATTR_DTIM_PERIOD
, dtim_period
);
3664 static int nl80211_set_mesh_config(void *priv
,
3665 struct wpa_driver_mesh_bss_params
*params
)
3667 struct i802_bss
*bss
= priv
;
3668 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3672 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_MESH_CONFIG
);
3676 ret
= nl80211_put_mesh_config(msg
, params
);
3682 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3684 wpa_printf(MSG_ERROR
,
3685 "nl80211: Mesh config set failed: %d (%s)",
3686 ret
, strerror(-ret
));
3691 #endif /* CONFIG_MESH */
3694 static int nl80211_put_beacon_rate(struct nl_msg
*msg
, const u64 flags
,
3695 struct wpa_driver_ap_params
*params
)
3697 struct nlattr
*bands
, *band
;
3698 struct nl80211_txrate_vht vht_rate
;
3700 if (!params
->freq
||
3701 (params
->beacon_rate
== 0 &&
3702 params
->rate_type
== BEACON_RATE_LEGACY
))
3705 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
3709 switch (params
->freq
->mode
) {
3710 case HOSTAPD_MODE_IEEE80211B
:
3711 case HOSTAPD_MODE_IEEE80211G
:
3712 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
3714 case HOSTAPD_MODE_IEEE80211A
:
3715 band
= nla_nest_start(msg
, NL80211_BAND_5GHZ
);
3717 case HOSTAPD_MODE_IEEE80211AD
:
3718 band
= nla_nest_start(msg
, NL80211_BAND_60GHZ
);
3727 os_memset(&vht_rate
, 0, sizeof(vht_rate
));
3729 switch (params
->rate_type
) {
3730 case BEACON_RATE_LEGACY
:
3731 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY
)) {
3732 wpa_printf(MSG_INFO
,
3733 "nl80211: Driver does not support setting Beacon frame rate (legacy)");
3737 if (nla_put_u8(msg
, NL80211_TXRATE_LEGACY
,
3738 (u8
) params
->beacon_rate
/ 5) ||
3739 nla_put(msg
, NL80211_TXRATE_HT
, 0, NULL
) ||
3740 (params
->freq
->vht_enabled
&&
3741 nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
3745 wpa_printf(MSG_DEBUG
, " * beacon_rate = legacy:%u (* 100 kbps)",
3746 params
->beacon_rate
);
3748 case BEACON_RATE_HT
:
3749 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_HT
)) {
3750 wpa_printf(MSG_INFO
,
3751 "nl80211: Driver does not support setting Beacon frame rate (HT)");
3754 if (nla_put(msg
, NL80211_TXRATE_LEGACY
, 0, NULL
) ||
3755 nla_put_u8(msg
, NL80211_TXRATE_HT
, params
->beacon_rate
) ||
3756 (params
->freq
->vht_enabled
&&
3757 nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
3760 wpa_printf(MSG_DEBUG
, " * beacon_rate = HT-MCS %u",
3761 params
->beacon_rate
);
3763 case BEACON_RATE_VHT
:
3764 if (!(flags
& WPA_DRIVER_FLAGS_BEACON_RATE_VHT
)) {
3765 wpa_printf(MSG_INFO
,
3766 "nl80211: Driver does not support setting Beacon frame rate (VHT)");
3769 vht_rate
.mcs
[0] = BIT(params
->beacon_rate
);
3770 if (nla_put(msg
, NL80211_TXRATE_LEGACY
, 0, NULL
))
3772 if (nla_put(msg
, NL80211_TXRATE_HT
, 0, NULL
))
3774 if (nla_put(msg
, NL80211_TXRATE_VHT
, sizeof(vht_rate
),
3777 wpa_printf(MSG_DEBUG
, " * beacon_rate = VHT-MCS %u",
3778 params
->beacon_rate
);
3782 nla_nest_end(msg
, band
);
3783 nla_nest_end(msg
, bands
);
3789 static int nl80211_set_multicast_to_unicast(struct i802_bss
*bss
,
3790 int multicast_to_unicast
)
3792 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3796 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST
);
3798 (multicast_to_unicast
&&
3799 nla_put_flag(msg
, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
))) {
3800 wpa_printf(MSG_ERROR
,
3801 "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s",
3807 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3811 wpa_printf(MSG_DEBUG
,
3812 "nl80211: multicast to unicast %s on interface %s",
3813 multicast_to_unicast
? "enabled" : "disabled",
3817 if (!multicast_to_unicast
)
3819 wpa_printf(MSG_INFO
,
3820 "nl80211: multicast to unicast not supported on interface %s",
3824 wpa_printf(MSG_ERROR
,
3825 "nl80211: %s multicast to unicast failed with %d (%s) on interface %s",
3826 multicast_to_unicast
? "enabling" : "disabling",
3827 ret
, strerror(-ret
), bss
->ifname
);
3835 static int wpa_driver_nl80211_set_ap(void *priv
,
3836 struct wpa_driver_ap_params
*params
)
3838 struct i802_bss
*bss
= priv
;
3839 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3841 u8 cmd
= NL80211_CMD_NEW_BEACON
;
3846 u32 suites
[10], suite
;
3849 struct wpa_driver_mesh_bss_params mesh_params
;
3850 #endif /* CONFIG_MESH */
3852 beacon_set
= params
->reenable
? 0 : bss
->beacon_set
;
3854 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
3857 cmd
= NL80211_CMD_SET_BEACON
;
3858 else if (!drv
->device_ap_sme
&& !drv
->use_monitor
&&
3859 !nl80211_get_wiphy_data_ap(bss
))
3862 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon head",
3863 params
->head
, params
->head_len
);
3864 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon tail",
3865 params
->tail
, params
->tail_len
);
3866 wpa_printf(MSG_DEBUG
, "nl80211: ifindex=%d", bss
->ifindex
);
3867 wpa_printf(MSG_DEBUG
, "nl80211: beacon_int=%d", params
->beacon_int
);
3868 wpa_printf(MSG_DEBUG
, "nl80211: beacon_rate=%u", params
->beacon_rate
);
3869 wpa_printf(MSG_DEBUG
, "nl80211: rate_type=%d", params
->rate_type
);
3870 wpa_printf(MSG_DEBUG
, "nl80211: dtim_period=%d", params
->dtim_period
);
3871 wpa_hexdump_ascii(MSG_DEBUG
, "nl80211: ssid",
3872 params
->ssid
, params
->ssid_len
);
3873 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
3874 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
,
3876 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
,
3878 nl80211_put_beacon_int(msg
, params
->beacon_int
) ||
3879 nl80211_put_beacon_rate(msg
, drv
->capa
.flags
, params
) ||
3880 nl80211_put_dtim_period(msg
, params
->dtim_period
) ||
3881 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
3883 if (params
->proberesp
&& params
->proberesp_len
) {
3884 wpa_hexdump(MSG_DEBUG
, "nl80211: proberesp (offload)",
3885 params
->proberesp
, params
->proberesp_len
);
3886 if (nla_put(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
3890 switch (params
->hide_ssid
) {
3891 case NO_SSID_HIDING
:
3892 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID not in use");
3893 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3894 NL80211_HIDDEN_SSID_NOT_IN_USE
))
3897 case HIDDEN_SSID_ZERO_LEN
:
3898 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero len");
3899 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3900 NL80211_HIDDEN_SSID_ZERO_LEN
))
3903 case HIDDEN_SSID_ZERO_CONTENTS
:
3904 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero contents");
3905 if (nla_put_u32(msg
, NL80211_ATTR_HIDDEN_SSID
,
3906 NL80211_HIDDEN_SSID_ZERO_CONTENTS
))
3910 wpa_printf(MSG_DEBUG
, "nl80211: privacy=%d", params
->privacy
);
3911 if (params
->privacy
&&
3912 nla_put_flag(msg
, NL80211_ATTR_PRIVACY
))
3914 wpa_printf(MSG_DEBUG
, "nl80211: auth_algs=0x%x", params
->auth_algs
);
3915 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
3916 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
3917 /* Leave out the attribute */
3918 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
) {
3919 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
3920 NL80211_AUTHTYPE_SHARED_KEY
))
3923 if (nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
,
3924 NL80211_AUTHTYPE_OPEN_SYSTEM
))
3928 wpa_printf(MSG_DEBUG
, "nl80211: wpa_version=0x%x", params
->wpa_version
);
3930 if (params
->wpa_version
& WPA_PROTO_WPA
)
3931 ver
|= NL80211_WPA_VERSION_1
;
3932 if (params
->wpa_version
& WPA_PROTO_RSN
)
3933 ver
|= NL80211_WPA_VERSION_2
;
3935 nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
3938 wpa_printf(MSG_DEBUG
, "nl80211: key_mgmt_suites=0x%x",
3939 params
->key_mgmt_suites
);
3941 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
3942 suites
[num_suites
++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
;
3943 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
3944 suites
[num_suites
++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
;
3946 nla_put(msg
, NL80211_ATTR_AKM_SUITES
, num_suites
* sizeof(u32
),
3950 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
3951 (!params
->pairwise_ciphers
||
3952 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
)) &&
3953 (nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, ETH_P_PAE
) ||
3954 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
3957 wpa_printf(MSG_DEBUG
, "nl80211: pairwise_ciphers=0x%x",
3958 params
->pairwise_ciphers
);
3959 num_suites
= wpa_cipher_to_cipher_suites(params
->pairwise_ciphers
,
3960 suites
, ARRAY_SIZE(suites
));
3962 nla_put(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
3963 num_suites
* sizeof(u32
), suites
))
3966 wpa_printf(MSG_DEBUG
, "nl80211: group_cipher=0x%x",
3967 params
->group_cipher
);
3968 suite
= wpa_cipher_to_cipher_suite(params
->group_cipher
);
3970 nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, suite
))
3973 if (params
->ht_opmode
!= -1) {
3974 switch (params
->smps_mode
) {
3975 case HT_CAP_INFO_SMPS_DYNAMIC
:
3976 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - dynamic");
3977 smps_mode
= NL80211_SMPS_DYNAMIC
;
3979 case HT_CAP_INFO_SMPS_STATIC
:
3980 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - static");
3981 smps_mode
= NL80211_SMPS_STATIC
;
3984 /* invalid - fallback to smps off */
3985 case HT_CAP_INFO_SMPS_DISABLED
:
3986 wpa_printf(MSG_DEBUG
, "nl80211: SMPS mode - off");
3987 smps_mode
= NL80211_SMPS_OFF
;
3990 if (nla_put_u8(msg
, NL80211_ATTR_SMPS_MODE
, smps_mode
))
3994 if (params
->beacon_ies
) {
3995 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: beacon_ies",
3996 params
->beacon_ies
);
3997 if (nla_put(msg
, NL80211_ATTR_IE
,
3998 wpabuf_len(params
->beacon_ies
),
3999 wpabuf_head(params
->beacon_ies
)))
4002 if (params
->proberesp_ies
) {
4003 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: proberesp_ies",
4004 params
->proberesp_ies
);
4005 if (nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
4006 wpabuf_len(params
->proberesp_ies
),
4007 wpabuf_head(params
->proberesp_ies
)))
4010 if (params
->assocresp_ies
) {
4011 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: assocresp_ies",
4012 params
->assocresp_ies
);
4013 if (nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
4014 wpabuf_len(params
->assocresp_ies
),
4015 wpabuf_head(params
->assocresp_ies
)))
4019 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
4020 wpa_printf(MSG_DEBUG
, "nl80211: ap_max_inactivity=%d",
4021 params
->ap_max_inactivity
);
4022 if (nla_put_u16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
4023 params
->ap_max_inactivity
))
4028 if (params
->p2p_go_ctwindow
> 0) {
4029 if (drv
->p2p_go_ctwindow_supported
) {
4030 wpa_printf(MSG_DEBUG
, "nl80211: P2P GO ctwindow=%d",
4031 params
->p2p_go_ctwindow
);
4032 if (nla_put_u8(msg
, NL80211_ATTR_P2P_CTWINDOW
,
4033 params
->p2p_go_ctwindow
))
4036 wpa_printf(MSG_INFO
,
4037 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
4040 #endif /* CONFIG_P2P */
4043 wpa_printf(MSG_DEBUG
, "nl80211: PBSS");
4044 if (nla_put_flag(msg
, NL80211_ATTR_PBSS
))
4048 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4050 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
4051 ret
, strerror(-ret
));
4053 bss
->beacon_set
= 1;
4054 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
4055 params
->short_slot_time
, params
->ht_opmode
,
4056 params
->isolate
, params
->basic_rates
);
4057 nl80211_set_multicast_to_unicast(bss
,
4058 params
->multicast_to_unicast
);
4059 if (beacon_set
&& params
->freq
&&
4060 params
->freq
->bandwidth
!= bss
->bandwidth
) {
4061 wpa_printf(MSG_DEBUG
,
4062 "nl80211: Update BSS %s bandwidth: %d -> %d",
4063 bss
->ifname
, bss
->bandwidth
,
4064 params
->freq
->bandwidth
);
4065 ret
= nl80211_set_channel(bss
, params
->freq
, 1);
4067 wpa_printf(MSG_DEBUG
,
4068 "nl80211: Frequency set failed: %d (%s)",
4069 ret
, strerror(-ret
));
4071 wpa_printf(MSG_DEBUG
,
4072 "nl80211: Frequency set succeeded for ht2040 coex");
4073 bss
->bandwidth
= params
->freq
->bandwidth
;
4075 } else if (!beacon_set
&& params
->freq
) {
4077 * cfg80211 updates the driver on frequence change in AP
4078 * mode only at the point when beaconing is started, so
4079 * set the initial value here.
4081 bss
->bandwidth
= params
->freq
->bandwidth
;
4086 if (is_mesh_interface(drv
->nlmode
) && params
->ht_opmode
!= -1) {
4087 os_memset(&mesh_params
, 0, sizeof(mesh_params
));
4088 mesh_params
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE
;
4089 mesh_params
.ht_opmode
= params
->ht_opmode
;
4090 ret
= nl80211_set_mesh_config(priv
, &mesh_params
);
4094 #endif /* CONFIG_MESH */
4103 static int nl80211_put_freq_params(struct nl_msg
*msg
,
4104 const struct hostapd_freq_params
*freq
)
4106 wpa_printf(MSG_DEBUG
, " * freq=%d", freq
->freq
);
4107 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
))
4110 wpa_printf(MSG_DEBUG
, " * vht_enabled=%d", freq
->vht_enabled
);
4111 wpa_printf(MSG_DEBUG
, " * ht_enabled=%d", freq
->ht_enabled
);
4113 if (freq
->vht_enabled
) {
4114 enum nl80211_chan_width cw
;
4116 wpa_printf(MSG_DEBUG
, " * bandwidth=%d", freq
->bandwidth
);
4117 switch (freq
->bandwidth
) {
4119 cw
= NL80211_CHAN_WIDTH_20
;
4122 cw
= NL80211_CHAN_WIDTH_40
;
4125 if (freq
->center_freq2
)
4126 cw
= NL80211_CHAN_WIDTH_80P80
;
4128 cw
= NL80211_CHAN_WIDTH_80
;
4131 cw
= NL80211_CHAN_WIDTH_160
;
4137 wpa_printf(MSG_DEBUG
, " * channel_width=%d", cw
);
4138 wpa_printf(MSG_DEBUG
, " * center_freq1=%d",
4139 freq
->center_freq1
);
4140 wpa_printf(MSG_DEBUG
, " * center_freq2=%d",
4141 freq
->center_freq2
);
4142 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, cw
) ||
4143 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
,
4144 freq
->center_freq1
) ||
4145 (freq
->center_freq2
&&
4146 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
,
4147 freq
->center_freq2
)))
4149 } else if (freq
->ht_enabled
) {
4150 enum nl80211_channel_type ct
;
4152 wpa_printf(MSG_DEBUG
, " * sec_channel_offset=%d",
4153 freq
->sec_channel_offset
);
4154 switch (freq
->sec_channel_offset
) {
4156 ct
= NL80211_CHAN_HT40MINUS
;
4159 ct
= NL80211_CHAN_HT40PLUS
;
4162 ct
= NL80211_CHAN_HT20
;
4166 wpa_printf(MSG_DEBUG
, " * channel_type=%d", ct
);
4167 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, ct
))
4170 wpa_printf(MSG_DEBUG
, " * channel_type=%d",
4171 NL80211_CHAN_NO_HT
);
4172 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
4173 NL80211_CHAN_NO_HT
))
4180 static int nl80211_set_channel(struct i802_bss
*bss
,
4181 struct hostapd_freq_params
*freq
, int set_chan
)
4183 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4187 wpa_printf(MSG_DEBUG
,
4188 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
4189 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
4190 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
4192 msg
= nl80211_drv_msg(drv
, 0, set_chan
? NL80211_CMD_SET_CHANNEL
:
4193 NL80211_CMD_SET_WIPHY
);
4194 if (!msg
|| nl80211_put_freq_params(msg
, freq
) < 0) {
4199 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4201 bss
->freq
= freq
->freq
;
4204 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
4205 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
4210 static u32
sta_flags_nl80211(int flags
)
4214 if (flags
& WPA_STA_AUTHORIZED
)
4215 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
4216 if (flags
& WPA_STA_WMM
)
4217 f
|= BIT(NL80211_STA_FLAG_WME
);
4218 if (flags
& WPA_STA_SHORT_PREAMBLE
)
4219 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
4220 if (flags
& WPA_STA_MFP
)
4221 f
|= BIT(NL80211_STA_FLAG_MFP
);
4222 if (flags
& WPA_STA_TDLS_PEER
)
4223 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
4224 if (flags
& WPA_STA_AUTHENTICATED
)
4225 f
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
4226 if (flags
& WPA_STA_ASSOCIATED
)
4227 f
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
4234 static u32
sta_plink_state_nl80211(enum mesh_plink_state state
)
4238 return NL80211_PLINK_LISTEN
;
4240 return NL80211_PLINK_OPN_SNT
;
4241 case PLINK_OPN_RCVD
:
4242 return NL80211_PLINK_OPN_RCVD
;
4243 case PLINK_CNF_RCVD
:
4244 return NL80211_PLINK_CNF_RCVD
;
4246 return NL80211_PLINK_ESTAB
;
4248 return NL80211_PLINK_HOLDING
;
4250 return NL80211_PLINK_BLOCKED
;
4252 wpa_printf(MSG_ERROR
, "nl80211: Invalid mesh plink state %d",
4257 #endif /* CONFIG_MESH */
4260 static int wpa_driver_nl80211_sta_add(void *priv
,
4261 struct hostapd_sta_add_params
*params
)
4263 struct i802_bss
*bss
= priv
;
4264 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4266 struct nl80211_sta_flag_update upd
;
4269 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
4270 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
4273 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
4274 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
4275 msg
= nl80211_bss_msg(bss
, 0, params
->set
? NL80211_CMD_SET_STATION
:
4276 NL80211_CMD_NEW_STATION
);
4277 if (!msg
|| nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
))
4281 * Set the below properties only in one of the following cases:
4282 * 1. New station is added, already associated.
4283 * 2. Set WPA_STA_TDLS_PEER station.
4284 * 3. Set an already added unassociated station, if driver supports
4285 * full AP client state. (Set these properties after station became
4286 * associated will be rejected by the driver).
4288 if (!params
->set
|| (params
->flags
& WPA_STA_TDLS_PEER
) ||
4289 (params
->set
&& FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
) &&
4290 (params
->flags
& WPA_STA_ASSOCIATED
))) {
4291 wpa_hexdump(MSG_DEBUG
, " * supported rates",
4292 params
->supp_rates
, params
->supp_rates_len
);
4293 wpa_printf(MSG_DEBUG
, " * capability=0x%x",
4294 params
->capability
);
4295 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
,
4296 params
->supp_rates_len
, params
->supp_rates
) ||
4297 nla_put_u16(msg
, NL80211_ATTR_STA_CAPABILITY
,
4298 params
->capability
))
4301 if (params
->ht_capabilities
) {
4302 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
4303 (u8
*) params
->ht_capabilities
,
4304 sizeof(*params
->ht_capabilities
));
4305 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
,
4306 sizeof(*params
->ht_capabilities
),
4307 params
->ht_capabilities
))
4311 if (params
->vht_capabilities
) {
4312 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
4313 (u8
*) params
->vht_capabilities
,
4314 sizeof(*params
->vht_capabilities
));
4315 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
,
4316 sizeof(*params
->vht_capabilities
),
4317 params
->vht_capabilities
))
4321 if (params
->ext_capab
) {
4322 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
4323 params
->ext_capab
, params
->ext_capab_len
);
4324 if (nla_put(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
4325 params
->ext_capab_len
, params
->ext_capab
))
4329 if (is_ap_interface(drv
->nlmode
) &&
4330 nla_put_u8(msg
, NL80211_ATTR_STA_SUPPORT_P2P_PS
,
4331 params
->support_p2p_ps
?
4332 NL80211_P2P_PS_SUPPORTED
:
4333 NL80211_P2P_PS_UNSUPPORTED
))
4338 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
4339 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, params
->aid
))
4343 * cfg80211 validates that AID is non-zero, so we have
4344 * to make this a non-zero value for the TDLS case where
4345 * a dummy STA entry is used for now and for a station
4346 * that is still not associated.
4348 wpa_printf(MSG_DEBUG
, " * aid=1 (%s workaround)",
4349 (params
->flags
& WPA_STA_TDLS_PEER
) ?
4350 "TDLS" : "UNASSOC_STA");
4351 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, 1))
4354 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
4355 params
->listen_interval
);
4356 if (nla_put_u16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
4357 params
->listen_interval
))
4359 } else if (params
->aid
&& (params
->flags
& WPA_STA_TDLS_PEER
)) {
4360 wpa_printf(MSG_DEBUG
, " * peer_aid=%u", params
->aid
);
4361 if (nla_put_u16(msg
, NL80211_ATTR_PEER_AID
, params
->aid
))
4363 } else if (FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
) &&
4364 (params
->flags
& WPA_STA_ASSOCIATED
)) {
4365 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
4366 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
4367 params
->listen_interval
);
4368 if (nla_put_u16(msg
, NL80211_ATTR_STA_AID
, params
->aid
) ||
4369 nla_put_u16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
4370 params
->listen_interval
))
4374 if (params
->vht_opmode_enabled
) {
4375 wpa_printf(MSG_DEBUG
, " * opmode=%u", params
->vht_opmode
);
4376 if (nla_put_u8(msg
, NL80211_ATTR_OPMODE_NOTIF
,
4377 params
->vht_opmode
))
4381 if (params
->supp_channels
) {
4382 wpa_hexdump(MSG_DEBUG
, " * supported channels",
4383 params
->supp_channels
, params
->supp_channels_len
);
4384 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_CHANNELS
,
4385 params
->supp_channels_len
, params
->supp_channels
))
4389 if (params
->supp_oper_classes
) {
4390 wpa_hexdump(MSG_DEBUG
, " * supported operating classes",
4391 params
->supp_oper_classes
,
4392 params
->supp_oper_classes_len
);
4393 if (nla_put(msg
, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
,
4394 params
->supp_oper_classes_len
,
4395 params
->supp_oper_classes
))
4399 os_memset(&upd
, 0, sizeof(upd
));
4400 upd
.set
= sta_flags_nl80211(params
->flags
);
4401 upd
.mask
= upd
.set
| sta_flags_nl80211(params
->flags_mask
);
4404 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
4405 * flags, as nl80211 driver moves a new station, by default, into
4408 * On the other hand, if the driver supports that feature and the
4409 * station is added in unauthenticated state, set the
4410 * authenticated/associated bits in the mask to prevent moving this
4411 * station to associated state before it is actually associated.
4413 * This is irrelevant for mesh mode where the station is added to the
4414 * driver as authenticated already, and ASSOCIATED isn't part of the
4417 if (!is_mesh_interface(drv
->nlmode
)) {
4418 if (!FULL_AP_CLIENT_STATE_SUPP(drv
->capa
.flags
)) {
4419 wpa_printf(MSG_DEBUG
,
4420 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
4421 upd
.mask
&= ~(BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4422 BIT(NL80211_STA_FLAG_AUTHENTICATED
));
4423 } else if (!params
->set
&&
4424 !(params
->flags
& WPA_STA_TDLS_PEER
)) {
4425 if (!(params
->flags
& WPA_STA_AUTHENTICATED
))
4426 upd
.mask
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
4427 if (!(params
->flags
& WPA_STA_ASSOCIATED
))
4428 upd
.mask
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
4432 if (params
->plink_state
== PLINK_ESTAB
&& params
->peer_aid
) {
4433 ret
= nla_put_u16(msg
, NL80211_ATTR_MESH_PEER_AID
,
4438 #endif /* CONFIG_MESH */
4441 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
4443 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
4447 if (params
->plink_state
&&
4448 nla_put_u8(msg
, NL80211_ATTR_STA_PLINK_STATE
,
4449 sta_plink_state_nl80211(params
->plink_state
)))
4451 #endif /* CONFIG_MESH */
4453 if (params
->flags
& WPA_STA_WMM
) {
4454 struct nlattr
*wme
= nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
4456 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
4458 nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
4459 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
) ||
4460 nla_put_u8(msg
, NL80211_STA_WME_MAX_SP
,
4461 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
4462 WMM_QOSINFO_STA_SP_MASK
))
4464 nla_nest_end(msg
, wme
);
4467 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4470 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
4471 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
4481 static void rtnl_neigh_delete_fdb_entry(struct i802_bss
*bss
, const u8
*addr
)
4483 #ifdef CONFIG_LIBNL3_ROUTE
4484 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4485 struct rtnl_neigh
*rn
;
4486 struct nl_addr
*nl_addr
;
4489 rn
= rtnl_neigh_alloc();
4493 rtnl_neigh_set_family(rn
, AF_BRIDGE
);
4494 rtnl_neigh_set_ifindex(rn
, bss
->ifindex
);
4495 nl_addr
= nl_addr_build(AF_BRIDGE
, (void *) addr
, ETH_ALEN
);
4500 rtnl_neigh_set_lladdr(rn
, nl_addr
);
4502 err
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
4504 wpa_printf(MSG_DEBUG
, "nl80211: bridge FDB entry delete for "
4505 MACSTR
" ifindex=%d failed: %s", MAC2STR(addr
),
4506 bss
->ifindex
, nl_geterror(err
));
4508 wpa_printf(MSG_DEBUG
, "nl80211: deleted bridge FDB entry for "
4509 MACSTR
, MAC2STR(addr
));
4512 nl_addr_put(nl_addr
);
4514 #endif /* CONFIG_LIBNL3_ROUTE */
4518 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
,
4519 int deauth
, u16 reason_code
)
4521 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4525 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
)) ||
4526 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
4528 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
4529 WLAN_FC_STYPE_DISASSOC
)) ||
4531 nla_put_u8(msg
, NL80211_ATTR_MGMT_SUBTYPE
,
4532 WLAN_FC_STYPE_DEAUTH
)) ||
4534 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
))) {
4539 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4540 wpa_printf(MSG_DEBUG
, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
4542 bss
->ifname
, MAC2STR(addr
), ret
, strerror(-ret
));
4545 rtnl_neigh_delete_fdb_entry(bss
, addr
);
4553 void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
4556 struct wpa_driver_nl80211_data
*drv2
;
4558 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
4560 /* stop listening for EAPOL on this interface */
4561 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
4562 struct wpa_driver_nl80211_data
, list
)
4564 del_ifidx(drv2
, ifidx
, IFIDX_ANY
);
4565 /* Remove all bridges learned for this iface */
4566 del_ifidx(drv2
, IFIDX_ANY
, ifidx
);
4569 msg
= nl80211_ifindex_msg(drv
, ifidx
, 0, NL80211_CMD_DEL_INTERFACE
);
4570 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
4572 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
4576 const char * nl80211_iftype_str(enum nl80211_iftype mode
)
4579 case NL80211_IFTYPE_ADHOC
:
4581 case NL80211_IFTYPE_STATION
:
4583 case NL80211_IFTYPE_AP
:
4585 case NL80211_IFTYPE_AP_VLAN
:
4587 case NL80211_IFTYPE_WDS
:
4589 case NL80211_IFTYPE_MONITOR
:
4591 case NL80211_IFTYPE_MESH_POINT
:
4592 return "MESH_POINT";
4593 case NL80211_IFTYPE_P2P_CLIENT
:
4594 return "P2P_CLIENT";
4595 case NL80211_IFTYPE_P2P_GO
:
4597 case NL80211_IFTYPE_P2P_DEVICE
:
4598 return "P2P_DEVICE";
4605 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
4607 enum nl80211_iftype iftype
,
4608 const u8
*addr
, int wds
,
4609 int (*handler
)(struct nl_msg
*, void *),
4616 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
4617 iftype
, nl80211_iftype_str(iftype
));
4619 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_NEW_INTERFACE
);
4621 nla_put_string(msg
, NL80211_ATTR_IFNAME
, ifname
) ||
4622 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, iftype
))
4625 if (iftype
== NL80211_IFTYPE_MONITOR
) {
4626 struct nlattr
*flags
;
4628 flags
= nla_nest_start(msg
, NL80211_ATTR_MNTR_FLAGS
);
4630 nla_put_flag(msg
, NL80211_MNTR_FLAG_COOK_FRAMES
))
4633 nla_nest_end(msg
, flags
);
4635 if (nla_put_u8(msg
, NL80211_ATTR_4ADDR
, wds
))
4640 * Tell cfg80211 that the interface belongs to the socket that created
4641 * it, and the interface should be deleted when the socket is closed.
4643 if (nla_put_flag(msg
, NL80211_ATTR_IFACE_SOCKET_OWNER
))
4646 ret
= send_and_recv_msgs(drv
, msg
, handler
, arg
);
4651 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
4652 ifname
, ret
, strerror(-ret
));
4656 if (iftype
== NL80211_IFTYPE_P2P_DEVICE
)
4659 ifidx
= if_nametoindex(ifname
);
4660 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
4667 * Some virtual interfaces need to process EAPOL packets and events on
4668 * the parent interface. This is used mainly with hostapd.
4671 iftype
== NL80211_IFTYPE_AP_VLAN
||
4672 iftype
== NL80211_IFTYPE_WDS
||
4673 iftype
== NL80211_IFTYPE_MONITOR
) {
4674 /* start listening for EAPOL on this interface */
4675 add_ifidx(drv
, ifidx
, IFIDX_ANY
);
4678 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
4679 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
4680 nl80211_remove_iface(drv
, ifidx
);
4688 int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
4689 const char *ifname
, enum nl80211_iftype iftype
,
4690 const u8
*addr
, int wds
,
4691 int (*handler
)(struct nl_msg
*, void *),
4692 void *arg
, int use_existing
)
4696 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
, handler
,
4699 /* if error occurred and interface exists already */
4700 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
4702 wpa_printf(MSG_DEBUG
, "nl80211: Continue using existing interface %s",
4704 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
4705 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
4707 (linux_set_iface_flags(drv
->global
->ioctl_sock
,
4709 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
4711 linux_set_iface_flags(drv
->global
->ioctl_sock
,
4716 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
4718 /* Try to remove the interface that was already there. */
4719 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
4721 /* Try to create the interface again */
4722 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
4726 if (ret
>= 0 && is_p2p_net_interface(iftype
)) {
4727 wpa_printf(MSG_DEBUG
,
4728 "nl80211: Interface %s created for P2P - disable 11b rates",
4730 nl80211_disable_11b_rates(drv
, ret
, 1);
4737 static int nl80211_setup_ap(struct i802_bss
*bss
)
4739 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4741 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4742 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
4745 * Disable Probe Request reporting unless we need it in this way for
4746 * devices that include the AP SME, in the other case (unless using
4747 * monitor iface) we'll get it through the nl_mgmt socket instead.
4749 if (!drv
->device_ap_sme
)
4750 wpa_driver_nl80211_probe_req_report(bss
, 0);
4752 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
4753 if (nl80211_mgmt_subscribe_ap(bss
))
4756 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
4757 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
4758 wpa_printf(MSG_DEBUG
,
4759 "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
4761 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
4762 nl80211_create_monitor_interface(drv
) &&
4763 !drv
->device_ap_sme
)
4766 if (drv
->device_ap_sme
&&
4767 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
4768 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
4769 "Probe Request frame reporting in AP mode");
4770 /* Try to survive without this */
4777 static void nl80211_teardown_ap(struct i802_bss
*bss
)
4779 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4781 wpa_printf(MSG_DEBUG
, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4782 bss
->ifname
, drv
->device_ap_sme
, drv
->use_monitor
);
4783 if (drv
->device_ap_sme
) {
4784 wpa_driver_nl80211_probe_req_report(bss
, 0);
4785 if (!drv
->use_monitor
)
4786 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
4787 } else if (drv
->use_monitor
)
4788 nl80211_remove_monitor_interface(drv
);
4790 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
4792 nl80211_put_wiphy_data_ap(bss
);
4793 bss
->beacon_set
= 0;
4797 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
4798 const u8
*addr
, const u8
*data
,
4801 struct sockaddr_ll ll
;
4804 if (bss
->drv
->eapol_tx_sock
< 0) {
4805 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
4809 os_memset(&ll
, 0, sizeof(ll
));
4810 ll
.sll_family
= AF_PACKET
;
4811 ll
.sll_ifindex
= bss
->ifindex
;
4812 ll
.sll_protocol
= htons(ETH_P_PAE
);
4813 ll
.sll_halen
= ETH_ALEN
;
4814 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
4815 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
4816 (struct sockaddr
*) &ll
, sizeof(ll
));
4818 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
4825 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4827 static int wpa_driver_nl80211_hapd_send_eapol(
4828 void *priv
, const u8
*addr
, const u8
*data
,
4829 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
4831 struct i802_bss
*bss
= priv
;
4832 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4833 struct ieee80211_hdr
*hdr
;
4837 int qos
= flags
& WPA_STA_WMM
;
4839 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
4840 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
4842 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
4844 hdr
= os_zalloc(len
);
4846 wpa_printf(MSG_INFO
, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4847 (unsigned long) len
);
4851 hdr
->frame_control
=
4852 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
4853 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
4855 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
4857 hdr
->frame_control
|=
4858 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
4861 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
4862 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
4863 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
4864 pos
= (u8
*) (hdr
+ 1);
4867 /* Set highest priority in QoS header */
4873 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
4874 pos
+= sizeof(rfc1042_header
);
4875 WPA_PUT_BE16(pos
, ETH_P_PAE
);
4877 memcpy(pos
, data
, data_len
);
4879 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
4880 0, 0, 0, 0, NULL
, 0);
4882 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
4884 (unsigned long) len
, errno
, strerror(errno
));
4892 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
4893 unsigned int total_flags
,
4894 unsigned int flags_or
,
4895 unsigned int flags_and
)
4897 struct i802_bss
*bss
= priv
;
4899 struct nlattr
*flags
;
4900 struct nl80211_sta_flag_update upd
;
4902 wpa_printf(MSG_DEBUG
, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4903 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4904 bss
->ifname
, MAC2STR(addr
), total_flags
, flags_or
, flags_and
,
4905 !!(total_flags
& WPA_STA_AUTHORIZED
));
4907 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
4908 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
4912 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4913 * can be removed eventually.
4915 flags
= nla_nest_start(msg
, NL80211_ATTR_STA_FLAGS
);
4917 ((total_flags
& WPA_STA_AUTHORIZED
) &&
4918 nla_put_flag(msg
, NL80211_STA_FLAG_AUTHORIZED
)) ||
4919 ((total_flags
& WPA_STA_WMM
) &&
4920 nla_put_flag(msg
, NL80211_STA_FLAG_WME
)) ||
4921 ((total_flags
& WPA_STA_SHORT_PREAMBLE
) &&
4922 nla_put_flag(msg
, NL80211_STA_FLAG_SHORT_PREAMBLE
)) ||
4923 ((total_flags
& WPA_STA_MFP
) &&
4924 nla_put_flag(msg
, NL80211_STA_FLAG_MFP
)) ||
4925 ((total_flags
& WPA_STA_TDLS_PEER
) &&
4926 nla_put_flag(msg
, NL80211_STA_FLAG_TDLS_PEER
)))
4929 nla_nest_end(msg
, flags
);
4931 os_memset(&upd
, 0, sizeof(upd
));
4932 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
4933 upd
.set
= sta_flags_nl80211(flags_or
);
4934 if (nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
))
4937 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
4944 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
4945 struct wpa_driver_associate_params
*params
)
4947 enum nl80211_iftype nlmode
, old_mode
;
4950 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
4952 nlmode
= NL80211_IFTYPE_P2P_GO
;
4954 nlmode
= NL80211_IFTYPE_AP
;
4956 old_mode
= drv
->nlmode
;
4957 if (wpa_driver_nl80211_set_mode(drv
->first_bss
, nlmode
)) {
4958 nl80211_remove_monitor_interface(drv
);
4962 if (params
->freq
.freq
&&
4963 nl80211_set_channel(drv
->first_bss
, ¶ms
->freq
, 0)) {
4964 if (old_mode
!= nlmode
)
4965 wpa_driver_nl80211_set_mode(drv
->first_bss
, old_mode
);
4966 nl80211_remove_monitor_interface(drv
);
4974 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
,
4980 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_IBSS
);
4981 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4983 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
4984 "(%s)", ret
, strerror(-ret
));
4986 wpa_printf(MSG_DEBUG
,
4987 "nl80211: Leave IBSS request sent successfully");
4991 wpa_driver_nl80211_set_mode(drv
->first_bss
,
4992 NL80211_IFTYPE_STATION
)) {
4993 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
5001 static int nl80211_ht_vht_overrides(struct nl_msg
*msg
,
5002 struct wpa_driver_associate_params
*params
)
5004 if (params
->disable_ht
&& nla_put_flag(msg
, NL80211_ATTR_DISABLE_HT
))
5007 if (params
->htcaps
&& params
->htcaps_mask
) {
5008 int sz
= sizeof(struct ieee80211_ht_capabilities
);
5009 wpa_hexdump(MSG_DEBUG
, " * htcaps", params
->htcaps
, sz
);
5010 wpa_hexdump(MSG_DEBUG
, " * htcaps_mask",
5011 params
->htcaps_mask
, sz
);
5012 if (nla_put(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
,
5014 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
5015 params
->htcaps_mask
))
5019 #ifdef CONFIG_VHT_OVERRIDES
5020 if (params
->disable_vht
) {
5021 wpa_printf(MSG_DEBUG
, " * VHT disabled");
5022 if (nla_put_flag(msg
, NL80211_ATTR_DISABLE_VHT
))
5026 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
5027 int sz
= sizeof(struct ieee80211_vht_capabilities
);
5028 wpa_hexdump(MSG_DEBUG
, " * vhtcaps", params
->vhtcaps
, sz
);
5029 wpa_hexdump(MSG_DEBUG
, " * vhtcaps_mask",
5030 params
->vhtcaps_mask
, sz
);
5031 if (nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
,
5033 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
5034 params
->vhtcaps_mask
))
5037 #endif /* CONFIG_VHT_OVERRIDES */
5043 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
5044 struct wpa_driver_associate_params
*params
)
5050 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
5052 if (wpa_driver_nl80211_set_mode_ibss(drv
->first_bss
, ¶ms
->freq
)) {
5053 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
5059 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_IBSS
)) ||
5060 params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
5063 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5064 params
->ssid
, params
->ssid_len
);
5065 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
))
5067 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5068 drv
->ssid_len
= params
->ssid_len
;
5070 if (nl80211_put_freq_params(msg
, ¶ms
->freq
) < 0 ||
5071 nl80211_put_beacon_int(msg
, params
->beacon_int
))
5074 ret
= nl80211_set_conn_keys(params
, msg
);
5078 if (params
->bssid
&& params
->fixed_bssid
) {
5079 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
5080 MAC2STR(params
->bssid
));
5081 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
5085 if (params
->fixed_freq
) {
5086 wpa_printf(MSG_DEBUG
, " * fixed_freq");
5087 if (nla_put_flag(msg
, NL80211_ATTR_FREQ_FIXED
))
5091 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
5092 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5093 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
5094 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
) {
5095 wpa_printf(MSG_DEBUG
, " * control port");
5096 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
5100 if (params
->wpa_ie
) {
5101 wpa_hexdump(MSG_DEBUG
,
5102 " * Extra IEs for Beacon/Probe Response frames",
5103 params
->wpa_ie
, params
->wpa_ie_len
);
5104 if (nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
5109 ret
= nl80211_ht_vht_overrides(msg
, params
);
5113 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5116 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
5117 ret
, strerror(-ret
));
5119 if (ret
== -EALREADY
&& count
== 1) {
5120 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
5122 nl80211_leave_ibss(drv
, 0);
5127 wpa_printf(MSG_DEBUG
,
5128 "nl80211: Join IBSS request sent successfully");
5137 static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data
*drv
,
5138 struct wpa_driver_associate_params
*params
,
5141 if (params
->fils_erp_username_len
) {
5142 wpa_hexdump_ascii(MSG_DEBUG
, " * FILS ERP EMSKname/username",
5143 params
->fils_erp_username
,
5144 params
->fils_erp_username_len
);
5145 if (nla_put(msg
, NL80211_ATTR_FILS_ERP_USERNAME
,
5146 params
->fils_erp_username_len
,
5147 params
->fils_erp_username
))
5151 if (params
->fils_erp_realm_len
) {
5152 wpa_hexdump_ascii(MSG_DEBUG
, " * FILS ERP Realm",
5153 params
->fils_erp_realm
,
5154 params
->fils_erp_realm_len
);
5155 if (nla_put(msg
, NL80211_ATTR_FILS_ERP_REALM
,
5156 params
->fils_erp_realm_len
, params
->fils_erp_realm
))
5160 wpa_printf(MSG_DEBUG
, " * FILS ERP next seq %u",
5161 params
->fils_erp_next_seq_num
);
5162 if (nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
5163 params
->fils_erp_next_seq_num
))
5166 if (params
->fils_erp_rrk_len
) {
5167 wpa_printf(MSG_DEBUG
, " * FILS ERP rRK (len=%lu)",
5168 (unsigned long) params
->fils_erp_rrk_len
);
5169 if (nla_put(msg
, NL80211_ATTR_FILS_ERP_RRK
,
5170 params
->fils_erp_rrk_len
, params
->fils_erp_rrk
))
5178 static int nl80211_connect_common(struct wpa_driver_nl80211_data
*drv
,
5179 struct wpa_driver_associate_params
*params
,
5182 if (nla_put_flag(msg
, NL80211_ATTR_IFACE_SOCKET_OWNER
))
5185 if (params
->bssid
) {
5186 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5187 MAC2STR(params
->bssid
));
5188 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
))
5192 if (params
->bssid_hint
) {
5193 wpa_printf(MSG_DEBUG
, " * bssid_hint=" MACSTR
,
5194 MAC2STR(params
->bssid_hint
));
5195 if (nla_put(msg
, NL80211_ATTR_MAC_HINT
, ETH_ALEN
,
5196 params
->bssid_hint
))
5200 if (params
->freq
.freq
) {
5201 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
.freq
);
5202 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
5205 drv
->assoc_freq
= params
->freq
.freq
;
5207 drv
->assoc_freq
= 0;
5209 if (params
->freq_hint
) {
5210 wpa_printf(MSG_DEBUG
, " * freq_hint=%d", params
->freq_hint
);
5211 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ_HINT
,
5216 if (params
->bg_scan_period
>= 0) {
5217 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
5218 params
->bg_scan_period
);
5219 if (nla_put_u16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
5220 params
->bg_scan_period
))
5225 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5226 params
->ssid
, params
->ssid_len
);
5227 if (nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5230 if (params
->ssid_len
> sizeof(drv
->ssid
))
5232 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
5233 drv
->ssid_len
= params
->ssid_len
;
5236 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
5237 if (params
->wpa_ie
&&
5238 nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
, params
->wpa_ie
))
5241 if (params
->wpa_proto
) {
5242 enum nl80211_wpa_versions ver
= 0;
5244 if (params
->wpa_proto
& WPA_PROTO_WPA
)
5245 ver
|= NL80211_WPA_VERSION_1
;
5246 if (params
->wpa_proto
& WPA_PROTO_RSN
)
5247 ver
|= NL80211_WPA_VERSION_2
;
5249 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
5250 if (nla_put_u32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
))
5254 if (params
->pairwise_suite
!= WPA_CIPHER_NONE
) {
5255 u32 cipher
= wpa_cipher_to_cipher_suite(params
->pairwise_suite
);
5256 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
5257 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
5262 if (params
->group_suite
== WPA_CIPHER_GTK_NOT_USED
&&
5263 !(drv
->capa
.enc
& WPA_DRIVER_CAPA_ENC_GTK_NOT_USED
)) {
5265 * This is likely to work even though many drivers do not
5266 * advertise support for operations without GTK.
5268 wpa_printf(MSG_DEBUG
, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
5269 } else if (params
->group_suite
!= WPA_CIPHER_NONE
) {
5270 u32 cipher
= wpa_cipher_to_cipher_suite(params
->group_suite
);
5271 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
5272 if (nla_put_u32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
))
5276 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
5277 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5278 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_IEEE8021X
||
5279 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
||
5280 params
->key_mgmt_suite
== WPA_KEY_MGMT_CCKM
||
5281 params
->key_mgmt_suite
== WPA_KEY_MGMT_OSEN
||
5282 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
5283 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
5284 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B
||
5285 params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
||
5286 params
->key_mgmt_suite
== WPA_KEY_MGMT_FILS_SHA256
||
5287 params
->key_mgmt_suite
== WPA_KEY_MGMT_FILS_SHA384
||
5288 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_FILS_SHA256
||
5289 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_FILS_SHA384
||
5290 params
->key_mgmt_suite
== WPA_KEY_MGMT_OWE
||
5291 params
->key_mgmt_suite
== WPA_KEY_MGMT_DPP
) {
5292 int mgmt
= RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
;
5294 switch (params
->key_mgmt_suite
) {
5295 case WPA_KEY_MGMT_CCKM
:
5296 mgmt
= RSN_AUTH_KEY_MGMT_CCKM
;
5298 case WPA_KEY_MGMT_IEEE8021X
:
5299 mgmt
= RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
;
5301 case WPA_KEY_MGMT_FT_IEEE8021X
:
5302 mgmt
= RSN_AUTH_KEY_MGMT_FT_802_1X
;
5304 case WPA_KEY_MGMT_FT_PSK
:
5305 mgmt
= RSN_AUTH_KEY_MGMT_FT_PSK
;
5307 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
5308 mgmt
= RSN_AUTH_KEY_MGMT_802_1X_SHA256
;
5310 case WPA_KEY_MGMT_PSK_SHA256
:
5311 mgmt
= RSN_AUTH_KEY_MGMT_PSK_SHA256
;
5313 case WPA_KEY_MGMT_OSEN
:
5314 mgmt
= RSN_AUTH_KEY_MGMT_OSEN
;
5316 case WPA_KEY_MGMT_IEEE8021X_SUITE_B
:
5317 mgmt
= RSN_AUTH_KEY_MGMT_802_1X_SUITE_B
;
5319 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
:
5320 mgmt
= RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192
;
5322 case WPA_KEY_MGMT_FILS_SHA256
:
5323 mgmt
= RSN_AUTH_KEY_MGMT_FILS_SHA256
;
5325 case WPA_KEY_MGMT_FILS_SHA384
:
5326 mgmt
= RSN_AUTH_KEY_MGMT_FILS_SHA384
;
5328 case WPA_KEY_MGMT_FT_FILS_SHA256
:
5329 mgmt
= RSN_AUTH_KEY_MGMT_FT_FILS_SHA256
;
5331 case WPA_KEY_MGMT_FT_FILS_SHA384
:
5332 mgmt
= RSN_AUTH_KEY_MGMT_FT_FILS_SHA384
;
5334 case WPA_KEY_MGMT_OWE
:
5335 mgmt
= RSN_AUTH_KEY_MGMT_OWE
;
5337 case WPA_KEY_MGMT_DPP
:
5338 mgmt
= RSN_AUTH_KEY_MGMT_DPP
;
5340 case WPA_KEY_MGMT_PSK
:
5342 mgmt
= RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
;
5345 wpa_printf(MSG_DEBUG
, " * akm=0x%x", mgmt
);
5346 if (nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
))
5350 /* Add PSK in case of 4-way handshake offload */
5352 (drv
->capa
.flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
)) {
5353 wpa_hexdump_key(MSG_DEBUG
, " * PSK", params
->psk
, 32);
5354 if (nla_put(msg
, NL80211_ATTR_PMK
, 32, params
->psk
))
5358 if (nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT
))
5361 if (params
->key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
5362 (params
->pairwise_suite
== WPA_CIPHER_NONE
||
5363 params
->pairwise_suite
== WPA_CIPHER_WEP104
||
5364 params
->pairwise_suite
== WPA_CIPHER_WEP40
) &&
5365 (nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, ETH_P_PAE
) ||
5366 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
5369 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
&&
5370 nla_put_u32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
))
5373 if (params
->rrm_used
) {
5374 u32 drv_rrm_flags
= drv
->capa
.rrm_flags
;
5375 if ((!((drv_rrm_flags
&
5376 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) &&
5377 (drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
)) &&
5378 !(drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_RRM
)) ||
5379 nla_put_flag(msg
, NL80211_ATTR_USE_RRM
))
5383 if (nl80211_ht_vht_overrides(msg
, params
) < 0)
5387 wpa_printf(MSG_DEBUG
, " * P2P group");
5390 wpa_printf(MSG_DEBUG
, " * PBSS");
5391 if (nla_put_flag(msg
, NL80211_ATTR_PBSS
))
5395 drv
->connect_reassoc
= 0;
5396 if (params
->prev_bssid
) {
5397 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
5398 MAC2STR(params
->prev_bssid
));
5399 if (nla_put(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
5400 params
->prev_bssid
))
5402 drv
->connect_reassoc
= 1;
5405 if ((params
->auth_alg
& WPA_AUTH_ALG_FILS
) &&
5406 nl80211_put_fils_connect_params(drv
, params
, msg
) != 0)
5409 if ((params
->auth_alg
& WPA_AUTH_ALG_SAE
) &&
5410 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) &&
5411 nla_put_flag(msg
, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
))
5418 static int wpa_driver_nl80211_try_connect(
5419 struct wpa_driver_nl80211_data
*drv
,
5420 struct wpa_driver_associate_params
*params
,
5421 struct nl_handle
*nl_connect
)
5424 enum nl80211_auth_type type
;
5428 #ifdef CONFIG_DRIVER_NL80211_QCA
5429 if (params
->req_key_mgmt_offload
&& params
->psk
&&
5430 (params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
5431 params
->key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
5432 params
->key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
)) {
5433 wpa_printf(MSG_DEBUG
, "nl80211: Key management set PSK");
5434 ret
= issue_key_mgmt_set_key(drv
, params
->psk
, 32);
5438 #endif /* CONFIG_DRIVER_NL80211_QCA */
5440 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
5441 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_CONNECT
);
5445 ret
= nl80211_connect_common(drv
, params
, msg
);
5450 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5452 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5454 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5456 if (params
->auth_alg
& WPA_AUTH_ALG_FILS
)
5459 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
5461 goto skip_auth_type
;
5464 type
= get_nl_auth_type(params
->auth_alg
);
5465 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
5466 if (type
== NL80211_AUTHTYPE_MAX
||
5467 nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
5471 ret
= nl80211_set_conn_keys(params
, msg
);
5476 ret
= send_and_recv(drv
->global
, nl_connect
, msg
, NULL
, NULL
);
5478 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5482 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
5483 "(%s)", ret
, strerror(-ret
));
5485 wpa_printf(MSG_DEBUG
,
5486 "nl80211: Connect request send successfully");
5496 static int wpa_driver_nl80211_connect(
5497 struct wpa_driver_nl80211_data
*drv
,
5498 struct wpa_driver_associate_params
*params
,
5499 struct nl_handle
*nl_connect
)
5503 /* Store the connection attempted bssid for future use */
5505 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
5507 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
5509 ret
= wpa_driver_nl80211_try_connect(drv
, params
, nl_connect
);
5510 if (ret
== -EALREADY
) {
5512 * cfg80211 does not currently accept new connections if
5513 * we are already connected. As a workaround, force
5514 * disconnection and try again.
5516 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
5517 "disconnecting before reassociation "
5519 if (wpa_driver_nl80211_disconnect(
5520 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
))
5522 ret
= wpa_driver_nl80211_try_connect(drv
, params
, nl_connect
);
5528 static int wpa_driver_nl80211_associate(
5529 void *priv
, struct wpa_driver_associate_params
*params
)
5531 struct i802_bss
*bss
= priv
;
5532 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5536 nl80211_unmask_11b_rates(bss
);
5538 if (params
->mode
== IEEE80211_MODE_AP
)
5539 return wpa_driver_nl80211_ap(drv
, params
);
5541 if (params
->mode
== IEEE80211_MODE_IBSS
)
5542 return wpa_driver_nl80211_ibss(drv
, params
);
5544 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
5545 enum nl80211_iftype nlmode
= params
->p2p
?
5546 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
5547 struct nl_handle
*nl_connect
= NULL
;
5549 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
5551 if (params
->auth_alg
& WPA_AUTH_ALG_SAE
)
5552 nl_connect
= bss
->nl_connect
;
5553 return wpa_driver_nl80211_connect(drv
, params
, nl_connect
);
5556 nl80211_mark_disconnected(drv
);
5558 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
5560 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_ASSOCIATE
);
5564 ret
= nl80211_connect_common(drv
, params
, msg
);
5568 if (params
->fils_kek
) {
5569 wpa_printf(MSG_DEBUG
, " * FILS KEK (len=%u)",
5570 (unsigned int) params
->fils_kek_len
);
5571 if (nla_put(msg
, NL80211_ATTR_FILS_KEK
, params
->fils_kek_len
,
5575 if (params
->fils_nonces
) {
5576 wpa_hexdump(MSG_DEBUG
, " * FILS nonces (for AAD)",
5577 params
->fils_nonces
,
5578 params
->fils_nonces_len
);
5579 if (nla_put(msg
, NL80211_ATTR_FILS_NONCES
,
5580 params
->fils_nonces_len
, params
->fils_nonces
))
5584 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5587 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
5588 "nl80211: MLME command failed (assoc): ret=%d (%s)",
5589 ret
, strerror(-ret
));
5590 nl80211_dump_scan(drv
);
5592 wpa_printf(MSG_DEBUG
,
5593 "nl80211: Association request send successfully");
5602 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
5603 int ifindex
, enum nl80211_iftype mode
)
5608 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
5609 ifindex
, mode
, nl80211_iftype_str(mode
));
5611 msg
= nl80211_cmd_msg(drv
->first_bss
, 0, NL80211_CMD_SET_INTERFACE
);
5612 if (!msg
|| nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, mode
))
5615 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5621 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
5622 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
5627 static int wpa_driver_nl80211_set_mode_impl(
5628 struct i802_bss
*bss
,
5629 enum nl80211_iftype nlmode
,
5630 struct hostapd_freq_params
*desired_freq_params
)
5632 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5635 int was_ap
= is_ap_interface(drv
->nlmode
);
5637 int mode_switch_res
;
5642 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
5643 if (mode_switch_res
&& nlmode
== nl80211_get_ifmode(bss
))
5644 mode_switch_res
= 0;
5646 if (mode_switch_res
== 0) {
5647 drv
->nlmode
= nlmode
;
5652 if (mode_switch_res
== -ENODEV
)
5655 if (nlmode
== drv
->nlmode
) {
5656 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
5657 "requested mode - ignore error");
5659 goto done
; /* Already in the requested mode */
5662 /* mac80211 doesn't allow mode changes while the device is up, so
5663 * take the device down, try to set the mode again, and bring the
5666 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
5668 for (i
= 0; i
< 10; i
++) {
5669 res
= i802_set_iface_flags(bss
, 0);
5670 if (res
== -EACCES
|| res
== -ENODEV
)
5673 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
5675 os_sleep(0, 100000);
5680 * Setting the mode will fail for some drivers if the phy is
5681 * on a frequency that the mode is disallowed in.
5683 if (desired_freq_params
) {
5684 res
= nl80211_set_channel(bss
, desired_freq_params
, 0);
5686 wpa_printf(MSG_DEBUG
,
5687 "nl80211: Failed to set frequency on interface");
5691 /* Try to set the mode again while the interface is down */
5692 mode_switch_res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
5693 if (mode_switch_res
== -EBUSY
) {
5694 wpa_printf(MSG_DEBUG
,
5695 "nl80211: Delaying mode set while interface going down");
5696 os_sleep(0, 100000);
5699 ret
= mode_switch_res
;
5704 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
5705 "interface is down");
5706 drv
->nlmode
= nlmode
;
5707 drv
->ignore_if_down_event
= 1;
5710 /* Bring the interface back up */
5711 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1);
5713 wpa_printf(MSG_DEBUG
,
5714 "nl80211: Failed to set interface up after switching mode");
5720 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
5721 "from %d failed", nlmode
, drv
->nlmode
);
5725 if (is_p2p_net_interface(nlmode
)) {
5726 wpa_printf(MSG_DEBUG
,
5727 "nl80211: Interface %s mode change to P2P - disable 11b rates",
5729 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
5730 } else if (drv
->disabled_11b_rates
) {
5731 wpa_printf(MSG_DEBUG
,
5732 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
5734 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
5737 if (is_ap_interface(nlmode
)) {
5738 nl80211_mgmt_unsubscribe(bss
, "start AP");
5739 /* Setup additional AP mode functionality if needed */
5740 if (nl80211_setup_ap(bss
))
5742 } else if (was_ap
) {
5743 /* Remove additional AP mode functionality */
5744 nl80211_teardown_ap(bss
);
5746 nl80211_mgmt_unsubscribe(bss
, "mode change");
5749 if (is_mesh_interface(nlmode
) &&
5750 nl80211_mgmt_subscribe_mesh(bss
))
5753 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
5754 !is_mesh_interface(nlmode
) &&
5755 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
5756 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
5757 "frame processing - ignore for now");
5763 int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
5764 enum nl80211_iftype nlmode
)
5766 return wpa_driver_nl80211_set_mode_impl(bss
, nlmode
, NULL
);
5770 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss
*bss
,
5771 struct hostapd_freq_params
*freq
)
5773 return wpa_driver_nl80211_set_mode_impl(bss
, NL80211_IFTYPE_ADHOC
,
5778 static int wpa_driver_nl80211_get_capa(void *priv
,
5779 struct wpa_driver_capa
*capa
)
5781 struct i802_bss
*bss
= priv
;
5782 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5784 if (!drv
->has_capability
)
5786 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
5787 if (drv
->extended_capa
&& drv
->extended_capa_mask
) {
5788 capa
->extended_capa
= drv
->extended_capa
;
5789 capa
->extended_capa_mask
= drv
->extended_capa_mask
;
5790 capa
->extended_capa_len
= drv
->extended_capa_len
;
5797 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
5799 struct i802_bss
*bss
= priv
;
5800 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5802 wpa_printf(MSG_DEBUG
, "nl80211: Set %s operstate %d->%d (%s)",
5803 bss
->ifname
, drv
->operstate
, state
,
5804 state
? "UP" : "DORMANT");
5805 drv
->operstate
= state
;
5806 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
5807 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
5811 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
5813 struct i802_bss
*bss
= priv
;
5814 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5816 struct nl80211_sta_flag_update upd
;
5819 if (!drv
->associated
&& is_zero_ether_addr(drv
->bssid
) && !authorized
) {
5820 wpa_printf(MSG_DEBUG
, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5824 wpa_printf(MSG_DEBUG
, "nl80211: Set supplicant port %sauthorized for "
5825 MACSTR
, authorized
? "" : "un", MAC2STR(drv
->bssid
));
5827 os_memset(&upd
, 0, sizeof(upd
));
5828 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5830 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
5832 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
5833 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
) ||
5834 nla_put(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
)) {
5839 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5842 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set STA flag: %d (%s)",
5843 ret
, strerror(-ret
));
5848 /* Set kernel driver on given frequency (MHz) */
5849 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
5851 struct i802_bss
*bss
= priv
;
5852 return nl80211_set_channel(bss
, freq
, 0);
5856 static inline int min_int(int a
, int b
)
5864 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
5866 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5867 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5869 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5870 genlmsg_attrlen(gnlh
, 0), NULL
);
5873 * TODO: validate the key index and mac address!
5874 * Otherwise, there's a race condition as soon as
5875 * the kernel starts sending key notifications.
5878 if (tb
[NL80211_ATTR_KEY_SEQ
])
5879 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
5880 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
5885 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
5888 struct i802_bss
*bss
= priv
;
5889 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5892 msg
= nl80211_ifindex_msg(drv
, if_nametoindex(iface
), 0,
5893 NL80211_CMD_GET_KEY
);
5895 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
5896 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, idx
)) {
5903 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
5907 static int i802_set_rts(void *priv
, int rts
)
5909 struct i802_bss
*bss
= priv
;
5910 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5920 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
5921 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
)) {
5926 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5929 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
5930 "%d (%s)", rts
, ret
, strerror(-ret
));
5935 static int i802_set_frag(void *priv
, int frag
)
5937 struct i802_bss
*bss
= priv
;
5938 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5948 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_WIPHY
)) ||
5949 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
)) {
5954 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5957 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
5958 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
5963 static int i802_flush(void *priv
)
5965 struct i802_bss
*bss
= priv
;
5969 wpa_printf(MSG_DEBUG
, "nl80211: flush -> DEL_STATION %s (all)",
5973 * XXX: FIX! this needs to flush all VLANs too
5975 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_DEL_STATION
);
5976 res
= send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
5978 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
5979 "(%s)", res
, strerror(-res
));
5985 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
5987 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
5988 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5989 struct hostap_sta_driver_data
*data
= arg
;
5990 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
5991 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
5992 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
5993 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
5994 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
5995 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
5996 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
5997 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
5998 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
5999 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
6000 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
6002 struct nlattr
*rate
[NL80211_RATE_INFO_MAX
+ 1];
6003 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
6004 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
6005 [NL80211_RATE_INFO_BITRATE32
] = { .type
= NLA_U32
},
6006 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
6007 [NL80211_RATE_INFO_VHT_MCS
] = { .type
= NLA_U8
},
6008 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
6009 [NL80211_RATE_INFO_VHT_NSS
] = { .type
= NLA_U8
},
6012 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6013 genlmsg_attrlen(gnlh
, 0), NULL
);
6016 * TODO: validate the interface and mac address!
6017 * Otherwise, there's a race condition as soon as
6018 * the kernel starts sending station notifications.
6021 if (!tb
[NL80211_ATTR_STA_INFO
]) {
6022 wpa_printf(MSG_DEBUG
, "sta stats missing!");
6025 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
6026 tb
[NL80211_ATTR_STA_INFO
],
6028 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
6032 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
6033 data
->inactive_msec
=
6034 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
6035 /* For backwards compatibility, fetch the 32-bit counters first. */
6036 if (stats
[NL80211_STA_INFO_RX_BYTES
])
6037 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
6038 if (stats
[NL80211_STA_INFO_TX_BYTES
])
6039 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
6040 if (stats
[NL80211_STA_INFO_RX_BYTES64
] &&
6041 stats
[NL80211_STA_INFO_TX_BYTES64
]) {
6043 * The driver supports 64-bit counters, so use them to override
6044 * the 32-bit values.
6047 nla_get_u64(stats
[NL80211_STA_INFO_RX_BYTES64
]);
6049 nla_get_u64(stats
[NL80211_STA_INFO_TX_BYTES64
]);
6050 data
->bytes_64bit
= 1;
6052 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
6054 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
6055 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
6057 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
6058 if (stats
[NL80211_STA_INFO_TX_FAILED
])
6059 data
->tx_retry_failed
=
6060 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
6061 if (stats
[NL80211_STA_INFO_SIGNAL
])
6062 data
->signal
= nla_get_u8(stats
[NL80211_STA_INFO_SIGNAL
]);
6064 if (stats
[NL80211_STA_INFO_TX_BITRATE
] &&
6065 nla_parse_nested(rate
, NL80211_RATE_INFO_MAX
,
6066 stats
[NL80211_STA_INFO_TX_BITRATE
],
6067 rate_policy
) == 0) {
6068 if (rate
[NL80211_RATE_INFO_BITRATE32
])
6069 data
->current_tx_rate
=
6070 nla_get_u32(rate
[NL80211_RATE_INFO_BITRATE32
]);
6071 else if (rate
[NL80211_RATE_INFO_BITRATE
])
6072 data
->current_tx_rate
=
6073 nla_get_u16(rate
[NL80211_RATE_INFO_BITRATE
]);
6075 if (rate
[NL80211_RATE_INFO_MCS
]) {
6076 data
->tx_mcs
= nla_get_u8(rate
[NL80211_RATE_INFO_MCS
]);
6077 data
->flags
|= STA_DRV_DATA_TX_MCS
;
6079 if (rate
[NL80211_RATE_INFO_VHT_MCS
]) {
6081 nla_get_u8(rate
[NL80211_RATE_INFO_VHT_MCS
]);
6082 data
->flags
|= STA_DRV_DATA_TX_VHT_MCS
;
6084 if (rate
[NL80211_RATE_INFO_SHORT_GI
])
6085 data
->flags
|= STA_DRV_DATA_TX_SHORT_GI
;
6086 if (rate
[NL80211_RATE_INFO_VHT_NSS
]) {
6088 nla_get_u8(rate
[NL80211_RATE_INFO_VHT_NSS
]);
6089 data
->flags
|= STA_DRV_DATA_TX_VHT_NSS
;
6093 if (stats
[NL80211_STA_INFO_RX_BITRATE
] &&
6094 nla_parse_nested(rate
, NL80211_RATE_INFO_MAX
,
6095 stats
[NL80211_STA_INFO_RX_BITRATE
],
6096 rate_policy
) == 0) {
6097 if (rate
[NL80211_RATE_INFO_BITRATE32
])
6098 data
->current_rx_rate
=
6099 nla_get_u32(rate
[NL80211_RATE_INFO_BITRATE32
]);
6100 else if (rate
[NL80211_RATE_INFO_BITRATE
])
6101 data
->current_rx_rate
=
6102 nla_get_u16(rate
[NL80211_RATE_INFO_BITRATE
]);
6104 if (rate
[NL80211_RATE_INFO_MCS
]) {
6106 nla_get_u8(rate
[NL80211_RATE_INFO_MCS
]);
6107 data
->flags
|= STA_DRV_DATA_RX_MCS
;
6109 if (rate
[NL80211_RATE_INFO_VHT_MCS
]) {
6111 nla_get_u8(rate
[NL80211_RATE_INFO_VHT_MCS
]);
6112 data
->flags
|= STA_DRV_DATA_RX_VHT_MCS
;
6114 if (rate
[NL80211_RATE_INFO_SHORT_GI
])
6115 data
->flags
|= STA_DRV_DATA_RX_SHORT_GI
;
6116 if (rate
[NL80211_RATE_INFO_VHT_NSS
]) {
6118 nla_get_u8(rate
[NL80211_RATE_INFO_VHT_NSS
]);
6119 data
->flags
|= STA_DRV_DATA_RX_VHT_NSS
;
6126 static int i802_read_sta_data(struct i802_bss
*bss
,
6127 struct hostap_sta_driver_data
*data
,
6132 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_GET_STATION
)) ||
6133 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
6138 return send_and_recv_msgs(bss
->drv
, msg
, get_sta_handler
, data
);
6142 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
6143 int cw_min
, int cw_max
, int burst_time
)
6145 struct i802_bss
*bss
= priv
;
6146 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6148 struct nlattr
*txq
, *params
;
6150 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_WIPHY
);
6154 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
6158 /* We are only sending parameters for a single TXQ at a time */
6159 params
= nla_nest_start(msg
, 1);
6165 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
))
6169 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
))
6173 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
))
6177 if (nla_put_u8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
))
6181 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
6182 * 32 usec, so need to convert the value here. */
6183 if (nla_put_u16(msg
, NL80211_TXQ_ATTR_TXOP
,
6184 (burst_time
* 100 + 16) / 32) ||
6185 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
) ||
6186 nla_put_u16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
) ||
6187 nla_put_u8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
))
6190 nla_nest_end(msg
, params
);
6192 nla_nest_end(msg
, txq
);
6194 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
6203 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
6204 const char *ifname
, int vlan_id
)
6206 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6210 wpa_printf(MSG_DEBUG
, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
6211 ", ifname=%s[%d], vlan_id=%d)",
6212 bss
->ifname
, if_nametoindex(bss
->ifname
),
6213 MAC2STR(addr
), ifname
, if_nametoindex(ifname
), vlan_id
);
6214 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_STATION
)) ||
6215 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
6216 nla_put_u32(msg
, NL80211_ATTR_STA_VLAN
, if_nametoindex(ifname
))) {
6221 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6223 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
6224 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
6225 MAC2STR(addr
), ifname
, vlan_id
, ret
,
6232 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
6234 struct hostap_sta_driver_data data
;
6237 os_memset(&data
, 0, sizeof(data
));
6238 data
.inactive_msec
= (unsigned long) -1;
6239 ret
= i802_read_sta_data(priv
, &data
, addr
);
6242 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
6244 return data
.inactive_msec
/ 1000;
6248 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
6257 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
6260 struct i802_bss
*bss
= priv
;
6261 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6262 struct ieee80211_mgmt mgmt
;
6265 if (ieee80211_freq_to_chan(bss
->freq
, &channel
) ==
6266 HOSTAPD_MODE_IEEE80211AD
) {
6267 /* Deauthentication is not used in DMG/IEEE 802.11ad;
6268 * disassociate the STA instead. */
6269 return i802_sta_disassoc(priv
, own_addr
, addr
, reason
);
6272 if (is_mesh_interface(drv
->nlmode
))
6275 if (drv
->device_ap_sme
)
6276 return wpa_driver_nl80211_sta_remove(bss
, addr
, 1, reason
);
6278 memset(&mgmt
, 0, sizeof(mgmt
));
6279 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6280 WLAN_FC_STYPE_DEAUTH
);
6281 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6282 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6283 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6284 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
6285 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6287 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
6292 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
6295 struct i802_bss
*bss
= priv
;
6296 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6297 struct ieee80211_mgmt mgmt
;
6299 if (is_mesh_interface(drv
->nlmode
))
6302 if (drv
->device_ap_sme
)
6303 return wpa_driver_nl80211_sta_remove(bss
, addr
, 0, reason
);
6305 memset(&mgmt
, 0, sizeof(mgmt
));
6306 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
6307 WLAN_FC_STYPE_DISASSOC
);
6308 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
6309 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
6310 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
6311 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
6312 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
6314 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
6319 static void dump_ifidx(struct wpa_driver_nl80211_data
*drv
)
6321 char buf
[200], *pos
, *end
;
6325 end
= pos
+ sizeof(buf
);
6327 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6328 if (!drv
->if_indices
[i
])
6330 res
= os_snprintf(pos
, end
- pos
, " %d(%d)",
6332 drv
->if_indices_reason
[i
]);
6333 if (os_snprintf_error(end
- pos
, res
))
6339 wpa_printf(MSG_DEBUG
, "nl80211: if_indices[%d]:%s",
6340 drv
->num_if_indices
, buf
);
6344 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6348 int *old
, *old_reason
;
6350 wpa_printf(MSG_DEBUG
,
6351 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
6352 ifidx
, ifidx_reason
);
6353 if (have_ifidx(drv
, ifidx
, ifidx_reason
)) {
6354 wpa_printf(MSG_DEBUG
, "nl80211: ifindex %d already in the list",
6358 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6359 if (drv
->if_indices
[i
] == 0) {
6360 drv
->if_indices
[i
] = ifidx
;
6361 drv
->if_indices_reason
[i
] = ifidx_reason
;
6367 if (drv
->if_indices
!= drv
->default_if_indices
)
6368 old
= drv
->if_indices
;
6372 if (drv
->if_indices_reason
!= drv
->default_if_indices_reason
)
6373 old_reason
= drv
->if_indices_reason
;
6377 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
6379 drv
->if_indices_reason
= os_realloc_array(old_reason
,
6380 drv
->num_if_indices
+ 1,
6382 if (!drv
->if_indices
) {
6384 drv
->if_indices
= drv
->default_if_indices
;
6386 drv
->if_indices
= old
;
6388 if (!drv
->if_indices_reason
) {
6390 drv
->if_indices_reason
= drv
->default_if_indices_reason
;
6392 drv
->if_indices_reason
= old_reason
;
6394 if (!drv
->if_indices
|| !drv
->if_indices_reason
) {
6395 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
6397 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
6401 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
6402 sizeof(drv
->default_if_indices
));
6404 os_memcpy(drv
->if_indices_reason
,
6405 drv
->default_if_indices_reason
,
6406 sizeof(drv
->default_if_indices_reason
));
6407 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
6408 drv
->if_indices_reason
[drv
->num_if_indices
] = ifidx_reason
;
6409 drv
->num_if_indices
++;
6414 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6419 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
6420 if ((drv
->if_indices
[i
] == ifidx
|| ifidx
== IFIDX_ANY
) &&
6421 (drv
->if_indices_reason
[i
] == ifidx_reason
||
6422 ifidx_reason
== IFIDX_ANY
)) {
6423 drv
->if_indices
[i
] = 0;
6431 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
,
6436 for (i
= 0; i
< drv
->num_if_indices
; i
++)
6437 if (drv
->if_indices
[i
] == ifidx
&&
6438 (drv
->if_indices_reason
[i
] == ifidx_reason
||
6439 ifidx_reason
== IFIDX_ANY
))
6446 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
6447 const char *bridge_ifname
, char *ifname_wds
)
6449 struct i802_bss
*bss
= priv
;
6450 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6451 char name
[IFNAMSIZ
+ 1];
6453 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
6455 os_strlcpy(ifname_wds
, name
, IFNAMSIZ
+ 1);
6457 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
6458 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
6460 if (!if_nametoindex(name
)) {
6461 if (nl80211_create_iface(drv
, name
,
6462 NL80211_IFTYPE_AP_VLAN
,
6463 bss
->addr
, 1, NULL
, NULL
, 0) <
6466 if (bridge_ifname
&&
6467 linux_br_add_if(drv
->global
->ioctl_sock
,
6468 bridge_ifname
, name
) < 0)
6471 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
6472 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
6473 "interface %s up", name
);
6475 return i802_set_sta_vlan(priv
, addr
, name
, 0);
6478 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
6481 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
6482 nl80211_remove_iface(drv
, if_nametoindex(name
));
6488 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
6490 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
6491 struct sockaddr_ll lladdr
;
6492 unsigned char buf
[3000];
6494 socklen_t fromlen
= sizeof(lladdr
);
6496 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
6497 (struct sockaddr
*)&lladdr
, &fromlen
);
6499 wpa_printf(MSG_ERROR
, "nl80211: EAPOL recv failed: %s",
6504 if (have_ifidx(drv
, lladdr
.sll_ifindex
, IFIDX_ANY
))
6505 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
6509 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
6510 struct i802_bss
*bss
,
6511 const char *brname
, const char *ifname
)
6514 char in_br
[IFNAMSIZ
];
6516 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
6517 br_ifindex
= if_nametoindex(brname
);
6518 if (br_ifindex
== 0) {
6520 * Bridge was configured, but the bridge device does
6521 * not exist. Try to add it now.
6523 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
6524 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
6525 "bridge interface %s: %s",
6526 brname
, strerror(errno
));
6529 bss
->added_bridge
= 1;
6530 br_ifindex
= if_nametoindex(brname
);
6531 add_ifidx(drv
, br_ifindex
, drv
->ifindex
);
6533 bss
->br_ifindex
= br_ifindex
;
6535 if (linux_br_get(in_br
, ifname
) == 0) {
6536 if (os_strcmp(in_br
, brname
) == 0)
6537 return 0; /* already in the bridge */
6539 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
6540 "bridge %s", ifname
, in_br
);
6541 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
6543 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
6544 "remove interface %s from bridge "
6546 ifname
, in_br
, strerror(errno
));
6551 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
6553 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
6554 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
6555 "into bridge %s: %s",
6556 ifname
, brname
, strerror(errno
));
6559 bss
->added_if_into_bridge
= 1;
6565 static void *i802_init(struct hostapd_data
*hapd
,
6566 struct wpa_init_params
*params
)
6568 struct wpa_driver_nl80211_data
*drv
;
6569 struct i802_bss
*bss
;
6571 char master_ifname
[IFNAMSIZ
];
6572 int ifindex
, br_ifindex
= 0;
6575 bss
= wpa_driver_nl80211_drv_init(hapd
, params
->ifname
,
6576 params
->global_priv
, 1,
6577 params
->bssid
, params
->driver_params
);
6583 if (linux_br_get(master_ifname
, params
->ifname
) == 0) {
6584 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
6585 params
->ifname
, master_ifname
);
6586 br_ifindex
= if_nametoindex(master_ifname
);
6587 os_strlcpy(bss
->brname
, master_ifname
, IFNAMSIZ
);
6588 } else if ((params
->num_bridge
== 0 || !params
->bridge
[0]) &&
6589 linux_master_get(master_ifname
, params
->ifname
) == 0) {
6590 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in master %s",
6591 params
->ifname
, master_ifname
);
6592 /* start listening for EAPOL on the master interface */
6593 add_ifidx(drv
, if_nametoindex(master_ifname
), drv
->ifindex
);
6595 /* check if master itself is under bridge */
6596 if (linux_br_get(master_ifname
, master_ifname
) == 0) {
6597 wpa_printf(MSG_DEBUG
, "nl80211: which is in bridge %s",
6599 br_ifindex
= if_nametoindex(master_ifname
);
6600 os_strlcpy(bss
->brname
, master_ifname
, IFNAMSIZ
);
6603 master_ifname
[0] = '\0';
6606 bss
->br_ifindex
= br_ifindex
;
6608 for (i
= 0; i
< params
->num_bridge
; i
++) {
6609 if (params
->bridge
[i
]) {
6610 ifindex
= if_nametoindex(params
->bridge
[i
]);
6612 add_ifidx(drv
, ifindex
, drv
->ifindex
);
6613 if (ifindex
== br_ifindex
)
6618 /* start listening for EAPOL on the default AP interface */
6619 add_ifidx(drv
, drv
->ifindex
, IFIDX_ANY
);
6621 if (params
->num_bridge
&& params
->bridge
[0]) {
6622 if (i802_check_bridge(drv
, bss
, params
->bridge
[0],
6623 params
->ifname
) < 0)
6625 if (os_strcmp(params
->bridge
[0], master_ifname
) != 0)
6629 if (!br_added
&& br_ifindex
&&
6630 (params
->num_bridge
== 0 || !params
->bridge
[0]))
6631 add_ifidx(drv
, br_ifindex
, drv
->ifindex
);
6633 #ifdef CONFIG_LIBNL3_ROUTE
6634 if (bss
->added_if_into_bridge
) {
6635 drv
->rtnl_sk
= nl_socket_alloc();
6636 if (drv
->rtnl_sk
== NULL
) {
6637 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate nl_sock");
6641 if (nl_connect(drv
->rtnl_sk
, NETLINK_ROUTE
)) {
6642 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
6647 #endif /* CONFIG_LIBNL3_ROUTE */
6649 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
6650 if (drv
->eapol_sock
< 0) {
6651 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
6656 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
6658 wpa_printf(MSG_INFO
, "nl80211: Could not register read socket for eapol");
6662 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
6665 os_memcpy(drv
->perm_addr
, params
->own_addr
, ETH_ALEN
);
6667 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
6672 wpa_driver_nl80211_deinit(bss
);
6677 static void i802_deinit(void *priv
)
6679 struct i802_bss
*bss
= priv
;
6680 wpa_driver_nl80211_deinit(bss
);
6684 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
6685 enum wpa_driver_if_type type
)
6688 case WPA_IF_STATION
:
6689 return NL80211_IFTYPE_STATION
;
6690 case WPA_IF_P2P_CLIENT
:
6691 case WPA_IF_P2P_GROUP
:
6692 return NL80211_IFTYPE_P2P_CLIENT
;
6693 case WPA_IF_AP_VLAN
:
6694 return NL80211_IFTYPE_AP_VLAN
;
6696 return NL80211_IFTYPE_AP
;
6698 return NL80211_IFTYPE_P2P_GO
;
6699 case WPA_IF_P2P_DEVICE
:
6700 return NL80211_IFTYPE_P2P_DEVICE
;
6702 return NL80211_IFTYPE_MESH_POINT
;
6709 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
6711 struct wpa_driver_nl80211_data
*drv
;
6712 dl_list_for_each(drv
, &global
->interfaces
,
6713 struct wpa_driver_nl80211_data
, list
) {
6714 if (os_memcmp(addr
, drv
->first_bss
->addr
, ETH_ALEN
) == 0)
6721 static int nl80211_vif_addr(struct wpa_driver_nl80211_data
*drv
, u8
*new_addr
)
6728 os_memcpy(new_addr
, drv
->first_bss
->addr
, ETH_ALEN
);
6729 for (idx
= 0; idx
< 64; idx
++) {
6730 new_addr
[0] = drv
->first_bss
->addr
[0] | 0x02;
6731 new_addr
[0] ^= idx
<< 2;
6732 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
6738 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new virtual interface address "
6739 MACSTR
, MAC2STR(new_addr
));
6748 u8 macaddr
[ETH_ALEN
];
6751 static int nl80211_wdev_handler(struct nl_msg
*msg
, void *arg
)
6753 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6754 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
6755 struct wdev_info
*wi
= arg
;
6757 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6758 genlmsg_attrlen(gnlh
, 0), NULL
);
6759 if (tb
[NL80211_ATTR_WDEV
]) {
6760 wi
->wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
6761 wi
->wdev_id_set
= 1;
6764 if (tb
[NL80211_ATTR_MAC
])
6765 os_memcpy(wi
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
6772 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
6773 const char *ifname
, const u8
*addr
,
6774 void *bss_ctx
, void **drv_priv
,
6775 char *force_ifname
, u8
*if_addr
,
6776 const char *bridge
, int use_existing
,
6779 enum nl80211_iftype nlmode
;
6780 struct i802_bss
*bss
= priv
;
6781 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6786 os_memcpy(if_addr
, addr
, ETH_ALEN
);
6787 nlmode
= wpa_driver_nl80211_if_type(type
);
6788 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
6789 struct wdev_info p2pdev_info
;
6791 os_memset(&p2pdev_info
, 0, sizeof(p2pdev_info
));
6792 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
6793 0, nl80211_wdev_handler
,
6794 &p2pdev_info
, use_existing
);
6795 if (!p2pdev_info
.wdev_id_set
|| ifidx
!= 0) {
6796 wpa_printf(MSG_ERROR
, "nl80211: Failed to create a P2P Device interface %s",
6801 drv
->global
->if_add_wdevid
= p2pdev_info
.wdev_id
;
6802 drv
->global
->if_add_wdevid_set
= p2pdev_info
.wdev_id_set
;
6803 if (!is_zero_ether_addr(p2pdev_info
.macaddr
))
6804 os_memcpy(if_addr
, p2pdev_info
.macaddr
, ETH_ALEN
);
6805 wpa_printf(MSG_DEBUG
, "nl80211: New P2P Device interface %s (0x%llx) created",
6807 (long long unsigned int) p2pdev_info
.wdev_id
);
6809 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
6810 0, NULL
, NULL
, use_existing
);
6811 if (use_existing
&& ifidx
== -ENFILE
) {
6813 ifidx
= if_nametoindex(ifname
);
6814 } else if (ifidx
< 0) {
6820 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
6821 os_memcpy(if_addr
, bss
->addr
, ETH_ALEN
);
6822 else if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
6823 ifname
, if_addr
) < 0) {
6825 nl80211_remove_iface(drv
, ifidx
);
6831 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
6832 type
== WPA_IF_P2P_GO
|| type
== WPA_IF_MESH
||
6833 type
== WPA_IF_STATION
)) {
6834 /* Enforce unique address */
6835 u8 new_addr
[ETH_ALEN
];
6837 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
6840 nl80211_remove_iface(drv
, ifidx
);
6843 if (nl80211_addr_in_use(drv
->global
, new_addr
)) {
6844 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
6845 "for interface %s type %d", ifname
, type
);
6846 if (nl80211_vif_addr(drv
, new_addr
) < 0) {
6848 nl80211_remove_iface(drv
, ifidx
);
6851 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
6854 nl80211_remove_iface(drv
, ifidx
);
6858 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
6861 if (type
== WPA_IF_AP_BSS
&& setup_ap
) {
6862 struct i802_bss
*new_bss
= os_zalloc(sizeof(*new_bss
));
6863 if (new_bss
== NULL
) {
6865 nl80211_remove_iface(drv
, ifidx
);
6870 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
6871 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
6872 "interface %s to a bridge %s",
6875 nl80211_remove_iface(drv
, ifidx
);
6880 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
6883 nl80211_remove_iface(drv
, ifidx
);
6887 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
6888 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
6889 new_bss
->ifindex
= ifidx
;
6891 new_bss
->next
= drv
->first_bss
->next
;
6892 new_bss
->freq
= drv
->first_bss
->freq
;
6893 new_bss
->ctx
= bss_ctx
;
6894 new_bss
->added_if
= added
;
6895 drv
->first_bss
->next
= new_bss
;
6897 *drv_priv
= new_bss
;
6898 nl80211_init_bss(new_bss
);
6900 /* Subscribe management frames for this WPA_IF_AP_BSS */
6901 if (nl80211_setup_ap(new_bss
))
6906 drv
->global
->if_add_ifindex
= ifidx
;
6909 * Some virtual interfaces need to process EAPOL packets and events on
6910 * the parent interface. This is used mainly with hostapd.
6914 nlmode
== NL80211_IFTYPE_AP_VLAN
||
6915 nlmode
== NL80211_IFTYPE_WDS
||
6916 nlmode
== NL80211_IFTYPE_MONITOR
))
6917 add_ifidx(drv
, ifidx
, IFIDX_ANY
);
6923 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
6924 enum wpa_driver_if_type type
,
6927 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6928 int ifindex
= if_nametoindex(ifname
);
6930 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
6931 __func__
, type
, ifname
, ifindex
, bss
->added_if
);
6932 if (ifindex
> 0 && (bss
->added_if
|| bss
->ifindex
!= ifindex
))
6933 nl80211_remove_iface(drv
, ifindex
);
6934 else if (ifindex
> 0 && !bss
->added_if
) {
6935 struct wpa_driver_nl80211_data
*drv2
;
6936 dl_list_for_each(drv2
, &drv
->global
->interfaces
,
6937 struct wpa_driver_nl80211_data
, list
) {
6938 del_ifidx(drv2
, ifindex
, IFIDX_ANY
);
6939 del_ifidx(drv2
, IFIDX_ANY
, ifindex
);
6943 if (type
!= WPA_IF_AP_BSS
)
6946 if (bss
->added_if_into_bridge
) {
6947 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
6949 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6950 "interface %s from bridge %s: %s",
6951 bss
->ifname
, bss
->brname
, strerror(errno
));
6953 if (bss
->added_bridge
) {
6954 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
6955 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
6957 bss
->brname
, strerror(errno
));
6960 if (bss
!= drv
->first_bss
) {
6961 struct i802_bss
*tbss
;
6963 wpa_printf(MSG_DEBUG
, "nl80211: Not the first BSS - remove it");
6964 for (tbss
= drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
6965 if (tbss
->next
== bss
) {
6966 tbss
->next
= bss
->next
;
6967 /* Unsubscribe management frames */
6968 nl80211_teardown_ap(bss
);
6969 nl80211_destroy_bss(bss
);
6971 i802_set_iface_flags(bss
, 0);
6978 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
6979 "BSS %p in the list", __func__
, bss
);
6981 wpa_printf(MSG_DEBUG
, "nl80211: First BSS - reassign context");
6982 nl80211_teardown_ap(bss
);
6983 if (!bss
->added_if
&& !drv
->first_bss
->next
)
6984 wpa_driver_nl80211_del_beacon(bss
);
6985 nl80211_destroy_bss(bss
);
6987 i802_set_iface_flags(bss
, 0);
6988 if (drv
->first_bss
->next
) {
6989 drv
->first_bss
= drv
->first_bss
->next
;
6990 drv
->ctx
= drv
->first_bss
->ctx
;
6993 wpa_printf(MSG_DEBUG
, "nl80211: No second BSS to reassign context to");
7001 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
7003 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7004 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7006 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7007 genlmsg_attrlen(gnlh
, 0), NULL
);
7008 if (tb
[NL80211_ATTR_COOKIE
])
7009 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
7014 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
7015 unsigned int freq
, unsigned int wait
,
7016 const u8
*buf
, size_t buf_len
,
7017 u64
*cookie_out
, int no_cck
, int no_ack
,
7018 int offchanok
, const u16
*csa_offs
,
7019 size_t csa_offs_len
)
7021 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7026 wpa_printf(MSG_MSGDUMP
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
7027 "no_ack=%d offchanok=%d",
7028 freq
, wait
, no_cck
, no_ack
, offchanok
);
7029 wpa_hexdump(MSG_MSGDUMP
, "CMD_FRAME", buf
, buf_len
);
7031 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME
)) ||
7032 (freq
&& nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
7033 (wait
&& nla_put_u32(msg
, NL80211_ATTR_DURATION
, wait
)) ||
7034 (offchanok
&& ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
7035 drv
->test_use_roc_tx
) &&
7036 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
)) ||
7037 (no_cck
&& nla_put_flag(msg
, NL80211_ATTR_TX_NO_CCK_RATE
)) ||
7038 (no_ack
&& nla_put_flag(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
)) ||
7039 (csa_offs
&& nla_put(msg
, NL80211_ATTR_CSA_C_OFFSETS_TX
,
7040 csa_offs_len
* sizeof(u16
), csa_offs
)) ||
7041 nla_put(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
))
7045 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
7048 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
7049 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
7052 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame TX command accepted%s; "
7053 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
7054 (long long unsigned int) cookie
);
7057 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
7059 if (drv
->num_send_action_cookies
== MAX_SEND_ACTION_COOKIES
) {
7060 wpa_printf(MSG_DEBUG
,
7061 "nl80211: Drop oldest pending send action cookie 0x%llx",
7062 (long long unsigned int)
7063 drv
->send_action_cookies
[0]);
7064 os_memmove(&drv
->send_action_cookies
[0],
7065 &drv
->send_action_cookies
[1],
7066 (MAX_SEND_ACTION_COOKIES
- 1) *
7068 drv
->num_send_action_cookies
--;
7070 drv
->send_action_cookies
[drv
->num_send_action_cookies
] = cookie
;
7071 drv
->num_send_action_cookies
++;
7080 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
7082 unsigned int wait_time
,
7083 const u8
*dst
, const u8
*src
,
7085 const u8
*data
, size_t data_len
,
7088 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7091 struct ieee80211_hdr
*hdr
;
7093 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
7094 "freq=%u MHz wait=%d ms no_cck=%d)",
7095 drv
->ifindex
, freq
, wait_time
, no_cck
);
7097 buf
= os_zalloc(24 + data_len
);
7100 os_memcpy(buf
+ 24, data
, data_len
);
7101 hdr
= (struct ieee80211_hdr
*) buf
;
7102 hdr
->frame_control
=
7103 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
7104 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
7105 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
7106 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
7108 if (os_memcmp(bss
->addr
, src
, ETH_ALEN
) != 0) {
7109 wpa_printf(MSG_DEBUG
, "nl80211: Use random TA " MACSTR
,
7111 os_memcpy(bss
->rand_addr
, src
, ETH_ALEN
);
7113 os_memset(bss
->rand_addr
, 0, ETH_ALEN
);
7116 if (is_ap_interface(drv
->nlmode
) &&
7117 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
7118 (int) freq
== bss
->freq
|| drv
->device_ap_sme
||
7120 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
7122 wait_time
, NULL
, 0);
7124 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
7126 &drv
->send_action_cookie
,
7127 no_cck
, 0, 1, NULL
, 0);
7134 static void nl80211_frame_wait_cancel(struct i802_bss
*bss
, u64 cookie
)
7136 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7140 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
7141 (long long unsigned int) cookie
);
7142 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
)) ||
7143 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
)) {
7148 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7150 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
7151 "(%s)", ret
, strerror(-ret
));
7155 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
7157 struct i802_bss
*bss
= priv
;
7158 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7162 /* Cancel the last pending TX cookie */
7163 nl80211_frame_wait_cancel(bss
, drv
->send_action_cookie
);
7166 * Cancel the other pending TX cookies, if any. This is needed since
7167 * the driver may keep a list of all pending offchannel TX operations
7168 * and free up the radio only once they have expired or cancelled.
7170 for (i
= drv
->num_send_action_cookies
; i
> 0; i
--) {
7171 cookie
= drv
->send_action_cookies
[i
- 1];
7172 if (cookie
!= drv
->send_action_cookie
)
7173 nl80211_frame_wait_cancel(bss
, cookie
);
7175 drv
->num_send_action_cookies
= 0;
7179 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
7180 unsigned int duration
)
7182 struct i802_bss
*bss
= priv
;
7183 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7188 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
)) ||
7189 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
7190 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
)) {
7196 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
7198 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
7199 "0x%llx for freq=%u MHz duration=%u",
7200 (long long unsigned int) cookie
, freq
, duration
);
7201 drv
->remain_on_chan_cookie
= cookie
;
7202 drv
->pending_remain_on_chan
= 1;
7205 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
7206 "(freq=%d duration=%u): %d (%s)",
7207 freq
, duration
, ret
, strerror(-ret
));
7212 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
7214 struct i802_bss
*bss
= priv
;
7215 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7219 if (!drv
->pending_remain_on_chan
) {
7220 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
7225 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
7227 (long long unsigned int) drv
->remain_on_chan_cookie
);
7229 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
7231 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
)) {
7236 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7239 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
7240 "%d (%s)", ret
, strerror(-ret
));
7245 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
7247 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7250 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
7251 is_ap_interface(drv
->nlmode
) && !bss
->in_deinit
&&
7254 * Do not disable Probe Request reporting that was
7255 * enabled in nl80211_setup_ap().
7257 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
7258 "Probe Request reporting nl_preq=%p while "
7259 "in AP mode", bss
->nl_preq
);
7260 } else if (bss
->nl_preq
) {
7261 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
7262 "reporting nl_preq=%p", bss
->nl_preq
);
7263 nl80211_destroy_eloop_handle(&bss
->nl_preq
, 0);
7269 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
7270 "already on! nl_preq=%p", bss
->nl_preq
);
7274 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
7275 if (bss
->nl_preq
== NULL
)
7277 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
7278 "reporting nl_preq=%p", bss
->nl_preq
);
7280 if (nl80211_register_frame(bss
, bss
->nl_preq
,
7281 (WLAN_FC_TYPE_MGMT
<< 2) |
7282 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
7286 nl80211_register_eloop_read(&bss
->nl_preq
,
7287 wpa_driver_nl80211_event_receive
,
7293 nl_destroy_handles(&bss
->nl_preq
);
7298 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
7299 int ifindex
, int disabled
)
7302 struct nlattr
*bands
, *band
;
7305 wpa_printf(MSG_DEBUG
,
7306 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
7307 ifindex
, disabled
? "NL80211_TXRATE_LEGACY=OFDM-only" :
7308 "no NL80211_TXRATE_LEGACY constraint");
7310 msg
= nl80211_ifindex_msg(drv
, ifindex
, 0,
7311 NL80211_CMD_SET_TX_BITRATE_MASK
);
7315 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
7320 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
7321 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
7322 * rates. All 5 GHz rates are left enabled.
7324 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
7326 (disabled
&& nla_put(msg
, NL80211_TXRATE_LEGACY
, 8,
7327 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
7329 nla_nest_end(msg
, band
);
7331 nla_nest_end(msg
, bands
);
7333 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7335 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
7336 "(%s)", ret
, strerror(-ret
));
7338 drv
->disabled_11b_rates
= disabled
;
7348 static int wpa_driver_nl80211_deinit_ap(void *priv
)
7350 struct i802_bss
*bss
= priv
;
7351 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7352 if (!is_ap_interface(drv
->nlmode
))
7354 wpa_driver_nl80211_del_beacon(bss
);
7355 bss
->beacon_set
= 0;
7358 * If the P2P GO interface was dynamically added, then it is
7359 * possible that the interface change to station is not possible.
7361 if (drv
->nlmode
== NL80211_IFTYPE_P2P_GO
&& bss
->if_dynamic
)
7364 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
7368 static int wpa_driver_nl80211_stop_ap(void *priv
)
7370 struct i802_bss
*bss
= priv
;
7371 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7372 if (!is_ap_interface(drv
->nlmode
))
7374 wpa_driver_nl80211_del_beacon(bss
);
7375 bss
->beacon_set
= 0;
7380 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
7382 struct i802_bss
*bss
= priv
;
7383 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7384 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
7388 * If the P2P Client interface was dynamically added, then it is
7389 * possible that the interface change to station is not possible.
7391 if (bss
->if_dynamic
)
7394 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
7398 static void wpa_driver_nl80211_resume(void *priv
)
7400 struct i802_bss
*bss
= priv
;
7401 enum nl80211_iftype nlmode
= nl80211_get_ifmode(bss
);
7403 if (i802_set_iface_flags(bss
, 1))
7404 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on resume event");
7406 if (is_p2p_net_interface(nlmode
))
7407 nl80211_disable_11b_rates(bss
->drv
, bss
->drv
->ifindex
, 1);
7411 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
7413 struct i802_bss
*bss
= priv
;
7414 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7418 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
7419 "hysteresis=%d", threshold
, hysteresis
);
7421 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_CQM
)) ||
7422 !(cqm
= nla_nest_start(msg
, NL80211_ATTR_CQM
)) ||
7423 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
) ||
7424 nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
)) {
7428 nla_nest_end(msg
, cqm
);
7430 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7434 static int get_channel_width(struct nl_msg
*msg
, void *arg
)
7436 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7437 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7438 struct wpa_signal_info
*sig_change
= arg
;
7440 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7441 genlmsg_attrlen(gnlh
, 0), NULL
);
7443 sig_change
->center_frq1
= -1;
7444 sig_change
->center_frq2
= -1;
7445 sig_change
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
7447 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
]) {
7448 sig_change
->chanwidth
= convert2width(
7449 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
7450 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
7451 sig_change
->center_frq1
=
7452 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
7453 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
7454 sig_change
->center_frq2
=
7455 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
7462 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data
*drv
,
7463 struct wpa_signal_info
*sig
)
7467 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_GET_INTERFACE
);
7468 return send_and_recv_msgs(drv
, msg
, get_channel_width
, sig
);
7472 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
7474 struct i802_bss
*bss
= priv
;
7475 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7478 os_memset(si
, 0, sizeof(*si
));
7479 res
= nl80211_get_link_signal(drv
, si
);
7481 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
&&
7482 drv
->nlmode
!= NL80211_IFTYPE_MESH_POINT
)
7484 si
->current_signal
= 0;
7487 res
= nl80211_get_channel_width(drv
, si
);
7491 return nl80211_get_link_noise(drv
, si
);
7495 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
7498 struct i802_bss
*bss
= priv
;
7499 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
7500 0, 0, 0, 0, NULL
, 0);
7504 static int nl80211_set_param(void *priv
, const char *param
)
7506 struct i802_bss
*bss
= priv
;
7507 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7511 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
7514 if (os_strstr(param
, "use_p2p_group_interface=1")) {
7515 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
7517 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
7518 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
7520 #endif /* CONFIG_P2P */
7522 if (os_strstr(param
, "use_monitor=1"))
7523 drv
->use_monitor
= 1;
7525 if (os_strstr(param
, "force_connect_cmd=1")) {
7526 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_SME
;
7527 drv
->force_connect_cmd
= 1;
7530 if (os_strstr(param
, "force_bss_selection=1"))
7531 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
7533 if (os_strstr(param
, "no_offchannel_tx=1")) {
7534 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
7535 drv
->test_use_roc_tx
= 1;
7542 static void * nl80211_global_init(void *ctx
)
7544 struct nl80211_global
*global
;
7545 struct netlink_config
*cfg
;
7547 global
= os_zalloc(sizeof(*global
));
7551 global
->ioctl_sock
= -1;
7552 dl_list_init(&global
->interfaces
);
7553 global
->if_add_ifindex
= -1;
7555 cfg
= os_zalloc(sizeof(*cfg
));
7560 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
7561 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
7562 global
->netlink
= netlink_init(cfg
);
7563 if (global
->netlink
== NULL
) {
7568 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
7571 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
7572 if (global
->ioctl_sock
< 0) {
7573 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
7581 nl80211_global_deinit(global
);
7586 static void nl80211_global_deinit(void *priv
)
7588 struct nl80211_global
*global
= priv
;
7591 if (!dl_list_empty(&global
->interfaces
)) {
7592 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
7593 "nl80211_global_deinit",
7594 dl_list_len(&global
->interfaces
));
7597 if (global
->netlink
)
7598 netlink_deinit(global
->netlink
);
7600 nl_destroy_handles(&global
->nl
);
7602 if (global
->nl_event
)
7603 nl80211_destroy_eloop_handle(&global
->nl_event
, 0);
7605 nl_cb_put(global
->nl_cb
);
7607 if (global
->ioctl_sock
>= 0)
7608 close(global
->ioctl_sock
);
7614 static const char * nl80211_get_radio_name(void *priv
)
7616 struct i802_bss
*bss
= priv
;
7617 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7618 return drv
->phyname
;
7622 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
,
7623 struct wpa_pmkid_params
*params
)
7626 const size_t PMK_MAX_LEN
= 48; /* current cfg80211 limit */
7628 if (!(msg
= nl80211_bss_msg(bss
, 0, cmd
)) ||
7630 nla_put(msg
, NL80211_ATTR_PMKID
, 16, params
->pmkid
)) ||
7632 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
)) ||
7633 (params
->ssid_len
&&
7634 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
, params
->ssid
)) ||
7635 (params
->fils_cache_id
&&
7636 nla_put(msg
, NL80211_ATTR_FILS_CACHE_ID
, 2,
7637 params
->fils_cache_id
)) ||
7638 (params
->pmk_len
&& params
->pmk_len
<= PMK_MAX_LEN
&&
7639 nla_put(msg
, NL80211_ATTR_PMK
, params
->pmk_len
, params
->pmk
))) {
7644 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
7648 static int nl80211_add_pmkid(void *priv
, struct wpa_pmkid_params
*params
)
7650 struct i802_bss
*bss
= priv
;
7654 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
,
7655 MAC2STR(params
->bssid
));
7656 else if (params
->fils_cache_id
&& params
->ssid_len
) {
7657 wpa_printf(MSG_DEBUG
,
7658 "nl80211: Add PMKSA for cache id %02x%02x SSID %s",
7659 params
->fils_cache_id
[0], params
->fils_cache_id
[1],
7660 wpa_ssid_txt(params
->ssid
, params
->ssid_len
));
7663 ret
= nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, params
);
7665 wpa_printf(MSG_DEBUG
,
7666 "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)",
7667 ret
, strerror(-ret
));
7674 static int nl80211_remove_pmkid(void *priv
, struct wpa_pmkid_params
*params
)
7676 struct i802_bss
*bss
= priv
;
7680 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
7681 MAC2STR(params
->bssid
));
7682 else if (params
->fils_cache_id
&& params
->ssid_len
) {
7683 wpa_printf(MSG_DEBUG
,
7684 "nl80211: Delete PMKSA for cache id %02x%02x SSID %s",
7685 params
->fils_cache_id
[0], params
->fils_cache_id
[1],
7686 wpa_ssid_txt(params
->ssid
, params
->ssid_len
));
7689 ret
= nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, params
);
7691 wpa_printf(MSG_DEBUG
,
7692 "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)",
7693 ret
, strerror(-ret
));
7700 static int nl80211_flush_pmkid(void *priv
)
7702 struct i802_bss
*bss
= priv
;
7705 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
7706 msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_FLUSH_PMKSA
);
7709 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
7713 static void clean_survey_results(struct survey_results
*survey_results
)
7715 struct freq_survey
*survey
, *tmp
;
7717 if (dl_list_empty(&survey_results
->survey_list
))
7720 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
7721 struct freq_survey
, list
) {
7722 dl_list_del(&survey
->list
);
7728 static void add_survey(struct nlattr
**sinfo
, u32 ifidx
,
7729 struct dl_list
*survey_list
)
7731 struct freq_survey
*survey
;
7733 survey
= os_zalloc(sizeof(struct freq_survey
));
7737 survey
->ifidx
= ifidx
;
7738 survey
->freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
7741 if (sinfo
[NL80211_SURVEY_INFO_NOISE
]) {
7742 survey
->nf
= (int8_t)
7743 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
7744 survey
->filled
|= SURVEY_HAS_NF
;
7747 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]) {
7748 survey
->channel_time
=
7749 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]);
7750 survey
->filled
|= SURVEY_HAS_CHAN_TIME
;
7753 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]) {
7754 survey
->channel_time_busy
=
7755 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]);
7756 survey
->filled
|= SURVEY_HAS_CHAN_TIME_BUSY
;
7759 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]) {
7760 survey
->channel_time_rx
=
7761 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]);
7762 survey
->filled
|= SURVEY_HAS_CHAN_TIME_RX
;
7765 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]) {
7766 survey
->channel_time_tx
=
7767 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]);
7768 survey
->filled
|= SURVEY_HAS_CHAN_TIME_TX
;
7771 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)",
7774 (unsigned long int) survey
->channel_time
,
7775 (unsigned long int) survey
->channel_time_busy
,
7776 (unsigned long int) survey
->channel_time_tx
,
7777 (unsigned long int) survey
->channel_time_rx
,
7780 dl_list_add_tail(survey_list
, &survey
->list
);
7784 static int check_survey_ok(struct nlattr
**sinfo
, u32 surveyed_freq
,
7785 unsigned int freq_filter
)
7790 return freq_filter
== surveyed_freq
;
7794 static int survey_handler(struct nl_msg
*msg
, void *arg
)
7796 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
7797 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
7798 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
7799 struct survey_results
*survey_results
;
7800 u32 surveyed_freq
= 0;
7803 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
7804 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
7805 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
7808 survey_results
= (struct survey_results
*) arg
;
7810 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
7811 genlmsg_attrlen(gnlh
, 0), NULL
);
7813 if (!tb
[NL80211_ATTR_IFINDEX
])
7816 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
7818 if (!tb
[NL80211_ATTR_SURVEY_INFO
])
7821 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
7822 tb
[NL80211_ATTR_SURVEY_INFO
],
7826 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) {
7827 wpa_printf(MSG_ERROR
, "nl80211: Invalid survey data");
7831 surveyed_freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
7833 if (!check_survey_ok(sinfo
, surveyed_freq
,
7834 survey_results
->freq_filter
))
7837 if (survey_results
->freq_filter
&&
7838 survey_results
->freq_filter
!= surveyed_freq
) {
7839 wpa_printf(MSG_EXCESSIVE
, "nl80211: Ignoring survey data for freq %d MHz",
7844 add_survey(sinfo
, ifidx
, &survey_results
->survey_list
);
7850 static int wpa_driver_nl80211_get_survey(void *priv
, unsigned int freq
)
7852 struct i802_bss
*bss
= priv
;
7853 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7856 union wpa_event_data data
;
7857 struct survey_results
*survey_results
;
7859 os_memset(&data
, 0, sizeof(data
));
7860 survey_results
= &data
.survey_results
;
7862 dl_list_init(&survey_results
->survey_list
);
7864 msg
= nl80211_drv_msg(drv
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
7869 data
.survey_results
.freq_filter
= freq
;
7872 wpa_printf(MSG_DEBUG
, "nl80211: Fetch survey data");
7873 err
= send_and_recv_msgs(drv
, msg
, survey_handler
,
7878 wpa_printf(MSG_ERROR
, "nl80211: Failed to process survey data");
7880 wpa_supplicant_event(drv
->ctx
, EVENT_SURVEY
, &data
);
7882 clean_survey_results(survey_results
);
7887 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, size_t kek_len
,
7888 const u8
*kck
, size_t kck_len
,
7889 const u8
*replay_ctr
)
7891 struct i802_bss
*bss
= priv
;
7892 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7893 struct nlattr
*replay_nested
;
7897 if (!drv
->set_rekey_offload
)
7900 wpa_printf(MSG_DEBUG
, "nl80211: Set rekey offload");
7901 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
)) ||
7902 !(replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
)) ||
7903 nla_put(msg
, NL80211_REKEY_DATA_KEK
, kek_len
, kek
) ||
7904 (kck_len
&& nla_put(msg
, NL80211_REKEY_DATA_KCK
, kck_len
, kck
)) ||
7905 nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
7907 nl80211_nlmsg_clear(msg
);
7912 nla_nest_end(msg
, replay_nested
);
7914 ret
= send_and_recv_msgs(drv
, msg
, NULL
, (void *) -1);
7915 if (ret
== -EOPNOTSUPP
) {
7916 wpa_printf(MSG_DEBUG
,
7917 "nl80211: Driver does not support rekey offload");
7918 drv
->set_rekey_offload
= 0;
7923 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
7924 const u8
*addr
, int qos
)
7926 /* send data frame to poll STA and check whether
7927 * this frame is ACKed */
7929 struct ieee80211_hdr hdr
;
7931 } STRUCT_PACKED nulldata
;
7934 /* Send data frame to poll STA and check whether this frame is ACKed */
7936 os_memset(&nulldata
, 0, sizeof(nulldata
));
7939 nulldata
.hdr
.frame_control
=
7940 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7941 WLAN_FC_STYPE_QOS_NULL
);
7942 size
= sizeof(nulldata
);
7944 nulldata
.hdr
.frame_control
=
7945 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
7946 WLAN_FC_STYPE_NULLFUNC
);
7947 size
= sizeof(struct ieee80211_hdr
);
7950 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
7951 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
7952 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
7953 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
7955 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
7957 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
7961 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
7964 struct i802_bss
*bss
= priv
;
7965 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7969 if (!drv
->poll_command_supported
) {
7970 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
7974 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_PROBE_CLIENT
)) ||
7975 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
7980 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7982 wpa_printf(MSG_DEBUG
, "nl80211: Client probe request for "
7983 MACSTR
" failed: ret=%d (%s)",
7984 MAC2STR(addr
), ret
, strerror(-ret
));
7989 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
7993 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_SET_POWER_SAVE
)) ||
7994 nla_put_u32(msg
, NL80211_ATTR_PS_STATE
,
7995 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
)) {
7999 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
8003 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
8006 struct i802_bss
*bss
= priv
;
8008 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
8009 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
8011 if (opp_ps
!= -1 || ctwindow
!= -1) {
8013 wpa_driver_set_p2p_ps(priv
, legacy_ps
, opp_ps
, ctwindow
);
8014 #else /* ANDROID_P2P */
8015 return -1; /* Not yet supported */
8016 #endif /* ANDROID_P2P */
8019 if (legacy_ps
== -1)
8021 if (legacy_ps
!= 0 && legacy_ps
!= 1)
8022 return -1; /* Not yet supported */
8024 return nl80211_set_power_save(bss
, legacy_ps
);
8028 static int nl80211_start_radar_detection(void *priv
,
8029 struct hostapd_freq_params
*freq
)
8031 struct i802_bss
*bss
= priv
;
8032 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8036 wpa_printf(MSG_DEBUG
, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
8037 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
8038 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
8040 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_RADAR
)) {
8041 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support radar "
8046 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_RADAR_DETECT
)) ||
8047 nl80211_put_freq_params(msg
, freq
) < 0) {
8052 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8055 wpa_printf(MSG_DEBUG
, "nl80211: Failed to start radar detection: "
8056 "%d (%s)", ret
, strerror(-ret
));
8062 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
8063 u8 dialog_token
, u16 status_code
,
8064 u32 peer_capab
, int initiator
, const u8
*buf
,
8067 struct i802_bss
*bss
= priv
;
8068 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8071 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8077 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_MGMT
)) ||
8078 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
8079 nla_put_u8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
) ||
8080 nla_put_u8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
) ||
8081 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
))
8085 * The internal enum tdls_peer_capability definition is
8086 * currently identical with the nl80211 enum
8087 * nl80211_tdls_peer_capability, so no conversion is needed
8090 if (nla_put_u32(msg
, NL80211_ATTR_TDLS_PEER_CAPABILITY
,
8095 nla_put_flag(msg
, NL80211_ATTR_TDLS_INITIATOR
)) ||
8096 nla_put(msg
, NL80211_ATTR_IE
, len
, buf
))
8099 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8107 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
8109 struct i802_bss
*bss
= priv
;
8110 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8112 enum nl80211_tdls_operation nl80211_oper
;
8115 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
8119 case TDLS_DISCOVERY_REQ
:
8120 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
8123 nl80211_oper
= NL80211_TDLS_SETUP
;
8126 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
8128 case TDLS_ENABLE_LINK
:
8129 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
8131 case TDLS_DISABLE_LINK
:
8132 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
8142 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_TDLS_OPER
)) ||
8143 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
) ||
8144 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
)) {
8149 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8150 wpa_printf(MSG_DEBUG
, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR
8151 " --> res=%d (%s)", nl80211_oper
, MAC2STR(peer
), res
,
8158 nl80211_tdls_enable_channel_switch(void *priv
, const u8
*addr
, u8 oper_class
,
8159 const struct hostapd_freq_params
*params
)
8161 struct i802_bss
*bss
= priv
;
8162 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8166 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
8167 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
8170 wpa_printf(MSG_DEBUG
, "nl80211: Enable TDLS channel switch " MACSTR
8171 " oper_class=%u freq=%u",
8172 MAC2STR(addr
), oper_class
, params
->freq
);
8173 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH
);
8175 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8176 nla_put_u8(msg
, NL80211_ATTR_OPER_CLASS
, oper_class
) ||
8177 (ret
= nl80211_put_freq_params(msg
, params
))) {
8179 wpa_printf(MSG_DEBUG
, "nl80211: Could not build TDLS chan switch");
8183 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8188 nl80211_tdls_disable_channel_switch(void *priv
, const u8
*addr
)
8190 struct i802_bss
*bss
= priv
;
8191 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8194 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
) ||
8195 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
))
8198 wpa_printf(MSG_DEBUG
, "nl80211: Disable TDLS channel switch " MACSTR
,
8200 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
);
8202 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
8204 wpa_printf(MSG_DEBUG
,
8205 "nl80211: Could not build TDLS cancel chan switch");
8209 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8212 #endif /* CONFIG TDLS */
8215 static int driver_nl80211_set_key(const char *ifname
, void *priv
,
8216 enum wpa_alg alg
, const u8
*addr
,
8217 int key_idx
, int set_tx
,
8218 const u8
*seq
, size_t seq_len
,
8219 const u8
*key
, size_t key_len
)
8221 struct i802_bss
*bss
= priv
;
8222 return wpa_driver_nl80211_set_key(ifname
, bss
, alg
, addr
, key_idx
,
8223 set_tx
, seq
, seq_len
, key
, key_len
);
8227 static int driver_nl80211_scan2(void *priv
,
8228 struct wpa_driver_scan_params
*params
)
8230 struct i802_bss
*bss
= priv
;
8231 #ifdef CONFIG_DRIVER_NL80211_QCA
8232 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8235 * Do a vendor specific scan if possible. If only_new_results is
8236 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
8237 * cannot be achieved through a vendor scan. The below condition may
8238 * need to be modified if new scan flags are added in the future whose
8239 * functionality can only be achieved through a normal scan.
8241 if (drv
->scan_vendor_cmd_avail
&& !params
->only_new_results
)
8242 return wpa_driver_nl80211_vendor_scan(bss
, params
);
8243 #endif /* CONFIG_DRIVER_NL80211_QCA */
8244 return wpa_driver_nl80211_scan(bss
, params
);
8248 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
8251 struct i802_bss
*bss
= priv
;
8252 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
8256 static int driver_nl80211_authenticate(void *priv
,
8257 struct wpa_driver_auth_params
*params
)
8259 struct i802_bss
*bss
= priv
;
8260 return wpa_driver_nl80211_authenticate(bss
, params
);
8264 static void driver_nl80211_deinit(void *priv
)
8266 struct i802_bss
*bss
= priv
;
8267 wpa_driver_nl80211_deinit(bss
);
8271 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
8274 struct i802_bss
*bss
= priv
;
8275 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
8279 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
8280 size_t data_len
, int noack
,
8282 const u16
*csa_offs
, size_t csa_offs_len
)
8284 struct i802_bss
*bss
= priv
;
8285 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
8286 freq
, 0, 0, 0, csa_offs
,
8291 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
8293 struct i802_bss
*bss
= priv
;
8294 return wpa_driver_nl80211_sta_remove(bss
, addr
, -1, 0);
8298 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
8299 const char *ifname
, int vlan_id
)
8301 struct i802_bss
*bss
= priv
;
8302 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
8306 static int driver_nl80211_read_sta_data(void *priv
,
8307 struct hostap_sta_driver_data
*data
,
8310 struct i802_bss
*bss
= priv
;
8312 os_memset(data
, 0, sizeof(*data
));
8313 return i802_read_sta_data(bss
, data
, addr
);
8317 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
8318 unsigned int wait_time
,
8319 const u8
*dst
, const u8
*src
,
8321 const u8
*data
, size_t data_len
,
8324 struct i802_bss
*bss
= priv
;
8325 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
8326 bssid
, data
, data_len
, no_cck
);
8330 static int driver_nl80211_probe_req_report(void *priv
, int report
)
8332 struct i802_bss
*bss
= priv
;
8333 return wpa_driver_nl80211_probe_req_report(bss
, report
);
8337 static int wpa_driver_nl80211_update_ft_ies(void *priv
, const u8
*md
,
8338 const u8
*ies
, size_t ies_len
)
8342 struct i802_bss
*bss
= priv
;
8343 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8344 u16 mdid
= WPA_GET_LE16(md
);
8346 wpa_printf(MSG_DEBUG
, "nl80211: Updating FT IEs");
8347 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_UPDATE_FT_IES
)) ||
8348 nla_put(msg
, NL80211_ATTR_IE
, ies_len
, ies
) ||
8349 nla_put_u16(msg
, NL80211_ATTR_MDID
, mdid
)) {
8354 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8356 wpa_printf(MSG_DEBUG
, "nl80211: update_ft_ies failed "
8357 "err=%d (%s)", ret
, strerror(-ret
));
8364 static const u8
* wpa_driver_nl80211_get_macaddr(void *priv
)
8366 struct i802_bss
*bss
= priv
;
8367 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8369 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
8376 static const char * scan_state_str(enum scan_states scan_state
)
8378 switch (scan_state
) {
8381 case SCAN_REQUESTED
:
8382 return "SCAN_REQUESTED";
8384 return "SCAN_STARTED";
8385 case SCAN_COMPLETED
:
8386 return "SCAN_COMPLETED";
8388 return "SCAN_ABORTED";
8389 case SCHED_SCAN_STARTED
:
8390 return "SCHED_SCAN_STARTED";
8391 case SCHED_SCAN_STOPPED
:
8392 return "SCHED_SCAN_STOPPED";
8393 case SCHED_SCAN_RESULTS
:
8394 return "SCHED_SCAN_RESULTS";
8401 static int wpa_driver_nl80211_status(void *priv
, char *buf
, size_t buflen
)
8403 struct i802_bss
*bss
= priv
;
8404 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8411 res
= os_snprintf(pos
, end
- pos
,
8423 bss
->beacon_set
? "beacon_set=1\n" : "",
8424 bss
->added_if_into_bridge
?
8425 "added_if_into_bridge=1\n" : "",
8426 bss
->added_bridge
? "added_bridge=1\n" : "",
8427 bss
->in_deinit
? "in_deinit=1\n" : "",
8428 bss
->if_dynamic
? "if_dynamic=1\n" : "");
8429 if (os_snprintf_error(end
- pos
, res
))
8433 if (bss
->wdev_id_set
) {
8434 res
= os_snprintf(pos
, end
- pos
, "wdev_id=%llu\n",
8435 (unsigned long long) bss
->wdev_id
);
8436 if (os_snprintf_error(end
- pos
, res
))
8441 res
= os_snprintf(pos
, end
- pos
,
8443 "perm_addr=" MACSTR
"\n"
8447 "auth_bssid=" MACSTR
"\n"
8448 "auth_attempt_bssid=" MACSTR
"\n"
8449 "bssid=" MACSTR
"\n"
8450 "prev_bssid=" MACSTR
"\n"
8454 "monitor_ifidx=%d\n"
8455 "monitor_refcount=%d\n"
8456 "last_mgmt_freq=%u\n"
8457 "eapol_tx_sock=%d\n"
8458 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
8460 MAC2STR(drv
->perm_addr
),
8463 scan_state_str(drv
->scan_state
),
8464 MAC2STR(drv
->auth_bssid
),
8465 MAC2STR(drv
->auth_attempt_bssid
),
8466 MAC2STR(drv
->bssid
),
8467 MAC2STR(drv
->prev_bssid
),
8472 drv
->monitor_refcount
,
8473 drv
->last_mgmt_freq
,
8475 drv
->ignore_if_down_event
?
8476 "ignore_if_down_event=1\n" : "",
8477 drv
->scan_complete_events
?
8478 "scan_complete_events=1\n" : "",
8479 drv
->disabled_11b_rates
?
8480 "disabled_11b_rates=1\n" : "",
8481 drv
->pending_remain_on_chan
?
8482 "pending_remain_on_chan=1\n" : "",
8483 drv
->in_interface_list
? "in_interface_list=1\n" : "",
8484 drv
->device_ap_sme
? "device_ap_sme=1\n" : "",
8485 drv
->poll_command_supported
?
8486 "poll_command_supported=1\n" : "",
8487 drv
->data_tx_status
? "data_tx_status=1\n" : "",
8488 drv
->scan_for_auth
? "scan_for_auth=1\n" : "",
8489 drv
->retry_auth
? "retry_auth=1\n" : "",
8490 drv
->use_monitor
? "use_monitor=1\n" : "",
8491 drv
->ignore_next_local_disconnect
?
8492 "ignore_next_local_disconnect=1\n" : "",
8493 drv
->ignore_next_local_deauth
?
8494 "ignore_next_local_deauth=1\n" : "");
8495 if (os_snprintf_error(end
- pos
, res
))
8499 if (drv
->has_capability
) {
8500 res
= os_snprintf(pos
, end
- pos
,
8501 "capa.key_mgmt=0x%x\n"
8504 "capa.flags=0x%llx\n"
8505 "capa.rrm_flags=0x%x\n"
8506 "capa.max_scan_ssids=%d\n"
8507 "capa.max_sched_scan_ssids=%d\n"
8508 "capa.sched_scan_supported=%d\n"
8509 "capa.max_match_sets=%d\n"
8510 "capa.max_remain_on_chan=%u\n"
8511 "capa.max_stations=%u\n"
8512 "capa.probe_resp_offloads=0x%x\n"
8513 "capa.max_acl_mac_addrs=%u\n"
8514 "capa.num_multichan_concurrent=%u\n"
8515 "capa.mac_addr_rand_sched_scan_supported=%d\n"
8516 "capa.mac_addr_rand_scan_supported=%d\n"
8517 "capa.conc_capab=%u\n"
8518 "capa.max_conc_chan_2_4=%u\n"
8519 "capa.max_conc_chan_5_0=%u\n"
8520 "capa.max_sched_scan_plans=%u\n"
8521 "capa.max_sched_scan_plan_interval=%u\n"
8522 "capa.max_sched_scan_plan_iterations=%u\n",
8526 (unsigned long long) drv
->capa
.flags
,
8527 drv
->capa
.rrm_flags
,
8528 drv
->capa
.max_scan_ssids
,
8529 drv
->capa
.max_sched_scan_ssids
,
8530 drv
->capa
.sched_scan_supported
,
8531 drv
->capa
.max_match_sets
,
8532 drv
->capa
.max_remain_on_chan
,
8533 drv
->capa
.max_stations
,
8534 drv
->capa
.probe_resp_offloads
,
8535 drv
->capa
.max_acl_mac_addrs
,
8536 drv
->capa
.num_multichan_concurrent
,
8537 drv
->capa
.mac_addr_rand_sched_scan_supported
,
8538 drv
->capa
.mac_addr_rand_scan_supported
,
8539 drv
->capa
.conc_capab
,
8540 drv
->capa
.max_conc_chan_2_4
,
8541 drv
->capa
.max_conc_chan_5_0
,
8542 drv
->capa
.max_sched_scan_plans
,
8543 drv
->capa
.max_sched_scan_plan_interval
,
8544 drv
->capa
.max_sched_scan_plan_iterations
);
8545 if (os_snprintf_error(end
- pos
, res
))
8554 static int set_beacon_data(struct nl_msg
*msg
, struct beacon_data
*settings
)
8556 if ((settings
->head
&&
8557 nla_put(msg
, NL80211_ATTR_BEACON_HEAD
,
8558 settings
->head_len
, settings
->head
)) ||
8560 nla_put(msg
, NL80211_ATTR_BEACON_TAIL
,
8561 settings
->tail_len
, settings
->tail
)) ||
8562 (settings
->beacon_ies
&&
8563 nla_put(msg
, NL80211_ATTR_IE
,
8564 settings
->beacon_ies_len
, settings
->beacon_ies
)) ||
8565 (settings
->proberesp_ies
&&
8566 nla_put(msg
, NL80211_ATTR_IE_PROBE_RESP
,
8567 settings
->proberesp_ies_len
, settings
->proberesp_ies
)) ||
8568 (settings
->assocresp_ies
&&
8569 nla_put(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
8570 settings
->assocresp_ies_len
, settings
->assocresp_ies
)) ||
8571 (settings
->probe_resp
&&
8572 nla_put(msg
, NL80211_ATTR_PROBE_RESP
,
8573 settings
->probe_resp_len
, settings
->probe_resp
)))
8580 static int nl80211_switch_channel(void *priv
, struct csa_settings
*settings
)
8583 struct i802_bss
*bss
= priv
;
8584 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8585 struct nlattr
*beacon_csa
;
8587 int csa_off_len
= 0;
8590 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
8591 settings
->cs_count
, settings
->block_tx
,
8592 settings
->freq_params
.freq
, settings
->freq_params
.bandwidth
,
8593 settings
->freq_params
.center_freq1
,
8594 settings
->freq_params
.center_freq2
);
8596 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
8597 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support channel switch command");
8601 if ((drv
->nlmode
!= NL80211_IFTYPE_AP
) &&
8602 (drv
->nlmode
!= NL80211_IFTYPE_P2P_GO
))
8606 * Remove empty counters, assuming Probe Response and Beacon frame
8607 * counters match. This implementation assumes that there are only two
8610 if (settings
->counter_offset_beacon
[0] &&
8611 !settings
->counter_offset_beacon
[1]) {
8613 } else if (settings
->counter_offset_beacon
[1] &&
8614 !settings
->counter_offset_beacon
[0]) {
8616 settings
->counter_offset_beacon
[0] =
8617 settings
->counter_offset_beacon
[1];
8618 settings
->counter_offset_presp
[0] =
8619 settings
->counter_offset_presp
[1];
8620 } else if (settings
->counter_offset_beacon
[1] &&
8621 settings
->counter_offset_beacon
[0]) {
8624 wpa_printf(MSG_ERROR
, "nl80211: No CSA counters provided");
8628 /* Check CSA counters validity */
8629 if (drv
->capa
.max_csa_counters
&&
8630 csa_off_len
> drv
->capa
.max_csa_counters
) {
8631 wpa_printf(MSG_ERROR
,
8632 "nl80211: Too many CSA counters provided");
8636 if (!settings
->beacon_csa
.tail
)
8639 for (i
= 0; i
< csa_off_len
; i
++) {
8640 u16 csa_c_off_bcn
= settings
->counter_offset_beacon
[i
];
8641 u16 csa_c_off_presp
= settings
->counter_offset_presp
[i
];
8643 if ((settings
->beacon_csa
.tail_len
<= csa_c_off_bcn
) ||
8644 (settings
->beacon_csa
.tail
[csa_c_off_bcn
] !=
8645 settings
->cs_count
))
8648 if (settings
->beacon_csa
.probe_resp
&&
8649 ((settings
->beacon_csa
.probe_resp_len
<=
8651 (settings
->beacon_csa
.probe_resp
[csa_c_off_presp
] !=
8652 settings
->cs_count
)))
8656 if (!(msg
= nl80211_bss_msg(bss
, 0, NL80211_CMD_CHANNEL_SWITCH
)) ||
8657 nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
,
8658 settings
->cs_count
) ||
8659 (ret
= nl80211_put_freq_params(msg
, &settings
->freq_params
)) ||
8660 (settings
->block_tx
&&
8661 nla_put_flag(msg
, NL80211_ATTR_CH_SWITCH_BLOCK_TX
)))
8664 /* beacon_after params */
8665 ret
= set_beacon_data(msg
, &settings
->beacon_after
);
8669 /* beacon_csa params */
8670 beacon_csa
= nla_nest_start(msg
, NL80211_ATTR_CSA_IES
);
8674 ret
= set_beacon_data(msg
, &settings
->beacon_csa
);
8678 if (nla_put(msg
, NL80211_ATTR_CSA_C_OFF_BEACON
,
8679 csa_off_len
* sizeof(u16
),
8680 settings
->counter_offset_beacon
) ||
8681 (settings
->beacon_csa
.probe_resp
&&
8682 nla_put(msg
, NL80211_ATTR_CSA_C_OFF_PRESP
,
8683 csa_off_len
* sizeof(u16
),
8684 settings
->counter_offset_presp
)))
8687 nla_nest_end(msg
, beacon_csa
);
8688 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8690 wpa_printf(MSG_DEBUG
, "nl80211: switch_channel failed err=%d (%s)",
8691 ret
, strerror(-ret
));
8699 wpa_printf(MSG_DEBUG
, "nl80211: Could not build channel switch request");
8704 static int nl80211_add_ts(void *priv
, u8 tsid
, const u8
*addr
,
8705 u8 user_priority
, u16 admitted_time
)
8707 struct i802_bss
*bss
= priv
;
8708 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8712 wpa_printf(MSG_DEBUG
,
8713 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
8714 tsid
, admitted_time
, user_priority
);
8716 if (!is_sta_interface(drv
->nlmode
))
8719 msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_ADD_TX_TS
);
8721 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
8722 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8723 nla_put_u8(msg
, NL80211_ATTR_USER_PRIO
, user_priority
) ||
8724 nla_put_u16(msg
, NL80211_ATTR_ADMITTED_TIME
, admitted_time
)) {
8729 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8731 wpa_printf(MSG_DEBUG
, "nl80211: add_ts failed err=%d (%s)",
8732 ret
, strerror(-ret
));
8737 static int nl80211_del_ts(void *priv
, u8 tsid
, const u8
*addr
)
8739 struct i802_bss
*bss
= priv
;
8740 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8744 wpa_printf(MSG_DEBUG
, "nl80211: del_ts request: tsid=%u", tsid
);
8746 if (!is_sta_interface(drv
->nlmode
))
8749 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_DEL_TX_TS
)) ||
8750 nla_put_u8(msg
, NL80211_ATTR_TSID
, tsid
) ||
8751 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) {
8756 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8758 wpa_printf(MSG_DEBUG
, "nl80211: del_ts failed err=%d (%s)",
8759 ret
, strerror(-ret
));
8764 #ifdef CONFIG_TESTING_OPTIONS
8765 static int cmd_reply_handler(struct nl_msg
*msg
, void *arg
)
8767 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8768 struct wpabuf
*buf
= arg
;
8773 if ((size_t) genlmsg_attrlen(gnlh
, 0) > wpabuf_tailroom(buf
)) {
8774 wpa_printf(MSG_INFO
, "nl80211: insufficient buffer space for reply");
8778 wpabuf_put_data(buf
, genlmsg_attrdata(gnlh
, 0),
8779 genlmsg_attrlen(gnlh
, 0));
8783 #endif /* CONFIG_TESTING_OPTIONS */
8786 static int vendor_reply_handler(struct nl_msg
*msg
, void *arg
)
8788 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8789 struct nlattr
*nl_vendor_reply
, *nl
;
8790 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8791 struct wpabuf
*buf
= arg
;
8797 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8798 genlmsg_attrlen(gnlh
, 0), NULL
);
8799 nl_vendor_reply
= tb
[NL80211_ATTR_VENDOR_DATA
];
8801 if (!nl_vendor_reply
)
8804 if ((size_t) nla_len(nl_vendor_reply
) > wpabuf_tailroom(buf
)) {
8805 wpa_printf(MSG_INFO
, "nl80211: Vendor command: insufficient buffer space for reply");
8809 nla_for_each_nested(nl
, nl_vendor_reply
, rem
) {
8810 wpabuf_put_data(buf
, nla_data(nl
), nla_len(nl
));
8817 static int nl80211_vendor_cmd(void *priv
, unsigned int vendor_id
,
8818 unsigned int subcmd
, const u8
*data
,
8819 size_t data_len
, struct wpabuf
*buf
)
8821 struct i802_bss
*bss
= priv
;
8822 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8826 #ifdef CONFIG_TESTING_OPTIONS
8827 if (vendor_id
== 0xffffffff) {
8828 msg
= nlmsg_alloc();
8832 nl80211_cmd(drv
, msg
, 0, subcmd
);
8833 if (nlmsg_append(msg
, (void *) data
, data_len
, NLMSG_ALIGNTO
) <
8836 ret
= send_and_recv_msgs(drv
, msg
, cmd_reply_handler
, buf
);
8838 wpa_printf(MSG_DEBUG
, "nl80211: command failed err=%d",
8842 #endif /* CONFIG_TESTING_OPTIONS */
8844 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_VENDOR
)) ||
8845 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, vendor_id
) ||
8846 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
, subcmd
) ||
8848 nla_put(msg
, NL80211_ATTR_VENDOR_DATA
, data_len
, data
)))
8851 ret
= send_and_recv_msgs(drv
, msg
, vendor_reply_handler
, buf
);
8853 wpa_printf(MSG_DEBUG
, "nl80211: vendor command failed err=%d",
8863 static int nl80211_set_qos_map(void *priv
, const u8
*qos_map_set
,
8866 struct i802_bss
*bss
= priv
;
8867 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8871 wpa_hexdump(MSG_DEBUG
, "nl80211: Setting QoS Map",
8872 qos_map_set
, qos_map_set_len
);
8874 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_SET_QOS_MAP
)) ||
8875 nla_put(msg
, NL80211_ATTR_QOS_MAP
, qos_map_set_len
, qos_map_set
)) {
8880 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8882 wpa_printf(MSG_DEBUG
, "nl80211: Setting QoS Map failed");
8888 static int nl80211_set_wowlan(void *priv
,
8889 const struct wowlan_triggers
*triggers
)
8891 struct i802_bss
*bss
= priv
;
8892 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8894 struct nlattr
*wowlan_triggers
;
8897 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan");
8899 if (!(msg
= nl80211_cmd_msg(bss
, 0, NL80211_CMD_SET_WOWLAN
)) ||
8900 !(wowlan_triggers
= nla_nest_start(msg
,
8901 NL80211_ATTR_WOWLAN_TRIGGERS
)) ||
8903 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
8904 (triggers
->disconnect
&&
8905 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
8906 (triggers
->magic_pkt
&&
8907 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
8908 (triggers
->gtk_rekey_failure
&&
8909 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
8910 (triggers
->eap_identity_req
&&
8911 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
8912 (triggers
->four_way_handshake
&&
8913 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
8914 (triggers
->rfkill_release
&&
8915 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))) {
8920 nla_nest_end(msg
, wowlan_triggers
);
8922 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8924 wpa_printf(MSG_DEBUG
, "nl80211: Setting wowlan failed");
8930 #ifdef CONFIG_DRIVER_NL80211_QCA
8931 static int nl80211_roaming(void *priv
, int allowed
, const u8
*bssid
)
8933 struct i802_bss
*bss
= priv
;
8934 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8936 struct nlattr
*params
;
8938 wpa_printf(MSG_DEBUG
, "nl80211: Roaming policy: allowed=%d", allowed
);
8940 if (!drv
->roaming_vendor_cmd_avail
) {
8941 wpa_printf(MSG_DEBUG
,
8942 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
8946 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8947 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8948 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8949 QCA_NL80211_VENDOR_SUBCMD_ROAMING
) ||
8950 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8951 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY
,
8952 allowed
? QCA_ROAMING_ALLOWED_WITHIN_ESS
:
8953 QCA_ROAMING_NOT_ALLOWED
) ||
8955 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_MAC_ADDR
, ETH_ALEN
, bssid
))) {
8959 nla_nest_end(msg
, params
);
8961 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8965 static int nl80211_disable_fils(void *priv
, int disable
)
8967 struct i802_bss
*bss
= priv
;
8968 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8970 struct nlattr
*params
;
8972 wpa_printf(MSG_DEBUG
, "nl80211: Disable FILS=%d", disable
);
8974 if (!drv
->set_wifi_conf_vendor_cmd_avail
)
8977 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
8978 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
8979 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
8980 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION
) ||
8981 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
8982 nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS
,
8987 nla_nest_end(msg
, params
);
8989 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8993 /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */
8994 #define WPA_SUPPLICANT_CLIENT_ID 1
8996 static int nl80211_set_bssid_blacklist(void *priv
, unsigned int num_bssid
,
8999 struct i802_bss
*bss
= priv
;
9000 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9002 struct nlattr
*params
, *nlbssids
, *attr
;
9005 wpa_printf(MSG_DEBUG
, "nl80211: Set blacklist BSSID (num=%u)",
9008 if (!drv
->roam_vendor_cmd_avail
)
9011 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9012 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9013 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9014 QCA_NL80211_VENDOR_SUBCMD_ROAM
) ||
9015 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9016 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD
,
9017 QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID
) ||
9018 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID
,
9019 WPA_SUPPLICANT_CLIENT_ID
) ||
9021 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID
,
9025 nlbssids
= nla_nest_start(
9026 msg
, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS
);
9030 for (i
= 0; i
< num_bssid
; i
++) {
9031 attr
= nla_nest_start(msg
, i
);
9035 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID
,
9036 ETH_ALEN
, &bssid
[i
* ETH_ALEN
]))
9038 wpa_printf(MSG_DEBUG
, "nl80211: BSSID[%u]: " MACSTR
, i
,
9039 MAC2STR(&bssid
[i
* ETH_ALEN
]));
9040 nla_nest_end(msg
, attr
);
9042 nla_nest_end(msg
, nlbssids
);
9043 nla_nest_end(msg
, params
);
9045 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9052 #endif /* CONFIG_DRIVER_NL80211_QCA */
9055 static int nl80211_set_mac_addr(void *priv
, const u8
*addr
)
9057 struct i802_bss
*bss
= priv
;
9058 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9059 int new_addr
= addr
!= NULL
;
9065 addr
= drv
->perm_addr
;
9067 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0) < 0)
9070 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
, addr
) < 0)
9072 wpa_printf(MSG_DEBUG
,
9073 "nl80211: failed to set_mac_addr for %s to " MACSTR
,
9074 bss
->ifname
, MAC2STR(addr
));
9075 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
,
9077 wpa_printf(MSG_DEBUG
,
9078 "nl80211: Could not restore interface UP after failed set_mac_addr");
9083 wpa_printf(MSG_DEBUG
, "nl80211: set_mac_addr for %s to " MACSTR
,
9084 bss
->ifname
, MAC2STR(addr
));
9085 drv
->addr_changed
= new_addr
;
9086 os_memcpy(bss
->addr
, addr
, ETH_ALEN
);
9088 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1) < 0)
9090 wpa_printf(MSG_DEBUG
,
9091 "nl80211: Could not restore interface UP after set_mac_addr");
9100 static int wpa_driver_nl80211_init_mesh(void *priv
)
9102 if (wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_MESH_POINT
)) {
9103 wpa_printf(MSG_INFO
,
9104 "nl80211: Failed to set interface into mesh mode");
9111 static int nl80211_put_mesh_id(struct nl_msg
*msg
, const u8
*mesh_id
,
9115 wpa_hexdump_ascii(MSG_DEBUG
, " * Mesh ID (SSID)",
9116 mesh_id
, mesh_id_len
);
9117 return nla_put(msg
, NL80211_ATTR_MESH_ID
, mesh_id_len
, mesh_id
);
9124 static int nl80211_put_mesh_config(struct nl_msg
*msg
,
9125 struct wpa_driver_mesh_bss_params
*params
)
9127 struct nlattr
*container
;
9129 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
9133 if (((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS
) &&
9134 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
9135 params
->auto_plinks
)) ||
9136 ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS
) &&
9137 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
9138 params
->max_peer_links
)) ||
9139 ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD
) &&
9140 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
9141 params
->rssi_threshold
)))
9145 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
9146 * the timer could disconnect stations even in that case.
9148 if ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT
) &&
9149 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
9150 params
->peer_link_timeout
)) {
9151 wpa_printf(MSG_ERROR
, "nl80211: Failed to set PLINK_TIMEOUT");
9155 if ((params
->flags
& WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE
) &&
9156 nla_put_u16(msg
, NL80211_MESHCONF_HT_OPMODE
, params
->ht_opmode
)) {
9157 wpa_printf(MSG_ERROR
, "nl80211: Failed to set HT_OP_MODE");
9161 nla_nest_end(msg
, container
);
9167 static int nl80211_join_mesh(struct i802_bss
*bss
,
9168 struct wpa_driver_mesh_join_params
*params
)
9170 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9172 struct nlattr
*container
;
9175 wpa_printf(MSG_DEBUG
, "nl80211: mesh join (ifindex=%d)", drv
->ifindex
);
9176 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_JOIN_MESH
);
9178 nl80211_put_freq_params(msg
, ¶ms
->freq
) ||
9179 nl80211_put_basic_rates(msg
, params
->basic_rates
) ||
9180 nl80211_put_mesh_id(msg
, params
->meshid
, params
->meshid_len
) ||
9181 nl80211_put_beacon_int(msg
, params
->beacon_int
) ||
9182 nl80211_put_dtim_period(msg
, params
->dtim_period
))
9185 wpa_printf(MSG_DEBUG
, " * flags=%08X", params
->flags
);
9187 container
= nla_nest_start(msg
, NL80211_ATTR_MESH_SETUP
);
9192 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ies
, params
->ie_len
);
9193 if (nla_put(msg
, NL80211_MESH_SETUP_IE
, params
->ie_len
,
9197 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
9198 if (params
->flags
& WPA_DRIVER_MESH_FLAG_SAE_AUTH
) {
9199 if (nla_put_u8(msg
, NL80211_MESH_SETUP_AUTH_PROTOCOL
, 0x1) ||
9200 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AUTH
))
9203 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_AMPE
) &&
9204 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_AMPE
))
9206 if ((params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
) &&
9207 nla_put_flag(msg
, NL80211_MESH_SETUP_USERSPACE_MPM
))
9209 nla_nest_end(msg
, container
);
9211 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS
;
9212 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT
;
9213 params
->conf
.flags
|= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS
;
9214 if (nl80211_put_mesh_config(msg
, ¶ms
->conf
) < 0)
9217 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9220 wpa_printf(MSG_DEBUG
, "nl80211: mesh join failed: ret=%d (%s)",
9221 ret
, strerror(-ret
));
9225 drv
->assoc_freq
= bss
->freq
= params
->freq
.freq
;
9226 wpa_printf(MSG_DEBUG
, "nl80211: mesh join request send successfully");
9235 wpa_driver_nl80211_join_mesh(void *priv
,
9236 struct wpa_driver_mesh_join_params
*params
)
9238 struct i802_bss
*bss
= priv
;
9241 timeout
= params
->conf
.peer_link_timeout
;
9243 /* Disable kernel inactivity timer */
9244 if (params
->flags
& WPA_DRIVER_MESH_FLAG_USER_MPM
)
9245 params
->conf
.peer_link_timeout
= 0;
9247 ret
= nl80211_join_mesh(bss
, params
);
9248 if (ret
== -EINVAL
&& params
->conf
.peer_link_timeout
== 0) {
9249 wpa_printf(MSG_DEBUG
,
9250 "nl80211: Mesh join retry for peer_link_timeout");
9252 * Old kernel does not support setting
9253 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
9254 * into future from peer_link_timeout.
9256 params
->conf
.peer_link_timeout
= timeout
+ 60;
9257 ret
= nl80211_join_mesh(priv
, params
);
9260 params
->conf
.peer_link_timeout
= timeout
;
9265 static int wpa_driver_nl80211_leave_mesh(void *priv
)
9267 struct i802_bss
*bss
= priv
;
9268 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9272 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave (ifindex=%d)", drv
->ifindex
);
9273 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_LEAVE_MESH
);
9274 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9276 wpa_printf(MSG_DEBUG
, "nl80211: mesh leave failed: ret=%d (%s)",
9277 ret
, strerror(-ret
));
9279 wpa_printf(MSG_DEBUG
,
9280 "nl80211: mesh leave request send successfully");
9283 if (wpa_driver_nl80211_set_mode(drv
->first_bss
,
9284 NL80211_IFTYPE_STATION
)) {
9285 wpa_printf(MSG_INFO
,
9286 "nl80211: Failed to set interface into station mode");
9291 #endif /* CONFIG_MESH */
9294 static int wpa_driver_br_add_ip_neigh(void *priv
, u8 version
,
9295 const u8
*ipaddr
, int prefixlen
,
9298 #ifdef CONFIG_LIBNL3_ROUTE
9299 struct i802_bss
*bss
= priv
;
9300 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9301 struct rtnl_neigh
*rn
;
9302 struct nl_addr
*nl_ipaddr
= NULL
;
9303 struct nl_addr
*nl_lladdr
= NULL
;
9304 int family
, addrsize
;
9307 if (!ipaddr
|| prefixlen
== 0 || !addr
)
9310 if (bss
->br_ifindex
== 0) {
9311 wpa_printf(MSG_DEBUG
,
9312 "nl80211: bridge must be set before adding an ip neigh to it");
9316 if (!drv
->rtnl_sk
) {
9317 wpa_printf(MSG_DEBUG
,
9318 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9325 } else if (version
== 6) {
9332 rn
= rtnl_neigh_alloc();
9336 /* set the destination ip address for neigh */
9337 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
9338 if (nl_ipaddr
== NULL
) {
9339 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
9343 nl_addr_set_prefixlen(nl_ipaddr
, prefixlen
);
9344 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
9346 wpa_printf(MSG_DEBUG
,
9347 "nl80211: neigh set destination addr failed");
9351 /* set the corresponding lladdr for neigh */
9352 nl_lladdr
= nl_addr_build(AF_BRIDGE
, (u8
*) addr
, ETH_ALEN
);
9353 if (nl_lladdr
== NULL
) {
9354 wpa_printf(MSG_DEBUG
, "nl80211: neigh set lladdr failed");
9358 rtnl_neigh_set_lladdr(rn
, nl_lladdr
);
9360 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
9361 rtnl_neigh_set_state(rn
, NUD_PERMANENT
);
9363 res
= rtnl_neigh_add(drv
->rtnl_sk
, rn
, NLM_F_CREATE
);
9365 wpa_printf(MSG_DEBUG
,
9366 "nl80211: Adding bridge ip neigh failed: %s",
9371 nl_addr_put(nl_lladdr
);
9373 nl_addr_put(nl_ipaddr
);
9377 #else /* CONFIG_LIBNL3_ROUTE */
9379 #endif /* CONFIG_LIBNL3_ROUTE */
9383 static int wpa_driver_br_delete_ip_neigh(void *priv
, u8 version
,
9386 #ifdef CONFIG_LIBNL3_ROUTE
9387 struct i802_bss
*bss
= priv
;
9388 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9389 struct rtnl_neigh
*rn
;
9390 struct nl_addr
*nl_ipaddr
;
9391 int family
, addrsize
;
9400 } else if (version
== 6) {
9407 if (bss
->br_ifindex
== 0) {
9408 wpa_printf(MSG_DEBUG
,
9409 "nl80211: bridge must be set to delete an ip neigh");
9413 if (!drv
->rtnl_sk
) {
9414 wpa_printf(MSG_DEBUG
,
9415 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9419 rn
= rtnl_neigh_alloc();
9423 /* set the destination ip address for neigh */
9424 nl_ipaddr
= nl_addr_build(family
, (void *) ipaddr
, addrsize
);
9425 if (nl_ipaddr
== NULL
) {
9426 wpa_printf(MSG_DEBUG
, "nl80211: nl_ipaddr build failed");
9430 res
= rtnl_neigh_set_dst(rn
, nl_ipaddr
);
9432 wpa_printf(MSG_DEBUG
,
9433 "nl80211: neigh set destination addr failed");
9437 rtnl_neigh_set_ifindex(rn
, bss
->br_ifindex
);
9439 res
= rtnl_neigh_delete(drv
->rtnl_sk
, rn
, 0);
9441 wpa_printf(MSG_DEBUG
,
9442 "nl80211: Deleting bridge ip neigh failed: %s",
9447 nl_addr_put(nl_ipaddr
);
9451 #else /* CONFIG_LIBNL3_ROUTE */
9453 #endif /* CONFIG_LIBNL3_ROUTE */
9457 static int linux_write_system_file(const char *path
, unsigned int val
)
9462 len
= os_snprintf(buf
, sizeof(buf
), "%u\n", val
);
9463 if (os_snprintf_error(sizeof(buf
), len
))
9466 fd
= open(path
, O_WRONLY
);
9470 if (write(fd
, buf
, len
) < 0) {
9471 wpa_printf(MSG_DEBUG
,
9472 "nl80211: Failed to write Linux system file: %s with the value of %d",
9483 static const char * drv_br_port_attr_str(enum drv_br_port_attr attr
)
9486 case DRV_BR_PORT_ATTR_PROXYARP
:
9487 return "proxyarp_wifi";
9488 case DRV_BR_PORT_ATTR_HAIRPIN_MODE
:
9489 return "hairpin_mode";
9496 static int wpa_driver_br_port_set_attr(void *priv
, enum drv_br_port_attr attr
,
9499 struct i802_bss
*bss
= priv
;
9501 const char *attr_txt
;
9503 attr_txt
= drv_br_port_attr_str(attr
);
9504 if (attr_txt
== NULL
)
9507 os_snprintf(path
, sizeof(path
), "/sys/class/net/%s/brport/%s",
9508 bss
->ifname
, attr_txt
);
9510 if (linux_write_system_file(path
, val
))
9517 static const char * drv_br_net_param_str(enum drv_br_net_param param
)
9520 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
9521 return "arp_accept";
9528 static int wpa_driver_br_set_net_param(void *priv
, enum drv_br_net_param param
,
9531 struct i802_bss
*bss
= priv
;
9533 const char *param_txt
;
9536 if (param
== DRV_BR_MULTICAST_SNOOPING
) {
9537 os_snprintf(path
, sizeof(path
),
9538 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
9543 param_txt
= drv_br_net_param_str(param
);
9544 if (param_txt
== NULL
)
9548 case DRV_BR_NET_PARAM_GARP_ACCEPT
:
9555 os_snprintf(path
, sizeof(path
), "/proc/sys/net/ipv%d/conf/%s/%s",
9556 ip_version
, bss
->brname
, param_txt
);
9559 if (linux_write_system_file(path
, val
))
9566 #ifdef CONFIG_DRIVER_NL80211_QCA
9568 static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode
)
9571 case HOSTAPD_MODE_IEEE80211B
:
9572 return QCA_ACS_MODE_IEEE80211B
;
9573 case HOSTAPD_MODE_IEEE80211G
:
9574 return QCA_ACS_MODE_IEEE80211G
;
9575 case HOSTAPD_MODE_IEEE80211A
:
9576 return QCA_ACS_MODE_IEEE80211A
;
9577 case HOSTAPD_MODE_IEEE80211AD
:
9578 return QCA_ACS_MODE_IEEE80211AD
;
9579 case HOSTAPD_MODE_IEEE80211ANY
:
9580 return QCA_ACS_MODE_IEEE80211ANY
;
9587 static int add_acs_freq_list(struct nl_msg
*msg
, const int *freq_list
)
9594 len
= int_array_len(freq_list
);
9595 freqs
= os_malloc(sizeof(u32
) * len
);
9598 for (i
= 0; i
< len
; i
++)
9599 freqs
[i
] = freq_list
[i
];
9600 ret
= nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST
,
9601 sizeof(u32
) * len
, freqs
);
9607 static int wpa_driver_do_acs(void *priv
, struct drv_acs_params
*params
)
9609 struct i802_bss
*bss
= priv
;
9610 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9612 struct nlattr
*data
;
9616 mode
= hw_mode_to_qca_acs(params
->hw_mode
);
9620 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9621 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9622 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9623 QCA_NL80211_VENDOR_SUBCMD_DO_ACS
) ||
9624 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9625 nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE
, mode
) ||
9626 (params
->ht_enabled
&&
9627 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED
)) ||
9628 (params
->ht40_enabled
&&
9629 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED
)) ||
9630 (params
->vht_enabled
&&
9631 nla_put_flag(msg
, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED
)) ||
9632 nla_put_u16(msg
, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH
,
9633 params
->ch_width
) ||
9634 (params
->ch_list_len
&&
9635 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST
, params
->ch_list_len
,
9636 params
->ch_list
)) ||
9637 add_acs_freq_list(msg
, params
->freq_list
)) {
9641 nla_nest_end(msg
, data
);
9643 wpa_printf(MSG_DEBUG
,
9644 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
9645 params
->hw_mode
, params
->ht_enabled
, params
->ht40_enabled
,
9646 params
->vht_enabled
, params
->ch_width
, params
->ch_list_len
);
9648 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9650 wpa_printf(MSG_DEBUG
,
9651 "nl80211: Failed to invoke driver ACS function: %s",
9658 static int nl80211_set_band(void *priv
, enum set_band band
)
9660 struct i802_bss
*bss
= priv
;
9661 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9663 struct nlattr
*data
;
9665 enum qca_set_band qca_band
;
9667 if (!drv
->setband_vendor_cmd_avail
)
9671 case WPA_SETBAND_AUTO
:
9672 qca_band
= QCA_SETBAND_AUTO
;
9674 case WPA_SETBAND_5G
:
9675 qca_band
= QCA_SETBAND_5G
;
9677 case WPA_SETBAND_2G
:
9678 qca_band
= QCA_SETBAND_2G
;
9684 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9685 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9686 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9687 QCA_NL80211_VENDOR_SUBCMD_SETBAND
) ||
9688 !(data
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9689 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE
, qca_band
)) {
9693 nla_nest_end(msg
, data
);
9695 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9697 wpa_printf(MSG_DEBUG
,
9698 "nl80211: Driver setband function failed: %s",
9705 struct nl80211_pcl
{
9707 unsigned int *freq_list
;
9710 static int preferred_freq_info_handler(struct nl_msg
*msg
, void *arg
)
9712 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9713 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9714 struct nl80211_pcl
*param
= arg
;
9715 struct nlattr
*nl_vend
, *attr
;
9716 enum qca_iface_type iface_type
;
9717 struct nlattr
*tb_vendor
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
9718 unsigned int num
, max_num
;
9721 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9722 genlmsg_attrlen(gnlh
, 0), NULL
);
9724 nl_vend
= tb
[NL80211_ATTR_VENDOR_DATA
];
9728 nla_parse(tb_vendor
, QCA_WLAN_VENDOR_ATTR_MAX
,
9729 nla_data(nl_vend
), nla_len(nl_vend
), NULL
);
9732 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE
];
9734 wpa_printf(MSG_ERROR
, "nl80211: iface_type couldn't be found");
9739 iface_type
= (enum qca_iface_type
) nla_get_u32(attr
);
9740 wpa_printf(MSG_DEBUG
, "nl80211: Driver returned iface_type=%d",
9743 attr
= tb_vendor
[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST
];
9745 wpa_printf(MSG_ERROR
,
9746 "nl80211: preferred_freq_list couldn't be found");
9752 * param->num has the maximum number of entries for which there
9753 * is room in the freq_list provided by the caller.
9755 freqs
= nla_data(attr
);
9756 max_num
= nla_len(attr
) / sizeof(u32
);
9757 if (max_num
> param
->num
)
9758 max_num
= param
->num
;
9759 for (num
= 0; num
< max_num
; num
++)
9760 param
->freq_list
[num
] = freqs
[num
];
9767 static int nl80211_get_pref_freq_list(void *priv
,
9768 enum wpa_driver_if_type if_type
,
9770 unsigned int *freq_list
)
9772 struct i802_bss
*bss
= priv
;
9773 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9777 struct nlattr
*params
;
9778 struct nl80211_pcl param
;
9779 enum qca_iface_type iface_type
;
9781 if (!drv
->get_pref_freq_list
)
9785 case WPA_IF_STATION
:
9786 iface_type
= QCA_IFACE_TYPE_STA
;
9789 iface_type
= QCA_IFACE_TYPE_AP
;
9792 iface_type
= QCA_IFACE_TYPE_P2P_GO
;
9794 case WPA_IF_P2P_CLIENT
:
9795 iface_type
= QCA_IFACE_TYPE_P2P_CLIENT
;
9798 iface_type
= QCA_IFACE_TYPE_IBSS
;
9801 iface_type
= QCA_IFACE_TYPE_TDLS
;
9808 param
.freq_list
= freq_list
;
9810 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9811 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
) ||
9812 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9813 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9814 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST
) ||
9815 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9817 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE
,
9819 wpa_printf(MSG_ERROR
,
9820 "%s: err in adding vendor_cmd and vendor_data",
9825 nla_nest_end(msg
, params
);
9827 os_memset(freq_list
, 0, *num
* sizeof(freq_list
[0]));
9828 ret
= send_and_recv_msgs(drv
, msg
, preferred_freq_info_handler
, ¶m
);
9830 wpa_printf(MSG_ERROR
,
9831 "%s: err in send_and_recv_msgs", __func__
);
9837 for (i
= 0; i
< *num
; i
++) {
9838 wpa_printf(MSG_DEBUG
, "nl80211: preferred_channel_list[%d]=%d",
9846 static int nl80211_set_prob_oper_freq(void *priv
, unsigned int freq
)
9848 struct i802_bss
*bss
= priv
;
9849 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9852 struct nlattr
*params
;
9854 if (!drv
->set_prob_oper_freq
)
9857 wpa_printf(MSG_DEBUG
,
9858 "nl80211: Set P2P probable operating freq %u for ifindex %d",
9859 freq
, bss
->ifindex
);
9861 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9862 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9863 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9864 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL
) ||
9865 !(params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
)) ||
9867 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE
,
9868 QCA_IFACE_TYPE_P2P_CLIENT
) ||
9870 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ
,
9872 wpa_printf(MSG_ERROR
,
9873 "%s: err in adding vendor_cmd and vendor_data",
9878 nla_nest_end(msg
, params
);
9880 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9883 wpa_printf(MSG_ERROR
, "%s: err in send_and_recv_msgs",
9892 static int nl80211_p2p_lo_start(void *priv
, unsigned int freq
,
9893 unsigned int period
, unsigned int interval
,
9894 unsigned int count
, const u8
*device_types
,
9895 size_t dev_types_len
,
9896 const u8
*ies
, size_t ies_len
)
9898 struct i802_bss
*bss
= priv
;
9899 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9901 struct nlattr
*container
;
9904 wpa_printf(MSG_DEBUG
,
9905 "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u",
9906 freq
, period
, interval
, count
);
9908 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD
))
9911 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9912 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9913 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9914 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START
))
9917 container
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
9921 if (nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL
,
9923 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD
,
9925 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL
,
9927 nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT
,
9929 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES
,
9930 dev_types_len
, device_types
) ||
9931 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE
,
9935 nla_nest_end(msg
, container
);
9936 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9939 wpa_printf(MSG_DEBUG
,
9940 "nl80211: Failed to send P2P Listen offload vendor command");
9952 static int nl80211_p2p_lo_stop(void *priv
)
9954 struct i802_bss
*bss
= priv
;
9955 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9958 wpa_printf(MSG_DEBUG
, "nl80211: Stop P2P Listen offload");
9960 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD
))
9963 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9964 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9965 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9966 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP
)) {
9971 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9975 static int nl80211_set_tdls_mode(void *priv
, int tdls_external_control
)
9977 struct i802_bss
*bss
= priv
;
9978 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9980 struct nlattr
*params
;
9984 wpa_printf(MSG_DEBUG
,
9985 "nl80211: Set TDKS mode: tdls_external_control=%d",
9986 tdls_external_control
);
9988 if (tdls_external_control
== 1)
9989 tdls_mode
= QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT
|
9990 QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL
;
9992 tdls_mode
= QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT
;
9994 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
9995 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
9996 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
9997 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS
))
10000 params
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
10004 if (nla_put_u32(msg
, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE
,
10008 nla_nest_end(msg
, params
);
10010 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10013 wpa_printf(MSG_ERROR
,
10014 "nl80211: Set TDLS mode failed: ret=%d (%s)",
10015 ret
, strerror(-ret
));
10027 static enum mbo_transition_reject_reason
10028 nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status
)
10031 case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED
:
10032 return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS
;
10033 case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED
:
10034 return MBO_TRANSITION_REJECT_REASON_DELAY
;
10035 case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY
:
10036 return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY
;
10037 case QCA_STATUS_REJECT_LOW_RSSI
:
10038 return MBO_TRANSITION_REJECT_REASON_RSSI
;
10039 case QCA_STATUS_REJECT_HIGH_INTERFERENCE
:
10040 return MBO_TRANSITION_REJECT_REASON_INTERFERENCE
;
10041 case QCA_STATUS_REJECT_UNKNOWN
:
10043 return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED
;
10048 static void nl80211_parse_btm_candidate_info(struct candidate_list
*candidate
,
10049 struct nlattr
*tb
[], int num
)
10051 enum qca_wlan_btm_candidate_status status
;
10054 os_memcpy(candidate
->bssid
,
10055 nla_data(tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID
]),
10058 status
= nla_get_u32(
10059 tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS
]);
10060 candidate
->is_accept
= status
== QCA_STATUS_ACCEPT
;
10061 candidate
->reject_reason
= nl80211_mbo_reject_reason_mapping(status
);
10063 if (candidate
->is_accept
)
10064 os_snprintf(buf
, sizeof(buf
), "Accepted");
10066 os_snprintf(buf
, sizeof(buf
),
10067 "Rejected, Reject_reason: %d",
10068 candidate
->reject_reason
);
10069 wpa_printf(MSG_DEBUG
, "nl80211: BSSID[%d]: " MACSTR
" %s",
10070 num
, MAC2STR(candidate
->bssid
), buf
);
10075 nl80211_get_bss_transition_status_handler(struct nl_msg
*msg
, void *arg
)
10077 struct wpa_bss_candidate_info
*info
= arg
;
10078 struct candidate_list
*candidate
= info
->candidates
;
10079 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
10080 struct nlattr
*tb_vendor
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
10081 struct nlattr
*tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX
+ 1];
10082 static struct nla_policy policy
[
10083 QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX
+ 1] = {
10084 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID
] = {
10087 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS
] = {
10091 struct nlattr
*attr
;
10093 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
10096 num
= info
->num
; /* number of candidates sent to driver */
10098 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
10099 genlmsg_attrlen(gnlh
, 0), NULL
);
10101 if (!tb_msg
[NL80211_ATTR_VENDOR_DATA
] ||
10102 nla_parse_nested(tb_vendor
, QCA_WLAN_VENDOR_ATTR_MAX
,
10103 tb_msg
[NL80211_ATTR_VENDOR_DATA
], NULL
) ||
10104 !tb_vendor
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO
])
10107 wpa_printf(MSG_DEBUG
,
10108 "nl80211: WNM Candidate list received from driver");
10109 nla_for_each_nested(attr
,
10110 tb_vendor
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO
],
10112 if (info
->num
>= num
||
10114 tb
, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX
,
10116 !tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID
] ||
10117 !tb
[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS
])
10120 nl80211_parse_btm_candidate_info(candidate
, tb
, info
->num
);
10130 static struct wpa_bss_candidate_info
*
10131 nl80211_get_bss_transition_status(void *priv
, struct wpa_bss_trans_info
*params
)
10133 struct i802_bss
*bss
= priv
;
10134 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10135 struct nl_msg
*msg
;
10136 struct nlattr
*attr
, *attr1
, *attr2
;
10137 struct wpa_bss_candidate_info
*info
;
10142 if (!drv
->fetch_bss_trans_status
)
10145 info
= os_zalloc(sizeof(*info
));
10148 /* Allocate memory for number of candidates sent to driver */
10149 info
->candidates
= os_calloc(params
->n_candidates
,
10150 sizeof(*info
->candidates
));
10151 if (!info
->candidates
) {
10156 /* Copy the number of candidates being sent to driver. This is used in
10157 * nl80211_get_bss_transition_status_handler() to limit the number of
10158 * candidates that can be populated in info->candidates and will be
10159 * later overwritten with the actual number of candidates received from
10162 info
->num
= params
->n_candidates
;
10164 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10165 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10166 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10167 QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS
))
10170 attr
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
10174 if (nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON
,
10175 params
->mbo_transition_reason
))
10178 attr1
= nla_nest_start(msg
, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO
);
10182 wpa_printf(MSG_DEBUG
,
10183 "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d",
10184 params
->mbo_transition_reason
, params
->n_candidates
);
10185 pos
= params
->bssid
;
10186 for (i
= 0; i
< params
->n_candidates
; i
++) {
10187 wpa_printf(MSG_DEBUG
, "nl80211: BSSID[%d]: " MACSTR
, i
,
10189 attr2
= nla_nest_start(msg
, i
);
10191 nla_put(msg
, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID
,
10195 nla_nest_end(msg
, attr2
);
10198 nla_nest_end(msg
, attr1
);
10199 nla_nest_end(msg
, attr
);
10201 ret
= send_and_recv_msgs(drv
, msg
,
10202 nl80211_get_bss_transition_status_handler
,
10206 wpa_printf(MSG_ERROR
,
10207 "nl80211: WNM Get BSS transition status failed: ret=%d (%s)",
10208 ret
, strerror(-ret
));
10215 os_free(info
->candidates
);
10222 * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow
10223 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
10224 * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore
10225 * Returns: 0 on success, -1 on failure
10227 static int nl80211_ignore_assoc_disallow(void *priv
, int ignore_disallow
)
10229 struct i802_bss
*bss
= priv
;
10230 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10231 struct nl_msg
*msg
;
10232 struct nlattr
*attr
;
10235 if (!drv
->set_wifi_conf_vendor_cmd_avail
)
10238 if (!(msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_VENDOR
)) ||
10239 nla_put_u32(msg
, NL80211_ATTR_VENDOR_ID
, OUI_QCA
) ||
10240 nla_put_u32(msg
, NL80211_ATTR_VENDOR_SUBCMD
,
10241 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION
))
10244 attr
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
10248 wpa_printf(MSG_DEBUG
, "nl80211: Set ignore_assoc_disallow %d",
10250 if (nla_put_u8(msg
, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED
,
10254 nla_nest_end(msg
, attr
);
10256 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10259 wpa_printf(MSG_ERROR
,
10260 "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)",
10261 ret
, strerror(-ret
));
10270 #endif /* CONFIG_MBO */
10272 #endif /* CONFIG_DRIVER_NL80211_QCA */
10275 static int nl80211_write_to_file(const char *name
, unsigned int val
)
10280 fd
= open(name
, O_RDWR
);
10282 wpa_printf(MSG_ERROR
, "nl80211: Failed to open %s: %s",
10283 name
, strerror(errno
));
10287 len
= os_snprintf(tmp
, sizeof(tmp
), "%u\n", val
);
10288 len
= write(fd
, tmp
, len
);
10290 wpa_printf(MSG_ERROR
, "nl80211: Failed to write to %s: %s",
10291 name
, strerror(errno
));
10298 static int nl80211_configure_data_frame_filters(void *priv
, u32 filter_flags
)
10300 struct i802_bss
*bss
= priv
;
10304 wpa_printf(MSG_DEBUG
, "nl80211: Data frame filter flags=0x%x",
10307 /* Configure filtering of unicast frame encrypted using GTK */
10308 ret
= os_snprintf(path
, sizeof(path
),
10309 "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast",
10311 if (os_snprintf_error(sizeof(path
), ret
))
10314 ret
= nl80211_write_to_file(path
,
10316 WPA_DATA_FRAME_FILTER_FLAG_GTK
));
10318 wpa_printf(MSG_ERROR
,
10319 "nl80211: Failed to set IPv4 unicast in multicast filter");
10323 os_snprintf(path
, sizeof(path
),
10324 "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast",
10326 ret
= nl80211_write_to_file(path
,
10328 WPA_DATA_FRAME_FILTER_FLAG_GTK
));
10331 wpa_printf(MSG_ERROR
,
10332 "nl80211: Failed to set IPv6 unicast in multicast filter");
10336 /* Configure filtering of unicast frame encrypted using GTK */
10337 os_snprintf(path
, sizeof(path
),
10338 "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp",
10340 ret
= nl80211_write_to_file(path
,
10342 WPA_DATA_FRAME_FILTER_FLAG_ARP
));
10344 wpa_printf(MSG_ERROR
,
10345 "nl80211: Failed set gratuitous ARP filter");
10349 /* Configure filtering of IPv6 NA frames */
10350 os_snprintf(path
, sizeof(path
),
10351 "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na",
10353 ret
= nl80211_write_to_file(path
,
10355 WPA_DATA_FRAME_FILTER_FLAG_NA
));
10357 wpa_printf(MSG_ERROR
,
10358 "nl80211: Failed to set unsolicited NA filter");
10366 static int nl80211_get_ext_capab(void *priv
, enum wpa_driver_if_type type
,
10367 const u8
**ext_capa
, const u8
**ext_capa_mask
,
10368 unsigned int *ext_capa_len
)
10370 struct i802_bss
*bss
= priv
;
10371 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10372 enum nl80211_iftype nlmode
;
10375 if (!ext_capa
|| !ext_capa_mask
|| !ext_capa_len
)
10378 nlmode
= wpa_driver_nl80211_if_type(type
);
10380 /* By default, use the per-radio values */
10381 *ext_capa
= drv
->extended_capa
;
10382 *ext_capa_mask
= drv
->extended_capa_mask
;
10383 *ext_capa_len
= drv
->extended_capa_len
;
10385 /* Replace the default value if a per-interface type value exists */
10386 for (i
= 0; i
< drv
->num_iface_ext_capa
; i
++) {
10387 if (nlmode
== drv
->iface_ext_capa
[i
].iftype
) {
10388 *ext_capa
= drv
->iface_ext_capa
[i
].ext_capa
;
10389 *ext_capa_mask
= drv
->iface_ext_capa
[i
].ext_capa_mask
;
10390 *ext_capa_len
= drv
->iface_ext_capa
[i
].ext_capa_len
;
10399 static int nl80211_update_connection_params(
10400 void *priv
, struct wpa_driver_associate_params
*params
,
10401 enum wpa_drv_update_connect_params_mask mask
)
10403 struct i802_bss
*bss
= priv
;
10404 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10405 struct nl_msg
*msg
;
10407 enum nl80211_auth_type type
;
10409 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS
);
10413 wpa_printf(MSG_DEBUG
, "nl80211: Update connection params (ifindex=%d)",
10416 if ((mask
& WPA_DRV_UPDATE_ASSOC_IES
) && params
->wpa_ie
) {
10417 if (nla_put(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
10420 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
,
10421 params
->wpa_ie_len
);
10424 if (mask
& WPA_DRV_UPDATE_AUTH_TYPE
) {
10425 type
= get_nl_auth_type(params
->auth_alg
);
10426 if (type
== NL80211_AUTHTYPE_MAX
||
10427 nla_put_u32(msg
, NL80211_ATTR_AUTH_TYPE
, type
))
10429 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
10432 if ((mask
& WPA_DRV_UPDATE_FILS_ERP_INFO
) &&
10433 nl80211_put_fils_connect_params(drv
, params
, msg
))
10436 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10439 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
10440 "nl80211: Update connect params command failed: ret=%d (%s)",
10441 ret
, strerror(-ret
));
10449 static int nl80211_send_external_auth_status(void *priv
,
10450 struct external_auth
*params
)
10452 struct i802_bss
*bss
= priv
;
10453 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10454 struct nl_msg
*msg
= NULL
;
10457 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
10458 "nl80211: External auth status: %u", params
->status
);
10460 msg
= nl80211_drv_msg(drv
, 0, NL80211_CMD_EXTERNAL_AUTH
);
10462 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, params
->status
) ||
10463 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
10465 nla_put(msg
, NL80211_ATTR_BSSID
, ETH_ALEN
, params
->bssid
))
10467 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10470 wpa_printf(MSG_DEBUG
,
10471 "nl80211: External Auth status update failed: ret=%d (%s)",
10472 ret
, strerror(-ret
));
10481 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
10483 .desc
= "Linux nl80211/cfg80211",
10484 .get_bssid
= wpa_driver_nl80211_get_bssid
,
10485 .get_ssid
= wpa_driver_nl80211_get_ssid
,
10486 .set_key
= driver_nl80211_set_key
,
10487 .scan2
= driver_nl80211_scan2
,
10488 .sched_scan
= wpa_driver_nl80211_sched_scan
,
10489 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
10490 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
10491 .abort_scan
= wpa_driver_nl80211_abort_scan
,
10492 .deauthenticate
= driver_nl80211_deauthenticate
,
10493 .authenticate
= driver_nl80211_authenticate
,
10494 .associate
= wpa_driver_nl80211_associate
,
10495 .global_init
= nl80211_global_init
,
10496 .global_deinit
= nl80211_global_deinit
,
10497 .init2
= wpa_driver_nl80211_init
,
10498 .deinit
= driver_nl80211_deinit
,
10499 .get_capa
= wpa_driver_nl80211_get_capa
,
10500 .set_operstate
= wpa_driver_nl80211_set_operstate
,
10501 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
10502 .set_country
= wpa_driver_nl80211_set_country
,
10503 .get_country
= wpa_driver_nl80211_get_country
,
10504 .set_ap
= wpa_driver_nl80211_set_ap
,
10505 .set_acl
= wpa_driver_nl80211_set_acl
,
10506 .if_add
= wpa_driver_nl80211_if_add
,
10507 .if_remove
= driver_nl80211_if_remove
,
10508 .send_mlme
= driver_nl80211_send_mlme
,
10509 .get_hw_feature_data
= nl80211_get_hw_feature_data
,
10510 .sta_add
= wpa_driver_nl80211_sta_add
,
10511 .sta_remove
= driver_nl80211_sta_remove
,
10512 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
10513 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
10514 .hapd_init
= i802_init
,
10515 .hapd_deinit
= i802_deinit
,
10516 .set_wds_sta
= i802_set_wds_sta
,
10517 .get_seqnum
= i802_get_seqnum
,
10518 .flush
= i802_flush
,
10519 .get_inact_sec
= i802_get_inact_sec
,
10520 .sta_clear_stats
= i802_sta_clear_stats
,
10521 .set_rts
= i802_set_rts
,
10522 .set_frag
= i802_set_frag
,
10523 .set_tx_queue_params
= i802_set_tx_queue_params
,
10524 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
10525 .sta_deauth
= i802_sta_deauth
,
10526 .sta_disassoc
= i802_sta_disassoc
,
10527 .read_sta_data
= driver_nl80211_read_sta_data
,
10528 .set_freq
= i802_set_freq
,
10529 .send_action
= driver_nl80211_send_action
,
10530 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
10531 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
10532 .cancel_remain_on_channel
=
10533 wpa_driver_nl80211_cancel_remain_on_channel
,
10534 .probe_req_report
= driver_nl80211_probe_req_report
,
10535 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
10536 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
10537 .resume
= wpa_driver_nl80211_resume
,
10538 .signal_monitor
= nl80211_signal_monitor
,
10539 .signal_poll
= nl80211_signal_poll
,
10540 .send_frame
= nl80211_send_frame
,
10541 .set_param
= nl80211_set_param
,
10542 .get_radio_name
= nl80211_get_radio_name
,
10543 .add_pmkid
= nl80211_add_pmkid
,
10544 .remove_pmkid
= nl80211_remove_pmkid
,
10545 .flush_pmkid
= nl80211_flush_pmkid
,
10546 .set_rekey_info
= nl80211_set_rekey_info
,
10547 .poll_client
= nl80211_poll_client
,
10548 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
10549 .start_dfs_cac
= nl80211_start_radar_detection
,
10550 .stop_ap
= wpa_driver_nl80211_stop_ap
,
10552 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
10553 .tdls_oper
= nl80211_tdls_oper
,
10554 .tdls_enable_channel_switch
= nl80211_tdls_enable_channel_switch
,
10555 .tdls_disable_channel_switch
= nl80211_tdls_disable_channel_switch
,
10556 #endif /* CONFIG_TDLS */
10557 .update_ft_ies
= wpa_driver_nl80211_update_ft_ies
,
10558 .get_mac_addr
= wpa_driver_nl80211_get_macaddr
,
10559 .get_survey
= wpa_driver_nl80211_get_survey
,
10560 .status
= wpa_driver_nl80211_status
,
10561 .switch_channel
= nl80211_switch_channel
,
10563 .set_noa
= wpa_driver_set_p2p_noa
,
10564 .get_noa
= wpa_driver_get_p2p_noa
,
10565 .set_ap_wps_ie
= wpa_driver_set_ap_wps_p2p_ie
,
10566 #endif /* ANDROID_P2P */
10568 #ifndef ANDROID_LIB_STUB
10569 .driver_cmd
= wpa_driver_nl80211_driver_cmd
,
10570 #endif /* !ANDROID_LIB_STUB */
10571 #endif /* ANDROID */
10572 .vendor_cmd
= nl80211_vendor_cmd
,
10573 .set_qos_map
= nl80211_set_qos_map
,
10574 .set_wowlan
= nl80211_set_wowlan
,
10575 .set_mac_addr
= nl80211_set_mac_addr
,
10577 .init_mesh
= wpa_driver_nl80211_init_mesh
,
10578 .join_mesh
= wpa_driver_nl80211_join_mesh
,
10579 .leave_mesh
= wpa_driver_nl80211_leave_mesh
,
10580 #endif /* CONFIG_MESH */
10581 .br_add_ip_neigh
= wpa_driver_br_add_ip_neigh
,
10582 .br_delete_ip_neigh
= wpa_driver_br_delete_ip_neigh
,
10583 .br_port_set_attr
= wpa_driver_br_port_set_attr
,
10584 .br_set_net_param
= wpa_driver_br_set_net_param
,
10585 .add_tx_ts
= nl80211_add_ts
,
10586 .del_tx_ts
= nl80211_del_ts
,
10587 .get_ifindex
= nl80211_get_ifindex
,
10588 #ifdef CONFIG_DRIVER_NL80211_QCA
10589 .roaming
= nl80211_roaming
,
10590 .disable_fils
= nl80211_disable_fils
,
10591 .do_acs
= wpa_driver_do_acs
,
10592 .set_band
= nl80211_set_band
,
10593 .get_pref_freq_list
= nl80211_get_pref_freq_list
,
10594 .set_prob_oper_freq
= nl80211_set_prob_oper_freq
,
10595 .p2p_lo_start
= nl80211_p2p_lo_start
,
10596 .p2p_lo_stop
= nl80211_p2p_lo_stop
,
10597 .set_default_scan_ies
= nl80211_set_default_scan_ies
,
10598 .set_tdls_mode
= nl80211_set_tdls_mode
,
10600 .get_bss_transition_status
= nl80211_get_bss_transition_status
,
10601 .ignore_assoc_disallow
= nl80211_ignore_assoc_disallow
,
10602 #endif /* CONFIG_MBO */
10603 .set_bssid_blacklist
= nl80211_set_bssid_blacklist
,
10604 #endif /* CONFIG_DRIVER_NL80211_QCA */
10605 .configure_data_frame_filters
= nl80211_configure_data_frame_filters
,
10606 .get_ext_capab
= nl80211_get_ext_capab
,
10607 .update_connect_params
= nl80211_update_connection_params
,
10608 .send_external_auth_status
= nl80211_send_external_auth_status
,